:root {
    --bg: #fafafa;
    --surface: #ffffff;
    --surface-2: #f4f4f5;
    --text: #18181b;
    --muted: #71717a;
    --border: #e4e4e7;
    --accent: #18181b;
    --accent-text: #ffffff;
    --accent-soft: #f4f4f5;
    --brand: #7c3aed;
    --admin: #ea580c;
    --ok: #15803d;
    --ok-soft: #dcfce7;
    --warn: #a16207;
    --warn-soft: #fef3c7;
    --danger: #b91c1c;
    --danger-soft: #fee2e2;
    --radius: 10px;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.04);
    --mono: "Cascadia Code", "JetBrains Mono", "SF Mono", "Fira Code", Consolas, Menlo, monospace;
    --particle: 24 24 27;
    --seg-active: #18181b;
    --chart-bar: #52525b;
    --chart-bar-dim: #d4d4d8;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0f0f11;
        --surface: #18181b;
        --surface-2: #232327;
        --text: #f4f4f5;
        --muted: #a1a1aa;
        --border: #2a2a2f;
        --accent: #f4f4f5;
        --accent-text: #18181b;
        --accent-soft: #27272a;
        --brand: #a78bfa;
        --admin: #fb923c;
        --ok: #4ade80;
        --ok-soft: #14301f;
        --warn: #facc15;
        --warn-soft: #352d0e;
        --danger: #f87171;
        --danger-soft: #3b1717;
        --shadow: none;
        --particle: 244 244 245;
        --seg-active: #c4c4cc;
        --chart-bar: #a1a1aa;
        --chart-bar-dim: #3f3f46;
        color-scheme: dark;
    }
}

* { box-sizing: border-box; }
/* hidden 屬性一定要藏起來 (按鈕等元素自己的 display 會蓋掉瀏覽器預設) */
[hidden] { display: none !important; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 15px/1.55 system-ui, -apple-system, "Segoe UI", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
}

h1 { font-size: 1.4rem; margin: 0; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }
h2:not(:first-child) { margin-top: 1.5rem; }
code { background: var(--surface-2); padding: .1em .35em; border-radius: 4px; font-size: .9em; }
a { color: var(--accent); }

.muted { color: var(--muted); }
.small-text { font-size: .85rem; }
.hint { color: var(--muted); font-size: .88rem; margin: 0 0 1rem; }
.spacer { flex: 1; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.boot { padding: 2rem; color: var(--muted); }

/* 按鈕 */
button, .button {
    font: inherit;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    border-radius: 8px;
    padding: .5rem 1rem;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: .4rem;
}
button:hover:not(:disabled), .button:hover { border-color: var(--accent); }
button:disabled { opacity: .45; cursor: not-allowed; }
.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.primary:hover:not(:disabled) { filter: brightness(1.08); }
.secondary { background: var(--accent-soft); border-color: transparent; color: var(--accent); font-weight: 600; }
.ghost { background: transparent; }
.danger { color: var(--danger); }
.danger:hover:not(:disabled) { border-color: var(--danger); }
.small { padding: .25rem .65rem; font-size: .85rem; }
button:focus-visible, .button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* 表單 */
input, select, textarea {
    font: inherit;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: .5rem .65rem;
    width: 100%;
}
textarea { resize: vertical; }
input[type="checkbox"] { width: auto; accent-color: var(--accent); }
.form label { display: flex; flex-direction: column; gap: .3rem; margin-bottom: 1rem; font-weight: 500; }
.form label small, .check small { display: block; color: var(--muted); font-weight: 400; font-size: .82rem; }
.form label.check { flex-direction: row; align-items: flex-start; gap: .6rem; }
.form label.check input { margin-top: .3rem; }
.form label.switch { flex-direction: row; align-items: center; gap: .6rem; margin-bottom: 0; }
.form-actions { display: flex; align-items: center; justify-content: flex-end; gap: 1rem; flex-wrap: wrap; }
.form-actions .hint { margin: 0; flex: 1; min-width: 14rem; }
.inline-form { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: 1rem; }
.inline-form input { width: auto; flex: 1; min-width: 10rem; max-width: 18rem; }
label.inline { display: inline-flex; align-items: center; gap: .5rem; white-space: nowrap; color: var(--muted); }
label.inline select { width: auto; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 1rem; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 1rem; }
/* 功能設定頁首：實況主資料 + bot 開關 */
.channel-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem 2rem; flex-wrap: wrap; }
.channel-head h1 { margin: .1rem 0 .5rem; }
.owner-meta { display: flex; flex-wrap: wrap; gap: .25rem 1.5rem; margin: 0; }
.owner-meta div { display: flex; gap: .4rem; align-items: baseline; }
.owner-meta dt { color: var(--muted); font-size: .8rem; }
.owner-meta dd { margin: 0; font-weight: 500; overflow-wrap: anywhere; }
.channel-head-bot { display: flex; flex-direction: column; align-items: flex-end; gap: .35rem; }
.bot-mode-picker { display: inline-flex; align-items: center; gap: .5rem; font-size: .9rem; color: var(--muted); }
.bot-mode-picker select { width: auto; padding: .3rem .5rem; color: var(--text); }
.form h3 { font-size: .95rem; margin: 1.25rem 0 .6rem; color: var(--muted); font-weight: 600; }
.form h2 + h3 { margin-top: .5rem; }
@media (max-width: 760px) { .channel-head-bot { align-items: flex-start; } }

