:root {
    --wood-0: #17100b;
    --wood-1: #241710;
    --felt-0: #16321f;
    --felt-1: #0f2417;
    --gold: #e0a94a;
    --gold-deep: #a9761f;
    --parchment: #f4e7c9;
    --parchment-2: #e8d6ac;
    --ink: #2b2118;
    --ink-soft: #5c4a34;
    --you: #4f9bff;
    --them: #ff7ab0;
    --good: #4fd47f;
    --bad: #ff7a7a;
    --shadow: 0 14px 34px rgba(0, 0, 0, 0.5);
    --serif: Georgia, "Times New Roman", "Palatino Linotype", serif;
    --sans: "Trebuchet MS", "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
}

body {
    font-family: var(--sans);
    color: var(--parchment);
    background:
        radial-gradient(120% 90% at 50% 0%, #3a2717 0%, var(--wood-1) 45%, var(--wood-0) 100%);
    -webkit-user-select: none;
    user-select: none;
    overflow: hidden;
    touch-action: manipulation;
}

#app {
    position: relative;
    height: 100%;
    display: flex;
    flex-direction: column;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.hidden { display: none !important; }

button { font-family: inherit; cursor: pointer; }

/* ============================================================ HUD */
.hud {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 14px;
    background: linear-gradient(180deg, rgba(0, 0, 0, 0.45), rgba(0, 0, 0, 0.12));
    border-bottom: 1px solid rgba(224, 169, 74, 0.28);
}

.hud-side { display: flex; gap: 14px; min-width: 84px; }
.hud-side.right { justify-content: flex-end; }

.hud-stat { display: flex; flex-direction: column; line-height: 1.05; }
.hud-k { font-size: 9px; letter-spacing: 0.16em; color: rgba(244, 231, 201, 0.55); }
.hud-v { font-family: var(--serif); font-size: 19px; font-weight: 700; color: var(--parchment); }
.hud-v.score { color: var(--gold); }
.hud-v.streak { color: var(--them); }

.hud-mid { flex: 1 1 auto; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.hud-phase {
    font-size: 12px;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--gold);
    font-weight: 700;
    text-align: center;
    min-height: 15px;
}

.timebar {
    width: min(320px, 60vw);
    height: 6px;
    border-radius: 6px;
    background: rgba(0, 0, 0, 0.4);
    overflow: hidden;
    box-shadow: inset 0 0 0 1px rgba(224, 169, 74, 0.22);
}
.timebar i {
    display: block;
    height: 100%;
    width: 100%;
    background: linear-gradient(90deg, var(--gold-deep), var(--gold));
    transition: width 0.12s linear;
}
.timebar.you i { background: linear-gradient(90deg, #2a6cd0, var(--you)); }
.timebar.resolve i { background: linear-gradient(90deg, var(--good), #bff7d1); }

/* ============================================================ STAGE */
#stage {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.table {
    position: relative;
    z-index: 1;
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px clamp(8px, 3vw, 40px) 10px;
    background:
        radial-gradient(120% 70% at 50% 0%, var(--felt-0), var(--felt-1) 78%);
    border-bottom: 2px solid rgba(0, 0, 0, 0.4);
}
.table::before {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    background-image:
        repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.015) 0 8px, transparent 8px 16px);
    opacity: 0.6;
}

/* ============================================================ BOARD */
.board {
    position: relative;
    z-index: 1;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: clamp(6px, 1.4vw, 14px);
    width: 100%;
    max-width: 640px;
    margin: 0 auto;
}

.tile {
    position: relative;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    min-height: 58px;
    border-radius: 12px;
    border: 2px solid rgba(224, 169, 74, 0.4);
    background: linear-gradient(180deg, #fbf1d8, var(--parchment-2));
    color: var(--ink);
    font-weight: 700;
    text-align: left;
    box-shadow: 0 3px 0 rgba(0, 0, 0, 0.35), inset 0 1px 0 #fff8e6;
    transition: transform 0.1s ease, box-shadow 0.1s ease, opacity 0.15s ease;
}
.tile .tile-emoji { font-size: clamp(20px, 5vw, 30px); line-height: 1; }
.tile .tile-label { font-size: clamp(12px, 2.6vw, 16px); letter-spacing: 0.01em; }
.tile.selectable { cursor: pointer; }
.tile.selectable:hover { transform: translateY(-2px); box-shadow: 0 6px 0 rgba(0, 0, 0, 0.35), inset 0 1px 0 #fff8e6; }
.tile.selectable:active { transform: translateY(1px); box-shadow: 0 1px 0 rgba(0, 0, 0, 0.35); }
.tile.locked { cursor: default; }
.tile.dimmed { opacity: 0.42; }
.tile.pick-you { border-color: var(--you); box-shadow: 0 0 0 3px rgba(79, 155, 255, 0.5), 0 3px 0 rgba(0, 0, 0, 0.3); }
.tile.pick-them { border-color: var(--them); box-shadow: 0 0 0 3px rgba(255, 122, 176, 0.5), 0 3px 0 rgba(0, 0, 0, 0.3); }
.tile.pick-both { border-color: var(--good); box-shadow: 0 0 0 3px rgba(79, 212, 127, 0.55), 0 3px 0 rgba(0, 0, 0, 0.3); }
.tile.answer { border-color: var(--good); background: linear-gradient(180deg, #e6ffe9, #bff0c8); }
.tile .tag {
    position: absolute;
    top: -9px;
    font-size: 9px;
    font-weight: 800;
    letter-spacing: 0.08em;
    padding: 2px 6px;
    border-radius: 6px;
    color: #10100c;
}
.tile .tag.you { left: 6px; background: var(--you); color: #fff; }
.tile .tag.them { right: 6px; background: var(--them); color: #3a0d21; }
.tile .tag.answer-tag { left: 6px; background: var(--good); }

/* ============================================================ CLUES */
.clue-row {
    position: relative;
    z-index: 1;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: clamp(8px, 2vw, 18px);
    width: 100%;
    max-width: 640px;
    margin: 0 auto;
}
.clue-box { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.clue-head {
    font-size: 9px;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: rgba(244, 231, 201, 0.6);
    text-align: center;
}
.clue-card {
    min-height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 9px 12px;
    border-radius: 10px;
    border: 2px dashed rgba(224, 169, 74, 0.35);
    background: rgba(0, 0, 0, 0.26);
    color: rgba(244, 231, 201, 0.45);
    font-size: 13px;
    line-height: 1.28;
}
.clue-card.empty { font-style: italic; }
.clue-card.filled {
    border-style: solid;
    background: linear-gradient(180deg, #fbf1d8, var(--parchment-2));
    color: var(--ink);
    font-weight: 700;
    box-shadow: 0 3px 0 rgba(0, 0, 0, 0.35);
    animation: deal 0.28s ease;
}
.clue-card.mine.filled { border-color: var(--you); }
.clue-card.theirs.filled { border-color: var(--them); }
.clue-box.highlight .clue-card { animation: pulse 1.2s ease infinite; }

/* ============================================================ HAND */
.hand-wrap {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 720px;
    margin: auto auto 0;
    padding-top: 4px;
}
.hand-head {
    text-align: center;
    font-size: 10px;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: rgba(244, 231, 201, 0.6);
    margin-bottom: 7px;
}
.hand {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: clamp(6px, 1.6vw, 14px);
}
.clue-tile {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    min-height: 74px;
    padding: 10px 12px;
    border-radius: 12px;
    border: 2px solid rgba(224, 169, 74, 0.45);
    background: linear-gradient(180deg, #fffaf0, #efe0bd);
    color: var(--ink);
    font-size: clamp(12px, 2.3vw, 14px);
    font-weight: 700;
    line-height: 1.25;
    box-shadow: 0 3px 0 rgba(0, 0, 0, 0.4), inset 0 1px 0 #fffdf5;
    transition: transform 0.1s ease, box-shadow 0.1s ease, opacity 0.15s ease;
}
.clue-tile.selectable { cursor: pointer; }
.clue-tile.selectable:hover { transform: translateY(-4px) rotate(-0.5deg); box-shadow: 0 7px 0 rgba(0, 0, 0, 0.4), inset 0 1px 0 #fffdf5; }
.clue-tile.selectable:active { transform: translateY(1px); }
.clue-tile.not-turn { opacity: 0.5; cursor: default; }
.clue-tile.picked { border-color: var(--you); box-shadow: 0 0 0 3px rgba(79, 155, 255, 0.5), 0 3px 0 rgba(0, 0, 0, 0.4); }
.clue-tile.picked-both { border-color: var(--them); box-shadow: 0 0 0 3px rgba(255, 122, 176, 0.5), 0 3px 0 rgba(0, 0, 0, 0.4); }
.clue-tile .mini-tag {
    position: absolute;
    top: -9px;
    left: 8px;
    font-size: 9px;
    font-weight: 800;
    letter-spacing: 0.06em;
    padding: 2px 6px;
    border-radius: 6px;
    background: var(--you);
    color: #fff;
}

@keyframes deal {
    from { transform: translateY(-10px) rotate(-2deg); opacity: 0; }
    to { transform: none; opacity: 1; }
}
@keyframes pulse {
    0%, 100% { box-shadow: 0 3px 0 rgba(0, 0, 0, 0.35); }
    50% { box-shadow: 0 0 0 4px rgba(224, 169, 74, 0.35), 0 3px 0 rgba(0, 0, 0, 0.35); }
}

/* ============================================================ FLASH */
.flash {
    position: absolute;
    left: 50%;
    top: 40%;
    transform: translate(-50%, -50%) scale(0.7);
    z-index: 6;
    text-align: center;
    pointer-events: none;
    opacity: 0;
}
.flash.pop { animation: flashIn 0.4s cubic-bezier(0.2, 1.5, 0.4, 1) forwards; }
@keyframes flashIn {
    from { opacity: 0; transform: translate(-50%, -50%) scale(0.6); }
    to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}
.flash-word {
    font-family: var(--serif);
    font-size: clamp(34px, 9vw, 62px);
    font-weight: 800;
    letter-spacing: 0.02em;
    text-shadow: 0 4px 0 rgba(0, 0, 0, 0.45);
}
.flash-pts { font-size: clamp(18px, 4vw, 28px); font-weight: 800; color: var(--gold); }
.flash-picks { margin-top: 6px; font-size: 13px; color: rgba(244, 231, 201, 0.85); }
.flash.both .flash-word { color: #a9f5c2; }
.flash.one .flash-word { color: #ffd98a; }
.flash.none .flash-word { color: #ff9d9d; }

/* ============================================================ OVERLAY */
.overlay {
    position: absolute;
    inset: 0;
    z-index: 7;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 18px;
    background:
        radial-gradient(80% 60% at 50% 30%, rgba(58, 39, 23, 0.92), rgba(12, 8, 5, 0.96));
    overflow: auto;
}
.overlay.hidden { display: none !important; }

.panel {
    width: min(520px, 100%);
    text-align: center;
    padding: 26px clamp(18px, 5vw, 34px);
    border-radius: 18px;
    border: 2px solid rgba(224, 169, 74, 0.4);
    background: linear-gradient(180deg, rgba(47, 31, 19, 0.96), rgba(28, 18, 11, 0.98));
    box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.06);
    animation: panelIn 0.3s ease;
}
@keyframes panelIn {
    from { transform: translateY(12px) scale(0.98); opacity: 0; }
    to { transform: none; opacity: 1; }
}

.brand {
    font-family: var(--serif);
    font-size: clamp(30px, 8vw, 46px);
    font-weight: 800;
    letter-spacing: 0.06em;
    color: var(--parchment);
    text-shadow: 0 3px 0 rgba(0, 0, 0, 0.4);
}
.brand span { color: var(--gold); }
.brand.small { font-size: clamp(20px, 5vw, 26px); }
.tagline { margin: 6px 0 18px; color: rgba(244, 231, 201, 0.72); font-style: italic; }

.howto { text-align: left; display: flex; flex-direction: column; gap: 10px; margin-bottom: 20px; }
.howto-row { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; line-height: 1.35; color: rgba(244, 231, 201, 0.9); }
.howto-row b { color: var(--gold); }
.chip {
    flex: 0 0 auto;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--gold);
    color: #2a1c0c;
    font-weight: 800;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.howto-note {
    margin: 2px 0 0;
    padding-top: 10px;
    border-top: 1px dashed rgba(224, 169, 74, 0.3);
    font-size: 12px;
    line-height: 1.4;
    color: rgba(244, 231, 201, 0.6);
}

.btn {
    border: 2px solid rgba(224, 169, 74, 0.5);
    background: linear-gradient(180deg, #3a2817, #241710);
    color: var(--parchment);
    font-weight: 800;
    letter-spacing: 0.08em;
    font-size: 14px;
    text-transform: uppercase;
    padding: 12px 18px;
    border-radius: 12px;
    box-shadow: 0 3px 0 rgba(0, 0, 0, 0.4);
    transition: transform 0.1s ease, box-shadow 0.1s ease, filter 0.1s ease;
}
.btn:hover { filter: brightness(1.12); }
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0, 0, 0, 0.4); }
.btn.primary {
    background: linear-gradient(180deg, #f4cd77, var(--gold-deep));
    color: #2a1c0c;
    border-color: #f6d98f;
}
.btn.ghost { background: transparent; border-color: rgba(244, 231, 201, 0.3); color: rgba(244, 231, 201, 0.75); }
.btn.tiny { font-size: 11px; padding: 7px 11px; letter-spacing: 0.06em; }

.lobby-hint { margin-top: 14px; font-size: 12px; color: rgba(244, 231, 201, 0.55); }

.wait-title { font-family: var(--serif); font-size: 22px; margin: 12px 0 2px; }
.wait-sub { font-size: 12px; color: rgba(244, 231, 201, 0.6); margin-bottom: 14px; }
.dots i { animation: blink 1.2s infinite; }
.dots i:nth-child(2) { animation-delay: 0.2s; }
.dots i:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 60%, 100% { opacity: 0.2; } 30% { opacity: 1; } }

.practice { margin-bottom: 16px; }
.practice-board { grid-template-columns: repeat(2, 1fr); max-width: 360px; }
.practice-clues { display: flex; flex-direction: column; gap: 8px; max-width: 420px; margin: 12px auto 0; }
.practice-result { min-height: 20px; margin-top: 10px; font-weight: 800; letter-spacing: 0.04em; }
.practice-result.ok { color: var(--good); }
.practice-result.no { color: var(--bad); }
.practice-foot { margin-top: 8px; font-size: 12px; color: rgba(244, 231, 201, 0.55); }
.practice-foot b { color: var(--gold); }

/* ============================================================ RESULTS */
.result-kicker { font-size: 11px; letter-spacing: 0.22em; color: var(--gold); }
.result-score {
    font-family: var(--serif);
    font-size: clamp(52px, 14vw, 78px);
    font-weight: 800;
    line-height: 1;
    margin: 6px 0 0;
    color: var(--parchment);
    text-shadow: 0 4px 0 rgba(0, 0, 0, 0.4);
}
.result-link { color: rgba(244, 231, 201, 0.7); margin-top: 2px; }
.result-link span { font-size: 20px; font-weight: 800; color: var(--them); }
.result-summary { margin: 14px 0 16px; font-size: 14px; line-height: 1.45; color: rgba(244, 231, 201, 0.9); }
.stats { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-bottom: 20px; }
.stat {
    min-width: 78px;
    padding: 8px 10px;
    border-radius: 10px;
    border: 1px solid rgba(224, 169, 74, 0.28);
    background: rgba(0, 0, 0, 0.24);
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.stat-k { font-size: 9px; letter-spacing: 0.12em; color: rgba(244, 231, 201, 0.55); }
.stat-v { font-family: var(--serif); font-size: 18px; font-weight: 700; color: var(--gold); }
.result-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.result-wait { margin-top: 14px; font-size: 12px; color: rgba(244, 231, 201, 0.6); }
.goodbye-msg { margin: 14px 0 18px; color: rgba(244, 231, 201, 0.85); }

/* ============================================================ PAUSE / TOAST */
.pause-banner {
    position: absolute;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 5;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: 999px;
    background: rgba(20, 12, 7, 0.94);
    border: 1px solid rgba(224, 169, 74, 0.4);
    font-size: 12px;
    box-shadow: var(--shadow);
}
.pause-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--bad); animation: blink 1s infinite; }
.toast {
    position: absolute;
    bottom: 74px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 6;
    padding: 9px 16px;
    border-radius: 999px;
    background: rgba(20, 12, 7, 0.95);
    border: 1px solid rgba(224, 169, 74, 0.4);
    font-size: 13px;
    box-shadow: var(--shadow);
}

/* ============================================================ FX + CONTROLS */
.fx { position: absolute; inset: 0; z-index: 4; pointer-events: none; }

.controls {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 6px 12px;
    padding-bottom: calc(6px + env(safe-area-inset-bottom));
    background: rgba(0, 0, 0, 0.32);
    border-top: 1px solid rgba(224, 169, 74, 0.22);
}
.reactions { display: flex; gap: 6px; }
.reaction {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: 1px solid rgba(224, 169, 74, 0.3);
    background: rgba(255, 255, 255, 0.06);
    font-size: 17px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}
.reaction:hover { background: rgba(255, 255, 255, 0.14); }
.controls-right { display: flex; align-items: center; gap: 8px; }

.emoji-float {
    position: absolute;
    z-index: 5;
    font-size: 26px;
    pointer-events: none;
    animation: floatUp 1.4s ease forwards;
}
@keyframes floatUp {
    from { transform: translateY(0) scale(0.7); opacity: 0; }
    20% { opacity: 1; transform: translateY(-8px) scale(1.1); }
    to { transform: translateY(-90px) scale(0.9); opacity: 0; }
}

/* ============================================================ RESPONSIVE */
@media (max-width: 560px) {
    .board { grid-template-columns: repeat(2, 1fr); }
    .board .tile { min-height: 52px; padding: 8px 10px; }
    .clue-card { font-size: 12px; }
    .hand { gap: 6px; }
    .clue-tile { min-height: 68px; font-size: 11.5px; padding: 8px; }
    .hud-v { font-size: 16px; }
    .hud-side { min-width: 64px; gap: 10px; }
    .reaction { width: 30px; height: 30px; font-size: 15px; }
}

@media (max-height: 620px) {
    .clue-tile { min-height: 58px; }
    .tile { min-height: 48px; }
    .clue-card { min-height: 44px; }
}

@media (prefers-reduced-motion: reduce) {
    * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}
