:root {
  --bg: #f3efe4;
  --panel: #fffdf7;
  --ink: #23222a;
  --muted: #6d6a73;
  --line: #d9d3c3;
  --card: #ffffff;
  --shadow: 0 2px 0 rgba(0, 0, 0, .12), 0 6px 18px rgba(40, 30, 10, .08);
  --p0: #d8322a;        /* player 1 tray: red */
  --p0-soft: #fbe3de;
  --p1: #2f63c6;        /* player 2 tray: blue */
  --p1-soft: #dfe8fa;
  --yes: #2a9d57;
  --no: #d8322a;
  --accent: var(--p0);
  --accent-soft: var(--p0-soft);
  --pixel: "Press Start 2P", ui-monospace, monospace;
  --radius: 12px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17161c;
    --panel: #212028;
    --ink: #eeeaf2;
    --muted: #a19eab;
    --line: #37353f;
    --card: #2b2a33;
    --shadow: 0 2px 0 rgba(0, 0, 0, .4), 0 6px 18px rgba(0, 0, 0, .3);
    --p0: #ef5a4f;
    --p0-soft: #3b2222;
    --p1: #5b8cf0;
    --p1-soft: #1f2940;
  }
}

* { box-sizing: border-box; }

a { color: var(--p1); }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
}

.p0 { --accent: var(--p0); --accent-soft: var(--p0-soft); }
.p1 { --accent: var(--p1); --accent-soft: var(--p1-soft); }

h1, h2, h3, .kicker, .answer, .bar .who { font-family: var(--pixel); font-weight: 400; }
h3 { font-size: 11px; margin: 0 0 12px; text-transform: uppercase; letter-spacing: .04em; }
.muted { color: var(--muted); font-size: 13px; }
.kicker { font-size: 10px; letter-spacing: .08em; color: var(--muted); text-transform: uppercase; margin: 0 0 12px; }

.screen { max-width: 1280px; margin: 0 auto; padding: 16px; }

