:root {
    --bg-1: #eaf1fb;
    --bg-2: #dbe7fa;
    --card: #ffffff;
    --ink: #16223a;
    --ink-soft: #334155;
    --muted: #64748b;
    --line: #e6edf7;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-soft: #eff5ff;
    --success: #16a34a;
    --success-bg: #e9f9ef;
    --success-border: #b7f0c9;
    --row-h: 104px;
    --radius: 22px;
    --shadow: 0 14px 40px rgba(37, 99, 235, .10);
    --shadow-sm: 0 6px 18px rgba(37, 99, 235, .07);
}

* { box-sizing: border-box; }

html, body { height: 100%; }
html { background: var(--bg-2); }
button#fsBtn { display: none; }
#footRight { display: none; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    color: var(--ink);
    background: linear-gradient(160deg, var(--bg-1) 0%, var(--bg-2) 100%);
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

.stage {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    gap: 20px;
    padding: 22px 34px 16px;
    max-width: 1720px;
    margin: 0 auto;
}


/* ================= Header ================= */
.stage-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    flex-wrap: wrap;
}
.head-right { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: flex-end; }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-text { min-width: 0; }
.brand-text h1 { overflow: hidden; text-overflow: ellipsis; }
.brand-icon {
    width: 42px; height: 42px;
    display: grid; place-items: center;
    color: var(--primary);
}
.brand-icon svg { width: 38px; height: 38px; }
.brand-text h1 {
    margin: 0;
    font-size: 1.4rem;
    font-weight: 800;
    letter-spacing: -.01em;
    color: var(--primary);
}
.brand-text p { margin: 1px 0 0; color: var(--muted); font-size: .85rem; font-weight: 500; }

.datetime-card {
    display: flex;
    align-items: center;
    gap: 14px;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 9px 16px;
    box-shadow: var(--shadow-sm);
}
.dt-item { display: flex; align-items: center; gap: 8px; font-size: .98rem; font-weight: 600; color: var(--ink); }
.dt-item svg { width: 17px; height: 17px; color: var(--primary); }
.dt-divider { width: 1px; height: 22px; background: var(--line); }

.next-spin-card {
    display: flex; align-items: center; gap: 10px;
    background: var(--primary-soft); border: 1px solid #cfe0ff;
    border-radius: 12px; padding: 8px 15px; box-shadow: var(--shadow-sm);
    color: var(--primary);
}
.next-spin-card svg { width: 18px; height: 18px; flex-shrink: 0; }
.ns-text { display: flex; flex-direction: column; line-height: 1.15; }
.ns-label { font-size: .62rem; font-weight: 700; letter-spacing: .09em; color: var(--muted); }
.ns-value { font-size: 1.05rem; font-weight: 800; font-variant-numeric: tabular-nums; color: var(--primary); }
.ns-time { font-size: .82rem; font-weight: 600; color: var(--muted); margin-left: 6px; }

/* ================= Main ================= */
.stage-main {
    display: grid;
    grid-template-columns: 1.08fr 0.92fr;
    gap: 24px;
    align-items: stretch;
    flex: 1;
}
.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
/* Let grid/flex columns shrink so a wide history table never forces the
   whole layout wider than the screen (was cutting off the wheel on phones). */
.stage-main > .card { min-width: 0; }

/* ---------- Spin panel ---------- */
.spin-panel {
    padding: 28px 30px 30px;
    display: flex;
    flex-direction: column;
    align-items: center;
}
.spin-label {
    display: flex; align-items: center; gap: 16px;
    width: 100%; max-width: 520px; margin-bottom: 26px;
}
.spin-label .line { flex: 1; height: 2px; background: linear-gradient(90deg, transparent, var(--primary) 60%); border-radius: 2px; }
.spin-label .line:last-child { background: linear-gradient(90deg, var(--primary) 40%, transparent); }
.spin-label-text {
    font-size: .95rem; font-weight: 700; letter-spacing: .16em;
    color: var(--primary); white-space: nowrap;
}

