:root {
    --bg: #f7f2e7;
    --paper: #fffdf8;
    --ink: #18362f;
    --muted: #68766c;
    --primary: #20755b;
    --primary-dark: #175444;
    --secondary: #eadfc9;
    --line: #e3d8c2;
    --shadow: 0 16px 36px rgba(39, 46, 31, .10);
    --red: #db5a51;
    --green: #3a9965;
    --book-blue: #4486df;
    --book-green: #45a775;
    --book-yellow: #f2b53d;
    --book-purple: #8a69da;
    --book-orange: #e77b42;
    --book-pink: #db648c;
    --book-teal: #2caaa4;
    --book-lime: #88af3c;
    --book-brown: #9d6a44;
    --book-navy: #374c85;
}
* { box-sizing: border-box; }
html { min-height: 100%; }
body {
    margin: 0;
    min-height: 100vh;
    font-family: Inter, "Segoe UI", Arial, sans-serif;
    color: var(--ink);
    background: var(--bg);
}
button, input { font: inherit; }
button { touch-action: manipulation; }
a { color: inherit; text-decoration: none; }
.ambient { position: fixed; border-radius: 999px; filter: blur(35px); pointer-events: none; opacity: .55; }
.ambient-one { width: 240px; height: 240px; background: #e3c879; left: -90px; top: -70px; }
.ambient-two { width: 270px; height: 270px; background: #9bc8b4; right: -120px; bottom: -70px; }
.phone-shell {
    position: relative;
    z-index: 1;
    width: min(100%, 480px);
    /* min-height: 100vh; */
    margin: 0 auto;
    padding: max(18px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
    background: rgba(247, 242, 231, .78);
}
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.brand-book {
    width: 52px; height: 52px; display: grid; place-items: center;
    border-radius: 16px; font-size: 27px; background: var(--primary); box-shadow: var(--shadow);
}
.brand h1 { font-size: 22px; line-height: 1.1; margin: 2px 0 0; letter-spacing: -.03em; }
.eyebrow { text-transform: uppercase; font-size: 11px; line-height: 1.3; letter-spacing: .13em; color: var(--muted); font-weight: 750; margin: 0 0 4px; }
.screen { display: none; animation: rise .25s ease; }
.screen.active { display: block; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.hero-card {
    padding: 28px 22px; border-radius: 26px; margin: 8px 0 18px;
    color: #fff; background: linear-gradient(145deg, #19382e, #27664e);
    box-shadow: var(--shadow); overflow: hidden; position: relative;
}
.hero-card::after { content: "📗"; position: absolute; right: 16px; bottom: -8px; font-size: 73px; opacity: .13; transform: rotate(-8deg); }
.hero-card h2 { font-size: 29px; letter-spacing: -.045em; margin: 0 0 7px; max-width: 245px; }
.hero-card p { color: rgba(255,255,255,.75); margin: 0; max-width: 270px; line-height: 1.42; }
.menu-actions, .stack-actions { display: grid; gap: 11px; }
.button {
    display: flex; justify-content: center; align-items: center; min-height: 55px;
    border: 0; border-radius: 17px; padding: 15px 18px; font-weight: 730; cursor: pointer;
    transition: transform .13s ease, opacity .15s ease, background .15s ease;
}
.button:active { transform: scale(.985); }
.button:disabled { opacity: .45; cursor: not-allowed; }
.button.primary { background: var(--primary); color: white; box-shadow: 0 9px 19px rgba(32,117,91,.22); }
.button.primary:hover:not(:disabled) { background: var(--primary-dark); }
.button.secondary { background: var(--secondary); color: var(--ink); }
.panel, .qr-card, .players-card {
    margin-top: 16px; padding: 18px; border: 1px solid var(--line);
    background: var(--paper); border-radius: 22px; box-shadow: 0 5px 14px rgba(37,39,27,.04);
}
.panel h2 { font-size: 20px; margin: 0 0 15px; }
.hidden { display: none !important; }
label:not(.mode-option) { display: block; margin: 0 0 7px; font-size: 13px; font-weight: 700; }
input {
    width: 100%; min-height: 51px; border: 1.5px solid var(--line); border-radius: 14px;
    padding: 12px 14px; background: #fff; margin-bottom: 15px; outline: none; color: var(--ink);
}
input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(32,117,91,.12); }
.code-input { letter-spacing: .18em; font-weight: 800; text-transform: uppercase; text-align: center; font-size: 20px; }
.mode-picker { border: 0; padding: 0; margin: 3px 0 17px; }
.mode-picker legend { font-size: 13px; font-weight: 700; margin-bottom: 8px; }
.mode-option { display: flex; align-items: center; gap: 9px; border: 1.5px solid var(--line); border-radius: 14px; padding: 11px; margin-bottom: 8px; cursor: pointer; }
.mode-option:has(input:checked) { border-color: var(--primary); background: #edf6f0; }
.mode-option input { width: auto; min-height: 0; margin: 0; accent-color: var(--primary); }
.mode-option strong { display: block; font-size: 14px; }
.mode-option small { color: var(--muted); font-size: 12px; }
.section-heading { margin: 4px 0 15px; }
.section-heading h2, #host-results h2 { margin: 0 0 9px; font-size: 28px; letter-spacing: -.04em; }
.pill { display: inline-flex; align-items: center; padding: 7px 11px; border-radius: 999px; background: #e6f0eb; color: var(--primary-dark); font-size: 13px; font-weight: 700; margin: 0; }
.qr-card { text-align: center; margin-top: 0; }
.qr-card > p:first-child { font-weight: 700; margin: 0 0 12px; }
.qr-box { min-height: 188px; width: 188px; margin: 0 auto 12px; padding: 9px; border-radius: 12px; background: #fff; display: grid; place-items: center; }
.qr-box img, .qr-box canvas { width: 170px !important; height: 170px !important; }
.muted { color: var(--muted); font-size: 14px; line-height: 1.45; }
.qr-card .muted { margin: 0 0 7px; }
.join-code { font-size: 32px; font-weight: 800; letter-spacing: .17em; margin-left: .17em; }
.players-card { margin-bottom: 14px; }
.players-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: 11px; }
.players-heading h3 { font-size: 16px; margin: 0; }
.badge { background: var(--primary); color: #fff; border-radius: 999px; padding: 4px 10px; font-weight: 700; font-size: 13px; }
.player-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 7px; }
.player-list li { display: flex; gap: 9px; align-items: center; background: #f7f3eb; border-radius: 12px; padding: 10px; font-weight: 650; }
.player-list li::before { content: "👤"; }
.player-list .empty { font-weight: 500; color: var(--muted); justify-content: center; }
.player-list .empty::before { content: none; }
.center-state { text-align: center; min-height: calc(100vh - 122px); display: flex; flex-direction: column; justify-content: center; align-items: center; }
.center-state.compact { min-height: 63vh; }
.big-icon { font-size: 56px; margin-bottom: 17px; }
.center-state h2 { margin: 0 0 12px; font-size: 30px; letter-spacing: -.05em; }
.countdown-card { min-height: calc(100vh - 130px); display: flex; flex-direction: column; justify-content: center; text-align: center; }
.countdown-card > p:first-child { font-weight: 700; color: var(--muted); }
.countdown-number { font-size: 106px; line-height: 1; font-weight: 820; color: var(--primary); letter-spacing: -.08em; animation: pulse .9s ease infinite; }
@keyframes pulse { 50% { transform: scale(1.05); } }
.countdown-card h2 { font-size: 23px; margin: 25px 0 8px; }
.instruction { background: #fff; border-radius: 16px; padding: 13px; border: 1px solid var(--line); margin: 0; line-height: 1.4; }
.game-hud {
    display: flex; align-items: stretch; justify-content: space-between; gap: 8px;
    background: #fff; border: 1px solid var(--line); border-radius: 18px; padding: 11px 13px; margin-bottom: 12px;
    position: sticky; top: max(7px, env(safe-area-inset-top)); z-index: 20;
}
.game-hud strong { font-size: 20px; letter-spacing: -.02em; }
.hud-mode { text-align: right; max-width: 65%; }
.hud-mode strong { font-size: 14px; }
.game-note { font-size: 13px; color: var(--muted); margin: 0 0 10px; }
.progress-line { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; font-weight: 650; margin: 10px 0; }
/* Sorter */
.sorter-area .source-title, .shelf-title { font-weight: 720; font-size: 13px; margin: 0 0 7px; }
.sort-source { min-height: 116px; background: #efe6d7; border: 2px dashed #d5c7ab; border-radius: 17px; padding: 9px; display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 12px; }
.sort-shelves { display: grid; gap: 8px; }
.sort-shelf { min-height: 62px; border-radius: 15px; padding: 8px; border: 2px solid rgba(0,0,0,.05); background: #fff; position: relative; display: flex; flex-wrap: wrap; gap: 5px; padding-top: 29px; }
.sort-shelf .shelf-title { position: absolute; top: 7px; left: 9px; display: flex; gap: 6px; align-items: center; }
.color-dot { width: 11px; height: 11px; border-radius: 999px; background: var(--c); display: inline-block; }
.mini-book {
    appearance: none; border: 0; width: 22px; height: 40px; border-radius: 3px 5px 5px 3px;
    background: var(--c); box-shadow: inset 4px 0 rgba(255,255,255,.23), 0 2px 3px rgba(0,0,0,.13);
    padding: 0; cursor: grab; user-select: none; touch-action: none; position: relative;
}
.mini-book::after { content: ""; position: absolute; left: 4px; right: 3px; top: 12px; height: 3px; background: rgba(255,255,255,.47); }
.mini-book.selected { outline: 3px solid var(--ink); transform: translateY(-3px); }
.mini-book.ghost { position: fixed; z-index: 100; pointer-events: none; opacity: .88; transform: scale(1.16); }
.drop-over { outline: 3px solid rgba(32,117,91,.42); }
.correct-drop { animation: correctBounce .38s ease; }
@keyframes correctBounce { 45% { transform: translateY(-7px) scale(1.13); } 100% { transform: none; } }
/* Detective */
.detective-head { padding: 12px; border-radius: 16px; background: #fff; border: 1px solid var(--line); margin-bottom: 10px; }
.detective-head strong { color: var(--primary); }
.detect-grid { display: grid; grid-template-columns: repeat(var(--cols), 1fr); gap: clamp(3px, 1.25vw, 6px); }
.detect-book {
    appearance: none; border: 0; aspect-ratio: .65; min-height: 0; border-radius: 3px 6px 6px 3px;
    background: var(--c); position: relative; box-shadow: inset clamp(2px, .8vw, 4px) 0 rgba(255,255,255,.2), 0 2px 3px rgba(0,0,0,.11); padding: 0;
}
.detect-book::after { content: ""; position: absolute; left: 17%; right: 11%; top: 31%; height: clamp(1px, .6vw, 3px); background: rgba(255,255,255,.42); }
.detect-book.wrong { background: var(--red) !important; animation: shake .35s ease; }
.detect-book.right { animation: rightPop .42s ease; outline: 3px solid var(--green); }
@keyframes shake { 20%, 60% { transform: translateX(-3px); } 40%, 80% { transform: translateX(3px); } }
@keyframes rightPop { 45% { transform: scale(1.24); } }
/* Express */
.express-stats { display: flex; gap: 8px; margin-bottom: 11px; }
.stat-card { flex: 1; border-radius: 14px; padding: 9px; background: #fff; border: 1px solid var(--line); text-align: center; }
.stat-card small { display: block; color: var(--muted); font-size: 11px; margin-bottom: 3px; }
.stat-card strong { font-size: 17px; }
.target-card { border-radius: 17px; padding: 13px; margin-bottom: 11px; color: #fff; display: flex; align-items: center; justify-content: space-between; background: var(--c); font-weight: 750; }
.target-card span { background: rgba(255,255,255,.22); padding: 6px 9px; border-radius: 9px; font-size: 12px; }
.conveyor {
    height: 210px; border-radius: 20px; background: #ded7cb; border: 2px solid #c3b8a3; overflow: hidden; position: relative;
}
.conveyor::after { content: ""; position: absolute; left: 12px; right: 12px; bottom: 25px; height: 38px; border-radius: 9px; background: repeating-linear-gradient(90deg, #4d5651 0 22px, #636a65 22px 28px); }
.conveyor-line { position: absolute; left: 21px; top: 10px; bottom: 70px; width: 3px; border-left: 3px dashed rgba(24,54,47,.35); }
.belt-book {
    position: absolute; bottom: 55px; width: 41px; height: 66px; border: 0; border-radius: 5px 9px 9px 5px;
    background: var(--c); box-shadow: inset 7px 0 rgba(255,255,255,.25), 0 5px 7px rgba(0,0,0,.16); z-index: 2; touch-action: manipulation;
}
.belt-book::after { content: ""; position: absolute; left: 10px; right: 6px; top: 22px; height: 4px; background: rgba(255,255,255,.54); }
.belt-book.good { animation: bookGood .4s ease forwards; }
.belt-book.bad { animation: bookBad .42s ease forwards; }
@keyframes bookGood { 40% { transform: translateY(-13px) scale(1.1); } 100% { opacity: 0; transform: translateY(-18px); } }
@keyframes bookBad { 25%, 60% { transform: translateX(-4px); } 45%, 80% { transform: translateX(4px); } 100% { opacity: 0; } }
.express-help { margin: 11px 2px 0; font-size: 13px; color: var(--muted); text-align: center; }
/* Results and messages */
.table-wrap { overflow-x: auto; background: #fff; border: 1px solid var(--line); border-radius: 17px; margin: 14px 0 16px; }
.results-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.results-table th { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .08em; text-align: left; padding: 12px 10px; border-bottom: 1px solid var(--line); }
.results-table td { padding: 13px 10px; border-bottom: 1px solid #f0e9dd; font-weight: 600; }
.results-table tr:last-child td { border: 0; }
.results-table tr:first-child td:first-child::before { content: "🏆 "; }
.dq { color: var(--red); font-weight: 750; }
.toast {
    display: none; position: fixed; z-index: 500; left: 50%; bottom: max(18px, env(safe-area-inset-bottom)); transform: translateX(-50%);
    width: min(calc(100% - 32px), 440px); border-radius: 14px; padding: 12px 14px; background: #232c28; color: #fff; font-size: 14px;
    box-shadow: var(--shadow);
}
.toast.show { display: block; animation: rise .2s ease; }
@media (min-width: 700px) {
    body { display: grid; place-items: center; padding: 20px 0; }
    .phone-shell {/* min-height: min(920px, calc(100vh - 40px)); */border-radius: 30px;box-shadow: 0 18px 55px rgba(32,40,25,.14);}
    .center-state, .countdown-card { min-height: 650px; }
}
