/* ===== 色票：暗色舞台（預設）/ 淺色 ===== */
:root {
    --bg: #0a0f1e;
    --bg-2: #1a2344;
    --surface: rgba(20, 27, 52, 0.82);
    --surface-solid: #141b34;
    --surface-2: rgba(255, 255, 255, 0.05);
    --border: rgba(255, 255, 255, 0.09);
    --text: #f4f5f8;
    --muted: #98a2b8;
    --accent: #ff8a1f;
    --accent-2: #ffd23f;
    --accent-ink: #1c1204;
    --success: #2fd07a;
    --danger: #ff5c5c;
    --warn: #ffb020;
    --shadow: 0 12px 36px rgba(0, 0, 0, 0.45);
    --scrim: rgba(3, 6, 15, 0.55);
    /* canvas 用色 */
    --ring-rgb: 255, 138, 31;
    --verify-rgb: 47, 208, 122;
    --cell-border: #0a0f1e;
    --cell-ink: #10131c;
    --center-halo: rgba(10, 15, 30, 0.92);
    --center-stroke: #f4f5f8;
    --font: "Noto Sans TC", "Microsoft JhengHei", "微軟正黑體", sans-serif;
}
:root[data-theme="light"] {
    --bg: #f3efe6;
    --bg-2: #fffaf0;
    --surface: rgba(255, 255, 255, 0.9);
    --surface-solid: #ffffff;
    --surface-2: rgba(0, 0, 0, 0.04);
    --border: rgba(0, 0, 0, 0.1);
    --text: #1d2233;
    --muted: #667085;
    --accent: #e46f00;
    --accent-2: #f2b600;
    --accent-ink: #1c1204;
    --success: #179c55;
    --danger: #d63b3b;
    --warn: #c77c00;
    --shadow: 0 12px 30px rgba(60, 40, 10, 0.15);
    --scrim: rgba(30, 25, 15, 0.35);
    --ring-rgb: 228, 111, 0;
    --verify-rgb: 23, 156, 85;
    --cell-border: #ffffff;
    --cell-ink: #10131c;
    --center-halo: rgba(255, 255, 255, 0.95);
    --center-stroke: #1d2233;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
    margin: 0;
    font-family: var(--font);
    color: var(--text);
    background: radial-gradient(ellipse 70% 60% at 50% 48%, var(--bg-2), var(--bg) 75%), var(--bg);
    background-color: var(--bg);
    overflow: hidden;
    display: grid;
    grid-template-rows: auto 1fr auto;
}
button { font-family: inherit; }
[hidden] { display: none !important; }
kbd {
    font-family: inherit; font-size: 11px; padding: 1px 6px; border-radius: 4px;
    border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
}

/* ===== 頂部列 ===== */
.topbar {
    display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
    gap: 16px; padding: 14px 20px 6px; position: relative; z-index: 5;
}
.brand-eyebrow { font-size: 13px; color: var(--muted); font-weight: 700; letter-spacing: 0.08em; }
.brand-title { font-size: 26px; font-weight: 900; margin: 2px 0 0; line-height: 1.1; }
.top-left { display: flex; align-items: center; gap: 14px; min-width: 0; }
.brand { min-width: 0; }
.edge-tab {
    position: fixed; left: 0; top: 50%; transform: translateY(-50%); z-index: 20;
    display: flex; flex-direction: column; align-items: center; line-height: 1.3; padding: 12px 8px; cursor: pointer;
    font-family: inherit; font-size: 14px; font-weight: 900;
    background: var(--surface); color: var(--text); border: 1px solid var(--border); border-left: none;
    border-radius: 0 12px 12px 0; box-shadow: var(--shadow); transition: padding 0.2s, color 0.2s;
}
.edge-tab:hover { padding-left: 11px; color: var(--accent); }
.edge-arrow { font-size: 20px; line-height: 1; margin-top: 4px; }
body.ui-hidden .edge-tab { display: none; }
.brand-title { color: var(--accent); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand-eyebrow { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.text-field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); font-weight: 700; margin-bottom: 10px; }

.prize-card {
    background: var(--surface); border: 1px solid var(--border); border-radius: 18px;
    padding: 10px 32px 12px; text-align: center; min-width: min(40vw, 520px);
    box-shadow: var(--shadow); backdrop-filter: blur(8px);
}
.prize-label { font-size: 13px; color: var(--muted); font-weight: 700; letter-spacing: 0.06em; }
.prize-name {
    font-size: clamp(22px, 2.8vw, 40px); font-weight: 900; line-height: 1.25; margin-top: 2px;
    color: var(--accent-2);
}
:root[data-theme="light"] .prize-name { color: var(--accent); }