/* ---------- Wheel of fortune ---------- */
.wheel-stage {
    position: relative;
    display: flex; flex-direction: column; align-items: center;
    margin: 2px 0 20px;
    width: 100%;
}
.wheel-area {
    position: relative;
    width: min(100%, 460px);
    aspect-ratio: 1 / 1;
}
.wheel-wrap {
    position: relative;
    width: 100%; height: 100%;
    border-radius: 50%;
    background: #1e2430;                 /* dark rim */
    padding: 3.2%;                        /* rim thickness */
    box-shadow: 0 16px 36px rgba(15, 23, 42, .30), inset 0 0 0 3px #11151d;
}
#wheel {
    display: block;
    width: 100%; height: 100%;
    border-radius: 50%;
    transform: rotate(0deg);
    transform-origin: 50% 50%;
    will-change: transform;
    background: #fff;
}
.wheel-hub {
    position: absolute; top: 50%; left: 50%;
    width: 13%; height: 13%;
    transform: translate(-50%, -50%);
    border-radius: 50%;
    background: radial-gradient(circle at 35% 30%, #2b323f, #171b23);
    box-shadow: 0 4px 10px rgba(0, 0, 0, .35), inset 0 2px 4px rgba(255, 255, 255, .12);
    z-index: 3;
    border: 3px solid #eef2f8;
}
.wheel-pointer {
    position: absolute; top: -4px; left: 50%; transform: translateX(-50%);
    width: 0; height: 0; z-index: 4;
    border-left: 18px solid transparent;
    border-right: 18px solid transparent;
    border-top: 32px solid #ef4444;
    filter: drop-shadow(0 3px 3px rgba(0, 0, 0, .3));
}
.wheel-stand { display: flex; flex-direction: column; align-items: center; margin-top: -2px; }
.wheel-neck { width: 24px; height: 30px; background: #1e2430; border-radius: 0 0 4px 4px; }
.wheel-base { width: 140px; height: 20px; background: #1e2430; border-radius: 11px; box-shadow: 0 8px 16px rgba(15, 23, 42, .25); }

/* ---------- Current card ---------- */
.current-card {
    display: flex; align-items: stretch;
    width: 100%; max-width: 640px;
    background: #f7faff;
    border: 1px solid var(--line);
    border-radius: 16px;
    overflow: hidden;
    margin-bottom: 18px;
}
.cc-half { flex: 1; padding: 18px 20px; text-align: center; }
.cc-sep { width: 1px; background: var(--line); }
.cc-label { font-size: .82rem; font-weight: 700; letter-spacing: .08em; color: var(--muted); margin-bottom: 8px; }
.cc-value { font-weight: 800; line-height: 1; }
.cc-number { font-size: 2.9rem; color: var(--primary); font-variant-numeric: tabular-nums; }
.cc-vehicle { font-size: 2.2rem; color: var(--ink); }

/* Winner reveal — pop when the wheel stops */
.current-card { transition: box-shadow .3s ease; will-change: transform; }
.current-card.pop { animation: winnerPop .6s cubic-bezier(.2,1.3,.4,1); }
.current-card.pop .cc-vehicle { color: var(--success); }
.current-card.pop { box-shadow: 0 0 0 3px var(--success-border), 0 16px 34px rgba(22,163,74,.18); }
@keyframes winnerPop {
    0%   { transform: scale(.86); }
    45%  { transform: scale(1.11); }
    70%  { transform: scale(.98); }
    100% { transform: scale(1); }
}

/* ---------- Call banner ---------- */
.call-banner {
    display: flex; align-items: center; justify-content: center; gap: 12px;
    width: 100%; max-width: 640px;
    padding: 16px 20px; border-radius: 14px;
    font-size: 1.35rem; font-weight: 700;
}
.call-banner svg { width: 24px; height: 24px; }
.call-banner.is-called { background: var(--success-bg); color: var(--success); border: 1px solid var(--success-border); }
.call-banner.is-waiting { background: #f1f5f9; color: var(--muted); border: 1px solid var(--line); }
.call-banner.is-spinning { background: var(--primary-soft); color: var(--primary); border: 1px solid #cfe0ff; }

/* ================= History ================= */
.history-panel { padding: 26px 28px; display: flex; flex-direction: column; }
.history-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.hh-icon { width: 34px; height: 34px; display: grid; place-items: center; color: var(--primary); }
.hh-icon svg { width: 30px; height: 30px; }
.history-head h2 { margin: 0; font-size: 1.15rem; font-weight: 800; letter-spacing: .02em; color: var(--ink); }
.hh-sub { color: var(--muted); font-weight: 600; font-size: .95rem; }

.history-table-wrap { flex: 1; overflow-y: auto; }
.history-table { width: 100%; border-collapse: collapse; }
.history-table th {
    text-align: left; font-size: .82rem; font-weight: 700; color: var(--muted);
    padding: 12px 14px; background: #f4f7fc; position: sticky; top: 0;
}
.history-table th:first-child { border-radius: 10px 0 0 10px; }
.history-table th:last-child { border-radius: 0 10px 10px 0; }
.history-table td { padding: 15px 14px; border-bottom: 1px solid var(--line); font-size: 1.02rem; color: var(--ink-soft); }
.history-table .ta-right { text-align: right; }
.history-table tbody tr:hover { background: #f9fbff; }
.history-table .h-vehicle { font-weight: 600; color: var(--ink); }
.history-table .h-spin { font-weight: 800; color: var(--primary); font-variant-numeric: tabular-nums; }
.history-row-current { background: var(--primary-soft) !important; }
.history-table tr.row-hidden { display: none; }
.history-empty-row td { text-align: center; color: var(--muted); padding: 30px; }

.view-more {
    margin-top: 14px; align-self: center;
    display: inline-flex; align-items: center; gap: 6px;
    background: none; border: none; cursor: pointer;
    color: var(--primary); font-weight: 700; font-size: 1rem; font-family: inherit;
    padding: 8px 14px; border-radius: 10px;
}
.view-more:hover { background: var(--primary-soft); }
.view-more svg { width: 16px; height: 16px; transition: transform .2s ease; }
.view-more.open svg { transform: rotate(180deg); }

/* ================= Footer ================= */
.stage-foot { display: flex; gap: 16px; align-items: stretch; }
.foot-card {
    display: flex; align-items: center; gap: 12px;
    background: var(--card); border: 1px solid var(--line);
    border-radius: 14px; padding: 14px 20px; box-shadow: var(--shadow-sm);
    color: var(--muted); font-weight: 500; font-size: .98rem;
    flex: 1 1 0; min-width: 0;
}
.foot-card span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.foot-card svg { width: 22px; height: 22px; color: var(--primary); flex-shrink: 0; }
.foot-status {
    flex: 0 1 auto; justify-content: center; color: var(--primary); font-weight: 700;
    background: var(--primary-soft); border-color: #cfe0ff;
}
.foot-card:last-child { justify-content: flex-end; text-align: right; }

/* Colourful left & right footer cards (the middle status card stays as-is) */
.foot-card:first-child {
    background: linear-gradient(135deg, #fff4e6, #ffe8cc);
    border-color: #fed7aa; color: #9a3412; font-weight: 600;
}
.foot-card:first-child svg { color: #f59e0b; }
.foot-card:last-child {
    background: linear-gradient(135deg, #eafaf0, #d3f5e0);
    border-color: #b7f0c9; color: #0f7a4f; font-weight: 600;
}
.foot-card:last-child svg { color: #10b981; }

.foot-status .spin-icon { animation: spin 3.5s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.stage-credits {
    display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 10px;
    padding: 4px 2px 2px;
}
.copyright { grid-column: 2; text-align: center; color: var(--muted); font-size: .9rem; }
.crafted { grid-column: 3; justify-self: end; color: var(--muted); font-size: .92rem; font-weight: 500; white-space: nowrap; }
.crafted .heart { color: #ff5a5f; }
.crafted .w3care { color: #79c143; font-weight: 800; }

/* ================= Utility ================= */
.fs-btn {
    flex-shrink: 0;
    width: 42px; height: 42px; border-radius: 11px;
    border: 1px solid var(--line); background: var(--card); color: var(--primary);
    font-size: 1.1rem; cursor: pointer; box-shadow: var(--shadow-sm);
    display: grid; place-items: center;
}
.fs-btn:hover { background: var(--primary-soft); }
.offline-tag {
    position: fixed; left: 18px; bottom: 18px;
    background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca;
    padding: 8px 14px; border-radius: 20px; font-size: .85rem; font-weight: 600; z-index: 40;
}
.confetti-canvas {
    position: fixed; inset: 0; width: 100%; height: 100%;
    pointer-events: none; z-index: 60;
}

/* ================= Responsive ================= */
@media (max-width: 1200px) {
    .brand-text h1 { font-size: 1.6rem; }
    .cc-number { font-size: 2.4rem; }
    .cc-vehicle { font-size: 1.8rem; }
}
/* Keep the wheel from dominating shorter screens */
@media (min-width: 981px) and (max-height: 860px) {
    .wheel-area { width: min(100%, 380px); }
}
@media (min-width: 981px) and (max-height: 740px) {
    .wheel-area { width: min(100%, 320px); }
    .spin-label { margin-bottom: 14px; }
}
/* Tablet & below: single column, footer stacks, history can scroll sideways. */
@media (max-width: 980px) {
    .stage { padding: 18px 16px 14px; gap: 16px; }
    .stage-main { grid-template-columns: 1fr; }
    .spin-panel { padding: 22px 18px 24px; }
    .wheel-area { width: min(100%, 420px); }
    .stage-foot { flex-wrap: wrap; }
    .foot-card { flex: 1 1 100%; }
    .foot-card:last-child { justify-content: flex-start; text-align: left; order: 3; }
    .foot-status { flex: 1 1 100%; order: -1; }
    .history-panel { max-height: 60vh; }
    .history-table-wrap { overflow-x: auto; }
    .history-table { min-width: 460px; }
}
@media (max-width: 760px) {
    .stage-head { flex-direction: column; align-items: stretch; gap: 12px; }
    .head-right { flex-wrap: wrap; justify-content: center; gap: 10px; }
    .next-spin-card { flex: 1 1 auto; min-width: 0; justify-content: center; }
    .datetime-card { flex: 2 1 auto; min-width: 0; justify-content: center; }
    .fs-btn { flex: 0 0 auto; }
    .brand-text h1 { font-size: 1.5rem; }
}
/* Phones */
@media (max-width: 560px) {
    .brand-icon { width: 40px; height: 40px; }
    .brand-icon svg { width: 36px; height: 36px; }
    .brand-text h1 { font-size: 1.2rem; }
    .brand-text p { font-size: .82rem; }
    .next-spin-card, .datetime-card { flex: 1 1 100%; padding: 8px 12px; }
    .datetime-card { gap: 10px; }
    .dt-item { font-size: .92rem; }
    .dt-item svg { width: 15px; height: 15px; }
    .ns-value { font-size: .98rem; }
    .fs-btn { width: 40px; height: 40px; }
    .spin-label-text { font-size: .78rem; letter-spacing: .1em; }
    .cc-half { padding: 13px 8px; }
    .cc-label { font-size: .68rem; letter-spacing: .03em; }
    .cc-number { font-size: 1.6rem; }
    .cc-vehicle { font-size: 1.2rem; }
    .call-banner { font-size: 1rem; padding: 12px 12px; }
    .history-panel { padding: 18px 14px; }
    .history-head h2 { font-size: .98rem; }
    .history-table { min-width: 0; }
    .history-table th, .history-table td { padding: 9px 6px; font-size: .82rem; }
    .stage-credits { grid-template-columns: 1fr; }
    .copyright, .crafted { grid-column: 1; justify-self: center; text-align: center; }
}
/* Small phones */
@media (max-width: 380px) {
    .stage { padding: 14px 12px 12px; }
    .brand-text h1 { font-size: 1.08rem; }
    .cc-number { font-size: 1.4rem; }
    .cc-vehicle { font-size: 1.05rem; }
    .history-table { min-width: 0; }
    .history-table th, .history-table td { font-size: .8rem; padding: 8px 5px; }
}
