:root {
    --bg: #0a0b16;
    --bg2: #131629;
    --ink: #eef0ff;
    --muted: #9aa0c4;
    --line: rgba(255, 255, 255, .09);
    --panel: rgba(19, 21, 40, .92);
    --accent: #6c8bff;
    --accent2: #b06bff;
    --match: #37d67a;
    --match2: #9dffc4;
    --split: #c07bff;
    --miss: #ff8095;
    --card: clamp(88px, 24vw, 190px);
    color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
    margin: 0;
    height: 100%;
    overflow: hidden;
    background: var(--bg);
    color: var(--ink);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
    overscroll-behavior: none;
}

body {
    background:
        radial-gradient(1100px 700px at 50% -10%, rgba(108, 139, 255, .22), transparent 60%),
        radial-gradient(900px 700px at 85% 110%, rgba(176, 107, 255, .16), transparent 60%),
        radial-gradient(800px 600px at 10% 110%, rgba(55, 214, 122, .08), transparent 60%),
        linear-gradient(180deg, var(--bg), #06070f);
}

#app {
    position: relative;
    display: flex;
    flex-direction: column;
    height: 100dvh;
    max-width: 1100px;
    margin: 0 auto;
    padding: env(safe-area-inset-top) 14px env(safe-area-inset-bottom);
}

.hidden { display: none !important; }