.top-right { justify-self: end; display: flex; gap: 8px; white-space: nowrap; align-items: center; }
.stat {
    display: flex; flex-direction: column; align-items: flex-end; padding: 4px 14px;
    border-right: 1px solid var(--border); margin-right: 4px;
}
.stat-label { font-size: 12px; color: var(--muted); font-weight: 700; white-space: nowrap; }
.stat-value { font-size: 26px; font-weight: 900; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat-value small { font-size: 13px; color: var(--muted); font-weight: 700; margin-left: 2px; }
.icon-btn {
    height: 40px; min-width: 40px; padding: 0 12px; border-radius: 12px; cursor: pointer;
    border: 1px solid var(--border); background: var(--surface); color: var(--text);
    font-size: 14px; font-weight: 700; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
    transition: background 0.2s, border-color 0.2s;
}
.icon-btn:hover { border-color: var(--accent); }
.icon-btn .badge {
    background: var(--accent); color: var(--accent-ink); border-radius: 999px;
    font-size: 11px; padding: 0 6px; line-height: 18px;
}

/* ===== 舞台 ===== */
.stage { position: relative; min-height: 0; }
#wheelCanvas { position: absolute; inset: 0; width: 100%; height: 100%; cursor: grab; }
#wheelCanvas:active { cursor: grabbing; }
.empty-state {
    position: absolute; inset: 0; display: grid; place-items: center; text-align: center;
    pointer-events: none;
}
.empty-state > div { pointer-events: auto; }
.empty-ball { font-size: 72px; line-height: 1; margin-bottom: 12px; }
.empty-title { font-size: 28px; font-weight: 900; margin: 0 0 6px; }
.empty-sub { color: var(--muted); margin: 0 0 20px; }
.empty-actions { display: flex; gap: 10px; justify-content: center; }

/* ===== 底部列 ===== */
.bottombar {
    display: flex; justify-content: center; align-items: center; position: relative;
    padding: 8px 20px 22px; z-index: 5;
}
.action-btn {
    min-width: 300px; padding: 18px 44px; font-size: 24px; font-weight: 900;
    border-radius: 999px; cursor: pointer; letter-spacing: 0.04em;
    border: 2px solid transparent; transition: transform 0.12s, opacity 0.2s, box-shadow 0.2s;
}
.action-btn:active:not(:disabled) { transform: scale(0.96); }
.action-btn.go {
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    color: var(--accent-ink); box-shadow: 0 10px 32px rgba(var(--ring-rgb), 0.45);
}
.action-btn.warm { background: transparent; color: var(--accent); border-color: var(--accent); }
.action-btn.idle { background: var(--surface); color: var(--muted); border-color: var(--border); }
.action-btn:disabled { cursor: not-allowed; opacity: 0.6; box-shadow: none; }
.shortcut-hint {
    position: absolute; right: 20px; bottom: 26px; font-size: 12px; color: var(--muted);
    display: flex; gap: 10px;
}

body.ui-hidden .topbar, body.ui-hidden .bottombar { display: none; }

/* ===== 通用按鈕 ===== */
.btn {
    padding: 10px 16px; font-size: 15px; font-weight: 700; border-radius: 10px; cursor: pointer;
    border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
    transition: border-color 0.2s, filter 0.2s;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn.block { width: 100%; }

/* ===== 抽屜 ===== */
.scrim {
    position: fixed; inset: 0; background: var(--scrim); z-index: 30;
    opacity: 0; pointer-events: none; transition: opacity 0.25s;
}
.scrim.open { opacity: 1; pointer-events: auto; }
.drawer {
    position: fixed; top: 0; bottom: 0; width: min(380px, 92vw); z-index: 40;
    background: var(--surface-solid); border: 1px solid var(--border); box-shadow: var(--shadow);
    display: flex; flex-direction: column; transition: transform 0.3s ease;
}
.drawer.left { left: 0; transform: translateX(-105%); border-radius: 0 18px 18px 0; }
.drawer.right { right: 0; transform: translateX(105%); border-radius: 18px 0 0 18px; }
.drawer.open { transform: none; }
.drawer-head {
    display: flex; justify-content: space-between; align-items: center;
    padding: 18px 20px 12px; border-bottom: 1px solid var(--border);
}
.drawer-head h2 { margin: 0; font-size: 20px; font-weight: 900; }
.drawer-body { padding: 16px 20px 20px; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 16px; }
.section-title { font-size: 13px; font-weight: 900; color: var(--muted); letter-spacing: 0.06em; margin: 0 0 8px; }

.dropzone {
    border: 2px dashed var(--border); border-radius: 14px; padding: 18px; text-align: center;
    cursor: pointer; transition: border-color 0.2s, background 0.2s;
}
.dropzone:hover, .dropzone.drag { border-color: var(--accent); background: var(--surface-2); }
.dropzone strong { display: block; font-size: 16px; margin-bottom: 4px; }
.dropzone span { font-size: 13px; color: var(--muted); }
.link-btn { background: none; border: none; color: var(--accent); cursor: pointer; font-weight: 700; padding: 0; font-size: 13px; }

.summary-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.summary-cell { background: var(--surface-2); border-radius: 10px; padding: 8px; text-align: center; }
.summary-cell b { display: block; font-size: 22px; font-weight: 900; }
.summary-cell span { font-size: 12px; color: var(--muted); }
.summary-file { font-size: 12px; color: var(--muted); margin-top: 6px; word-break: break-all; }
.warn-list { margin: 8px 0 0; padding-left: 18px; font-size: 13px; color: var(--warn); }

.search {
    width: 100%; padding: 9px 12px; font-size: 14px; border-radius: 10px; font-family: inherit;
    border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
}
.search:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.verify-list { list-style: none; padding: 0; margin: 8px 0 0; max-height: 40vh; overflow-y: auto; }
.verify-item {
    display: flex; justify-content: space-between; align-items: center; gap: 8px;
    padding: 8px 10px; border-radius: 8px; cursor: pointer; font-size: 15px;
}
.verify-item:hover { background: var(--surface-2); }
.verify-item.highlight { background: rgba(var(--verify-rgb), 0.18); outline: 1px solid rgba(var(--verify-rgb), 0.6); }
.verify-item .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.verify-item .name { flex: 1; }
.verify-item .count { color: var(--muted); font-weight: 700; font-size: 13px; }
.muted-note { color: var(--muted); font-size: 13px; text-align: center; padding: 8px; }

.record-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.record-item {
    display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; align-items: center;
    padding: 10px 12px; border-radius: 12px; background: var(--surface-2);
}
.record-order {
    grid-row: span 2; width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center;
    background: var(--accent); color: var(--accent-ink); font-weight: 900; font-size: 14px;
}
.record-prize { font-size: 13px; color: var(--muted); font-weight: 700; }
.record-name { font-size: 18px; font-weight: 900; }
.record-name time { font-size: 12px; color: var(--muted); font-weight: 500; margin-left: 6px; }
.drawer-foot { padding: 14px 20px 20px; border-top: 1px solid var(--border); display: flex; gap: 8px; }
.drawer-foot .btn { flex: 1; }

.slider-row { display: grid; grid-template-columns: 1fr 1.2fr 42px; gap: 10px; align-items: center; font-size: 14px; margin-bottom: 10px; }
.slider-row input { width: 100%; accent-color: var(--accent); cursor: pointer; }
.slider-row output { text-align: right; color: var(--accent); font-weight: 900; font-variant-numeric: tabular-nums; }
.seg { display: flex; gap: 6px; }
.seg .btn { flex: 1; }
.seg .btn[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }

/* ===== 中獎揭曉 ===== */
.reveal {
    position: fixed; inset: 0; z-index: 60; display: grid; place-items: center;
    background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0.35), rgba(0, 0, 0, 0.7));
    opacity: 0; pointer-events: none; transition: opacity 0.35s;
}
:root[data-theme="light"] .reveal { background: radial-gradient(ellipse at center, rgba(255, 250, 240, 0.55), rgba(40, 30, 10, 0.55)); }
.reveal.open { opacity: 1; pointer-events: auto; }
.reveal-card {
    text-align: center; padding: 36px 56px 32px; border-radius: 28px; max-width: min(90vw, 900px);
    background: var(--surface-solid); border: 2px solid var(--accent); box-shadow: 0 0 80px rgba(var(--ring-rgb), 0.45);
    transform: scale(0.85); transition: transform 0.45s cubic-bezier(0.2, 1.4, 0.4, 1);
}
.reveal.open .reveal-card { transform: scale(1); }
.reveal-eyebrow { font-size: 16px; font-weight: 900; color: var(--muted); letter-spacing: 0.2em; }
.reveal-prize { font-size: clamp(22px, 3vw, 36px); font-weight: 900; margin-top: 8px; }
.reveal-name {
    font-size: clamp(64px, 11vw, 160px); font-weight: 900; line-height: 1.1; margin: 12px 0 24px;
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    -webkit-background-clip: text; background-clip: text; color: transparent;
    word-break: break-all;
}
.reveal-card .btn { font-size: 20px; padding: 14px 36px; border-radius: 999px; }