/* 頻道機器人選擇 (官方 / 自己的) */
.bot-table td { white-space: nowrap; }
.bot-table .segmented { flex-wrap: nowrap; }
.panel-head { display: flex; align-items: center; gap: .5rem 1.25rem; flex-wrap: wrap; margin-bottom: .75rem; }
.panel-head h2 { margin: 0; }

/* 儀表板：每次開台簽到人數 (長條圖) */
.chart-legend { display: flex; flex-wrap: wrap; gap: .35rem 1.25rem; font-size: .82rem; color: var(--muted); margin-bottom: .9rem; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: .4rem; vertical-align: -1px; background: var(--chart-bar); }
/* 舊版匯入的開台日：淡色 + 斜線，不只靠顏色區分 */
.swatch.imported, .bar.imported { background: repeating-linear-gradient(135deg, var(--chart-bar-dim) 0 3px, color-mix(in srgb, var(--chart-bar-dim) 45%, transparent) 3px 6px); }
.bar-chart { position: relative; height: 220px; }
.bar-grid { position: absolute; inset: 0 0 1.6rem 2.6rem; display: flex; flex-direction: column; justify-content: space-between; pointer-events: none; }
.grid-line { position: relative; border-top: 1px solid var(--border); }
.grid-line span { position: absolute; left: -2.6rem; top: -.55rem; width: 2.2rem; text-align: right; font-size: .72rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.bar-plot { position: absolute; inset: 0 0 0 2.6rem; display: flex; gap: 2px; }
.bar-col { position: relative; flex: 1; min-width: 0; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; padding-bottom: 1.6rem; border-radius: 4px; }
.bar-col:focus-visible { outline: 2px solid var(--accent); outline-offset: 0; }
.bar { width: 100%; max-width: 32px; min-height: 2px; border-radius: 4px 4px 0 0; background: var(--chart-bar); transition: background .12s; }
.bar-col:hover .bar:not(.imported), .bar-col:focus-visible .bar:not(.imported) { background: var(--text); }
.bar-value { font-size: .75rem; font-weight: 600; margin-bottom: .2rem; font-variant-numeric: tabular-nums; }
.bar-label { position: absolute; bottom: 0; left: 50%; transform: translateX(-50%); font-size: .72rem; color: var(--muted); white-space: nowrap; }
.chart-tip { position: absolute; top: -.4rem; z-index: 2; transform: translate(-50%, -100%); padding: .3rem .55rem; border-radius: 6px; background: var(--text); color: var(--bg); font-size: .8rem; white-space: nowrap; pointer-events: none; }
.chart-table { margin-top: 1rem; }
.chart-table summary { cursor: pointer; color: var(--muted); font-size: .85rem; }
.chart-table .table { margin-top: .5rem; }

/* 儀表板：排行榜 */
.leaderboards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem 2rem; }
.leaderboard h3 { margin: 0 0 .4rem; font-size: .9rem; font-weight: 600; color: var(--muted); }
.leaderboard ol { list-style: none; margin: 0; padding: 0; }
.leaderboard li { display: flex; align-items: center; gap: .75rem; padding: .45rem 0; border-bottom: 1px solid var(--border); }
.leaderboard li:last-child { border-bottom: 0; }
.rank { flex-shrink: 0; display: grid; place-items: center; width: 1.6rem; height: 1.6rem; border-radius: 6px; background: var(--surface-2); color: var(--muted); font-size: .8rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.rank.top1 { background: var(--text); color: var(--bg); }
.rank.top2, .rank.top3 { color: var(--text); box-shadow: inset 0 0 0 1px var(--muted); }
.leaderboard .who { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.leaderboard .score { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.leaderboard .score small { color: var(--muted); font-weight: 400; }
.bot-table td:nth-child(5) { white-space: normal; min-width: 10rem; }
.segmented.small label { padding: .25rem .7rem; font-size: .85rem; }
.dialog.wide { width: min(640px, calc(100vw - 2rem)); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.dialog-head h2 { margin: 0; }
.dialog-section { border-top: 1px solid var(--border); padding-top: 1rem; margin-top: 1rem; }
.own-bot-current { margin: 0; display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; }
.dialog-section h3 { font-size: 1rem; margin: 0 0 .5rem; }
.segmented { display: inline-flex; flex-wrap: wrap; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; align-self: flex-start; }
.segmented label { display: inline-flex; align-items: center; gap: .3rem; padding: .45rem .9rem; cursor: pointer; font-size: .9rem; }
.segmented label + label { border-left: 1px solid var(--border); }
.segmented label.active { background: var(--seg-active); color: var(--accent-text); font-weight: 600; }
.segmented label:not(.active):not(.disabled) { color: var(--muted); }
.segmented label:not(.active):not(.disabled):hover { color: var(--text); background: var(--surface-2); }
.segmented label.disabled { opacity: .5; cursor: not-allowed; }
.segmented input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.segmented label:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: -2px; }

/* Bot 開關 */
.switch { display: inline-flex; align-items: center; gap: .6rem; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch-track { position: relative; width: 52px; height: 28px; border-radius: 999px; background: var(--border); transition: background .15s; flex-shrink: 0; }
.switch-thumb { position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgb(0 0 0 / .3); transition: transform .15s; }
.switch input:checked + .switch-track { background: var(--ok); }
.switch input:checked + .switch-track.debug { background: var(--warn); }
.debug-panel { display: flex; align-items: center; justify-content: space-between; gap: 1rem 2rem; flex-wrap: wrap; border-color: var(--warn-soft); }
.debug-panel > div { flex: 1; min-width: 16rem; }
.debug-panel .hint { margin: 0; }
.switch input:checked + .switch-track .switch-thumb { transform: translateX(24px); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch input:disabled + .switch-track { opacity: .5; cursor: progress; }
.switch-label { font-weight: 600; min-width: 3.5em; }
.owner-card {display: flex; flex-wrap: wrap; gap: .5rem 2rem; margin: 0 0 1rem; padding: .75rem 1rem; background: var(--surface-2); border-radius: 8px; }
.owner-card div { min-width: 0; }
.owner-card dt { color: var(--muted); font-size: .8rem; }
.owner-card dd { margin: 0; font-weight: 500; overflow-wrap: anywhere; }
.form details { margin-bottom: 1rem; }
.form summary { cursor: pointer; color: var(--muted); font-size: .9rem; margin-bottom: .75rem; }
.checks { border: 0; padding: 0; margin: 0 0 1rem; display: flex; flex-wrap: wrap; gap: .25rem 1.25rem; }
.checks legend { font-weight: 500; margin-bottom: .4rem; padding: 0; }
.form .checks label.check { margin-bottom: 0; align-items: center; }
.form .checks label.check input { margin-top: 0; }

/* 外框 */
.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: .65rem 1.25rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; }
/* 手機才出現的選單按鈕 (三條線) */
.menu-button { display: none; place-items: center; width: 38px; height: 38px; padding: 0; border-radius: 10px; flex-shrink: 0; }
.menu-button span, .menu-button span::before, .menu-button span::after { display: block; width: 18px; height: 2px; border-radius: 2px; background: currentColor; }
.menu-button span { position: relative; }
.menu-button span::before, .menu-button span::after { content: ""; position: absolute; left: 0; }
.menu-button span::before { top: -6px; }
.menu-button span::after { top: 6px; }
.nav-backdrop[hidden] { display: none; }
#mode-toggle { flex-direction: column; align-items: center; gap: 0; line-height: 1.2; padding: .3rem .8rem; }
.mode-hint { font-size: .7rem; font-weight: 400; opacity: .75; }
.channel-picker select { width: auto; min-width: 12rem; padding: .35rem .6rem; }
/* 右上角：頭貼 + 名稱，滑過去 (或聚焦) 出現選單 */
.user-menu { position: relative; }
.user-chip { gap: .5rem; padding: .2rem .65rem .2rem .2rem; border-color: transparent; background: transparent; border-radius: 10px; font-weight: 600; font-size: .92rem; }
.user-menu:hover .user-chip, .user-menu:focus-within .user-chip { border-color: var(--border); background: var(--surface-2); }
.avatar { width: 28px; height: 28px; border-radius: 7px; object-fit: cover; border: 1px solid var(--border); flex-shrink: 0; }
.avatar-empty { display: grid; place-items: center; background: var(--surface-2); color: var(--muted); font-size: .8rem; }
.user-dropdown { position: absolute; right: 0; top: calc(100% + 6px); z-index: 20; min-width: 10rem; padding: .3rem; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 10px 30px -10px rgb(0 0 0 / .45); opacity: 0; visibility: hidden; transform: translateY(-4px); transition: opacity .12s, transform .12s, visibility .12s; }
/* 頭貼和選單之間的空隙也算在 hover 範圍，滑鼠移過去才不會關掉 */
.user-dropdown::before { content: ""; position: absolute; left: 0; right: 0; top: -8px; height: 8px; }
.user-menu:hover .user-dropdown, .user-menu:focus-within .user-dropdown { opacity: 1; visibility: visible; transform: none; }
.user-dropdown a { display: block; padding: .5rem .7rem; border-radius: 7px; color: var(--text); text-decoration: none; font-size: .9rem; white-space: nowrap; }
.user-dropdown a:hover, .user-dropdown a:focus-visible { background: var(--surface-2); }
.shell { display: grid; grid-template-columns: 200px minmax(0, 1fr); min-height: calc(100vh - 57px); }
.sidebar { padding: 1rem .75rem; border-right: 1px solid var(--border); display: flex; flex-direction: column; gap: .2rem; }
/* 側邊欄：第一層有圖示，子選項用樹狀線連到上層 */
.nav-row { position: relative; display: flex; align-items: center; }
.nav-item { display: flex; align-items: center; gap: .65rem; padding: .55rem .75rem; border-radius: 10px; color: var(--text); text-decoration: none; }
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }
.nav-item.top { flex: 1; font-weight: 500; }
.nav-item.top:hover, .nav-item.child:hover { background: var(--surface-2); }
.nav-item.top.active, .nav-item.top.in-group { background: var(--surface-2); font-weight: 600; }
.nav-toggle { position: absolute; right: .3rem; display: grid; place-items: center; width: 28px; height: 28px; padding: 0; border: 0; border-radius: 6px; background: transparent; color: var(--muted); }
.nav-toggle:hover:not(:disabled) { color: var(--text); background: var(--border); box-shadow: none; }
.nav-toggle svg { width: 16px; height: 16px; transition: transform .15s; }
.nav-group:not(.open) .nav-toggle svg { transform: rotate(-90deg); }
.nav-children { display: none; flex-direction: column; gap: .15rem; margin: .15rem 0 .35rem 1.35rem; padding-left: .85rem; }
.nav-group.open .nav-children { display: flex; }
.nav-item.child { position: relative; justify-content: space-between; padding: .45rem .75rem; color: var(--muted); font-size: .93rem; }
.nav-item.child svg { width: 16px; height: 16px; }
.nav-item.child.active { background: var(--surface-2); color: var(--text); font-weight: 600; }
/* 樹狀線：每個子選項畫一段彎到自己的線，不是最後一個就再往下接一段 */
.nav-item.child::before { content: ""; position: absolute; left: -.85rem; top: -.2rem; width: .7rem; height: calc(50% + .2rem); border-left: 1px solid var(--border); border-bottom: 1px solid var(--border); border-bottom-left-radius: 8px; }
.nav-item.child:not(:last-child)::after { content: ""; position: absolute; left: -.85rem; top: 50%; bottom: -.2rem; border-left: 1px solid var(--border); }
.content { padding: 1.5rem; max-width: 1100px; width: 100%; }
.page-head { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.25rem;
    margin-bottom: 1.25rem;
}

/* 統計卡片 */
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem 1.25rem; }
.stat-label { display: block; color: var(--muted); font-size: .85rem; }
.stat-value { font-size: 1.5rem; font-variant-numeric: tabular-nums; }

/* 表格 */
.toolbar { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; margin-bottom: 1rem; }
.toolbar input[type="search"] { flex: 1; min-width: 12rem; max-width: 22rem; }
.toolbar .inline-form { margin-bottom: 0; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th, .table td { padding: .55rem .6rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
.table th { color: var(--muted); font-weight: 500; font-size: .82rem; white-space: nowrap; }
.table tbody tr:hover { background: var(--surface-2); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .actions { text-align: right; }
.table .actions button { white-space: nowrap; }
.viewer-name { font-weight: 500; margin-right: .4rem; }
.empty-cell { text-align: center; color: var(--muted); padding: 2rem; }
.pager { display: flex; align-items: center; gap: .5rem; margin-top: .75rem; font-size: .88rem; }

/* 標籤 */
.badge {
    display: inline-block;
    padding: .05rem .5rem;
    border-radius: 999px;
    font-size: .75rem;
    background: var(--surface-2);
    color: var(--muted);
    margin-right: .35rem;
    white-space: nowrap;
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.status { font-size: .8rem; padding: .15rem .6rem; border-radius: 999px; white-space: nowrap; }
.status.on { background: var(--ok-soft); color: var(--ok); }
.status.off { background: var(--surface-2); color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; }
.chip { display: inline-flex; align-items: center; gap: .15rem; background: var(--surface-2); border-radius: 999px; padding: .15rem .3rem .15rem .7rem; font-size: .85rem; font-variant-numeric: tabular-nums; }
.chip-remove { border: 0; background: transparent; padding: 0 .35rem; font-size: 1rem; line-height: 1; color: var(--muted); }
.chip-remove:hover { color: var(--danger); }

/* 提示 */
.notice { border-radius: var(--radius); padding: .85rem 1rem; margin-bottom: 1.25rem; }
.notice.success { background: var(--ok-soft); color: var(--ok); }
.notice.error { background: var(--danger-soft); color: var(--danger); }
.notice.warn { background: var(--warn-soft); color: var(--warn); }
.notice.info { background: var(--surface-2); border: 1px solid var(--border); color: var(--text); }
/* 跳過目前贊助：直播中要一眼找到，做成醒目的紅色按鈕 */
.skip-button { justify-content: center; padding: .6rem 1.2rem; border-radius: 10px; border: 0; background: #dc2626; color: #fff; font-weight: 800; font-size: .95rem; box-shadow: 0 4px 14px rgb(0 0 0 / .25); }
.skip-button:hover { background: #b91c1c; color: #fff; }
.notice.info a { color: inherit; font-weight: 700; text-decoration: underline; text-underline-offset: 3px; }
.empty-state { color: var(--muted); padding: 3rem 1rem; text-align: center; }
.error-text { color: var(--danger); }

#toasts { position: fixed; right: 1rem; bottom: 1rem; display: flex; flex-direction: column; gap: .5rem; z-index: 100; }
.toast { background: var(--text); color: var(--bg); padding: .65rem 1rem; border-radius: 8px; box-shadow: 0 4px 16px rgb(0 0 0 / .2); max-width: 22rem; }
.toast.success { background: var(--ok); color: #fff; }
.toast.error { background: var(--danger); color: #fff; }

/* 對話框 */
.dialog {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    padding: 1.5rem;
    width: min(560px, calc(100vw - 2rem));
}
.dialog::backdrop { background: rgb(0 0 0 / .45); }
.dialog h2 { margin-bottom: .2rem; }
.dialog details { margin: .25rem 0 1rem; }
.dialog summary { cursor: pointer; color: var(--muted); font-size: .9rem; }
.dialog-actions { display: flex; gap: .5rem; align-items: center; }

/* 背景粒子 (particles.js 畫的 canvas) */
.particles { position: fixed; inset: 0; z-index: -1; width: 100%; height: 100%; pointer-events: none; }

/* 登入 */
.login { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login-card {
    background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow);
    padding: 2.5rem 2rem; text-align: center; max-width: 380px; width: 100%;
}
.login-tag { font-family: var(--mono); font-size: .75rem; letter-spacing: .08em; color: var(--muted); margin: 0 0 .75rem; }
.login-title { font-family: var(--mono); font-weight: 700; font-size: 2.2rem; letter-spacing: .04em; margin: 0 0 .75rem; }
.login-cursor { color: var(--brand); animation: login-blink 1.1s steps(1) infinite; }
@keyframes login-blink { 50% { opacity: 0; } }
.login-card .button { margin-top: 1rem; }
@media (prefers-reduced-motion: reduce) {
    .login-cursor { animation: none; }
}

/* 外框細節 */
.brand { font-family: var(--mono); letter-spacing: .04em; color: var(--text); text-decoration: none; }
.brand::after { content: "_"; color: var(--brand); }
/* 頂端一條細線：主播模式紫色，管理模式橘色 (一眼看得出權限比較大) */
.topbar { box-shadow: inset 0 2px 0 var(--brand); }
.topbar.admin-mode { box-shadow: inset 0 2px 0 var(--admin); }
.topbar.admin-mode .brand::after { content: "_ · 管理模式"; color: var(--admin); font-family: system-ui, "Noto Sans TC", "Microsoft JhengHei", sans-serif; font-weight: 600; letter-spacing: 0; }
.feature-link { display: flex; flex-direction: column; gap: .2rem; padding: .75rem 1rem; border: 1px solid var(--border); border-radius: 8px; color: var(--text); text-decoration: none; }
.feature-link:hover { border-color: var(--muted); background: var(--surface-2); }
.feature-links { display: grid; gap: .6rem; }
.feature-links h2 { margin-bottom: .15rem; }

/* 簽到動畫：樣式選擇 */
.style-options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .9rem; }
.style-option { position: relative; display: grid; gap: .35rem; padding: .9rem; border: 1px solid var(--border); border-radius: 12px; cursor: pointer; }
.style-option:hover { border-color: var(--muted); }
.style-option.active { border-color: var(--text); box-shadow: inset 0 0 0 1px var(--text); }
.style-option input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.style-option:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.style-option.active strong::after { content: "  ✓ 使用中"; color: var(--ok); font-size: .82rem; }
/* 樣式的小示意圖 (假的直播畫面 + 卡片的位置) */
/* 樣式的小示意圖：假的直播畫面 + 縮小版的實際卡片 (尺寸用 cqw，跟著示意圖大小縮放) */
.style-mock { position: relative; display: block; aspect-ratio: 16 / 9; border-radius: 8px; overflow: hidden; margin-bottom: .2rem; container-type: inline-size; color: #f4f4f5;
    background: radial-gradient(120% 90% at 20% 0%, #3a2d5c 0%, transparent 55%), radial-gradient(90% 80% at 100% 100%, #1d3b4f 0%, transparent 60%), linear-gradient(160deg, #1c1b26, #121218); }
.style-mock > span { position: absolute; bottom: 8%; line-height: 1.25; }
.m-card { right: 7%; display: grid; gap: .6cqw; padding: 2.4cqw 9cqw 2.4cqw 3.4cqw; border-radius: 2cqw; background: rgb(20 20 24 / .92); border: 1px solid rgb(255 255 255 / .12); box-shadow: 0 2cqw 4cqw rgb(0 0 0 / .45); }
.m-card b { font-size: 4cqw; }
.m-card small { font-size: 2.9cqw; color: rgb(255 255 255 / .7); }
.m-card em { position: absolute; right: -3.2cqw; top: 50%; width: 10cqw; height: 10cqw; margin-top: -5cqw; display: grid; place-items: center; border: .7cqw solid #d6402b; border-radius: 1.6cqw; color: #d6402b; font: 900 5.4cqw "DFKai-SB", "Kaiti TC", serif; font-style: normal; transform: rotate(-12deg); }
.m-timecard { right: 5%; width: 44%; padding: 2cqw 2.6cqw 2.4cqw; border-radius: 1.4cqw; background: #efe6cf; color: #33291c; font: 500 2.5cqw var(--mono); box-shadow: 0 2cqw 4cqw rgb(0 0 0 / .5); display: grid; }
.m-timecard b { display: flex; justify-content: space-between; font: 700 2.8cqw var(--sans, sans-serif); border-bottom: .4cqw solid #33291c; padding-bottom: .9cqw; margin-bottom: .4cqw; }
.m-timecard b small { font: 500 2.2cqw var(--mono); color: #6f604a; }
.m-timecard > span { display: grid; grid-template-columns: 7cqw 1fr .1fr 1fr; padding: .6cqw 0; border-bottom: 1px dashed rgb(51 41 28 / .3); min-height: 3.6cqw; color: #5b3fd1; }
.m-timecard > span i { font-style: normal; color: #8b7a5f; }
.m-timecard > span.now { background: rgb(91 63 209 / .1); font-weight: 700; }
.m-bingo { right: 5%; width: 30%; padding: 1.8cqw; border-radius: 1.6cqw; background: #fff7e6; color: #3b2f22; box-shadow: 0 2cqw 4cqw rgb(0 0 0 / .5); display: grid; gap: 1.4cqw; }
.m-bingo b { display: flex; justify-content: space-between; align-items: center; font-size: 2.8cqw; }
.m-bingo b small { font: 900 2.8cqw var(--mono); color: #c2410c; letter-spacing: .06em; }
.m-cells { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: .6cqw; }
.m-cells i { aspect-ratio: 1; border-radius: .7cqw; background: #f1e3c4; display: grid; place-items: center; font: 900 2.4cqw serif; font-style: normal; }
.m-cells i.on { background: #e8573f; }
.m-cells i.free { background: #3b2f22; color: #fff7e6; }
.m-fortune { right: 5%; display: flex; align-items: flex-end; gap: 2cqw; filter: drop-shadow(0 1.6cqw 3cqw rgb(0 0 0 / .5)); }
.m-fo-tube { position: relative; width: 9cqw; height: 15cqw; border-radius: 1cqw 1cqw 1.6cqw 1.6cqw; background: linear-gradient(90deg, #7c4a1e, #c08443 35%, #d9a15c 50%, #b3773a 70%, #6b3d16); border: .3cqw solid #4a2a0c; }
.m-fo-tube i { position: absolute; left: 50%; bottom: 70%; z-index: -1; width: 2.4cqw; height: 11cqw; margin-left: -1.2cqw; padding-top: .6cqw; border-radius: .4cqw .4cqw 0 0; background: #f0d49c; color: #7f1d1d; font: 900 1.4cqw serif; font-style: normal; writing-mode: vertical-rl; display: flex; justify-content: center; }
.m-fo-tube em { position: absolute; left: 50%; top: 22%; transform: translateX(-50%); padding: .8cqw .4cqw; background: #b91c1c; color: #fff7ed; font: 900 1.8cqw serif; font-style: normal; writing-mode: vertical-rl; }
.m-fo-slip { width: 30cqw; padding: 1.8cqw 2cqw; display: grid; justify-items: center; gap: .6cqw; text-align: center; background: #fffaf0; color: #3b2a1a; border: .4cqw solid #dc2626; }
.m-fo-slip small { font-size: 1.9cqw; color: #8a6f55; }
.m-fo-slip small:first-child { color: #dc2626; letter-spacing: .3em; font-weight: 700; }
.m-fo-slip b { font: 900 7.5cqw/1 serif; color: #dc2626; }
.m-fo-slip .m-fo-name { font-size: 2.6cqw; font-weight: 700; }

/* 贊助動畫模板的示意圖 (置中在畫面上方，圖片用目前上傳的或愛心) */
.style-options-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.style-mock > [class^="m-d-"] { left: 50%; bottom: auto; top: 50%; transform: translate(-50%, -50%); }
.style-mock img { display: block; object-fit: contain; }
.m-d-polaroid { display: flex; align-items: center; gap: 4cqw; }
.m-pl-photo { flex: none; padding: 3cqw 1.8cqw 7cqw; background: #fbfaf6; border-radius: .6cqw; transform: rotate(-4deg); box-shadow: 0 1.4cqw 3cqw rgb(0 0 0 / .5); }
.m-pl-photo img { width: 20cqw; height: 27cqw; object-fit: cover; background: #222; }
.m-pl-note { display: grid; gap: 1cqw; text-align: left; white-space: nowrap; }
.m-pl-note b { font-size: 4cqw; }
.m-pl-note i, .m-d-simple i { font-style: normal; color: #ffd84d; }
.m-pl-note strong { font: 900 5cqw var(--mono, monospace); }
.m-pl-note em { font-style: normal; font-weight: 700; font-size: 3cqw; padding: 1cqw 2cqw; background: #fff7b0; color: #3b2f00; transform: rotate(2deg); }
.m-d-simple { display: grid; justify-items: center; gap: 1.6cqw; text-align: center; white-space: nowrap; text-shadow: 0 0 .3cqw #000, 0 .4cqw 1cqw rgb(0 0 0 / .8); }
.m-d-simple img { width: 20cqw; height: 20cqw; }
.m-d-simple b { font-size: 4.6cqw; }
.m-d-simple strong { color: #ff7aa8; font-family: var(--mono, monospace); }
.m-d-simple em { font-style: normal; font-weight: 700; font-size: 3.4cqw; }
.m-d-character { display: flex; align-items: center; gap: 2cqw; }
.m-d-character img { width: 24cqw; height: 28cqw; object-position: bottom; }
.m-ch-bubble { display: grid; justify-items: start; gap: .8cqw; padding: 2.4cqw 3.4cqw; border-radius: 3cqw; background: #fff; color: #18181b; white-space: nowrap; }
.m-ch-bubble b { font-size: 3.6cqw; color: #7c3aed; }
.m-ch-bubble strong { padding: .3cqw 2.4cqw; border-radius: 99px; background: #7c3aed; color: #fff; font: 900 4.6cqw var(--mono, monospace); }
.m-ch-bubble em { font-style: normal; font-weight: 700; font-size: 3cqw; }

/* 贊助圖片上傳 */
.donate-image { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.donate-image-preview { width: 96px; height: 96px; object-fit: contain; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--border); }
.donate-image-info { display: grid; gap: .5rem; }

/* 簽到動畫：預覽 (iframe 裡就是 OBS 用的頁面) */
.preview-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.overlay-preview { aspect-ratio: 16 / 9; max-width: 100%; border-radius: 10px; overflow: hidden; background: radial-gradient(120% 90% at 20% 0%, #3a2d5c 0%, transparent 55%), radial-gradient(90% 80% at 100% 100%, #1d3b4f 0%, transparent 60%), linear-gradient(160deg, #1c1b26, #121218); }
.overlay-preview iframe { display: block; width: 100%; height: 100%; border: 0; background: transparent; }
.obs-steps { margin: 0 0 1rem; padding-left: 1.3rem; display: grid; gap: .3rem; }

/* OBS 畫面：版面編輯器 (底下是實際的 OBS 頁面預覽，上面疊可以拖曳的元件框) */
.layout-canvas { position: relative; aspect-ratio: 16 / 9; max-width: 100%; border-radius: 10px; user-select: none; touch-action: none; outline: 2px solid rgb(255 255 255 / .25); outline-offset: 0;
    background: radial-gradient(120% 90% at 20% 0%, #3a2d5c 0%, transparent 55%), radial-gradient(90% 80% at 100% 100%, #1d3b4f 0%, transparent 60%), linear-gradient(160deg, #1c1b26, #121218); }
.layout-canvas iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; border-radius: 10px; background: transparent; pointer-events: none; }
/* 元件框可以拖到預覽外面一部分，超出預覽畫面的地方不顯示 (跟 OBS 一樣) */
.layout-boxes { position: absolute; inset: 0; overflow: hidden; border-radius: 10px; }
.layout-panel { overflow: clip; }
.layout-box { position: absolute; border: 2px dashed rgb(255 255 255 / .55); border-radius: 6px; background: rgb(167 139 250 / .08); cursor: move; }
.layout-box:hover, .layout-box:focus-visible, .layout-box.dragging { border-color: #fff; border-style: solid; background: rgb(167 139 250 / .16); outline: none; }
.layout-box.off { border-color: rgb(255 255 255 / .2); background: rgb(0 0 0 / .25); }
.layout-box .label { position: absolute; left: 6px; top: 6px; padding: 2px 8px; border-radius: 99px; background: rgb(0 0 0 / .7); color: #fff; font-size: .75rem; font-weight: 600; white-space: nowrap; pointer-events: none; }
.layout-box .size { position: absolute; right: 22px; bottom: 4px; color: rgb(255 255 255 / .8); font: 600 .7rem var(--mono); pointer-events: none; }
.layout-box .handle { position: absolute; right: -2px; bottom: -2px; width: 16px; height: 16px; border-radius: 4px 0 6px 0; background: #fff; cursor: nwse-resize; }
.widget-list { display: grid; gap: .25rem; margin-top: .9rem; }
.widget-row { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; padding: .45rem 0; border-bottom: 1px solid var(--border); }
.widget-row:last-child { border-bottom: 0; }
.widget-row .switch-label { min-width: 6em; }
.widget-row button { margin-left: auto; }
.sub-title { font-size: .95rem; margin: 1.2rem 0 .3rem; }
.upload-row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin-bottom: .6rem; }
.upload-row input[type="file"] { width: auto; flex: 1; min-width: 12rem; }
.sound-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .3rem; }
.sound-list li { display: flex; align-items: center; gap: .6rem; padding: .4rem 0; border-bottom: 1px solid var(--border); overflow-wrap: anywhere; }
.sound-list li:last-child { border-bottom: 0; }
.donate-message { max-width: 22rem; overflow-wrap: anywhere; }
.provider-form { margin-top: 1.1rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.form .stage-toggle label { flex-direction: row; margin-bottom: 0; font-weight: 500; }
.stage-toggle label.active { background: var(--admin); border-color: var(--admin); color: #fff; }
.provider-form h3 { margin: 0; display: flex; align-items: center; gap: .5rem; color: var(--text); }
.copy-row { display: flex; gap: .5rem; margin-bottom: .75rem; }
.copy-row input { flex: 1; min-width: 0; font-family: var(--mono); font-size: .82rem; }
a:not(.button):not(.nav-item) { text-underline-offset: 2px; }
.stat-value { font-weight: 600; }
.table .num { font-variant-numeric: tabular-nums; }
button, .button, input, select, textarea, .nav-item { transition: border-color .15s, background .15s; }
.content > * { animation: page-in .2s ease-out; }
@keyframes page-in { from { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .content > * { animation: none; } }

@media (max-width: 760px) {
    .topbar { flex-wrap: wrap; padding: .6rem 1rem; gap: .5rem; }
    .channel-picker { order: 5; width: 100%; }
    .channel-picker select { width: 100%; }
    .shell { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; }
    /* 側邊欄收成左邊滑出來的抽屜，樹狀選單照原本的樣子 */
    .menu-button { display: grid; }
    /* 上面一排擠不下：名字、「切回主播」小字、「· 管理模式」字樣先藏起來 (管理模式還是有橘色那條線和按鈕) */
    .user-name, .mode-hint { display: none; }
    .topbar.admin-mode .brand::after { content: "_"; }
    .sidebar {
        position: fixed; top: 0; bottom: 0; left: 0; z-index: 40; width: min(280px, 82vw); overflow-y: auto;
        padding: 1rem .75rem calc(1rem + env(safe-area-inset-bottom, 0px)); background: var(--surface);
        box-shadow: 0 0 40px rgb(0 0 0 / .45); transform: translateX(-105%); transition: transform .22s ease; visibility: hidden;
    }
    .sidebar.open { transform: none; visibility: visible; }
    .nav-backdrop { position: fixed; inset: 0; z-index: 35; background: rgb(0 0 0 / .45); }
    .content { padding: 1rem; }
    .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .grid3, .grid2, .leaderboards, .style-options { grid-template-columns: 1fr; }
}
/* 感謝訊息 (notify-editor.js)：開關關著只顯示一行 */
.notify-row { padding: .75rem 0; border-top: 1px solid var(--border); }
.notify-row:first-of-type { border-top: 0; }
.notify-row-head { display: flex; align-items: center; gap: .5rem 1rem; flex-wrap: wrap; }
.notify-row-head h3 { margin: 0; color: var(--text); min-width: 5em; font-size: .95rem; }
.notify-row-head + * { margin-top: .9rem; }
.notify-row .hint code { margin-right: .15rem; }
.chat-preview { margin: 0 0 1rem; padding: .55rem .75rem; border-radius: 8px; background: var(--surface-2); font-size: .9rem; overflow-wrap: anywhere; }
.form .segmented label, .form label.switch { flex-direction: row; margin-bottom: 0; }
.webhook-row { display: flex; align-items: center; gap: .5rem; font-weight: 400; }
.webhook-row input { flex: 1; min-width: 0; }
.switch.locked { cursor: not-allowed; opacity: .55; }
.embed-preview { display: grid; gap: .3rem; margin: 0 0 1rem; padding: .65rem .85rem; border-radius: 6px; border-left: 4px solid var(--border); background: var(--surface-2); font-size: .9rem; overflow-wrap: anywhere; }
.embed-preview .embed-footer { color: var(--muted); font-size: .75rem; }
