: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); }

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: 14px; }
.brand { display: flex; align-items: center; gap: 16px; min-width: 0; }
.brand-icon {
    width: 58px; height: 58px;
    display: grid; place-items: center;
    color: var(--primary);
}
.brand-icon svg { width: 52px; height: 52px; }
.brand-text h1 {
    margin: 0;
    font-size: 1.9rem;
    font-weight: 800;
    letter-spacing: -.01em;
    color: var(--primary);
}
.brand-text p { margin: 2px 0 0; color: var(--muted); font-size: 1rem; font-weight: 500; }

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

/* ================= 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);
}

/* ---------- 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;
}

/* ---------- Odometer ---------- */
.odometer-stage {
    position: relative;
    display: flex; align-items: center; justify-content: center;
    gap: 16px;
    margin: 6px 0 30px;
    width: 100%;
}
.odometer { display: flex; gap: 14px; }

.reel {
    position: relative;
    width: calc(var(--row-h) * 0.82);
    height: calc(var(--row-h) * 3);
    overflow: hidden;
    border-radius: 16px;
    background: linear-gradient(180deg, #f8fafc 0%, #dfe6f0 18%, #ffffff 50%, #dfe6f0 82%, #f1f5f9 100%);
    box-shadow:
        inset 0 2px 4px rgba(255,255,255,.9),
        inset 0 -2px 6px rgba(30,41,59,.10),
        0 6px 16px rgba(30,41,59,.16);
    border: 1px solid #cdd7e6;
}
.reel-strip { will-change: transform; }
.digit {
    height: var(--row-h);
    display: flex; align-items: center; justify-content: center;
    font-size: calc(var(--row-h) * 0.6);
    font-weight: 800;
    color: #0f213f;
    font-variant-numeric: tabular-nums;
    line-height: 1;
}
/* cylinder shading — fades the top & bottom (non-centre) digits */
.reel::before, .reel::after {
    content: ""; position: absolute; left: 0; right: 0; height: 33.34%;
    pointer-events: none; z-index: 2;
}
.reel::before { top: 0; background: linear-gradient(180deg, rgba(238,244,252,1) 16%, rgba(238,244,252,.62) 100%); }
.reel::after { bottom: 0; background: linear-gradient(0deg, rgba(238,244,252,1) 16%, rgba(238,244,252,.62) 100%); }
/* centre highlight band */
.reel-center {
    position: absolute; left: 0; right: 0; top: 33.34%; height: 33.34%;
    z-index: 1; pointer-events: none;
    background: linear-gradient(180deg, rgba(37,99,235,.10), rgba(37,99,235,.05));
    border-top: 1px solid rgba(37,99,235,.28);
    border-bottom: 1px solid rgba(37,99,235,.28);
}

.odometer-pointer {
    flex-shrink: 0;
    width: 0; height: 0;
    border-top: 18px solid transparent;
    border-bottom: 18px solid transparent;
    border-right: 26px solid var(--primary);
    filter: drop-shadow(0 3px 4px rgba(37,99,235,.35));
}

/* ---------- 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); }

/* ---------- 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-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; }
.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: 52px; height: 52px; border-radius: 14px;
    border: 1px solid var(--line); background: var(--card); color: var(--primary);
    font-size: 1.3rem; 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;
}

/* ================= Responsive ================= */
@media (max-width: 1200px) {
    :root { --row-h: 84px; }
    .brand-text h1 { font-size: 1.6rem; }
    .cc-number { font-size: 2.4rem; }
    .cc-vehicle { font-size: 1.8rem; }
}
/* Shrink the reels when vertical space is tight so the screen still fits. */
@media (min-width: 981px) and (max-height: 900px) {
    :root { --row-h: 82px; }
}
@media (min-width: 981px) and (max-height: 780px) {
    :root { --row-h: 66px; }
    .spin-panel { padding-top: 18px; }
    .spin-label { margin-bottom: 16px; }
}
/* Tablet & below: single column, footer stacks, history can scroll sideways. */
@media (max-width: 980px) {
    :root { --row-h: 76px; }
    .stage { padding: 18px 16px 14px; gap: 16px; }
    .stage-main { grid-template-columns: 1fr; }
    .spin-panel { padding: 22px 18px 24px; }
    .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 { justify-content: space-between; }
    .datetime-card { flex: 1; justify-content: center; }
    .brand-text h1 { font-size: 1.5rem; }
}
/* Phones */
@media (max-width: 560px) {
    :root { --row-h: 58px; }
    .brand-icon { width: 44px; height: 44px; }
    .brand-icon svg { width: 40px; height: 40px; }
    .brand-text h1 { font-size: 1.25rem; }
    .brand-text p { font-size: .85rem; }
    .datetime-card { padding: 10px 14px; gap: 12px; }
    .dt-item { font-size: .95rem; }
    .fs-btn { width: 44px; height: 44px; }
    .odometer { gap: 7px; }
    .odometer-stage { gap: 10px; }
    .reel { border-radius: 12px; }
    .spin-label-text { font-size: .8rem; letter-spacing: .1em; }
    .cc-half { padding: 14px 10px; }
    .cc-label { font-size: .7rem; letter-spacing: .04em; }
    .cc-number { font-size: 1.7rem; }
    .cc-vehicle { font-size: 1.3rem; }
    .call-banner { font-size: 1.05rem; padding: 13px 14px; }
    .history-panel { padding: 20px 16px; }
    .history-head h2 { font-size: 1rem; }
    .history-table th, .history-table td { padding: 10px 8px; font-size: .88rem; }
    .odometer-pointer { border-top-width: 14px; border-bottom-width: 14px; border-right-width: 20px; }
    .stage-credits { grid-template-columns: 1fr; }
    .copyright, .crafted { grid-column: 1; justify-self: center; text-align: center; }
}