/* ===== 結束畫面 ===== */
.finale {
    position: fixed; inset: 0; z-index: 55; display: grid; place-items: center; padding: 16px;
    background: var(--scrim); backdrop-filter: blur(6px);
    opacity: 0; pointer-events: none; transition: opacity 0.35s;
}
.finale.open { opacity: 1; pointer-events: auto; }
.finale-card {
    position: relative; width: min(820px, 100%); max-height: 100%; display: flex; flex-direction: column;
    text-align: center; padding: 32px 36px 28px; border-radius: 28px;
    background: var(--surface-solid); border: 2px solid var(--accent); box-shadow: 0 0 80px rgba(var(--ring-rgb), 0.35);
}
.finale-close { position: absolute; top: 16px; right: 16px; }
.finale-title { font-size: clamp(32px, 4.5vw, 56px); font-weight: 900; margin: 6px 0 4px; }
.finale-sub { color: var(--muted); margin: 0 0 20px; }
.finale-list {
    list-style: none; padding: 0; margin: 0 0 24px; overflow-y: auto; min-height: 0;
    display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; text-align: left;
}
.finale-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.finale-actions .btn { font-size: 17px; padding: 12px 22px; border-radius: 999px; }

/* ===== 使用說明 ===== */
.help { z-index: 57; }
.help-card { text-align: left; border-color: var(--border); box-shadow: var(--shadow); padding: 28px 32px 24px; }
.help-title { font-size: 28px; font-weight: 900; margin: 0 0 12px; }
.help-body { overflow-y: auto; min-height: 0; padding-right: 8px; line-height: 1.7; }
.help-body section { margin-bottom: 18px; }
.help-body h3 { font-size: 16px; font-weight: 900; color: var(--accent); margin: 0 0 6px; }
.help-body ul, .help-body ol { margin: 0; padding-left: 22px; }
.help-body li { margin-bottom: 2px; }
.help-body code { background: var(--surface-2); padding: 1px 6px; border-radius: 4px; }
.help-body .link-btn { font-size: inherit; }
.help-dl { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 0; }
.help-dl dt { font-weight: 700; }
.help-dl dd { margin: 0; color: var(--muted); }
@media (max-width: 640px) { .help-dl { grid-template-columns: 1fr; } .help-dl dd { margin-bottom: 6px; } }

