/* ==========================================================================
   Calchuay V2 — ดีไซน์ร่วมทุกหน้า
   2 ธีม สลับด้วย <html data-theme="neon|lucky"> — ทุกสีอ่านจากตัวแปรด้านล่าง
   ห้ามใส่สีตายตัวใน view ให้เพิ่มตัวแปรที่นี่แทน ทั้งสองธีมจะได้ไปด้วยกันเสมอ
   ========================================================================== */

:root,
[data-theme="neon"] {
    --bg: #070B1A;
    --surface: #111733;
    --surface-2: rgba(255, 255, 255, 0.05);
    --border: rgba(255, 255, 255, 0.08);
    --text: #EEF1FF;
    --muted: #9AA3C7;
    --accent: #8B5CF6;
    --accent-2: #22D3EE;
    --accent-soft: rgba(139, 92, 246, 0.18);
    --accent-border: rgba(139, 92, 246, 0.45);
    --accent-text: #C4B5FD;
    --on-accent: #FFFFFF;
    --highlight: #67E8F9;
    --link: #22D3EE;

    --glow-1: #8B5CF6;
    --glow-2: #22D3EE;
    --glow-1-opacity: 0.32;
    --glow-2-opacity: 0.16;

    --hero-bg: linear-gradient(160deg, #1E1B4B 0%, #111733 62%);
    --hero-border: rgba(139, 92, 246, 0.35);
    --hero-text: #EEF1FF;
    --hero-muted: #C4B5FD;
    --hero-chip: rgba(255, 255, 255, 0.06);
    --hero-highlight: #67E8F9;
    --hero-pill-bg: rgba(34, 211, 238, 0.12);
    --hero-pill-text: #67E8F9;

    --bar: linear-gradient(90deg, #8B5CF6, #22D3EE);
    --bar-track: rgba(255, 255, 255, 0.08);

    --nav-bg: rgba(17, 23, 51, 0.88);
    --nav-border: rgba(255, 255, 255, 0.1);
    --nav-text: #9AA3C7;
    --nav-active: #C4B5FD;
    --fab-bg: linear-gradient(135deg, #8B5CF6, #22D3EE);
    --fab-text: #070B1A;
    --fab-ring: #070B1A;
    --fab-shadow: 0 0 28px rgba(139, 92, 246, 0.75);

    --sidebar-bg: rgba(11, 16, 40, 0.7);
    --sidebar-text: #9AA3C7;
    --sidebar-active-bg: rgba(139, 92, 246, 0.18);
    --sidebar-active-border: rgba(139, 92, 246, 0.45);
    --sidebar-active-text: #EEF1FF;

    --logo-bg: linear-gradient(135deg, #8B5CF6, #22D3EE);
    --logo-text: #070B1A;
    --logo-radius: 14px;

    --shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
    --shadow-sm: 0 8px 24px rgba(0, 0, 0, 0.35);
    --scrim: rgba(3, 5, 14, 0.7);
    color-scheme: dark;
}

[data-theme="lucky"] {
    --bg: #FAF6F3;
    --surface: #FFFFFF;
    --surface-2: #FFF1F2;
    --border: #F1E4DC;
    --text: #1C1917;
    --muted: #57534E;
    --accent: #9F1239;
    --accent-2: #F59E0B;
    --accent-soft: #FFE4E6;
    --accent-border: #FDA4AF;
    --accent-text: #9F1239;
    --on-accent: #FDE68A;
    --highlight: #B45309;
    --link: #9F1239;

    --glow-1: #FBBF24;
    --glow-2: #E11D48;
    --glow-1-opacity: 0.26;
    --glow-2-opacity: 0.10;

    --hero-bg: radial-gradient(circle at 85% 0%, #BE123C 0%, #881337 55%, #4C0519 100%);
    --hero-border: transparent;
    --hero-text: #FFFFFF;
    --hero-muted: #FECDD3;
    --hero-chip: rgba(0, 0, 0, 0.22);
    --hero-highlight: #FDE68A;
    --hero-pill-bg: rgba(251, 191, 36, 0.2);
    --hero-pill-text: #FDE68A;

    --bar: linear-gradient(90deg, #E11D48, #F59E0B);
    --bar-track: #FFE4E6;

    --nav-bg: #4C0519;
    --nav-border: transparent;
    --nav-text: #FECDD3;
    --nav-active: #FBBF24;
    --fab-bg: radial-gradient(circle at 35% 30%, #FFFBEB, #FCD34D 45%, #D97706);
    --fab-text: #7F1D1D;
    --fab-ring: #FAF6F3;
    --fab-shadow: 0 6px 16px rgba(0, 0, 0, 0.3);

    --sidebar-bg: radial-gradient(circle at 50% 0%, #9F1239 0%, #4C0519 70%);
    --sidebar-text: #FECDD3;
    --sidebar-active-bg: #FBBF24;
    --sidebar-active-border: #FBBF24;
    --sidebar-active-text: #7F1D1D;

    --logo-bg: radial-gradient(circle at 35% 30%, #FDE68A, #F59E0B 60%, #B45309);
    --logo-text: #7F1D1D;
    --logo-radius: 50%;

    --shadow: 0 20px 44px rgba(76, 5, 25, 0.22);
    --shadow-sm: 0 6px 18px rgba(76, 5, 25, 0.10);
    --scrim: rgba(28, 25, 23, 0.55);
    color-scheme: light;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

/* ให้ attribute hidden ชนะ display ของคลาสเสมอ (เช่น .form-block ที่เป็น flex) */
[hidden] { display: none !important; }

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font-family: 'IBM Plex Sans Thai', system-ui, sans-serif;
    font-size: 15px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
    transition: background-color 0.3s ease, color 0.3s ease;
}

a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, .font-display {
    font-family: 'Kanit', 'IBM Plex Sans Thai', sans-serif;
    font-weight: 600;
    line-height: 1.25;
    margin: 0;
}

button { font: inherit; color: inherit; cursor: pointer; }

.icon { width: 22px; height: 22px; flex-shrink: 0; }
.icon-sm { width: 18px; height: 18px; }

:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; }

.visually-hidden {
    position: absolute !important;
    width: 1px; height: 1px;
    overflow: hidden; clip: rect(0 0 0 0);
    white-space: nowrap;
}

/* ---------- Shell ---------- */
.app-shell {
    position: relative;
    display: flex;
    min-height: 100vh;
    overflow-x: clip;
}

.bg-glow {
    position: absolute;
    border-radius: 50%;
    pointer-events: none;
    filter: blur(100px);
    z-index: 0;
}
.bg-glow.g1 { top: -140px; right: -100px; width: 380px; height: 380px; background: var(--glow-1); opacity: var(--glow-1-opacity); }
.bg-glow.g2 { top: 520px; left: -160px; width: 340px; height: 340px; background: var(--glow-2); opacity: var(--glow-2-opacity); }

.main {
    position: relative;
    z-index: 1;
    flex: 1;
    min-width: 0;
    width: 100%;
    max-width: 1240px;
    margin: 0 auto;
    padding: calc(16px + env(safe-area-inset-top)) 16px calc(96px + env(safe-area-inset-bottom));
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* ---------- Sidebar (คอม) ---------- */
.sidebar {
    display: none;
    position: relative;
    z-index: 2;
    flex-direction: column;
    gap: 28px;
    width: 250px;
    flex-shrink: 0;
    padding: 28px 18px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border);
    overflow: hidden;
}
[data-theme="lucky"] .sidebar { border-right: none; }
[data-theme="lucky"] .sidebar::before,
[data-theme="lucky"] .hero::before {
    content: "";
    position: absolute;
    inset: 0;
    background-image: radial-gradient(rgba(251, 191, 36, 0.16) 1.5px, transparent 1.5px);
    background-size: 22px 22px;
    pointer-events: none;
}
.sidebar > * { position: relative; }

.sidebar-brand { display: flex; align-items: center; gap: 12px; padding: 0 8px; }
.sidebar-brand span { font-family: 'Kanit', sans-serif; font-weight: 600; font-size: 20px; color: var(--sidebar-active-text); }
[data-theme="lucky"] .sidebar-brand span { color: #FFFFFF; }

.sidebar-nav { display: flex; flex-direction: column; gap: 6px; }
.sidebar-link {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 46px;
    padding: 0 14px;
    border-radius: 14px;
    border: 1px solid transparent;
    color: var(--sidebar-text);
    font-size: 15px;
    transition: background-color 0.2s, color 0.2s;
}
.sidebar-link:hover { text-decoration: none; background: var(--surface-2); color: var(--sidebar-active-text); }
[data-theme="lucky"] .sidebar-link:hover { background: rgba(0, 0, 0, 0.18); color: #FFFFFF; }
.sidebar-link.active {
    background: var(--sidebar-active-bg);
    border-color: var(--sidebar-active-border);
    color: var(--sidebar-active-text);
    font-weight: 600;
}
.sidebar-foot { margin-top: auto; font-size: 12px; color: var(--sidebar-text); opacity: 0.8; padding: 0 8px; }

/* ---------- Topbar ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.topbar-brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.topbar-title { display: flex; flex-direction: column; min-width: 0; }
.topbar-title .name { font-family: 'Kanit', sans-serif; font-weight: 600; font-size: 20px; line-height: 1.2; }
.topbar-title .sub { font-size: 13px; color: var(--muted); }
.topbar-page { display: none; }
.topbar-actions { display: flex; gap: 8px; }

.logo {
    width: 44px;
    height: 44px;
    border-radius: var(--logo-radius);
    background: var(--logo-bg);
    color: var(--logo-text);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Kanit', sans-serif;
    font-weight: 700;
    font-size: 22px;
    flex-shrink: 0;
    box-shadow: 0 0 24px color-mix(in srgb, var(--accent) 50%, transparent);
}

.icon-btn {
    width: 44px;
    height: 44px;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s ease, background-color 0.2s;
}
[data-theme="lucky"] .icon-btn { background: var(--surface); }
.icon-btn:hover { text-decoration: none; }
.icon-btn:active { transform: scale(0.94); }
.icon-btn.theme-toggle { color: var(--accent-text); border-color: var(--accent-border); background: var(--accent-soft); }

/* ไอคอนปุ่มสลับธีม: Neon แสดงพระจันทร์, มงคลแสดงพระอาทิตย์ */
.theme-toggle .when-lucky { display: none; }
[data-theme="lucky"] .theme-toggle .when-neon { display: none; }
[data-theme="lucky"] .theme-toggle .when-lucky { display: block; }

/* ---------- Bottom nav (มือถือ) ---------- */
/* ติดขอบล่างเต็มความกว้าง (ไม่ลอย) — เว้นที่ให้แถบ home ของ iPhone ด้วย safe-area */
.bottom-nav {
    position: fixed;
    z-index: 50;
    left: 0;
    right: 0;
    bottom: 0;
    height: calc(64px + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--nav-bg);
    border-top: 1px solid var(--nav-border);
    -webkit-backdrop-filter: blur(16px);
    backdrop-filter: blur(16px);
    box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.25);
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    align-items: center;
}
.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    min-height: 56px;
    color: var(--nav-text);
    font-size: 11px;
}
.nav-item:hover { text-decoration: none; }
.nav-item.active { color: var(--nav-active); font-weight: 600; }
.nav-fab {
    justify-self: center;
    width: 62px;
    height: 62px;
    margin-top: -34px;
    border-radius: 20px;
    background: var(--fab-bg);
    color: var(--fab-text);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--fab-shadow);
    transition: transform 0.15s ease;
}
[data-theme="lucky"] .nav-fab { border-radius: 50%; border: 4px solid var(--fab-ring); }
.nav-fab:active { transform: scale(0.92); }
.nav-fab.active { outline: 3px solid var(--nav-active); outline-offset: 3px; }

/* มือถือ: การ์ดปุ่มวิเคราะห์ตัดไอคอน/หัวข้อออก ให้ปุ่มขึ้นมาใกล้ตัวเลือกมากที่สุด */
@media (max-width: 1023px) {
    .run-card .cta-icon, .run-card h2 { display: none; }
    /* ปุ่ม "วิเคราะห์เลย" ลอยติดเหนือเมนูล่างเสมอ ไม่ต้องเลื่อนหา */
    .run-card .js-run {
        position: fixed;
        z-index: 45;
        left: 16px;
        right: 16px;
        bottom: calc(64px + env(safe-area-inset-bottom) + 10px);
        width: auto;
        min-height: 56px;
        margin: 0 !important;
        box-shadow: var(--fab-shadow), 0 8px 24px rgba(0, 0, 0, 0.35);
    }
    .run-card { margin-bottom: 72px; } /* เว้นที่ให้ปุ่มลอย เนื้อหาท้ายหน้าจะไม่โดนบัง */
}
.nav-fab .icon { width: 28px; height: 28px; }

/* ---------- Segmented (เลือกประเภทหวย) ---------- */
.segmented {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
    padding: 6px;
    border-radius: 18px;
    background: var(--surface-2);
    border: 1px solid var(--border);
}
[data-theme="lucky"] .segmented { background: var(--surface); }
.segmented a {
    min-height: 44px;
    border-radius: 13px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Kanit', sans-serif;
    font-size: 16px;
    font-weight: 500;
    color: var(--muted);
    transition: background-color 0.2s, color 0.2s;
}
.segmented a:hover { text-decoration: none; color: var(--text); }
.segmented a.active {
    background: var(--accent);
    color: var(--on-accent);
    box-shadow: 0 6px 20px color-mix(in srgb, var(--accent) 45%, transparent);
}

/* ---------- Cards ---------- */
.grid-2 {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr));
    gap: 20px;
}
.card {
    position: relative;
    border-radius: 24px;
    padding: 20px;
    background: var(--surface);
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 14px;
}
[data-theme="lucky"] .card { box-shadow: var(--shadow-sm); }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.card-head h2 { font-size: 20px; }
.card-head a { font-size: 14px; font-weight: 500; white-space: nowrap; }
.card-note { font-size: 13px; color: var(--muted); margin: 0; }

/* ---------- Hero (ผลรางวัลล่าสุด) ---------- */
.hero {
    position: relative;
    overflow: hidden;
    border-radius: 28px;
    padding: 22px;
    background: var(--hero-bg);
    border: 1px solid var(--hero-border);
    color: var(--hero-text);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    gap: 18px;
}
.hero > * { position: relative; }
.hero-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.hero-label { font-size: 14px; font-weight: 500; color: var(--hero-muted); }
.pill {
    font-size: 12px;
    padding: 4px 12px;
    border-radius: 999px;
    background: var(--hero-pill-bg);
    color: var(--hero-pill-text);
    white-space: nowrap;
}
.hero-sub { display: grid; grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); gap: 10px; }
.hero-chip { padding: 12px 14px; border-radius: 16px; background: var(--hero-chip); text-align: center; }
.hero-chip .k { font-size: 12px; color: var(--hero-muted); }
.hero-chip .v { font-family: 'Kanit', sans-serif; font-size: 26px; font-weight: 600; line-height: 1.2; letter-spacing: 1px; }
.hero-chip .v.hl { color: var(--hero-highlight); }
.hero-foot {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding-top: 14px;
    border-top: 1px solid var(--border);
    font-size: 13px;
    color: var(--hero-muted);
}
[data-theme="lucky"] .hero-foot { border-top-color: rgba(251, 191, 36, 0.25); }

/* ตัวเลขผลรางวัล: Neon = กล่องเรืองแสง, มงคล = ลูกบอลทอง */
.digits { display: grid; grid-template-columns: repeat(var(--n, 4), minmax(0, 1fr)); gap: calc(40px / var(--n, 4)); }
.digit {
    aspect-ratio: 1 / 1.05;
    border-radius: 18px;
    background: #0B1028;
    border: 1px solid rgba(139, 92, 246, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Kanit', sans-serif;
    font-weight: 700;
    font-size: clamp(26px, calc(150px / var(--n, 4) + 8px), 64px);
    line-height: 1;
    min-width: 0;
    overflow: hidden;
    color: #FFFFFF;
    text-shadow: 0 0 18px rgba(139, 92, 246, 0.9);
    animation: digit-in 0.5s cubic-bezier(.2, .8, .2, 1.2) both;
}
.digit.alt { border-color: rgba(34, 211, 238, 0.6); text-shadow: 0 0 18px rgba(34, 211, 238, 0.9); }
[data-theme="lucky"] .digit {
    aspect-ratio: 1;
    border-radius: 50%;
    border: none;
    background: radial-gradient(circle at 35% 30%, #FFFBEB, #FCD34D 45%, #D97706);
    color: #7F1D1D;
    text-shadow: none;
    box-shadow: 0 8px 18px rgba(0, 0, 0, 0.4), inset 0 -4px 8px rgba(0, 0, 0, 0.15);
}
.digit:nth-child(2) { animation-delay: 0.06s; }
.digit:nth-child(3) { animation-delay: 0.12s; }
.digit:nth-child(4) { animation-delay: 0.18s; }
.digit:nth-child(5) { animation-delay: 0.24s; }
.digit:nth-child(6) { animation-delay: 0.30s; }
@keyframes digit-in {
    from { opacity: 0; transform: translateY(12px) scale(0.85); }
    to   { opacity: 1; transform: none; }
}

/* ---------- Bars (ความแม่นยำสูตร) ---------- */
.bar-list { display: flex; flex-direction: column; gap: 4px; margin: 0; padding: 0; list-style: none; }
.bar-row {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 8px 10px;
    margin: 0 -10px;
    width: calc(100% + 20px);
    border: none;
    border-radius: 12px;
    background: transparent;
    text-align: left;
}
.bar-row:hover { background: var(--surface-2); }
.bar-top { display: flex; justify-content: space-between; font-size: 14px; }
.bar-top .val { color: var(--highlight); font-weight: 600; }
.bar { height: 8px; border-radius: 99px; background: var(--bar-track); overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: inherit; background: var(--bar); transform-origin: left; animation: bar-in 0.8s ease both; }
@keyframes bar-in { from { transform: scaleX(0); } to { transform: scaleX(1); } }

/* ---------- Draw list (งวดก่อนหน้า) ---------- */
.draw-list { display: flex; flex-direction: column; gap: 8px; margin: 0; padding: 0; list-style: none; }
.draw-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 16px;
    border-radius: 16px;
    background: var(--surface-2);
}
[data-theme="lucky"] .draw-row { background: var(--bg); }
.draw-date { font-size: 14px; color: var(--muted); }
.draw-nums { display: flex; align-items: baseline; gap: 12px; }
.draw-main { font-family: 'Kanit', sans-serif; font-size: 22px; font-weight: 600; letter-spacing: 3px; }
[data-theme="lucky"] .draw-main { color: #881337; }
.draw-tag { font-size: 13px; color: var(--muted); white-space: nowrap; }
.draw-tag b { color: var(--highlight); font-weight: 600; }

/* ---------- CTA ---------- */
.cta {
    align-items: flex-start;
    justify-content: center;
}
.cta-icon {
    width: 56px;
    height: 56px;
    border-radius: 18px;
    background: var(--fab-bg);
    color: var(--fab-text);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--fab-shadow);
}
[data-theme="lucky"] .cta-icon { border-radius: 50%; }
.cta-icon .icon { width: 28px; height: 28px; }
.cta p { margin: 0; color: var(--muted); }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 48px;
    padding: 0 22px;
    border-radius: 14px;
    border: none;
    background: var(--accent);
    color: var(--on-accent);
    font-family: 'Kanit', sans-serif;
    font-size: 16px;
    font-weight: 500;
    box-shadow: 0 6px 20px color-mix(in srgb, var(--accent) 45%, transparent);
    transition: transform 0.15s ease;
}
.btn:hover { text-decoration: none; }
.btn:active { transform: scale(0.97); }

.stat-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.stat-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 999px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    font-size: 13px;
    color: var(--muted);
}
[data-theme="lucky"] .stat-chip { background: var(--surface); }
.stat-chip b { color: var(--text); font-weight: 600; }

.empty {
    padding: 20px;
    border-radius: 16px;
    border: 1px dashed var(--border);
    color: var(--muted);
    font-size: 14px;
    text-align: center;
}

/* ---------- Sheet / ป๊อปอัพกลาง ---------- */
/* มือถือ: แผ่นเลื่อนขึ้นจากล่าง — คอม: กล่องกลางจอ (ใช้ <dialog> ของเบราว์เซอร์) */
.sheet {
    padding: 0;
    border: none;
    background: transparent;
    color: var(--text);
    width: 100%;
    max-width: 100%;
    max-height: 100%;
    margin: auto 0 0;
}
.sheet::backdrop { background: var(--scrim); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }
.sheet-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-bottom: none;
    border-radius: 28px 28px 0 0;
    padding: 10px 20px calc(24px + env(safe-area-inset-bottom));
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: var(--shadow);
}
.sheet[open] .sheet-panel { animation: sheet-up 0.3s cubic-bezier(.2, .8, .2, 1); }
.sheet-handle { width: 44px; height: 5px; border-radius: 99px; background: var(--border); margin: 0 auto 12px; }
[data-theme="lucky"] .sheet-handle { background: #E7D5CB; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.sheet-head h2 { font-size: 20px; }
@keyframes sheet-up { from { transform: translateY(100%); } to { transform: none; } }
@keyframes sheet-pop { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: none; } }

.kv { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.kv > div { padding: 14px; border-radius: 16px; background: var(--surface-2); }
[data-theme="lucky"] .kv > div { background: var(--bg); }
.kv .k { font-size: 13px; color: var(--muted); }
.kv .v { font-family: 'Kanit', sans-serif; font-size: 26px; font-weight: 600; }

/* ---------- Desktop ---------- */
@media (min-width: 1024px) {
    .sidebar { display: flex; position: sticky; top: 0; height: 100vh; }
    .bottom-nav { display: none; }
    .main { padding: 28px 36px 40px; gap: 24px; }
    .topbar-brand { display: none; }
    .topbar-page { display: block; }
    .topbar-page h1 { font-size: 30px; }
    .topbar-page p { margin: 4px 0 0; color: var(--muted); }
    .icon-btn { width: 48px; height: 48px; }
    .segmented { display: inline-grid; align-self: flex-start; min-width: 280px; }
    .card { padding: 26px; border-radius: 28px; }
    .hero { padding: 26px; }
    .digit { border-radius: 20px; }

    .sheet { width: min(560px, calc(100% - 48px)); margin: auto; }
    .sheet-panel { border-radius: 28px; border-bottom: 1px solid var(--border); padding: 20px 26px 26px; }
    .sheet[open] .sheet-panel { animation: sheet-pop 0.2s ease; }
    .sheet-handle { display: none; }
}

/* ==========================================================================
   หน้าทำนาย (v2/predict)
   ========================================================================== */
.form-block { display: flex; flex-direction: column; gap: 10px; }
.form-label { font-size: 14px; color: var(--muted); }

.choice-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.choice {
    min-height: 64px;
    border-radius: 18px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 14px;
    text-align: left;
    font-size: 15px;
    transition: border-color 0.2s, background-color 0.2s, box-shadow 0.2s;
}
.choice-mark {
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    border-radius: 12px;
    background: var(--surface-2);
    color: var(--muted);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Kanit', sans-serif;
    font-size: 13px;
}
/* จำนวนตัวเลือกเป็นเลขคี่ (หวยไทย 3 ประเภท) — ตัวสุดท้ายยืดเต็มแถว */
.choice:last-child:nth-child(odd) { grid-column: 1 / -1; }
.choice .icon-check { display: none; }
.choice[aria-pressed="true"] {
    border-color: var(--accent-border);
    background: var(--accent-soft);
    font-weight: 600;
    box-shadow: 0 0 20px color-mix(in srgb, var(--accent) 22%, transparent);
}
.choice[aria-pressed="true"] .choice-mark { background: var(--accent); color: var(--on-accent); }
.choice[aria-pressed="true"] .choice-digits { display: none; }
.choice[aria-pressed="true"] .icon-check { display: block; }

.pill-row { display: flex; flex-wrap: wrap; gap: 8px; }
.pill-row.days { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.pill-row.count { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 6px; }
.pill-btn {
    flex: 1;
    min-height: 44px;
    padding: 0 12px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--muted);
    white-space: nowrap;
}
.pill-row.count .pill-btn { border-radius: 12px; padding: 0; font-family: 'Kanit', sans-serif; font-size: 16px; }
.pill-btn[aria-pressed="true"] { background: var(--text); color: var(--bg); border-color: var(--text); font-weight: 600; }

.btn-hero {
    width: 100%;
    min-height: 60px;
    border: none;
    border-radius: 20px;
    background: var(--fab-bg);
    color: var(--fab-text);
    font-family: 'Kanit', sans-serif;
    font-size: 19px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    box-shadow: var(--fab-shadow);
    transition: transform 0.15s ease, opacity 0.2s;
}
.btn-hero:active { transform: scale(0.98); }
.btn-hero:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-hero .icon { width: 24px; height: 24px; }
.btn-ghost {
    min-height: 52px;
    border-radius: 16px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text);
    font-family: 'Kanit', sans-serif;
    font-size: 16px;
}
.form-hint { margin: -4px 0 0; text-align: center; font-size: 12px; color: var(--muted); }
.form-error { margin: 0; text-align: center; font-size: 14px; color: #F87171; }
[data-theme="lucky"] .form-error { color: #B91C1C; }

/* ---------- Loading overlay ---------- */
.loading {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 26px;
    padding: 32px;
    background: color-mix(in srgb, var(--bg) 92%, transparent);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    text-align: center;
}
.loading.show { display: flex; }
.loading-orb { position: relative; width: 190px; height: 190px; display: flex; align-items: center; justify-content: center; }
.loading-orb::before, .loading-orb::after { content: ""; position: absolute; border-radius: 50%; }
.loading-orb::before { inset: 0; border: 3px solid var(--bar-track); border-top-color: var(--accent); border-right-color: var(--accent-2); animation: spin 1.2s linear infinite; }
.loading-orb::after { inset: 22px; border: 2px dashed var(--accent-border); animation: spin 6s linear infinite reverse; }
.loading-core {
    width: 100px;
    height: 100px;
    border-radius: 30px;
    background: var(--fab-bg);
    color: var(--fab-text);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--fab-shadow);
    animation: pulse 1.6s ease-in-out infinite;
}
[data-theme="lucky"] .loading-core { border-radius: 50%; }
.loading-core .icon { width: 46px; height: 46px; }
.loading h2 { font-size: 24px; }
.loading p { margin: 6px 0 0; color: var(--muted); font-size: 14px; }
.loading-formula { min-height: 24px; font-size: 15px; color: var(--accent-text); font-weight: 500; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.07); } }

/* ---------- Result sheet ---------- */
.result { display: flex; flex-direction: column; gap: 16px; }
.result-tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; }
.result-tabs button {
    flex-shrink: 0;
    min-height: 40px;
    padding: 0 16px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--muted);
    font-size: 14px;
}
.result-tabs button[aria-selected="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }

.top-pick { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 6px 0; border: none; background: transparent; color: inherit; width: 100%; }
.top-pick .rank { font-size: 12px; letter-spacing: 2px; color: var(--accent-text); }
.top-ring {
    width: 156px;
    height: 156px;
    border-radius: 50%;
    background: conic-gradient(var(--accent-2) 0 var(--p, 0%), var(--bar-track) var(--p, 0%) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 60px color-mix(in srgb, var(--accent-2) 35%, transparent);
    animation: digit-in 0.6s cubic-bezier(.2, .8, .2, 1.2) both;
}
.top-num {
    width: 136px;
    height: 136px;
    border-radius: 50%;
    background: #0B1028;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Kanit', sans-serif;
    font-weight: 700;
    font-size: 64px;
    line-height: 1;
    color: #FFFFFF;
    text-shadow: 0 0 26px rgba(139, 92, 246, 0.95);
}
.top-num.len-3 { font-size: 52px; }
.top-num.len-4 { font-size: 42px; }
[data-theme="lucky"] .top-ring { background: conic-gradient(#E11D48 0 var(--p, 0%), var(--bar-track) var(--p, 0%) 100%); box-shadow: 0 10px 30px rgba(76, 5, 25, 0.25); }
[data-theme="lucky"] .top-num {
    background: radial-gradient(circle at 35% 30%, #FFFBEB, #FCD34D 45%, #D97706);
    color: #7F1D1D;
    text-shadow: none;
    box-shadow: inset 0 -6px 12px rgba(0, 0, 0, 0.15);
}
.top-pick .agree { font-size: 14px; color: var(--muted); }
.top-pick .agree b { color: var(--highlight); }

.rank-list { display: flex; flex-direction: column; gap: 8px; margin: 0; padding: 0; list-style: none; }
.rank-row {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 14px;
    min-height: 52px;
    padding: 8px 14px;
    border-radius: 16px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    text-align: left;
    animation: digit-in 0.4s ease both;
}
[data-theme="lucky"] .rank-row { background: var(--bg); }
.rank-row .r { width: 28px; font-size: 13px; color: var(--muted); }
.rank-row .n { min-width: 52px; font-family: 'Kanit', sans-serif; font-size: 26px; font-weight: 600; letter-spacing: 1px; }
[data-theme="lucky"] .rank-row .n { color: #881337; }
.rank-row .bar { flex: 1; height: 6px; }
.rank-row .c { width: 48px; text-align: right; font-size: 13px; color: var(--muted); }
/* นามสัตว์ (หวยลาว): ป้ายชื่อสัตว์ใต้เลข 2 ตัวท้าย + แท็บ "นามสัตว์" */
.animal-tag { padding: 3px 12px; border-radius: 999px; font-size: 13px; font-weight: 600; color: var(--c-due); background: color-mix(in srgb, var(--c-due) 14%, transparent); }
.animal-tag.sm { padding: 1px 8px; font-size: 11px; white-space: nowrap; }
.animal-view { display: flex; flex-direction: column; gap: 14px; }
.animal-top { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 18px 12px; border-radius: 22px; background: var(--hero-bg); color: var(--hero-text); border: 1px solid color-mix(in srgb, var(--c-due) 45%, transparent); box-shadow: 0 0 40px color-mix(in srgb, var(--c-due) 22%, transparent); animation: digit-in 0.6s cubic-bezier(.2, .8, .2, 1.2) both; }
[data-theme="lucky"] .animal-top { border: none; box-shadow: var(--shadow-sm); }
.animal-top .rank { font-size: 12px; letter-spacing: 2px; color: var(--hero-muted); }
.animal-top .animal-name { font-family: 'Kanit', sans-serif; font-size: 44px; font-weight: 700; line-height: 1.1; color: var(--hero-highlight); text-shadow: 0 0 20px color-mix(in srgb, var(--hero-highlight) 60%, transparent); }
.animal-top .agree { font-size: 13px; color: var(--hero-muted); }
.animal-top .agree b { color: var(--hero-highlight); }
.animal-nums { display: flex; gap: 6px; }
.animal-num { min-width: 46px; padding: 6px 8px; border-radius: 12px; text-align: center; font-family: 'Kanit', sans-serif; font-size: 22px; font-weight: 600; background: var(--hero-chip); color: var(--hero-muted); }
.animal-num.hit { background: var(--accent-2); color: var(--bg); box-shadow: 0 0 14px color-mix(in srgb, var(--accent-2) 55%, transparent); }
[data-theme="lucky"] .animal-num.hit { background: #FCD34D; color: #7F1D1D; }
.animal-nums.sm .animal-num { min-width: 34px; padding: 3px 6px; border-radius: 9px; font-size: 15px; background: var(--surface-2); color: var(--muted); }
.animal-nums.sm .animal-num.hit { background: color-mix(in srgb, var(--accent-2) 22%, transparent); color: var(--highlight); box-shadow: none; }
[data-theme="lucky"] .animal-nums.sm .animal-num { background: var(--surface); }
[data-theme="lucky"] .animal-nums.sm .animal-num.hit { background: #FEF3C7; color: #92400E; }
.animal-row .name { flex: 1; font-family: 'Kanit', sans-serif; font-size: 19px; font-weight: 600; }
/* การทำนายเพิ่ม: พลังเลข / เลขวิ่ง / 3 ตัวโต๊ด */
.strength-pill { padding: 3px 12px; border-radius: 999px; font-size: 12px; color: var(--c-ok); background: color-mix(in srgb, var(--c-ok) 12%, transparent); }
.strength-pill b { font-weight: 700; }
.extra-preds { display: flex; flex-direction: column; gap: 8px; padding: 12px 14px; border-radius: 16px; background: var(--surface-2); border: 1px solid var(--border); }
[data-theme="lucky"] .extra-preds { background: var(--bg); }
.extra-row { display: flex; align-items: center; gap: 10px; }
.extra-k { width: 72px; flex-shrink: 0; font-size: 13px; color: var(--muted); }
.extra-v { display: flex; flex-wrap: wrap; gap: 6px; }
.run-chip { padding: 4px 10px; border-radius: 10px; font-size: 12px; color: var(--muted); background: var(--surface); border: 1px solid var(--border); }
.run-chip b { font-family: 'Kanit', sans-serif; font-size: 18px; color: var(--text); letter-spacing: 1px; }
[data-theme="lucky"] .run-chip b { color: #881337; }
.extra-note { margin: 0; font-size: 11px; color: var(--muted); }
.result-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.result-actions .btn-hero { min-height: 52px; font-size: 16px; border-radius: 16px; }
.result-note { margin: 0; text-align: center; font-size: 12px; color: var(--muted); }

/* ---------- Number detail ---------- */
.detail-head { display: flex; align-items: center; gap: 16px; }
.detail-num {
    min-width: 84px;
    height: 84px;
    padding: 0 12px;
    border-radius: 24px;
    background: #0B1028;
    border: 1px solid var(--accent-2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Kanit', sans-serif;
    font-size: 42px;
    font-weight: 700;
    color: #FFFFFF;
    text-shadow: 0 0 20px rgba(34, 211, 238, 0.9);
}
[data-theme="lucky"] .detail-num { border: none; border-radius: 42px; background: radial-gradient(circle at 35% 30%, #FFFBEB, #FCD34D 45%, #D97706); color: #7F1D1D; text-shadow: none; }
.detail-head .meta { font-size: 13px; color: var(--muted); }
.detail-head .title { font-family: 'Kanit', sans-serif; font-size: 21px; font-weight: 600; line-height: 1.3; }
.formula-list { margin: 0; padding: 0; list-style: none; }
.formula-list li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 11px 4px; border-bottom: 1px solid var(--border); font-size: 15px; }
.formula-list li.off { color: var(--muted); }
.rank-badge { padding: 2px 10px; border-radius: 999px; font-size: 13px; background: var(--accent-soft); color: var(--accent-text); white-space: nowrap; }
.rank-badge.top { background: color-mix(in srgb, var(--accent-2) 16%, transparent); color: var(--highlight); }
.link-btn { border: none; background: none; padding: 8px 0; color: var(--link); font-size: 14px; }

/* ==========================================================================
   หน้าประวัติ (v2/history)
   ========================================================================== */
/* สีประจำวันแบบไทย — ใช้เหมือนกันทั้งสองธีม (ป้ายใช้พื้นจาง + ตัวหนังสือเข้ม ให้อ่านได้ทั้งพื้นมืด/สว่าง) */
:root {
    --day-0: #F87171; --day-1: #FACC15; --day-2: #F472B6; --day-3: #4ADE80;
    --day-4: #FB923C; --day-5: #60A5FA; --day-6: #C084FC;
}
[data-theme="lucky"] {
    --day-0: #DC2626; --day-1: #A16207; --day-2: #DB2777; --day-3: #15803D;
    --day-4: #C2410C; --day-5: #1D4ED8; --day-6: #7E22CE;
}

.hist-form { display: flex; flex-direction: column; gap: 12px; }
.hist-search { display: flex; gap: 8px; }
.search-box {
    flex: 1;
    min-width: 0;
    height: 50px;
    border-radius: 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 6px 0 14px;
    color: var(--muted);
    transition: border-color 0.2s, box-shadow 0.2s;
}
.search-box:focus-within, .search-box.active {
    border-color: var(--accent-2);
    box-shadow: 0 0 18px color-mix(in srgb, var(--accent-2) 25%, transparent);
}
.search-box input {
    flex: 1;
    min-width: 0;
    height: 100%;
    border: none;
    background: transparent;
    color: var(--text);
    font-family: 'Kanit', sans-serif;
    font-size: 18px;
    letter-spacing: 1px;
    outline: none;
}
.search-box input::placeholder { font-family: 'IBM Plex Sans Thai', sans-serif; font-size: 15px; letter-spacing: 0; color: var(--muted); }
.search-box input::-webkit-search-cancel-button { display: none; }
.search-clear { width: 40px; height: 40px; display: flex; align-items: center; justify-content: center; color: var(--muted); border-radius: 12px; }
.filter-btn { width: 50px; height: 50px; position: relative; color: var(--accent-text); border-color: var(--accent-border); background: var(--accent-soft); }
.filter-btn .dot { position: absolute; top: 9px; right: 9px; width: 8px; height: 8px; border-radius: 50%; background: var(--accent-2); box-shadow: 0 0 8px var(--accent-2); }

.hist-filters { display: none; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.field select {
    min-height: 48px;
    padding: 0 14px;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: 15px;
}
/* ตัวกรองในป๊อปอัพ (มือถือ): ปุ่มให้แตะเลือก */
.filter-sheet { display: flex; flex-direction: column; gap: 18px; }
.filter-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.filter-grid .pill-btn { min-height: 44px; padding: 0 4px; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 14px; }
.filter-grid .pill-btn:hover { text-decoration: none; }
.filter-grid .pill-btn[aria-current="true"] { background: var(--text); color: var(--bg); border-color: var(--text); font-weight: 600; }

.chip-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.filter-chip {
    min-height: 34px;
    padding: 0 8px 0 12px;
    border-radius: 999px;
    background: color-mix(in srgb, var(--accent-2) 12%, transparent);
    border: 1px solid color-mix(in srgb, var(--accent-2) 40%, transparent);
    color: var(--highlight);
    font-size: 13px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.filter-chip:hover { text-decoration: none; }
.filter-chip .icon { width: 15px; height: 15px; }
.chip-clear { font-size: 13px; padding: 6px 4px; }

/* สรุปผลค้นหา */
.search-sum {
    border-radius: 22px;
    padding: 16px;
    background: var(--hero-bg);
    border: 1px solid color-mix(in srgb, var(--accent-2) 40%, transparent);
    color: var(--hero-text);
    display: flex;
    flex-direction: column;
    gap: 12px;
}
[data-theme="lucky"] .search-sum { border: none; box-shadow: var(--shadow-sm); }
.search-sum-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.search-sum-head .q { font-family: 'Kanit', sans-serif; font-size: 40px; font-weight: 700; line-height: 1; letter-spacing: 2px; color: var(--hero-highlight); text-shadow: 0 0 18px color-mix(in srgb, var(--hero-highlight) 60%, transparent); }
.search-sum-head .where { font-size: 14px; color: var(--hero-muted); }
.search-sum-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.search-sum-stats > div { padding: 10px; border-radius: 14px; background: var(--hero-chip); display: flex; flex-direction: column; }
.search-sum-stats .k { font-size: 11px; color: var(--hero-muted); }
.search-sum-stats .v { font-family: 'Kanit', sans-serif; font-size: 16px; white-space: nowrap; font-weight: 600; }
.search-sum .pill-btn { display: flex; align-items: center; justify-content: center; min-height: 38px; font-size: 13px; color: var(--hero-muted); border-color: color-mix(in srgb, var(--hero-text) 18%, transparent); }
.search-sum .pill-btn:hover { text-decoration: none; }
.search-sum .pill-btn[aria-current="true"] { background: var(--hero-text); color: var(--bg); border-color: var(--hero-text); font-weight: 600; }
[data-theme="lucky"] .search-sum .pill-btn[aria-current="true"] { color: #881337; }
.search-sum .card-note { color: var(--hero-muted); }

/* รายการผล */
.hist-list { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
.hist-month {
    grid-column: 1 / -1;
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin: 10px 4px 2px;
    font-size: 18px;
}
.hist-month:first-child { margin-top: 0; }
.hist-month span { font-family: 'IBM Plex Sans Thai', sans-serif; font-size: 12px; font-weight: 400; color: var(--muted); }

.hcard {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    min-width: 0;
}
[data-theme="lucky"] .hcard { box-shadow: var(--shadow-sm); }
.hcard.latest { background: var(--hero-bg); border-color: var(--hero-border); color: var(--hero-text); box-shadow: 0 8px 24px color-mix(in srgb, var(--accent) 18%, transparent); }
.hcard-date { width: 38px; flex-shrink: 0; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.hcard-date b { font-family: 'Kanit', sans-serif; font-size: 20px; font-weight: 600; line-height: 1; }
.hcard-date span { font-size: 11px; color: var(--muted); }
.hcard-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.hcard-meta { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--muted); white-space: nowrap; }
.hcard-meta b { color: var(--text); font-weight: 600; }
.hcard-meta b.hl { color: var(--highlight); }
.hcard.latest .hcard-date span, .hcard.latest .hcard-meta { color: var(--hero-muted); }
.hcard.latest .hcard-meta b { color: var(--hero-text); }
.hcard.latest .hcard-meta b.hl { color: var(--hero-highlight); }
/* หวยไทย: สามตัวหน้า/ท้าย (งวดละ 2 ชุด) ใต้เลขรางวัลที่ 1 */
.hcard-three { display: flex; flex-wrap: wrap; gap: 2px 14px; font-size: 12px; color: var(--muted); }
.hcard-three b { color: var(--text); font-weight: 600; letter-spacing: 1px; }
.hcard.latest .hcard-three { color: var(--hero-muted); }
.hcard.latest .hcard-three b { color: var(--hero-text); }
.day-badge { padding: 1px 7px; border-radius: 999px; font-weight: 600; }
.day-badge.day-0 { color: var(--day-0); background: color-mix(in srgb, var(--day-0) 14%, transparent); }
.day-badge.day-1 { color: var(--day-1); background: color-mix(in srgb, var(--day-1) 14%, transparent); }
.day-badge.day-2 { color: var(--day-2); background: color-mix(in srgb, var(--day-2) 14%, transparent); }
.day-badge.day-3 { color: var(--day-3); background: color-mix(in srgb, var(--day-3) 14%, transparent); }
.day-badge.day-4 { color: var(--day-4); background: color-mix(in srgb, var(--day-4) 14%, transparent); }
.day-badge.day-5 { color: var(--day-5); background: color-mix(in srgb, var(--day-5) 14%, transparent); }
.day-badge.day-6 { color: var(--day-6); background: color-mix(in srgb, var(--day-6) 14%, transparent); }
[data-theme="lucky"] .hcard.latest .day-badge { background: #FFFFFF; }
.tag-latest { margin-left: auto; padding: 1px 7px; border-radius: 999px; background: var(--accent-2); color: var(--bg); font-size: 10px; font-weight: 600; }
[data-theme="lucky"] .tag-latest { background: #FDE68A; color: #7F1D1D; }

.hcard-nums { display: flex; align-items: center; gap: 6px; }
.mini-digits { display: flex; gap: 4px; }
/* กล่องตัวเลขเล็ก: ลาว 30px / ไทย (6 หลัก) 26px */
.md {
    --s: 30px;
    width: var(--s);
    height: calc(var(--s) + 4px);
    border-radius: 9px;
    background: #0B1028;
    border: 1px solid #8B5CF6;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Kanit', sans-serif;
    font-style: normal;
    font-size: calc(var(--s) * 0.62);
    font-weight: 700;
    color: #FFFFFF;
    text-shadow: 0 0 10px rgba(139, 92, 246, 0.85);
}
.md.alt { border-color: #22D3EE; text-shadow: 0 0 10px rgba(34, 211, 238, 0.85); }
.hcard-nums.six .md { --s: 26px; border-radius: 8px; }
.md.miss { background: rgba(255, 255, 255, 0.03); border-color: rgba(255, 255, 255, 0.08); color: #5B6488; text-shadow: none; }
.md.hit { box-shadow: 0 0 12px rgba(34, 211, 238, 0.55); }
[data-theme="lucky"] .md {
    height: var(--s);
    border-radius: 50%;
    border: none;
    background: radial-gradient(circle at 35% 30%, #FFFBEB, #FCD34D 45%, #D97706);
    color: #7F1D1D;
    text-shadow: none;
    box-shadow: 0 3px 6px rgba(76, 5, 25, 0.25);
}
[data-theme="lucky"] .md.miss { background: #F5EDE8; color: #B8A9A0; box-shadow: none; }
[data-theme="lucky"] .md.hit { box-shadow: 0 0 0 2px #E11D48; }

/* หวยลาว (4 หลัก): กล่องยืดเต็มความกว้างการ์ด — ธีมมงคลยังเป็นลูกบอลกลม แค่กระจายให้เต็มแถว */
.hcard-nums:not(.six) .mini-digits { flex: 1; min-width: 0; gap: 6px; }
.hcard-nums:not(.six) .md { --s: 36px; flex: 1; width: auto; min-width: 0; height: 40px; border-radius: 11px; font-size: 23px; }
[data-theme="lucky"] .hcard-nums:not(.six) .mini-digits { justify-content: space-around; }
[data-theme="lucky"] .hcard-nums:not(.six) .md { flex: 0 0 auto; width: 40px; height: 40px; border-radius: 50%; }

.low-pill {
    margin-left: auto;
    height: 30px;
    padding: 0 10px;
    border-radius: 10px;
    background: rgba(240, 171, 252, 0.1);
    border: 1px solid rgba(240, 171, 252, 0.45);
    display: flex;
    align-items: center;
    gap: 6px;
}
.low-pill small { font-size: 10px; line-height: 1.1; color: var(--muted); text-align: center; }
.low-pill b { font-family: 'Kanit', sans-serif; font-size: 18px; font-weight: 700; color: #F0ABFC; }
.low-pill.miss { opacity: 0.4; }
.low-pill.hit { box-shadow: 0 0 14px rgba(240, 171, 252, 0.6); }
[data-theme="lucky"] .low-pill { background: #FFF1F2; border-color: #FDA4AF; }
[data-theme="lucky"] .low-pill b { color: #9F1239; }
[data-theme="lucky"] .low-pill.hit { box-shadow: 0 0 0 2px #E11D48; }

.more-btn { width: 100%; }
.more-btn[aria-busy="true"] { opacity: 0.6; cursor: progress; }

@media (min-width: 1024px) {
    .hist-form { flex-direction: row; flex-wrap: wrap; align-items: flex-end; gap: 14px; padding: 18px; border-radius: 22px; background: var(--surface); border: 1px solid var(--border); }
    .hist-search { flex: 1 1 260px; }
    .hist-search .search-box { height: 48px; }
    .filter-btn { display: none; }
    .hist-filters { display: flex; gap: 12px; }
    .hist-filters .field select { min-width: 150px; }
    .hist-list { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
    /* หวยไทยออกเดือนละ 2 งวด: จอกว้างได้ 2 คอลัมน์พอดีแถว (จอแคบ 1 คอลัมน์) + เลข 6 หลักยืดเต็มการ์ด */
    .hist-list.thai { grid-template-columns: repeat(auto-fill, minmax(420px, 1fr)); }
    .hist-list.thai .hcard { padding: 12px 16px; gap: 14px; }
    .hcard-nums.six { gap: 12px; }
    .hcard-nums.six .mini-digits { flex: 1; min-width: 0; gap: 6px; }
    .hcard-nums.six .md { flex: 1; width: auto; min-width: 0; height: 42px; border-radius: 11px; font-size: 24px; }
    .hcard-nums.six .low-pill { height: 42px; margin-left: 0; }
    [data-theme="lucky"] .hcard-nums.six .mini-digits { justify-content: space-around; }
    [data-theme="lucky"] .hcard-nums.six .md { flex: 0 0 auto; width: 40px; height: 40px; border-radius: 50%; }
}

/* ==========================================================================
   หน้าสถิติ (v2/stats)
   ========================================================================== */
/* สีประจำการ์ด: ร้อน / ค้างนาน / เย็น / หลักหน่วย / แยกวัน */
:root { --c-hot: #FB923C; --c-due: #F0ABFC; --c-cold: #60A5FA; --c-digit: #22D3EE; --c-day: #FACC15; }
[data-theme="lucky"] { --c-hot: #C2410C; --c-due: #BE185D; --c-cold: #1D4ED8; --c-digit: #0E7490; --c-day: #A16207; }

.type-tabs { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 0 16px; }
.type-tabs::-webkit-scrollbar { display: none; }
.type-tabs .pill-btn { flex: 1 0 auto; display: flex; align-items: center; justify-content: center; min-height: 40px; padding: 0 16px; font-size: 14px; }
.type-tabs .pill-btn:hover { text-decoration: none; }
.type-tabs .pill-btn[aria-current="page"] { background: var(--text); color: var(--bg); border-color: var(--text); font-weight: 600; }

.stats-grid { display: flex; flex-direction: column; gap: 14px; }
.stat-card { gap: 14px; }
.stat-head { display: flex; align-items: center; gap: 10px; }
.stat-head h2 { font-size: 18px; }
.stat-head .note { margin-left: auto; font-size: 12px; color: var(--muted); }
.stat-icon { width: 34px; height: 34px; flex-shrink: 0; border-radius: 11px; display: flex; align-items: center; justify-content: center; }
[data-theme="lucky"] .stat-icon { border-radius: 50%; }
.c-hot   { --c: var(--c-hot); }
.c-due   { --c: var(--c-due); }
.c-cold  { --c: var(--c-cold); }
.c-digit { --c: var(--c-digit); }
.c-day   { --c: var(--c-day); }
.stat-icon { color: var(--c); background: color-mix(in srgb, var(--c) 15%, transparent); }
.stats-note { padding: 0 4px; }

/* เลขร้อน: แท่น 3 อันดับ + แถว 4-8 */
.podium { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; align-items: end; }
.podium-item {
    display: flex; flex-direction: column; align-items: center; gap: 6px;
    padding: 12px 6px; border-radius: 18px; min-width: 0;
    background: var(--surface-2); border: 1px solid var(--border);
}
.podium-item .rank { font-size: 11px; color: var(--muted); }
.podium-item .n { font-family: 'Kanit', sans-serif; font-size: 32px; font-weight: 700; line-height: 1; letter-spacing: 1px; }
.podium-item .n.len-3 { font-size: 28px; }
.podium-item .n.len-4 { font-size: 24px; }
.podium-item .c { font-size: 12px; color: var(--muted); }
.podium-item.first { padding: 16px 6px; background: var(--hero-bg); border-color: color-mix(in srgb, var(--accent-2) 50%, transparent); box-shadow: 0 0 24px color-mix(in srgb, var(--accent-2) 25%, transparent); color: var(--hero-text); }
.podium-item.first .n { font-size: 44px; color: var(--hero-highlight); text-shadow: 0 0 18px color-mix(in srgb, var(--hero-highlight) 70%, transparent); }
.podium-item.first .n.len-3 { font-size: 36px; }
.podium-item.first .n.len-4 { font-size: 30px; }
.podium-item.first .rank, .podium-item.first .c { color: var(--hero-muted); }
[data-theme="lucky"] .podium-item.first { border: none; box-shadow: var(--shadow-sm); }

.hot-rows { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.hot-rows li { display: flex; align-items: center; gap: 10px; }
.hot-rows .r { width: 18px; font-size: 12px; color: var(--muted); }
.hot-rows .n { min-width: 34px; font-family: 'Kanit', sans-serif; font-size: 20px; font-weight: 600; letter-spacing: 1px; }
.hot-rows .bar { flex: 1; height: 8px; }
.hot-rows .bar > span { display: block; height: 100%; border-radius: inherit; background: var(--bar); }
.hot-rows .c { width: 56px; text-align: right; font-size: 12px; color: var(--muted); }

/* เลขค้างนาน / เลขเย็น */
.num-chips { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
.num-chip {
    padding: 10px 4px; border-radius: 14px; min-width: 0;
    background: var(--surface-2); border: 1px solid color-mix(in srgb, var(--c) 40%, transparent);
    display: flex; flex-direction: column; align-items: center; gap: 2px; text-align: center;
}
.num-chip .n { font-family: 'Kanit', sans-serif; font-size: 24px; font-weight: 700; color: var(--c); line-height: 1.2; }
.num-chip .c { font-size: 11px; color: var(--muted); line-height: 1.3; }

/* หลักหน่วย 0-9 */
.digit-bars { display: grid; grid-template-columns: repeat(10, minmax(0, 1fr)); gap: 6px; height: 130px; }
.digit-bar { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 4px; min-width: 0; }
.digit-bar .p { font-size: 10px; color: var(--muted); }
.digit-bar .b { width: 100%; border-radius: 8px 8px 4px 4px; background: color-mix(in srgb, var(--accent) 45%, transparent); transform-origin: bottom; animation: grow-up 0.6s ease both; }
.digit-bar .d { font-family: 'Kanit', sans-serif; font-size: 15px; font-weight: 600; }
.digit-bar.top .p { color: var(--highlight); font-weight: 600; }
.digit-bar.top .b { background: linear-gradient(180deg, var(--accent-2), var(--accent)); box-shadow: 0 0 14px color-mix(in srgb, var(--accent-2) 50%, transparent); }
@keyframes grow-up { from { transform: scaleY(0); } to { transform: scaleY(1); } }

/* เลขเด่นแยกวัน (สีตามวันแบบไทย ใช้ --day-* ชุดเดียวกับหน้าประวัติ) */
.day-tops { display: grid; grid-template-columns: repeat(var(--n, 5), minmax(0, 1fr)); gap: 6px; }
.day-top {
    --c: var(--muted);
    padding: 10px 2px; border-radius: 14px; min-width: 0;
    background: color-mix(in srgb, var(--c) 9%, transparent); border: 1px solid color-mix(in srgb, var(--c) 30%, transparent);
    display: flex; flex-direction: column; align-items: center; gap: 2px; text-align: center;
}
.day-top.day-0 { --c: var(--day-0); } .day-top.day-1 { --c: var(--day-1); } .day-top.day-2 { --c: var(--day-2); }
.day-top.day-3 { --c: var(--day-3); } .day-top.day-4 { --c: var(--day-4); } .day-top.day-5 { --c: var(--day-5); }
.day-top.day-6 { --c: var(--day-6); }
.day-top .day { font-size: 11px; font-weight: 600; color: var(--c); }
.day-top .n { font-family: 'Kanit', sans-serif; font-size: 22px; font-weight: 700; line-height: 1.2; }
.day-top .n.len-3 { font-size: 18px; }
.day-top .n.len-4 { font-size: 15px; }
.day-top .c { font-size: 10px; color: var(--muted); }

@media (min-width: 1024px) {
    .type-tabs { margin: 0; padding: 0; max-width: 560px; }
    .stats-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; align-items: start; }
    .stats-grid > .stat-card:first-child { grid-row: span 2; }
    .stats-note { grid-column: 2; }
}

/* ==========================================================================
   เข้าสู่ระบบ / สมัครสมาชิก / โปรไฟล์ (v2/auth/*)
   ========================================================================== */
/* หน้าไม่มีเมนู (layout $bare) — เนื้อหากลางจอ */
.is-bare .main { max-width: 480px; padding-bottom: calc(32px + env(safe-area-inset-bottom)); justify-content: center; min-height: 100vh; min-height: 100dvh; }
.auth-wrap { display: flex; flex-direction: column; gap: 20px; }
.back-link { align-self: flex-start; display: inline-flex; align-items: center; gap: 4px; min-height: 44px; color: var(--muted); font-size: 14px; }
.back-link:hover { text-decoration: none; color: var(--text); }
.auth-head { display: flex; flex-direction: column; align-items: center; gap: 14px; text-align: center; }
.auth-head.row { flex-direction: row; text-align: left; }
.auth-head h1 { font-size: 28px; }
.auth-head p { margin: 4px 0 0; color: var(--muted); font-size: 14px; }
.logo.logo-lg { width: 72px; height: 72px; font-size: 36px; border-radius: 22px; box-shadow: 0 0 34px color-mix(in srgb, var(--accent) 65%, transparent); }
[data-theme="lucky"] .logo.logo-lg { border-radius: 50%; }
.auth-card {
    display: flex; flex-direction: column; gap: 14px;
    padding: 20px; border-radius: 26px;
    background: color-mix(in srgb, var(--surface) 80%, transparent);
    border: 1px solid var(--border);
    -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
}
[data-theme="lucky"] .auth-card { background: var(--surface); box-shadow: var(--shadow-sm); }
.auth-alt { margin: 0; text-align: center; font-size: 14px; color: var(--muted); }
.auth-alt a { font-weight: 600; }
.form-ok { margin: 0; padding: 12px 14px; border-radius: 14px; text-align: center; font-size: 14px; color: var(--c-ok); background: color-mix(in srgb, var(--c-ok) 12%, transparent); }
:root { --c-ok: #4ADE80; --c-bad: #F87171; }
[data-theme="lucky"] { --c-ok: #15803D; --c-bad: #B91C1C; }

.auth-field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.auth-field .input {
    height: 52px; display: flex; align-items: center; gap: 10px; padding: 0 6px 0 14px;
    border-radius: 16px; background: var(--surface); border: 1px solid var(--border);
    transition: border-color 0.2s, box-shadow 0.2s;
}
[data-theme="lucky"] .auth-field .input { background: var(--bg); }
.auth-field .input:focus-within { border-color: var(--accent-2); box-shadow: 0 0 18px color-mix(in srgb, var(--accent-2) 25%, transparent); }
.auth-field input { flex: 1; min-width: 0; height: 100%; border: none; background: transparent; color: var(--text); font: inherit; font-size: 16px; outline: none; }
.auth-field .eye { width: 40px; height: 40px; flex-shrink: 0; border: none; border-radius: 12px; background: transparent; color: var(--muted); display: flex; align-items: center; justify-content: center; }
.auth-field .eye.on { color: var(--highlight); }
.auth-field small { font-size: 12px; }
.auth-field small.ok { color: var(--c-ok); }
.auth-field small.bad { color: var(--c-bad); }
.strength { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; }
.strength i { height: 5px; border-radius: 9px; background: var(--bar-track); transition: background-color 0.2s; }
.strength[data-level="1"] i:nth-child(-n+1),
.strength[data-level="2"] i:nth-child(-n+2),
.strength[data-level="3"] i:nth-child(-n+3),
.strength[data-level="4"] i { background: var(--accent-2); }
.strength[data-level="1"] i:first-child { background: var(--c-due); }

/* โปรไฟล์ */
.profile { display: flex; flex-direction: column; gap: 16px; max-width: 640px; }
.profile-hero {
    display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center;
    padding: 24px; border-radius: 28px; background: var(--hero-bg); color: var(--hero-text);
    border: 1px solid var(--hero-border); box-shadow: var(--shadow);
}
.profile-hero h2 { font-size: 24px; }
.profile-hero p { margin: 2px 0 0; color: var(--hero-muted); font-size: 14px; }
.avatar { width: 92px; height: 92px; padding: 4px; border-radius: 50%; background: conic-gradient(var(--accent), var(--accent-2), var(--accent)); box-shadow: 0 0 34px color-mix(in srgb, var(--accent) 55%, transparent); }
.avatar span { width: 100%; height: 100%; border-radius: 50%; background: var(--bg); color: var(--text); display: flex; align-items: center; justify-content: center; font-family: 'Kanit', sans-serif; font-size: 38px; font-weight: 700; }
[data-theme="lucky"] .avatar { background: radial-gradient(circle at 35% 30%, #FFFBEB, #FCD34D 45%, #D97706); }
[data-theme="lucky"] .avatar span { background: #881337; color: #FDE68A; }
.role-badge { display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px; border-radius: 999px; font-size: 13px; font-weight: 600; background: var(--hero-pill-bg); color: var(--hero-pill-text); }

.info-list { gap: 0; padding-top: 6px; padding-bottom: 6px; }
.info-row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.info-row:last-child { border-bottom: none; }
.info-row .k { display: block; font-size: 12px; color: var(--muted); }
.info-row .v { display: block; font-size: 15px; word-break: break-word; }
.info-row .ic, .action-row .ic { width: 36px; height: 36px; flex-shrink: 0; border-radius: 11px; display: flex; align-items: center; justify-content: center; background: var(--surface-2); color: var(--muted); }

.action-list { display: flex; flex-direction: column; gap: 8px; }
.action-row {
    width: 100%; min-height: 58px; display: flex; align-items: center; gap: 12px; padding: 8px 14px;
    border-radius: 16px; border: 1px solid var(--border); background: var(--surface); color: var(--text);
    font-size: 15px; text-align: left;
}
[data-theme="lucky"] .action-row { box-shadow: var(--shadow-sm); }
a.action-row:hover { text-decoration: none; }
.action-row .ic { background: var(--accent-soft); color: var(--accent-text); }
.action-row .t { flex: 1; }
.action-row .t small { display: block; font-size: 12px; color: var(--muted); }
.action-row .chev { color: var(--muted); }
.action-row.danger { color: var(--c-bad); }
.action-row.danger .ic { background: color-mix(in srgb, var(--c-bad) 14%, transparent); color: var(--c-bad); }
.theme-pick { display: flex; gap: 4px; padding: 4px; border-radius: 12px; background: var(--surface-2); }
.theme-pick button { min-height: 36px; padding: 0 12px; border: none; border-radius: 9px; background: transparent; color: var(--muted); font-size: 13px; }
.theme-pick button[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); font-weight: 600; }
.sheet-form { display: flex; flex-direction: column; gap: 14px; }

/* คอม: 2 คอลัมน์ — การ์ดชื่อด้านซ้าย (ติดอยู่ตอนเลื่อน), ข้อมูล + เมนูด้านขวา */
@media (min-width: 1024px) {
    .profile { max-width: none; display: grid; grid-template-columns: minmax(280px, 380px) minmax(0, 1fr); gap: 20px; align-items: start; }
    .profile-hero { grid-row: span 2; position: sticky; top: 28px; padding: 40px 24px; }
    .profile-hero .avatar { width: 120px; height: 120px; }
    .profile-hero .avatar span { font-size: 50px; }
    .profile-hero h2 { font-size: 28px; }
    .info-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 24px; }
    .info-row:nth-last-child(2) { border-bottom: none; }
    .action-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
}

/* ==========================================================================
   หน้าจัดการข้อมูล (v2/admin)
   ========================================================================== */
.admin { display: flex; flex-direction: column; gap: 14px; }
.admin-stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.admin-stat { --c: var(--accent-text); display: flex; flex-direction: column; gap: 2px; min-width: 0; padding: 14px; border-radius: 18px; background: var(--surface); border: 1px solid color-mix(in srgb, var(--c) 30%, transparent); }
.admin-stat.thai { --c: var(--highlight); }
[data-theme="lucky"] .admin-stat { box-shadow: var(--shadow-sm); }
.admin-stat .name { font-size: 13px; font-weight: 600; color: var(--c); }
.admin-stat .n { font-family: 'Kanit', sans-serif; font-size: 26px; font-weight: 700; line-height: 1.2; }
.admin-stat .n small { font-size: 13px; font-weight: 500; color: var(--muted); }
.admin-stat .last { font-size: 12px; color: var(--muted); }
.admin-foot { margin: 0; text-align: center; font-size: 12px; }
.admin-foot a { color: var(--muted); }

.quick-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.quick-actions .quick:last-child:nth-child(odd) { grid-column: 1 / -1; } /* ปุ่มเศษตัวสุดท้ายบนมือถือ เต็มแถว */
@media (min-width: 1024px) {
    .quick-actions { grid-template-columns: repeat(5, minmax(0, 1fr)); }
    .quick-actions .quick:last-child:nth-child(odd) { grid-column: auto; }
}
.three-pair { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.quick { --c: var(--accent-2); min-height: 68px; padding: 8px 4px; border-radius: 16px; border: 1px solid color-mix(in srgb, var(--c) 35%, transparent); background: color-mix(in srgb, var(--c) 9%, transparent); color: var(--text); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; font-size: 12px; text-align: center; line-height: 1.3; }
.quick .icon { color: var(--c); }
.quick.c-cyan { --c: var(--c-digit); } .quick.c-pink { --c: var(--c-due); } .quick.c-gold { --c: var(--c-day); }
.quick:active { transform: scale(0.97); }

/* segmented ที่เป็นปุ่ม (แท็บในหน้า) — หน้าตาเดียวกับ .segmented a */
.segmented button { min-height: 44px; border: none; border-radius: 13px; background: transparent; color: var(--muted); font-family: 'Kanit', sans-serif; font-size: 16px; display: flex; align-items: center; justify-content: center; gap: 6px; }
.segmented button.active { background: var(--accent); color: var(--on-accent); box-shadow: 0 6px 20px color-mix(in srgb, var(--accent) 45%, transparent); }

.admin-form { display: flex; flex-direction: column; gap: 14px; }
.lottery-pick .pill-btn { flex: 1; }

/* ช่องกรอกเลขเป็นกล่องทีละหลัก: input จริงโปร่งใสทับกล่อง */
.digit-entry { position: relative; }
.digit-entry input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; z-index: 1; font-size: 16px; caret-color: transparent; }
.digit-entry .boxes { display: flex; gap: 8px; }
.digit-entry .boxes span {
    flex: 1; max-width: 72px; height: 62px; border-radius: 16px;
    background: #0B1028; border: 1px solid rgba(255, 255, 255, 0.12);
    display: flex; align-items: center; justify-content: center;
    font-family: 'Kanit', sans-serif; font-size: 34px; font-weight: 700; color: #FFFFFF;
}
.digit-entry .boxes span.on { border-color: #8B5CF6; text-shadow: 0 0 14px rgba(139, 92, 246, 0.9); }
.digit-entry .boxes span.on.alt { border-color: #22D3EE; text-shadow: 0 0 14px rgba(34, 211, 238, 0.9); }
.digit-entry .boxes span.cur { border: 2px solid var(--text); }
.digit-entry.short .boxes span { max-width: 62px; }
[data-theme="lucky"] .digit-entry .boxes span { background: var(--bg); border-color: var(--border); color: #881337; }
[data-theme="lucky"] .digit-entry .boxes span.on { background: radial-gradient(circle at 35% 30%, #FFFBEB, #FCD34D 45%, #D97706); border-color: transparent; color: #7F1D1D; text-shadow: none; }
[data-theme="lucky"] .digit-entry .boxes span.cur { border: 2px solid #9F1239; }
.num-preview { min-height: 18px; color: var(--muted); }

.list-tools { display: flex; flex-direction: column; gap: 10px; }
.date-search .input { height: 46px; }
.list-note { margin: 0; font-size: 12px; color: var(--muted); padding: 0 4px; }
.admin-list { display: flex; flex-direction: column; gap: 8px; }
.admin-row { display: flex; align-items: center; gap: 10px; padding: 8px 8px 8px 12px; border-radius: 16px; background: var(--surface-2); border: 1px solid var(--border); }
[data-theme="lucky"] .admin-row { background: var(--bg); }
.admin-row .d { width: 50px; flex-shrink: 0; display: flex; flex-direction: column; align-items: center; }
.admin-row .d b { font-family: 'Kanit', sans-serif; font-size: 20px; font-weight: 600; line-height: 1.1; }
.admin-row .d span { font-size: 11px; color: var(--muted); }
.admin-row .m { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.admin-row .num { font-family: 'Kanit', sans-serif; font-size: 22px; font-weight: 600; letter-spacing: 3px; }
[data-theme="lucky"] .admin-row .num { color: #881337; }
.admin-row .sub { font-size: 11px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-btn { width: 44px; height: 44px; flex-shrink: 0; border-radius: 12px; border: 1px solid var(--border); background: transparent; color: var(--accent-text); display: flex; align-items: center; justify-content: center; }
.row-btn.danger { color: var(--c-bad); }

.btn-danger { min-height: 52px; border: none; border-radius: 16px; background: var(--c-bad); color: #FFFFFF; font-family: 'Kanit', sans-serif; font-size: 16px; font-weight: 600; }
.btn-danger:disabled { opacity: 0.6; }
.confirm-text { margin: 0; font-size: 15px; line-height: 1.6; }
.tpl-links { margin: 0; font-size: 13px; color: var(--muted); }
.drop-zone { min-height: 96px; border-radius: 16px; border: 1.5px dashed var(--accent-border); color: var(--muted); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; font-size: 14px; cursor: pointer; text-align: center; padding: 10px; word-break: break-all; }
.drop-zone:focus-within, .drop-zone:hover { border-color: var(--accent-2); color: var(--text); }
.csv-preview { display: flex; flex-direction: column; gap: 4px; padding: 10px 12px; border-radius: 12px; background: var(--surface-2); }
.csv-preview .k { font-size: 12px; color: var(--muted); }
.csv-preview code { font-size: 13px; color: var(--text); }
.warn-box { margin: 0; padding: 10px 12px; border-radius: 12px; font-size: 13px; display: flex; flex-direction: column; gap: 2px; color: var(--c-day); background: color-mix(in srgb, var(--c-day) 12%, transparent); }

.fetch-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; max-height: 46vh; overflow-y: auto; }
.fetch-list label { display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 0 12px; border-radius: 14px; background: var(--surface-2); cursor: pointer; }
.fetch-list input { width: 20px; height: 20px; accent-color: var(--accent); }
.fetch-list .dt { flex: 1; font-size: 14px; }
.fetch-list .num { font-family: 'Kanit', sans-serif; font-size: 20px; font-weight: 600; letter-spacing: 2px; }
.fetch-list .an { min-width: 56px; text-align: right; font-size: 12px; color: var(--c-due); }
.fetch-list li.done label { opacity: 0.55; }
.fetch-list .fetch-sub { display: block; padding: 2px 12px 0 44px; font-size: 12px; color: var(--muted); }
.fetch-list li.done .dt::after { content: ' · บันทึกแล้ว'; color: var(--c-ok); }

.bar.progress { height: 10px; }
.bar.progress > span { animation: none; transition: width 0.3s ease; }
.combo-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; font-size: 14px; }
.combo-list li { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px; color: var(--muted); }
.combo-list .st { width: 18px; text-align: center; font-weight: 700; }
.combo-list li.run { background: var(--surface-2); color: var(--text); }
.combo-list li.run .st { color: var(--accent-2); animation: pulse 1s ease infinite; }
.combo-list li.ok { color: var(--text); }
.combo-list li.ok .st { color: var(--c-ok); }
.combo-list li.bad .st { color: var(--c-bad); }

/* คอม: ฟอร์มเพิ่มผลซ้าย + รายการขวา แสดงพร้อมกัน ไม่ต้องสลับแท็บ */
@media (min-width: 1024px) {
    .admin { display: grid; grid-template-columns: minmax(340px, 400px) minmax(0, 1fr); gap: 20px; align-items: start; }
    .admin-stats, .quick-actions, .admin-foot { grid-column: 1 / -1; }
    .admin-stat { padding: 16px 20px; }
    .admin-stat .n { font-size: 30px; }
    .quick { flex-direction: row; gap: 10px; min-height: 60px; font-size: 15px; }
    .admin-tabs { display: none; }
    .admin-panel[hidden] { display: flex !important; }
    #panel-add { position: sticky; top: 28px; }
    .list-tools { flex-direction: row; align-items: center; }
    .list-tools .lottery-pick { min-width: 260px; }
    .date-search { flex: 1; }
}

/* ==========================================================================
   หน้า Backtest (v2/backtest)
   ========================================================================== */
.bt-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); gap: 20px; align-items: start; }
.type-tabs .pill-btn[aria-pressed="true"] { background: var(--text); color: var(--bg); border-color: var(--text); font-weight: 600; }
.pill-row.count4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.pill-row.count4 .pill-btn { border-radius: 12px; padding: 0; font-family: 'Kanit', sans-serif; font-size: 16px; }
.bar-sub { font-size: 11px; color: var(--muted); }
.bar-row.is-final { background: color-mix(in srgb, var(--accent-2) 8%, transparent); }
.bar-row.is-final .bar-top span:first-child { font-weight: 600; }
.bar.stacked { display: flex; }
.bar.stacked > span { flex-shrink: 0; border-radius: 0; }
.bar.stacked > span.exact { background: var(--bar); }
.bar.stacked > span.rev { background: color-mix(in srgb, var(--c-day) 70%, transparent); }
.legend { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.legend i { width: 12px; height: 8px; border-radius: 4px; display: inline-block; }
.legend i.exact { background: var(--bar); }
.legend i.rev { background: color-mix(in srgb, var(--c-day) 70%, transparent); margin-left: 6px; }
.card-head .note { font-size: 12px; color: var(--muted); }
.bt-progress { display: flex; flex-direction: column; gap: 6px; }
.bt-result { display: flex; flex-direction: column; gap: 20px; scroll-margin-top: 16px; }
.bt-summary .hero-foot { margin: 0; }
.bt-draws { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.bt-draws li { padding: 10px 12px; border-radius: 14px; background: var(--surface-2); border-left: 3px solid var(--border); display: flex; flex-direction: column; gap: 6px; }
[data-theme="lucky"] .bt-draws li { background: var(--bg); }
.bt-draws li.hit { border-left-color: var(--c-ok); }
.bt-draws li.rev { border-left-color: var(--c-day); }
.bt-draws .top { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.bt-draws .dt { font-size: 13px; color: var(--muted); }
.bt-draws .num { font-family: 'Kanit', sans-serif; font-size: 22px; font-weight: 600; letter-spacing: 2px; }
.bt-draws .tags { display: flex; flex-wrap: wrap; gap: 4px; }
.bt-draws .none { font-size: 12px; color: var(--muted); }
.f-tag { padding: 2px 8px; border-radius: 999px; font-size: 12px; background: color-mix(in srgb, var(--c-ok) 14%, transparent); color: var(--c-ok); }
.f-tag.final { background: var(--accent-2); color: var(--bg); font-weight: 600; }
.f-tag.rev { background: color-mix(in srgb, var(--c-day) 14%, transparent); color: var(--c-day); }
@media (min-width: 1024px) {
    .bt-draws { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
}