.panel {
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

/* ---------- buttons ---------- */

.btn {
  font: inherit;
  font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%;
  padding: 11px 16px;
  border-radius: 10px;
  border: 2px solid var(--ink);
  background: var(--card);
  color: var(--ink);
  cursor: pointer;
  box-shadow: 0 3px 0 var(--ink);
  transition: transform .08s, box-shadow .08s;
}
a.btn { text-decoration: none; width: auto; }
.btn:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 4px 0 var(--ink); }
.btn:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 0 0 var(--ink); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn:focus-visible, .card:focus-visible, select:focus-visible, input:focus-visible {
  outline: 3px solid var(--accent); outline-offset: 2px;
}
.btn.primary { background: var(--accent); color: #fff; }
.btn.danger { background: var(--card); color: var(--no); border-color: var(--no); box-shadow: 0 3px 0 var(--no); }
.btn.ghost { border-color: var(--line); box-shadow: none; background: transparent; }
.btn.ghost:hover:not(:disabled) { box-shadow: none; background: var(--accent-soft); }
.btn.small { width: auto; padding: 6px 12px; font-size: 13px; }
.btn.big { padding: 14px 20px; font-size: 16px; }

/* ---------- setup ---------- */

.setup { max-width: 560px; display: grid; gap: 16px; padding-top: 32px; }
.title-card { text-align: center; }
.title-card h1 { font-size: clamp(20px, 6vw, 32px); line-height: 1.4; margin: 0; }
.title-card h1 span { color: var(--p0); }
.title-sprites { display: flex; justify-content: center; flex-wrap: wrap; margin-top: 12px; }
.title-sprites .sprite { width: 64px; height: 64px; }

.setup-form { display: grid; gap: 16px; }
.names { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.names label { display: grid; gap: 6px; font-weight: 600; font-size: 13px; color: var(--accent); }
.names input {
  font: inherit; font-size: 16px; color: var(--ink); background: var(--card);
  padding: 10px 12px; border: 2px solid var(--line); border-left: 6px solid var(--accent); border-radius: 8px; width: 100%;
}
.sizes { border: 0; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.sizes legend { font-weight: 600; font-size: 13px; margin-bottom: 6px; padding: 0; }
.size-opt input { position: absolute; opacity: 0; }
.size-opt span {
  display: grid; text-align: center; padding: 10px 6px; cursor: pointer;
  border: 2px solid var(--line); border-radius: 10px; background: var(--card);
}
.size-opt small { color: var(--muted); font-size: 12px; }
.size-opt input:checked + span { border-color: var(--ink); background: var(--p0-soft); box-shadow: 0 3px 0 var(--ink); }
.size-opt input:focus-visible + span { outline: 3px solid var(--p0); outline-offset: 2px; }

.rules summary { cursor: pointer; font-weight: 700; }
.rules ol { padding-left: 20px; margin: 12px 0; }
.rules li { margin-bottom: 8px; }
.rules ul { padding-left: 18px; margin-top: 6px; }

/* ---------- online: home, lobby, waiting ---------- */

.field { display: grid; gap: 6px; font-weight: 600; font-size: 13px; }
.field input {
  font: inherit; font-size: 16px; color: var(--ink); background: var(--card);
  padding: 10px 12px; border: 2px solid var(--line); border-left: 6px solid var(--p0); border-radius: 8px; width: 100%;
}
.field input.invalid { border-color: var(--no); }
.code-input { font-family: var(--pixel) !important; letter-spacing: .3em; text-transform: uppercase; }

.tabs { display: grid; grid-template-columns: 1fr 1fr; background: var(--bg); border-radius: 10px; padding: 4px; gap: 4px; }
.tab {
  font: inherit; font-weight: 600; border: 0; border-radius: 8px; padding: 9px; cursor: pointer;
  background: transparent; color: var(--muted);
}
.tab.active { background: var(--card); color: var(--ink); box-shadow: 0 2px 0 var(--line); }
.tab-body { display: grid; gap: 14px; }
.tab-body[hidden] { display: none; }
.tab-body .muted { margin: 0; text-align: center; }

.error {
  margin: 0; padding: 12px 14px; border-radius: 10px; font-weight: 600;
  background: var(--p0-soft); color: var(--no); border: 2px solid var(--no);
}

.center { min-height: 100vh; display: grid; place-items: center; align-content: center; }
.wait-box { display: grid; gap: 14px; justify-items: center; text-align: center; max-width: 440px; width: 100%; padding: 28px 24px; }
.wait-box h2 { font-size: 14px; margin: 0; line-height: 1.6; }
.wait-box p { margin: 0; }
.play .wait-box { margin: 40px auto; }
.room-code {
  font: 32px var(--pixel); letter-spacing: .25em; padding: 16px 12px 16px 20px;
  background: var(--p0-soft); color: var(--p0); border: 3px dashed var(--p0); border-radius: 12px;
}
.copy-row { display: flex; gap: 8px; width: 100%; }
.copy-row input {
  flex: 1; min-width: 0; font: inherit; font-size: 13px; padding: 8px 10px; color: var(--ink);
  background: var(--card); border: 2px solid var(--line); border-radius: 8px;
}

.dots { display: inline-flex; gap: 3px; margin-left: 4px; vertical-align: middle; }
.dots i { width: 4px; height: 4px; border-radius: 50%; background: currentColor; animation: blink 1.2s infinite; }
.dots i:nth-child(2) { animation-delay: .2s; }
.dots i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .2; } 40% { opacity: 1; } }

.spin { animation: spin 1.1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.last-q { margin: 0; background: var(--bg); border-radius: 8px; padding: 10px 12px; font-size: 14px; }
.last-q b { margin-left: 6px; }
.small { font-size: 12px; margin: 0; }
.bar .vs { font-size: 13px; opacity: .85; }
.their-turn-screen .board { filter: saturate(.75); }

.pokeball-big {
  width: 72px; height: 72px; margin: 0 auto 16px; border-radius: 50%; border: 4px solid var(--ink);
  background:
    radial-gradient(circle at 50% 50%, #fff 0 9px, var(--ink) 9px 14px, transparent 14px),
    linear-gradient(to bottom, var(--accent) 0 46%, var(--ink) 46% 54%, #fff 54%);
}

/* ---------- play ---------- */

.bar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 14px; margin-bottom: 16px; border-radius: var(--radius);
  background: var(--accent); color: #fff; box-shadow: var(--shadow);
}
.bar .who { font-size: 12px; display: flex; align-items: center; gap: 10px; }
.bar .dot { width: 12px; height: 12px; border-radius: 50%; background: #fff; box-shadow: 0 0 0 3px rgba(255, 255, 255, .35); }
.bar-title { flex: 1; font-weight: 600; opacity: .95; }
.bar .btn.ghost { color: #fff; border-color: rgba(255, 255, 255, .5); }
.bar .btn.ghost:hover { background: rgba(255, 255, 255, .15); }

.layout { display: grid; grid-template-columns: 280px minmax(0, 1fr); gap: 16px; align-items: start; }
.layout > * { min-width: 0; }
.side { display: grid; gap: 12px; position: sticky; top: 16px; }
.side, .side .panel, .side.panel { grid-template-columns: minmax(0, 1fr); }
.side .panel, .side.panel { display: grid; gap: 10px; }
.side h3 { margin-bottom: 2px; }

.secret { display: grid; justify-items: center; gap: 6px; text-align: center; padding: 8px 0; }
.secret.small { grid-template-columns: auto 1fr; justify-items: start; text-align: left; align-items: center; padding: 0; }
.secret-empty {
  width: 96px; height: 96px; display: grid; place-items: center; font: 32px var(--pixel);
  border: 3px dashed var(--line); border-radius: 12px; color: var(--muted);
}
.secret-panel { border-color: var(--accent); background: var(--accent-soft); }

select {
  font: inherit; width: 100%; max-width: 100%; padding: 10px; border-radius: 8px; color: var(--ink);
  border: 2px solid var(--line); background: var(--card);
}

.or { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; }
.or::before, .or::after { content: ""; flex: 1; height: 2px; background: var(--line); }

.q { margin: 0; font-weight: 600; }
.answer {
  font-size: 28px; text-align: center; padding: 14px; border-radius: 10px; color: #fff;
  animation: pop .35s cubic-bezier(.2, 1.6, .4, 1);
}
.answer.yes { background: var(--yes); }
.answer.no { background: var(--no); }
@keyframes pop { from { transform: scale(.6); opacity: 0; } }

.log ol { margin: 0; padding: 0; list-style: none; display: grid; gap: 6px; max-height: 240px; overflow: auto; }
.log li { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; border-bottom: 1px dashed var(--line); padding-bottom: 6px; }
b.yes, b.no { font-size: 12px; padding: 1px 8px; border-radius: 99px; color: #fff; align-self: start; flex-shrink: 0; }
b.yes { background: var(--yes); }
b.no { background: var(--no); }

/* ---------- board & cards ---------- */

.board {
  display: grid; gap: 10px; padding: 14px; border-radius: 16px;
  grid-template-columns: repeat(auto-fill, minmax(112px, 1fr));
  background: var(--accent);
  box-shadow: inset 0 -6px 0 rgba(0, 0, 0, .18), var(--shadow);
}
.board.size-max { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }

.card {
  all: unset; box-sizing: border-box; cursor: pointer; display: block;
  perspective: 600px; aspect-ratio: 4 / 5; position: relative;
}
.card-inner {
  position: absolute; inset: 0; display: block;
  transition: transform .45s cubic-bezier(.3, .7, .3, 1);
  transform-style: preserve-3d;
}
.face {
  position: absolute; inset: 0; border-radius: 10px; backface-visibility: hidden;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  padding: 6px 4px;
}
.front { background: var(--card); border: 2px solid rgba(0, 0, 0, .15); box-shadow: 0 3px 0 rgba(0, 0, 0, .2); }
.back {
  transform: rotateX(180deg);
  background: rgba(0, 0, 0, .22);
  border: 2px dashed rgba(255, 255, 255, .35);
}
.card.down .card-inner { transform: rotateX(180deg); }
.card:hover:not(.down) .front { transform: translateY(-2px); box-shadow: 0 5px 0 rgba(0, 0, 0, .2); }
.card:focus-visible { outline: 3px solid #fff; outline-offset: 2px; border-radius: 10px; }

.ball {
  width: 36%; aspect-ratio: 1; border-radius: 50%; opacity: .55;
  border: 3px solid rgba(255, 255, 255, .8);
  background:
    radial-gradient(circle, rgba(255, 255, 255, .9) 0 18%, transparent 19%),
    linear-gradient(to bottom, transparent 46%, rgba(255, 255, 255, .8) 46% 54%, transparent 54%);
}

.dex { position: absolute; top: 5px; left: 7px; font-size: 10px; color: var(--muted); font-variant-numeric: tabular-nums; }
.sprite { width: 72%; max-width: 80px; height: auto; aspect-ratio: 1; image-rendering: pixelated; }
.sprite.big { width: 112px; max-width: none; }
.secret.small .sprite { width: 64px; }
.name { font-weight: 700; font-size: 13px; text-align: center; line-height: 1.15; }

.chips { display: flex; gap: 3px; flex-wrap: wrap; justify-content: center; }
.chip {
  font-size: 9px; font-weight: 700; text-transform: uppercase; letter-spacing: .02em;
  padding: 1px 5px; border-radius: 4px; color: #fff; background: #888;
}
.board.size-max .chip { font-size: 8px; padding: 1px 3px; }
.board.size-max .name { font-size: 11px; }

.t-normal { background: #9a9a78; } .t-fire { background: #e8742c; } .t-water { background: #5b82e6; }
.t-grass { background: #5aaa3b; } .t-electric { background: #d9a800; } .t-ice { background: #5ebfbd; }
.t-fighting { background: #b3302a; } .t-poison { background: #9a3f99; } .t-ground { background: #c9a14b; }
.t-flying { background: #8f7ae0; } .t-psychic { background: #f0507c; } .t-bug { background: #93a81a; }
.t-rock { background: #aa9433; } .t-ghost { background: #6b5594; } .t-dragon { background: #6a3ef0; }
.t-dark { background: #6b5445; } .t-steel { background: #8e8ea8; } .t-fairy { background: #d5689c; }

/* pick phase */
.card.selected .front { outline: 4px solid var(--ink); outline-offset: -1px; background: var(--accent-soft); transform: translateY(-3px); }

/* after an answer: cards that the answer rules out */
.card.mark:not(.down) .front { box-shadow: inset 0 0 0 3px var(--no), 0 3px 0 rgba(0, 0, 0, .2); }
.card.mark:not(.down) .sprite { opacity: .45; }

/* guess mode */
.board.guessing { animation: glow 1.4s ease-in-out infinite alternate; }
.board.guessing .card:not(.down):hover .front { outline: 4px solid var(--ink); background: #fff7c2; color: #23222a; }
@keyframes glow { to { box-shadow: inset 0 -6px 0 rgba(0, 0, 0, .18), 0 0 0 6px rgba(255, 210, 60, .6); } }

/* ---------- game over ---------- */

.over-box { text-align: center; max-width: 520px; width: 100%; min-width: 0; border-color: var(--accent); }
.over-box h2 { color: var(--accent); font-size: clamp(18px, 5vw, 26px); margin: 0 0 12px; word-break: break-word; }
.reveal { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin: 20px 0; }
.reveal-card {
  display: grid; justify-items: center; gap: 4px; padding: 12px; border-radius: 12px;
  background: var(--accent-soft); border: 2px solid var(--accent);
}
.reveal-card small { color: var(--muted); }
.row { display: flex; gap: 10px; }
.row .btn { flex: 1; min-width: 0; }
.reveal-card small { overflow-wrap: anywhere; }

/* ---------- modal ---------- */

.modal {
  position: fixed; inset: 0; background: rgba(10, 10, 20, .55); display: grid; place-items: center; padding: 16px; z-index: 10;
}
.modal[hidden] { display: none; }
.modal-box {
  background: var(--panel); border-radius: 16px; padding: 24px; max-width: 360px; width: 100%;
  text-align: center; box-shadow: 0 8px 0 rgba(0, 0, 0, .3); animation: pop .25s ease-out;
}
.modal-box h3 { font-size: 13px; }
.modal-mon { display: grid; justify-items: center; gap: 4px; }
.modal-mon .sprite { width: 112px; max-width: none; }
.modal-actions { display: flex; gap: 10px; margin-top: 16px; }

/* ---------- small screens ---------- */

@media (max-width: 760px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .side { position: static; }
  .board { grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); padding: 10px; gap: 8px; }
  .board.size-max { grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); }
  .chip { font-size: 8px; padding: 1px 3px; }
  .name { font-size: 12px; }
  .names { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

.disclaimer { font-size: 11px; line-height: 1.5; color: var(--muted); text-align: center; padding: 4px 8px 16px; }
.disclaimer a { color: inherit; }

/* ---------- accounts & leaderboard ---------- */

.account { display: grid; gap: 12px; }
.account p { margin: 0; }
.account-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.account-actions .btn { width: auto; flex: 1; }
.account-actions .btn.small { flex: 0; }
.account-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; }
.account-stats span { display: grid; gap: 2px; font-weight: 700; font-size: 18px; background: var(--bg); border-radius: 8px; padding: 8px 4px; }
.account-stats small { font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.account-stats .rating { color: var(--p0); }

.bar .tag { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; background: rgba(255, 255, 255, .2); padding: 3px 8px; border-radius: 99px; }
.rank-note { font-weight: 600; background: var(--accent-soft); border-radius: 8px; padding: 8px 12px; }

.lb-head { display: flex; align-items: center; gap: 12px; }
.lb-head h2 { font-size: 16px; margin: 0; }
.lb { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.lb th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 6px 8px; border-bottom: 2px solid var(--line); }
.lb td { padding: 8px; border-bottom: 1px solid var(--line); }
.lb td:nth-child(2) { overflow-wrap: anywhere; }
.lb tr.me td { background: var(--p0-soft); font-weight: 700; }
.lb tbody tr:nth-child(-n+3) td:first-child { font-weight: 700; color: var(--p0); }
.lb-note { text-align: center; }
.disclaimer a + a, .disclaimer a[href="privacy.html"] { margin-left: 4px; }

/* ---------- room options, timer, notices ---------- */

.sizes.opts { grid-template-columns: repeat(4, 1fr); }
.sizes.opts .size-opt span { padding: 8px 4px; }
.rules-line { font-size: 13px; font-weight: 600; background: var(--bg); border-radius: 8px; padding: 8px 10px; margin: 0; text-align: center; }
.clocks { display: flex; gap: 6px; }
.clock { display: grid; justify-items: center; line-height: 1.1; padding: 4px 10px; border-radius: 8px; background: rgba(0, 0, 0, .18); opacity: .6; }
.clock small { font-size: 10px; font-weight: 600; max-width: 80px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.clock b { font-family: var(--pixel); font-size: 13px; font-weight: 400; }
.clock.running { background: #fff; color: #23222a; opacity: 1; }
.clock.low b { color: var(--no); }
.clock.running.low { animation: blink 1s infinite; }
.notice { margin: 0; padding: 8px 12px; border-radius: 8px; font-weight: 600; font-size: 14px; background: var(--accent-soft); border-left: 4px solid var(--accent); }

/* ---------- daily puzzle ---------- */

.daily-card { display: flex; align-items: center; gap: 12px; border-color: var(--p0); }
.daily-card > div { flex: 1; display: grid; gap: 2px; }
.daily-card .btn { width: auto; flex-shrink: 0; }
.daily-reveal { display: grid; justify-items: center; margin: 8px 0; }
.share-grid { font-size: 22px; letter-spacing: 2px; margin: 8px 0; }
.stats-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 12px 0; }
.stats-row span { display: grid; gap: 2px; background: var(--bg); border-radius: 8px; padding: 8px 4px; }
.stats-row strong { font-size: 20px; }
.stats-row small { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

.sizes.dexes { grid-template-columns: 1fr 1fr; }

/* ---------- daily ranking, donations, ads ---------- */

.daily-actions { display: grid; gap: 6px; flex-shrink: 0; }
.daily-actions .btn { width: auto; }
.daily-ranking { text-align: left; margin: 16px 0 8px; display: grid; gap: 8px; }
.daily-ranking h3 { margin: 0; text-align: center; }
.daily-ranking .lb td, .daily-ranking .lb th { padding: 6px; }
.bar .clock { opacity: 1; }

.support-btn {
  display: block; width: fit-content; margin: 4px auto; padding: 8px 16px; border-radius: 99px;
  background: #ffdd00; color: #23222a; font-weight: 700; font-size: 14px; text-decoration: none;
  box-shadow: 0 3px 0 rgba(0, 0, 0, .25);
}
.support-btn:hover { transform: translateY(-1px); }
.over-box .support-btn { margin-top: 12px; }

.ad-slot { max-width: 728px; margin: 0 auto 24px; padding: 0 16px; text-align: center; }
.ad-slot[hidden] { display: none; }
.ad-label { display: block; font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; margin-bottom: 4px; }

/* ---------- about page ---------- */

.article { max-width: 720px; }
.article .title-card .btn { width: auto; }
.article .rules h2 { font-size: 13px; line-height: 1.6; margin: 0 0 12px; }
.article .rules h3 { font-size: 10px; margin: 14px 0 6px; }
.article .rules p, .article .rules li { line-height: 1.6; }
.article .rules ul, .article .rules ol { padding-left: 20px; }