/* ===== 對話框 ===== */
.dialog {
    position: fixed; inset: 0; z-index: 70; display: grid; place-items: center; background: var(--scrim);
    opacity: 0; pointer-events: none; transition: opacity 0.2s;
}
.dialog.open { opacity: 1; pointer-events: auto; }
.dialog-card {
    width: min(460px, 92vw); background: var(--surface-solid); border: 1px solid var(--border);
    border-radius: 18px; padding: 22px 24px; box-shadow: var(--shadow);
}
.dialog-card h3 { margin: 0 0 8px; font-size: 20px; font-weight: 900; }
.dialog-card p { margin: 0 0 20px; color: var(--muted); white-space: pre-line; line-height: 1.6; }
.dialog-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }

/* ===== Toast ===== */
.toasts { position: fixed; bottom: 112px; left: 50%; transform: translateX(-50%); z-index: 80; display: flex; flex-direction: column-reverse; gap: 8px; align-items: center; pointer-events: none; }
.toast {
    padding: 10px 18px; border-radius: 12px; font-weight: 700; font-size: 15px; max-width: min(640px, 92vw);
    background: var(--surface-solid); border: 1px solid var(--border); border-left: 4px solid var(--accent);
    box-shadow: var(--shadow); opacity: 0; transform: translateY(8px); transition: opacity 0.25s, transform 0.25s;
}
.toast.show { opacity: 1; transform: none; }
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast.warn { border-left-color: var(--warn); }

@media (max-width: 1000px) {
    .topbar { grid-template-columns: 1fr auto; }
    .prize-card { grid-column: 1 / -1; grid-row: 2; min-width: 0; }
    .stat { display: none; }
    .shortcut-hint { display: none; }
    .action-btn { min-width: 0; width: 100%; max-width: 420px; font-size: 20px; }
}
@media (prefers-reduced-motion: reduce) {
    .drawer, .reveal, .reveal-card, .toast { transition: none; }
}
