/* ════════════════════════════════════════
   ChatFunny — SaaS Dashboard UI
   ════════════════════════════════════════ */

* { margin: 0; padding: 0; box-sizing: border-box; }

/* ── 常用工具快速列 (live page) ── */
.fav-bar {
    background: #fff;
    border: 1px solid #f0f2f5;
    border-radius: 12px;
    box-shadow: 0 1px 2px rgba(15,23,42,0.04);
    padding: 10px 16px;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}
.fav-label { font-size: 12px; font-weight: 700; color: #64748b; white-space: nowrap; }
.fav-chips { display: flex; flex-wrap: wrap; gap: 8px; flex: 1; }
.fav-empty { font-size: 12px; color: #94a3b8; }
.fav-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    background: linear-gradient(135deg, #f0f4ff, #faf5ff);
    border: 1px solid #e0e7ff;
    color: #0f172a;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}
.fav-chip:hover {
    background: linear-gradient(135deg, #2563eb, #8b5cf6);
    color: #fff;
    border-color: transparent;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(99,102,241,0.3);
}
.fav-chip-icon { font-size: 15px; }

/* ── Tool card 星號 ── */
.tool-card { position: relative; }
.fav-star {
    position: absolute;
    top: 12px; right: 12px;
    background: transparent;
    border: none;
    font-size: 20px;
    color: #cbd5e1;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 6px;
    transition: all 0.15s;
    line-height: 1;
}
.fav-star:hover { background: #fef3c7; color: #f59e0b; transform: scale(1.15); }
.fav-star.on { color: #f59e0b; }

:root {
    --bg: #f6f7fb;
    --sidebar: #0f1419;
    --sidebar-hover: #1a2028;
    --sidebar-active: #2563eb;
    --card: #ffffff;
    --border: #e4e6eb;
    --border-light: #f0f2f5;
    --text: #0f172a;
    --text-dim: #64748b;
    --text-mute: #94a3b8;
    --primary: #2563eb;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --purple: #8b5cf6;
    --pink: #ec4899;
    --orange: #f97316;
    --shadow-sm: 0 1px 2px rgba(15,23,42,0.04);
    --shadow:    0 1px 3px rgba(15,23,42,0.08), 0 1px 2px rgba(15,23,42,0.04);
    --shadow-lg: 0 10px 30px rgba(15,23,42,0.12);
    --radius: 12px;
    --radius-sm: 8px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", "PingFang TC", "Noto Sans TC", sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    display: flex;
    font-size: 14px;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; }

/* ══════════════ Sidebar ══════════════ */
.sidebar {
    width: 220px;
    background: var(--sidebar);
    color: #cbd5e1;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    border-right: 1px solid #1e293b;
}
.brand {
    padding: 20px 22px;
    border-bottom: 1px solid #1e293b;
    display: flex;
    align-items: center;
    gap: 10px;
}
.brand-logo {
    width: 32px; height: 32px;
    background: linear-gradient(135deg, #ff2d55, #f97316);
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-weight: 900; font-size: 15px;
}
.brand-name { color: #fff; font-weight: 800; font-size: 16px; letter-spacing: -0.2px; }
.brand-tag { font-size: 10px; color: #64748b; margin-top: 2px; letter-spacing: 1px; text-transform: uppercase; }

.nav-group-label {
    padding: 16px 22px 6px;
    font-size: 10px;
    color: #475569;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    font-weight: 700;
}
.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 22px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    color: #94a3b8;
    border-left: 3px solid transparent;
    transition: all 0.15s;
}
.nav-item:hover { background: var(--sidebar-hover); color: #e2e8f0; }
.nav-item.active {
    background: linear-gradient(90deg, rgba(37,99,235,0.15), transparent);
    color: #fff;
    border-left-color: var(--primary);
}
.nav-icon {
    width: 18px; height: 18px;
    display: flex; align-items: center; justify-content: center;
    font-size: 15px;
}
.nav-spacer { flex: 1; }
.sidebar-footer {
    padding: 14px 22px;
    border-top: 1px solid #1e293b;
    font-size: 11px;
    color: #475569;
}
.sidebar-footer .live-dot {
    display: inline-block;
    width: 8px; height: 8px;
    border-radius: 50%;
    background: #ef4444;
    margin-right: 6px;
    animation: pulse 1.5s infinite;
}
@keyframes pulse { 0%,100%{opacity:1;} 50%{opacity:0.3;} }

/* ══════════════ Main Layout ══════════════ */
.main-wrap {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ── Topbar ── */
.topbar {
    background: var(--card);
    border-bottom: 1px solid var(--border);
    padding: 12px 24px;
    display: flex;
    align-items: center;
    gap: 20px;
    min-height: 64px;
}
.topbar-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.3px;
}
.topbar-title span.sub { font-size: 12px; color: var(--text-mute); font-weight: 500; margin-left: 8px; }

.kpi-row { display: flex; gap: 18px; margin-left: auto; }
.kpi-chip {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: var(--border-light);
    border-radius: 20px;
    font-size: 12px;
    color: var(--text-dim);
}
.kpi-chip b { color: var(--text); font-size: 14px; font-weight: 700; }
.kpi-chip.live { background: #fef2f2; color: #dc2626; }
.kpi-chip.live b { color: #dc2626; }

.status-pill {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    background: #f0fdf4;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    color: #15803d;
}
.status-pill .dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: #10b981;
    box-shadow: 0 0 8px #10b981;
    animation: pulse 2s infinite;
}
.status-pill.off { background: #f1f5f9; color: var(--text-mute); }
.status-pill.off .dot { background: #94a3b8; box-shadow: none; animation: none; }
.status-pill.warn { background: #fffbeb; color: #b45309; }
.status-pill.warn .dot { background: #f59e0b; box-shadow: 0 0 8px #f59e0b; }

/* ── Content Area ── */
.content {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

/* 頁面切換：預設隱藏，.active 顯示 */
.page { display: none; }
.page.active { display: block; }

/* ── Cold alert banner ── */
.cold-alert {
    background: linear-gradient(90deg, #0ea5e9, #2563eb);
    color: #fff;
    padding: 14px 22px;
    display: none;
    align-items: center;
    gap: 14px;
    font-weight: 600;
    font-size: 14px;
}
.cold-alert.show { display: flex; }
.cold-icon { font-size: 22px; }
.cold-alert button {
    background: rgba(255,255,255,0.22);
    border: none;
    color: #fff;
    padding: 7px 16px;
    border-radius: 16px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}
.cold-alert button:hover { background: rgba(255,255,255,0.35); }
.cold-alert button:last-child { margin-left: auto; opacity: 0.7; }

/* ══════════════ Page: 即時助手 ══════════════ */
.live-grid {
    display: grid;
    grid-template-columns: 1.6fr 1fr;
    gap: 20px;
    height: 100%;
}

.card {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--border-light);
    overflow: hidden;
}
.card-header {
    padding: 14px 18px;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.card-title {
    font-size: 13px;
    font-weight: 700;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 8px;
}
.card-title .dot {
    width: 6px; height: 6px; border-radius: 50%;
    background: var(--primary);
}
.card-badge {
    background: var(--border-light);
    color: var(--text-dim);
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
}
.card-body { padding: 14px 18px; }
.card-body.flush { padding: 0; }

.script-columns {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
    height: 100%;
    overflow-y: auto;
}

.script-section {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--border-light);
    overflow: hidden;
}
.script-section-head {
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-light);
    background: #fafbfc;
}
.script-section-head h3 {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 1px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.script-section-head .tag {
    padding: 2px 8px;
    border-radius: 8px;
    font-size: 10px;
    font-weight: 700;
}
.script-section.chat .tag { background: #ede9fe; color: #6d28d9; }
.script-section.join .tag { background: #dbeafe; color: #1d4ed8; }
.script-section.gift .tag { background: #ffedd5; color: #c2410c; }

.script-list {
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 320px;
    overflow-y: auto;
}

.script-card {
    background: #fff;
    border: 1px solid var(--border-light);
    border-radius: 10px;
    padding: 12px 14px;
    cursor: pointer;
    transition: all 0.15s;
    border-left: 3px solid transparent;
}
.script-card:hover {
    box-shadow: 0 2px 10px rgba(15,23,42,0.08);
    transform: translateY(-1px);
}
.script-card.read { opacity: 0.35; }
.script-card.script-chat { border-left-color: var(--purple); }
.script-card.script-join { border-left-color: var(--primary); }
.script-card.script-gift { border-left-color: var(--orange); }
.script-meta { display: flex; justify-content: space-between; margin-bottom: 4px; }
.script-user { font-size: 11px; color: var(--text-mute); font-weight: 600; }
.script-time { font-size: 10px; color: var(--text-mute); }
.script-quote {
    background: #f8fafc;
    border-radius: 6px;
    padding: 5px 10px;
    margin: 6px 0;
    font-size: 12px;
    color: var(--text-dim);
    border-left: 2px solid var(--border);
}
.script-text {
    font-size: 17px;
    font-weight: 600;
    line-height: 1.45;
    color: var(--text);
}

/* ── Events feed ── */
.event-feed {
    max-height: calc(100vh - 220px);
    overflow-y: auto;
    padding: 6px 0;
}
.event-item {
    padding: 10px 18px;
    border-bottom: 1px solid var(--border-light);
    font-size: 13px;
    display: flex;
    align-items: flex-start;
    gap: 10px;
}
.event-item:last-child { border-bottom: none; }
.event-icon {
    width: 26px; height: 26px;
    border-radius: 7px;
    display: flex; align-items: center; justify-content: center;
    font-size: 10px; font-weight: 700;
    color: #fff;
    flex-shrink: 0;
}
.join-icon { background: var(--primary); }
.chat-icon { background: var(--purple); }
.gift-icon { background: var(--orange); }
.event-body { flex: 1; min-width: 0; }
.event-user { font-weight: 700; color: var(--text); font-size: 13px; }
.event-label { color: var(--text-mute); font-size: 12px; }
.event-join .event-user { color: var(--primary); }
.event-chat .event-user { color: var(--purple); }
.event-gift .event-user { color: var(--orange); }
.event-gift-name { color: var(--orange); font-weight: 700; }
.event-msg {
    margin-top: 4px;
    padding: 5px 10px;
    background: #f8fafc;
    border-radius: 6px;
    font-size: 12px;
    color: var(--text);
    word-break: break-word;
}
.event-time { font-size: 10px; color: var(--text-mute); flex-shrink: 0; }

/* VIP 進場 */
.event-vip {
    background: linear-gradient(90deg, #fef3c7, transparent);
    border-left: 3px solid #f59e0b;
    padding-left: 15px;
    animation: vipGlow 1.5s ease-in-out 2;
}
.event-vip .event-user { color: #c2410c !important; font-size: 14px; }
.vip-icon { background: linear-gradient(135deg, #f59e0b, #ef4444) !important; width: auto !important; padding: 0 8px; }
.vip-label { color: #dc2626 !important; font-weight: 700; font-size: 13px; }
@keyframes vipGlow { 0%,100%{box-shadow:none;} 50%{box-shadow:0 0 20px rgba(245,158,11,0.5);} }

/* Badges */
.badge {
    display: inline-block;
    font-size: 9px;
    padding: 1px 5px;
    border-radius: 4px;
    margin: 0 2px;
    font-weight: 700;
    vertical-align: middle;
}
.badge-mod    { background: #fee2e2; color: #991b1b; }
.badge-level  { background: #ede9fe; color: #5b21b6; }
.badge-fan    { background: #cffafe; color: #0e7490; }
.badge-friend { background: #dbeafe; color: #1e40af; }
/* ── 淺在大哥進場 Toast (整個畫面頂部飄下來) ── */
.whale-toast {
    position: fixed;
    top: 80px; left: 50%;
    transform: translateX(-50%) translateY(-200%);
    z-index: 1500;
    transition: transform 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
    pointer-events: none;
}
.whale-toast.show {
    transform: translateX(-50%) translateY(0);
    pointer-events: auto;
}
.whale-inner {
    display: flex;
    align-items: center;
    gap: 18px;
    background: linear-gradient(135deg, #fbbf24, #f97316, #ef4444);
    color: #fff;
    padding: 18px 28px;
    border-radius: 18px;
    box-shadow: 0 20px 60px rgba(249,115,22,0.6);
    min-width: 480px;
    max-width: 720px;
    border: 3px solid rgba(255,255,255,0.4);
    animation: whaleGlow 1.5s ease-in-out infinite;
}
@keyframes whaleGlow {
    0%,100% { box-shadow: 0 20px 60px rgba(249,115,22,0.6); }
    50%     { box-shadow: 0 20px 80px rgba(251,191,36,1); }
}
.whale-crown {
    font-size: 56px;
    animation: whaleBounce 0.8s ease-in-out infinite;
}
@keyframes whaleBounce {
    0%,100% { transform: scale(1) rotate(-5deg); }
    50%     { transform: scale(1.15) rotate(5deg); }
}
.whale-body { flex: 1; }
.whale-title { font-size: 15px; font-weight: 700; letter-spacing: 1px; opacity: 0.95; }
.whale-name { font-size: 28px; font-weight: 900; margin: 4px 0 6px; text-shadow: 0 2px 10px rgba(0,0,0,0.3); }
.whale-stats { font-size: 13px; line-height: 1.6; opacity: 0.95; }
.whale-hint { font-size: 10px; opacity: 0.7; margin-top: 6px; }
.whale-close {
    background: rgba(255,255,255,0.2);
    border: none;
    color: #fff;
    width: 28px; height: 28px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 14px;
    align-self: flex-start;
}

/* whale tier styles */
.tag-whale.whale-top {
    background: linear-gradient(135deg, #fbbf24, #ef4444, #8b5cf6) !important;
    font-size: 11px !important;
    padding: 3px 10px !important;
    box-shadow: 0 2px 12px rgba(239,68,68,0.6) !important;
}

.tag-whale {
    display: inline-block;
    font-size: 10px;
    padding: 2px 8px;
    background: linear-gradient(135deg, #fbbf24, #f97316);
    color: #fff;
    border-radius: 8px;
    font-weight: 700;
    margin: 0 3px;
    box-shadow: 0 2px 8px rgba(249,115,22,0.4);
    animation: whalePulse 2s ease-in-out infinite;
}
@keyframes whalePulse {
    0%,100% { box-shadow: 0 2px 8px rgba(249,115,22,0.4); }
    50%     { box-shadow: 0 2px 14px rgba(249,115,22,0.8); }
}
.tag-gifter {
    display: inline-block;
    font-size: 10px;
    padding: 1px 6px;
    background: #fef3c7;
    color: #92400e;
    border-radius: 6px;
    font-weight: 700;
    margin: 0 3px;
}
.tag-return {
    display: inline-block;
    font-size: 9px;
    padding: 1px 6px;
    background: #dcfce7;
    color: #15803d;
    border-radius: 6px;
    font-weight: 700;
    margin: 0 3px;
}

/* ══════════════ Page: 互動工具 ══════════════ */
.tools-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 16px;
}
.tool-card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-light);
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
    overflow: hidden;
}
.tool-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}
.tool-card .tool-icon {
    width: 44px; height: 44px;
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 22px;
    margin-bottom: 14px;
    color: #fff;
}
.tool-card h3 { font-size: 15px; font-weight: 700; margin-bottom: 4px; }
.tool-card p { font-size: 12px; color: var(--text-dim); line-height: 1.5; }
.tool-card .tool-action {
    margin-top: 14px;
    font-size: 12px;
    color: var(--primary);
    font-weight: 600;
}
.tool-section-title {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 1.5px;
    margin: 22px 0 12px;
    padding-left: 4px;
}
.tool-section-title:first-child { margin-top: 0; }
.tools-grid + .tool-section-title { margin-top: 28px; }

.tool-joke .tool-icon     { background: linear-gradient(135deg, #f59e0b, #f97316); }
.tool-warm .tool-icon     { background: linear-gradient(135deg, #ec4899, #ef4444); }
.tool-interact .tool-icon { background: linear-gradient(135deg, #8b5cf6, #6366f1); }
.tool-hype .tool-icon     { background: linear-gradient(135deg, #ef4444, #dc2626); }
.tool-gift .tool-icon     { background: linear-gradient(135deg, #a855f7, #8b5cf6); }
.tool-thanks .tool-icon   { background: linear-gradient(135deg, #10b981, #14b8a6); }
.tool-lottery .tool-icon  { background: linear-gradient(135deg, #fbbf24, #f97316); }
.tool-intro .tool-icon    { background: linear-gradient(135deg, #06b6d4, #3b82f6); }
.tool-outro .tool-icon    { background: linear-gradient(135deg, #6366f1, #1e40af); }
.tool-countdown .tool-icon{ background: linear-gradient(135deg, #fbbf24, #dc2626); }
.tool-topic .tool-icon    { background: linear-gradient(135deg, #22d3ee, #0ea5e9); }
.tool-praise .tool-icon   { background: linear-gradient(135deg, #facc15, #eab308); }
.tool-quiet .tool-icon    { background: linear-gradient(135deg, #a3a3a3, #525252); }
.tool-follow .tool-icon   { background: linear-gradient(135deg, #f43f5e, #e11d48); }
.tool-newfan .tool-icon   { background: linear-gradient(135deg, #14b8a6, #0d9488); }
.tool-share .tool-icon    { background: linear-gradient(135deg, #3b82f6, #1d4ed8); }
.tool-roast .tool-icon    { background: linear-gradient(135deg, #64748b, #334155); }
.tool-blush .tool-icon    { background: linear-gradient(135deg, #fb7185, #ec4899); }
.tool-refuse .tool-icon   { background: linear-gradient(135deg, #94a3b8, #475569); }
.tool-comfort .tool-icon  { background: linear-gradient(135deg, #c084fc, #a855f7); }
.tool-song .tool-icon     { background: linear-gradient(135deg, #e879f9, #c026d3); }
.tool-pk .tool-icon       { background: linear-gradient(135deg, #dc2626, #7c2d12); }

/* 浮動快捷結果 (跨頁顯示) */
.quick-result-float {
    position: fixed;
    top: 84px;
    left: 50%;
    transform: translateX(-50%) translateY(-20px);
    width: min(760px, 90vw);
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: #fff;
    padding: 22px 26px;
    border-radius: 14px;
    box-shadow: 0 20px 60px rgba(99,102,241,0.4);
    display: none;
    align-items: center;
    gap: 18px;
    z-index: 900;
    opacity: 0;
    transition: all 0.25s ease;
}
.quick-result-float.show {
    display: flex;
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}
.quick-result-float .quick-result-text { flex: 1; font-size: 22px; font-weight: 700; line-height: 1.5; }

/* (舊) 頁內版本 — 留著 for safety */
.quick-result {
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: #fff;
    padding: 22px 26px;
    display: none;
    align-items: center;
    gap: 18px;
    border-radius: var(--radius);
    margin-bottom: 20px;
    box-shadow: var(--shadow-lg);
}
.quick-result.show { display: flex; }
.quick-result-text { flex: 1; font-size: 22px; font-weight: 700; line-height: 1.5; }
.quick-close {
    padding: 9px 20px;
    background: rgba(255,255,255,0.25);
    color: #fff;
    border: none;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
}
.quick-close:hover { background: rgba(255,255,255,0.4); }

/* ══════════════ Page: 觀眾 & 分析 ══════════════ */
.stats-kpis {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 20px;
}
.kpi-box {
    background: var(--card);
    border-radius: var(--radius);
    padding: 18px 20px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-light);
    position: relative;
    overflow: hidden;
}
.kpi-box .kpi-label {
    font-size: 11px;
    color: var(--text-mute);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}
.kpi-box .kpi-value {
    font-size: 30px;
    font-weight: 800;
    color: var(--text);
    margin-top: 4px;
    letter-spacing: -0.5px;
}
.kpi-box .kpi-sub { font-size: 11px; color: var(--text-mute); margin-top: 4px; }
.kpi-box.blue   .kpi-value { color: var(--primary); }
.kpi-box.purple .kpi-value { color: var(--purple); }
.kpi-box.orange .kpi-value { color: var(--orange); }
.kpi-box.green  .kpi-value { color: var(--success); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border-light);
    font-size: 13px;
}
th {
    font-size: 11px;
    color: var(--text-mute);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    background: #fafbfc;
}
tr:last-child td { border-bottom: none; }
.vip-row { background: linear-gradient(90deg, #fef3c7, transparent); }
.rank-badge {
    display: inline-block;
    width: 22px; height: 22px;
    border-radius: 50%;
    background: var(--border-light);
    color: var(--text-dim);
    font-size: 11px;
    font-weight: 700;
    text-align: center;
    line-height: 22px;
}
.rank-badge.gold   { background: #fef3c7; color: #b45309; }
.rank-badge.silver { background: #e5e7eb; color: #374151; }
.rank-badge.bronze { background: #fed7aa; color: #9a3412; }

canvas { max-width: 100%; height: 260px !important; }

/* ══════════════ Page: 設定 ══════════════ */
.settings-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    max-width: 900px;
}
.settings-section {
    background: var(--card);
    border-radius: var(--radius);
    padding: 22px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-light);
}
.settings-section h3 { font-size: 14px; font-weight: 700; margin-bottom: 16px; }
.field { margin-bottom: 16px; }
.field label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-dim);
    margin-bottom: 6px;
}
.field select, .field input[type=text], .field input[type=number] {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 13px;
    background: #fff;
    color: var(--text);
    transition: all 0.15s;
}
.field select:focus, .field input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,0.1); }
.toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid var(--border-light);
}
.toggle-row:last-child { border-bottom: none; }
.toggle-row label { font-size: 13px; font-weight: 500; }
.toggle-row .hint { font-size: 11px; color: var(--text-mute); margin-top: 2px; }

/* Switch */
.switch { position: relative; display: inline-block; width: 38px; height: 22px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
    position: absolute; cursor: pointer; inset: 0;
    background: #cbd5e1; border-radius: 22px; transition: 0.2s;
}
.slider:before {
    content: ""; position: absolute; height: 18px; width: 18px;
    left: 2px; bottom: 2px; background: #fff; border-radius: 50%; transition: 0.2s;
}
.switch input:checked + .slider { background: var(--primary); }
.switch input:checked + .slider:before { transform: translateX(16px); }

/* ══════════════ Modals & Overlays ══════════════ */
.modal {
    position: fixed; inset: 0;
    background: rgba(15,23,42,0.6);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}
.modal.show { display: flex; }
.modal-box {
    background: #fff;
    border-radius: 16px;
    padding: 28px;
    width: 440px;
    max-width: 90%;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.modal-box h3 { margin-bottom: 18px; font-size: 17px; }
.modal-box label { display: block; font-size: 12px; color: var(--text-dim); font-weight: 600; margin: 14px 0 6px; }
.modal-box input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
}
.modal-btns { display: flex; gap: 10px; justify-content: flex-end; margin-top: 22px; }
.btn {
    padding: 9px 20px;
    border: none;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    background: var(--border-light);
    color: var(--text);
    transition: all 0.15s;
}
.btn:hover { background: var(--border); }
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover { background: #1d4ed8; }
.btn.danger  { background: var(--danger); color: #fff; }

/* Lottery HUD */
.lottery-hud {
    position: fixed;
    top: 80px;
    right: 24px;
    background: linear-gradient(135deg, #fbbf24, #f97316);
    color: #7c2d12;
    padding: 16px 22px;
    border-radius: 14px;
    box-shadow: 0 10px 40px rgba(249,115,22,0.5);
    display: none;
    flex-direction: column;
    gap: 6px;
    z-index: 500;
    min-width: 280px;
    animation: pulseHud 1.5s ease-in-out infinite;
}
.lottery-hud.show { display: flex; }
@keyframes pulseHud { 0%,100%{box-shadow:0 10px 40px rgba(249,115,22,0.5);} 50%{box-shadow:0 10px 50px rgba(249,115,22,0.8);} }
.lh-prize { font-size: 17px; font-weight: 800; }
.lh-main { font-size: 13px; font-weight: 600; }
.lottery-hud button {
    align-self: flex-end;
    background: rgba(0,0,0,0.15);
    border: none;
    padding: 4px 10px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 700;
    cursor: pointer;
    color: #7c2d12;
}
.lottery-result {
    position: fixed; inset: 0;
    background: rgba(15,23,42,0.85);
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    color: #fff;
    gap: 14px;
}
.lottery-result.show { display: flex; }
.lr-title { font-size: 32px; font-weight: 900; color: #fbbf24; }
.lr-winner { font-size: 60px; font-weight: 900; text-shadow: 0 4px 30px rgba(251,191,36,0.8); }
.lr-meta { font-size: 14px; color: #cbd5e1; }
.lottery-result button {
    margin-top: 20px;
    padding: 11px 34px;
    background: #fff;
    border: none;
    border-radius: 22px;
    font-weight: 700;
    cursor: pointer;
    color: var(--text);
}

/* Scrollbar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* Responsive */
@media (max-width: 1100px) {
    .live-grid { grid-template-columns: 1fr; }
    .stats-kpis { grid-template-columns: repeat(2, 1fr); }
}