/* ---------------------------------------------------------------- HUD */
.hud {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 12px;
    padding: 12px 4px 8px;
    flex: 0 0 auto;
}
.hud-side { display: flex; gap: 18px; }
.hud-side.right { justify-content: flex-end; }
.hud-stat { display: flex; flex-direction: column; line-height: 1.1; }
.hud-k { font-size: .62rem; letter-spacing: .14em; color: var(--muted); font-weight: 700; }
.hud-v { font-size: 1.35rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.hud-v.score { color: #cfe0ff; }
.hud-v.streak { color: var(--accent2); transition: color .2s, text-shadow .2s; }
.hud-mid { display: flex; flex-direction: column; align-items: center; gap: 6px; min-width: 120px; }
.hud-type {
    font-size: .72rem; font-weight: 800; letter-spacing: .18em;
    padding: 3px 12px; border-radius: 999px;
    color: #bcd0ff; background: rgba(108, 139, 255, .14);
    border: 1px solid rgba(108, 139, 255, .3);
}
.hud-type.split { color: #e6d0ff; background: rgba(176, 107, 255, .18); border-color: rgba(176, 107, 255, .45); }
.timebar { width: 100%; height: 6px; border-radius: 999px; background: rgba(255, 255, 255, .08); overflow: hidden; }
.timebar i { display: block; height: 100%; width: 100%; background: linear-gradient(90deg, var(--accent), var(--accent2)); transition: width .12s linear; }
.timebar.split i { background: linear-gradient(90deg, var(--split), #ff8ad4); }
.timebar.match i { background: linear-gradient(90deg, var(--match), var(--match2)); }
.timebar.miss i { background: linear-gradient(90deg, #b06580, var(--miss)); }

/* -------------------------------------------------------------- Stage */
#stage {
    position: relative;
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 0;
    padding: 6px 0 14px;
}

.prompt { text-align: center; margin-bottom: clamp(10px, 3vh, 26px); padding: 0 8px; }
.prompt-title { font-size: clamp(1rem, 3.4vw, 1.5rem); font-weight: 800; letter-spacing: -.01em; }
.prompt-title .hl { color: var(--accent2); }
.prompt-sub { margin-top: 5px; font-size: clamp(.75rem, 2.4vw, .95rem); color: var(--muted); min-height: 1.2em; }
.prompt.split-announce .prompt-title { color: var(--split); text-shadow: 0 0 22px rgba(176, 107, 255, .6); animation: splitPulse .9s ease-out; }
@keyframes splitPulse {
    0% { transform: scale(.85); opacity: .2; }
    40% { transform: scale(1.06); opacity: 1; }
    100% { transform: scale(1); opacity: 1; }
}

.cards { display: flex; gap: clamp(10px, 2.4vw, 22px); justify-content: center; align-items: stretch; width: 100%; }

.card {
    position: relative;
    width: var(--card);
    min-height: calc(var(--card) * 1.12);
    border: 1.5px solid var(--line);
    border-radius: 22px;
    background: linear-gradient(165deg, rgba(46, 51, 92, .72), rgba(22, 24, 46, .92));
    color: var(--ink);
    font-family: inherit;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 14px 8px;
    cursor: pointer;
    transition: transform .14s ease, border-color .14s ease, box-shadow .18s ease, opacity .18s ease, background .18s ease;
    box-shadow: 0 12px 30px rgba(0, 0, 0, .35), inset 0 1px 0 rgba(255, 255, 255, .06);
    touch-action: manipulation;
    overflow: hidden;
}
.card::after {
    content: "";
    position: absolute; inset: 0;
    background: radial-gradient(120% 80% at 50% 0%, rgba(108, 139, 255, .16), transparent 60%);
    opacity: 0; transition: opacity .18s ease;
}
.card-emoji { font-size: clamp(2.4rem, 9vw, 4.4rem); line-height: 1; filter: drop-shadow(0 6px 12px rgba(0, 0, 0, .4)); }
.card-label { font-size: clamp(.78rem, 2.5vw, 1.05rem); font-weight: 700; color: #d7dcff; text-align: center; }

.card.selectable:hover, .card.selectable:focus-visible {
    transform: translateY(-6px) scale(1.035);
    border-color: rgba(108, 139, 255, .7);
    box-shadow: 0 18px 40px rgba(108, 139, 255, .28), inset 0 1px 0 rgba(255, 255, 255, .1);
    outline: none;
}
.card.selectable:hover::after, .card.selectable:focus-visible::after { opacity: 1; }
.card.selectable:active { transform: translateY(-2px) scale(.99); }

.card.picked-you {
    border-color: var(--accent);
    background: linear-gradient(165deg, rgba(64, 84, 160, .9), rgba(30, 34, 66, .95));
    box-shadow: 0 0 0 2px rgba(108, 139, 255, .5), 0 18px 44px rgba(108, 139, 255, .35);
    transform: translateY(-4px);
}
.card.picked-them {
    border-color: var(--accent2);
    box-shadow: 0 0 0 2px rgba(176, 107, 255, .45), 0 18px 44px rgba(176, 107, 255, .3);
}
.card.picked-both {
    border-color: var(--match);
    background: linear-gradient(165deg, rgba(40, 120, 80, .85), rgba(22, 52, 40, .95));
    box-shadow: 0 0 0 2px rgba(55, 214, 122, .55), 0 18px 48px rgba(55, 214, 122, .35);
    transform: translateY(-4px) scale(1.02);
}
.card.dimmed { opacity: .4; transform: scale(.95); }
.card.locked { pointer-events: none; }

.card-tag {
    position: absolute;
    top: 9px;
    font-size: .58rem; font-weight: 800; letter-spacing: .1em;
    padding: 2px 8px; border-radius: 999px; opacity: 0; transition: opacity .2s;
}
.card-tag.you { left: 9px; background: var(--accent); color: #06102c; }
.card-tag.them { right: 9px; background: var(--accent2); color: #1a0630; }
.card.picked-you .card-tag.you, .card.picked-both .card-tag.you { opacity: 1; }
.card.picked-them .card-tag.them, .card.picked-both .card-tag.them { opacity: 1; }

/* --------------------------------------------------------------- flash */
.flash {
    position: absolute;
    top: 4%;
    left: 50%;
    transform: translate(-50%, 0);
    text-align: center;
    pointer-events: none;
    z-index: 6;
    width: 100%;
}
.flash-word {
    font-size: clamp(2.6rem, 11vw, 5.6rem);
    font-weight: 900;
    letter-spacing: -.02em;
    line-height: 1;
    text-shadow: 0 8px 30px rgba(0, 0, 0, .5);
}
.flash-pts { margin-top: 6px; font-size: clamp(1rem, 3.6vw, 1.5rem); font-weight: 800; color: #d9ffe9; }
.flash-picks { margin-top: 4px; font-size: clamp(.72rem, 2.6vw, .92rem); color: var(--muted); font-weight: 600; }
.flash.match .flash-word { color: var(--match2); }
.flash.split .flash-word { color: #e0b6ff; }
.flash.miss .flash-word { color: var(--miss); }
.flash.none .flash-word { color: #c9cde8; font-size: clamp(2rem, 8vw, 3.6rem); }
.flash.pop { animation: flashPop .5s cubic-bezier(.2, 1.4, .4, 1) both; }
@keyframes flashPop {
    0% { transform: translate(-50%, 0) scale(.5); opacity: 0; }
    55% { transform: translate(-50%, 0) scale(1.1); opacity: 1; }
    100% { transform: translate(-50%, 0) scale(1); opacity: 1; }
}
.flash.out { animation: flashOut .35s ease forwards; }
@keyframes flashOut { to { transform: translate(-50%, -14px) scale(1.04); opacity: 0; } }

/* ------------------------------------------------------------- partner */
.partner {
    position: absolute;
    bottom: 4px;
    left: 50%;
    transform: translateX(-50%);
    display: flex; align-items: center; gap: 8px;
    font-size: .72rem; font-weight: 800; letter-spacing: .14em;
    color: var(--muted);
    padding: 7px 16px; border-radius: 999px;
    background: rgba(255, 255, 255, .05);
    border: 1px solid var(--line);
}
.partner.locked { color: #d8c4ff; border-color: rgba(176, 107, 255, .5); }
.partner-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); animation: pulse 1.1s ease-in-out infinite; }
.partner.locked .partner-dot { background: var(--accent2); animation: none; }
@keyframes pulse { 0%, 100% { opacity: .35; transform: scale(.8); } 50% { opacity: 1; transform: scale(1.15); } }

.fx { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 5; }

/* ------------------------------------------------------------- overlay */
.overlay {
    position: absolute; inset: 0;
    display: flex; align-items: center; justify-content: center;
    padding: 16px;
    background: rgba(6, 7, 15, .72);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 10;
}
.overlay.hidden { display: none !important; }
.panel {
    width: min(560px, 100%);
    max-height: 100%;
    overflow-y: auto;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 26px;
    padding: clamp(22px, 4vw, 36px);
    text-align: center;
    box-shadow: 0 30px 80px rgba(0, 0, 0, .55);
    animation: panelIn .32s cubic-bezier(.2, 1, .3, 1) both;
}
@keyframes panelIn { from { transform: translateY(14px) scale(.98); opacity: 0; } to { transform: none; opacity: 1; } }

.brand { font-size: clamp(2rem, 8vw, 3.2rem); font-weight: 900; letter-spacing: -.02em; }
.brand span { color: var(--accent2); }
.brand.small { font-size: 1.4rem; }
.tagline { color: var(--muted); margin: 6px 0 22px; font-size: .95rem; }

.howto { text-align: left; display: grid; gap: 12px; margin: 0 auto 22px; max-width: 400px; }
.howto-row { display: flex; align-items: center; gap: 12px; font-size: .92rem; color: #d3d7f2; }
.howto-row .chip {
    flex: 0 0 auto; width: 26px; height: 26px; border-radius: 50%;
    display: grid; place-items: center; font-size: .8rem; font-weight: 800;
    background: rgba(108, 139, 255, .18); color: #bcd0ff; border: 1px solid rgba(108, 139, 255, .35);
}
.howto-note { font-size: .84rem; color: var(--muted); margin: 4px 0 0; }
.howto-note .split { color: var(--split); }
.lobby-hint { margin-top: 14px; font-size: .74rem; color: #6f7699; }

.btn {
    appearance: none; border: 1px solid var(--line); border-radius: 14px;
    background: rgba(255, 255, 255, .06); color: var(--ink);
    font-family: inherit; font-size: 1rem; font-weight: 800; letter-spacing: .02em;
    padding: 13px 22px; cursor: pointer;
    transition: transform .12s ease, background .15s ease, border-color .15s ease, box-shadow .15s ease;
}
.btn:hover { transform: translateY(-2px); border-color: rgba(255, 255, 255, .25); }
.btn:active { transform: translateY(0) scale(.99); }
.btn:disabled { opacity: .5; cursor: default; transform: none; }
.btn.primary {
    background: linear-gradient(135deg, var(--accent), var(--accent2));
    border-color: transparent; color: #fff;
    box-shadow: 0 12px 30px rgba(108, 139, 255, .35);
}
.btn.ghost { background: transparent; color: var(--muted); }
.btn.tiny { font-size: .78rem; padding: 8px 14px; border-radius: 10px; }

/* ------------------------------------------------------------ waiting */
.wait-title { font-size: 1.25rem; font-weight: 800; margin-top: 6px; }
.wait-sub { color: var(--muted); font-size: .85rem; margin: 4px 0 18px; }
.dots i { animation: blink 1.2s infinite; font-style: normal; }
.dots i:nth-child(2) { animation-delay: .2s; }
.dots i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 60%, 100% { opacity: .2; } 30% { opacity: 1; } }

.practice { background: rgba(0, 0, 0, .22); border: 1px solid var(--line); border-radius: 20px; padding: 16px 12px; margin-bottom: 18px; }
.practice-prompt { font-size: .78rem; font-weight: 700; letter-spacing: .04em; color: var(--muted); margin-bottom: 12px; }
.practice-cards { --card: clamp(70px, 19vw, 120px); }
.practice-result { min-height: 1.4em; margin-top: 12px; font-size: .9rem; font-weight: 800; }
.practice-result.ok { color: var(--match2); }
.practice-result.no { color: var(--miss); }
.practice-foot { margin-top: 8px; font-size: .74rem; color: #6f7699; }
.practice-foot b { color: var(--accent2); }

/* ------------------------------------------------------------- result */
.result-kicker { font-size: .72rem; font-weight: 800; letter-spacing: .2em; color: var(--muted); }
.result-score { font-size: clamp(3rem, 14vw, 5rem); font-weight: 900; line-height: 1; margin: 8px 0 2px; font-variant-numeric: tabular-nums; }
.result-sync { color: var(--match2); font-weight: 800; font-size: 1.1rem; }
.result-sync small { color: var(--muted); font-weight: 600; }
.result-summary { color: #d3d7f2; margin: 14px auto 18px; max-width: 360px; font-size: .95rem; }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 22px; }
.stat { background: rgba(255, 255, 255, .04); border: 1px solid var(--line); border-radius: 14px; padding: 12px; }
.stat .stat-k { display: block; font-size: .62rem; letter-spacing: .12em; color: var(--muted); font-weight: 700; }
.stat .stat-v { font-size: 1.4rem; font-weight: 900; font-variant-numeric: tabular-nums; }
.result-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.result-wait { margin-top: 14px; font-size: .8rem; color: var(--muted); }
.goodbye-msg { color: #d3d7f2; margin: 14px 0 20px; }

/* ------------------------------------------------------- pause banner */
.pause-banner {
    position: absolute; top: 10px; left: 50%; transform: translateX(-50%);
    display: flex; align-items: center; gap: 12px;
    background: rgba(40, 24, 30, .94); border: 1px solid rgba(255, 128, 149, .4);
    border-radius: 999px; padding: 8px 10px 8px 18px;
    font-size: .8rem; font-weight: 700; color: #ffd7de; z-index: 8;
    max-width: calc(100% - 20px);
}
.pause-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--miss); animation: pulse 1s infinite; flex: 0 0 auto; }

/* ----------------------------------------------------------- controls */
.controls {
    flex: 0 0 auto;
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px; padding: 8px 4px 10px;
}
.reactions { display: flex; gap: 8px; }
.controls-right { display: flex; align-items: center; gap: 10px; }
.reaction {
    appearance: none; border: 1px solid var(--line); background: rgba(255, 255, 255, .05);
    border-radius: 12px; width: 42px; height: 42px; font-size: 1.15rem; cursor: pointer;
    transition: transform .12s ease, background .15s ease, border-color .15s ease;
}
.reaction:hover { transform: translateY(-3px) scale(1.05); border-color: rgba(176, 107, 255, .5); }
.reaction:active { transform: scale(.94); }

.toast {
    position: absolute; bottom: 76px; left: 50%; transform: translateX(-50%);
    background: rgba(10, 12, 24, .95); border: 1px solid var(--line);
    border-radius: 999px; padding: 9px 18px; font-size: .8rem; font-weight: 700;
    color: #d3d7f2; z-index: 9; white-space: nowrap;
}

.emoji-float {
    position: absolute; font-size: 2rem; z-index: 7; pointer-events: none;
    animation: floatUp 1.4s ease-out forwards;
}
@keyframes floatUp {
    0% { transform: translateY(0) scale(.6); opacity: 0; }
    20% { opacity: 1; transform: translateY(-10px) scale(1.1); }
    100% { transform: translateY(-90px) scale(1); opacity: 0; }
}

/* streak escalation */
body.streak-warm .hud-v.streak { text-shadow: 0 0 18px rgba(176, 107, 255, .8); }
body.streak-hot .hud-v.streak { color: #ffd0ff; text-shadow: 0 0 26px rgba(255, 120, 220, .9); }
body.streak-hot #stage { animation: heat 2.4s ease-in-out infinite; }
@keyframes heat { 0%, 100% { filter: none; } 50% { filter: saturate(1.18) brightness(1.05); } }

@media (max-width: 520px) {
    .hud { grid-template-columns: 1fr auto 1fr; gap: 8px; }
    .hud-side { gap: 12px; }
    .hud-v { font-size: 1.1rem; }
    .stats { grid-template-columns: repeat(2, 1fr); }
    .card { border-radius: 18px; }
}
@media (max-height: 620px) {
    .prompt { margin-bottom: 8px; }
    .card { min-height: calc(var(--card) * .95); }
    .card-emoji { font-size: clamp(2rem, 7vw, 3rem); }
}
