/* Lychee Wordsearch: blush/rose shell, cream flesh, leaf green */
:root {
  --bg: #fbf0ee;
  --bg-2: #f7dbdf;
  --card: #fffaf6;
  --card-2: #fdf0ec;
  --ink: #3b2a31;
  --muted: #8d747c;
  --line: #f0d8d4;
  --accent: #d9466f;
  --accent-ink: #ffffff;
  --leaf: #4f9a5a;
  --leaf-soft: #e3f1e2;
  --gold: #e3a21a;
  --cell-bg: #fffaf7;
  --shadow: 0 6px 24px rgba(150, 80, 90, 0.10), 0 1px 3px rgba(150, 80, 90, 0.08);

  /* player colours: pink/teal, orange/blue etc. stay distinct for colour-blind eyes too */
  --p-pink: #e0457b;
  --p-teal: #0f9488;
  --p-orange: #e07a12;
  --p-purple: #8b5cf6;
  --p-blue: #2f74d0;
  --cap-fill: 0.3;
  --letter: #33242b;

  --radius: 20px;
  --font-display: "Fredoka", "Baloo 2", system-ui, sans-serif;
  --font-body: "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
}

/* Dark. The shared Lychee Games theme (<html data-theme>, set by /shared/theme.js from the Settings sheet)
   decides: dark and midnight are dark here too. Without the shared layer (no data-theme) the phone's
   own light/dark setting still decides, exactly as before. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    color-scheme: dark;
    --bg: #1e181c;
    --bg-2: #2c2027;
    --card: #282126;
    --card-2: #31282e;
    --ink: #f7e9ed;
    --muted: #b79ea6;
    --line: #3e3239;
    --accent: #ff7fa5;
    --accent-ink: #2a1219;
    --leaf: #7cc985;
    --leaf-soft: #233626;
    --gold: #f2c04e;
    --cell-bg: #282126;
    --shadow: 0 6px 24px rgba(0, 0, 0, 0.35), 0 1px 3px rgba(0, 0, 0, 0.3);

    --p-pink: #ff7fa5;
    --p-teal: #2ec4b6;
    --p-orange: #ffa04a;
    --p-purple: #b28cff;
    --p-blue: #64a6ff;
    --cap-fill: 0.34;
    --letter: #fbeff3;
  }
}
:root[data-theme="dark"], :root[data-theme="midnight"] {
  color-scheme: dark;
  --bg: #1e181c;
  --bg-2: #2c2027;
  --card: #282126;
  --card-2: #31282e;
  --ink: #f7e9ed;
  --muted: #b79ea6;
  --line: #3e3239;
  --accent: #ff7fa5;
  --accent-ink: #2a1219;
  --leaf: #7cc985;
  --leaf-soft: #233626;
  --gold: #f2c04e;
  --cell-bg: #282126;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.35), 0 1px 3px rgba(0, 0, 0, 0.3);

  --p-pink: #ff7fa5;
  --p-teal: #2ec4b6;
  --p-orange: #ffa04a;
  --p-purple: #b28cff;
  --p-blue: #64a6ff;
  --cap-fill: 0.34;
  --letter: #fbeff3;
}
/* Midnight, Lychee and Matcha take their surfaces and accent from the shared palette (--lg-*). */
:root[data-theme="midnight"], :root[data-theme="lychee"], :root[data-theme="matcha"] {
  --bg: var(--lg-cream);
  --bg-2: var(--lg-pink);
  --card: var(--lg-white);
  --card-2: var(--lg-tint-1);
  --ink: var(--lg-ink);
  --muted: var(--lg-muted);
  --line: var(--lg-line);
  --accent: var(--lg-rose);
  --accent-ink: var(--lg-on-rose);
  --leaf: var(--lg-leaf);
  --leaf-soft: var(--lg-tint-2);
  --cell-bg: var(--lg-white);
  --letter: var(--lg-ink);
}
/* Rainbow highlighter: one colour per found word in solo play (readable on light and dark) */
:root {
  --rb0: #e0457b; --rb1: #e07a12; --rb2: #c99a00; --rb3: #3f9a4a;
  --rb4: #0f9488; --rb5: #2f74d0; --rb6: #8b5cf6; --rb7: #c0399e;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --rb0: #ff7fa5; --rb1: #ffa04a; --rb2: #f2c04e; --rb3: #7cc985;
    --rb4: #2ec4b6; --rb5: #64a6ff; --rb6: #b28cff; --rb7: #f08ad6;
  }
}
:root[data-theme="dark"], :root[data-theme="midnight"] {
  --rb0: #ff7fa5; --rb1: #ffa04a; --rb2: #f2c04e; --rb3: #7cc985;
  --rb4: #2ec4b6; --rb5: #64a6ff; --rb6: #b28cff; --rb7: #f08ad6;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: var(--font-body);
  color: var(--ink);
  background-color: var(--bg);
  background-image:
    radial-gradient(circle at 12% 8%, var(--bg-2) 0, transparent 38%),
    radial-gradient(circle at 92% 88%, var(--bg-2) 0, transparent 40%);
  background-attachment: fixed;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3 { font-family: var(--font-display); font-weight: 600; margin: 0; }

#app { width: 100%; }
.screen {
  max-width: 980px;
  margin: 0 auto;
  padding: 16px 16px calc(24px + env(safe-area-inset-bottom));
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}

.label { display: block; font-size: 0.8rem; font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); margin: 0 0 8px; }
.muted { color: var(--muted); margin: 0; }
.msg { min-height: 1.3em; margin: 10px 0 0; color: var(--accent); font-weight: 700; font-size: 0.95rem; }

/* buttons */
.btn {
  font: 700 1rem var(--font-body);
  color: var(--ink);
  background: var(--card-2);
  border: 1.5px solid var(--line);
  border-radius: 999px;
  padding: 11px 20px;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.15s, box-shadow 0.15s, opacity 0.15s;
  touch-action: manipulation;
}
.btn:hover:not(:disabled) { transform: translateY(-1px); }
.btn:active:not(:disabled) { transform: translateY(1px) scale(0.98); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); box-shadow: 0 4px 14px color-mix(in srgb, var(--accent) 35%, transparent); }
.btn.ghost { background: transparent; }
.btn.big { font-family: var(--font-display); font-weight: 600; font-size: 1.12rem; padding: 13px 24px; }
.btn.small { padding: 8px 14px; font-size: 0.9rem; }
.btn:focus-visible, .icon-btn:focus-visible, .topic:focus-visible, .seg-btn:focus-visible, .swatch:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 2px; }

input[type="text"], textarea {
  width: 100%;
  font: 600 1.05rem var(--font-body);
  color: var(--ink);
  background: var(--bg);
  border: 1.5px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input[type="text"]:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 18%, transparent); }
textarea { resize: vertical; min-height: 120px; line-height: 1.45; }

.shake { animation: shake 0.35s; }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }

/* ---------- home ---------- */
.home { max-width: 480px; padding-top: max(4vh, 16px); display: flex; flex-direction: column; gap: 14px; }
.brand { text-align: center; margin-bottom: 4px; }
.logo-mark { width: 74px; height: 74px; display: block; margin: 0 auto 6px; filter: drop-shadow(0 6px 10px rgba(190, 60, 95, 0.22)); animation: bob 4s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-4px) rotate(-3deg); } }
.logo { font-size: clamp(2.1rem, 9.4vw, 3rem); font-weight: 700; letter-spacing: -0.01em; line-height: 1.02; }
.logo span { color: var(--accent); }
.tagline { margin: 8px 0 0; color: var(--leaf); font-weight: 800; font-size: 1.02rem; }
.home-actions { display: flex; flex-direction: column; gap: 10px; }
.join-row { display: flex; gap: 8px; }

/* welcome card (returning player) */
.welcome { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 14px; align-items: center; padding: 16px; }
.welcome-av {
  --pc: var(--accent);
  width: 66px; height: 66px; border-radius: 50%; border: 0; cursor: pointer;
  display: grid; place-items: center; font-size: 36px; line-height: 1;
  background: color-mix(in srgb, var(--pc) 14%, var(--card)); box-shadow: 0 0 0 3px var(--pc), var(--shadow);
}
.welcome-main { min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.welcome h2 { font-size: 1.3rem; line-height: 1.15; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lvl-row { display: flex; align-items: center; gap: 8px; min-width: 0; }
.lvl-badge {
  flex: none; font-family: var(--font-display); font-weight: 600; font-size: 0.88rem; line-height: 1;
  padding: 5px 9px; border-radius: 999px; background: var(--leaf); color: #fff;
}
.xpbar { flex: 1 1 auto; min-width: 40px; height: 9px; border-radius: 99px; background: color-mix(in srgb, var(--leaf) 16%, var(--line)); overflow: hidden; }
.xpbar > span { display: block; height: 100%; width: 0; border-radius: inherit; background: linear-gradient(90deg, var(--leaf), color-mix(in srgb, var(--leaf) 60%, #d6f0a0)); transition: width 1s cubic-bezier(.3,.9,.3,1); }
.xp-text { flex: none; font-size: 0.78rem; font-weight: 800; color: var(--muted); font-variant-numeric: tabular-nums; }
.streak { margin: 0; font-weight: 800; font-size: 0.9rem; color: var(--gold); }
.streak:empty { display: none; }

.setup { display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center; }
.setup-title { font-size: 1.35rem; }
.setup .btn.big { min-width: 220px; }
.small-note { font-size: 0.86rem; }

/* big home buttons: icon + title + one-line description */
.btn.act { display: flex; align-items: center; gap: 12px; text-align: left; border-radius: 20px; padding: 12px 16px; }
.act-ic { flex: none; width: 40px; height: 40px; display: grid; place-items: center; font-size: 1.6rem; border-radius: 14px; background: color-mix(in srgb, var(--card) 70%, transparent); }
.btn.primary .act-ic { background: rgba(255, 255, 255, 0.22); }
.act-logo { width: 34px; height: 34px; }
.act-t { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.act-t small { font-family: var(--font-body); font-weight: 700; font-size: 0.8rem; opacity: 0.8; margin-top: 2px; }
.act-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.btn.small-act { padding: 10px 12px; font-family: var(--font-display); font-weight: 600; font-size: 1.02rem; }
.btn.small-act .act-ic { width: 32px; height: 32px; font-size: 1.25rem; border-radius: 11px; }
#btnDaily .act-ic { background: var(--leaf-soft); }
.duo-box { display: flex; flex-direction: column; gap: 8px; padding: 12px; border-radius: 18px; background: var(--card); border: 1px dashed var(--line); animation: rise 0.2s ease; }
.home .msg { text-align: center; margin: 0; }
.home .msg:empty { display: none; }
.join-row input { text-transform: uppercase; letter-spacing: 0.3em; font-family: var(--font-display); text-align: center; min-width: 0; }
.foot { text-align: center; color: var(--muted); font-size: 0.86rem; margin: 6px 0 0; }

/* identity: avatar picker, fun name, colour */
.you { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.av-pick { display: flex; align-items: center; gap: 14px; }
.av-big {
  --pc: var(--accent);
  width: 84px; height: 84px; border-radius: 50%;
  display: grid; place-items: center; font-size: 46px; line-height: 1;
  background: color-mix(in srgb, var(--pc) 14%, var(--card));
  box-shadow: 0 0 0 3px var(--pc), var(--shadow);
  transition: box-shadow 0.2s, background 0.2s;
}
.name-row { display: flex; align-items: center; gap: 6px; max-width: 100%; min-height: 40px; }
.name-text { font-family: var(--font-display); font-weight: 600; font-size: 1.3rem; cursor: text; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.name-input { width: 200px !important; padding: 7px 12px !important; font-size: 1.1rem !important; text-align: center; }
.icon-btn.pen { width: 32px; height: 32px; font-size: 0.95rem; }
.swatches { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
.swatch {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--sw); border: 3px solid var(--card); box-shadow: 0 0 0 2px var(--line);
  cursor: pointer; transition: transform 0.15s, box-shadow 0.15s;
}
.swatch.on { box-shadow: 0 0 0 3px var(--sw); transform: scale(1.12); }

/* ---------- lobby ---------- */
.lobby { max-width: 1180px; display: flex; flex-direction: column; gap: 14px; }
.topbar { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 8px; }
.topbar h2 { text-align: center; font-size: 1.4rem; }
.topbar-spacer { width: 80px; display: flex; justify-content: flex-end; }
.settings-mount { position: absolute; top: 10px; right: 12px; z-index: 5; }
.settings-mount .lg-icon-button, .topbar-spacer .lg-icon-button { width: 44px; min-width: 44px; min-height: 44px; height: 44px; border-radius: 50%; padding: 0; background: var(--card); border: 1.5px solid var(--line); color: var(--ink); }
.screen.home { position: relative; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.lobby-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }
.col { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.col-title { font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin-bottom: 12px; text-align: center; }
@media (max-width: 979px) {
  .col-side { order: -1; }
  .col-you { order: -2; }
  .you-card .col-title { display: none; }
  .you-card .you { flex-direction: row; flex-wrap: wrap; justify-content: center; gap: 8px 14px; }
  .you-card .av-big { width: 60px; height: 60px; font-size: 32px; }
  .you-card .av-pick { gap: 8px; }
  .you-card .swatch { width: 28px; height: 28px; }
}
@media (min-width: 980px) {
  .lobby-grid { grid-template-columns: 220px minmax(0, 1fr) 250px; align-items: start; }
  .col-you, .col-side { position: sticky; top: 16px; }
}

.invite { text-align: center; }
.code-row { display: flex; align-items: center; justify-content: center; gap: 8px; margin: 0 0 12px; }
.code {
  font-family: var(--font-display); font-weight: 700;
  font-size: clamp(2.2rem, 11vw, 2.8rem); letter-spacing: 0.14em; padding-left: 0.14em;
  color: var(--accent); line-height: 1.1;
}
.code.loading { opacity: 0.4; animation: breathe 1.4s ease-in-out infinite; }
@keyframes breathe { 50% { opacity: 0.15; } }

.players { display: flex; align-items: center; justify-content: center; gap: 12px; flex-wrap: wrap; }
@media (min-width: 980px) { .players { flex-direction: column; gap: 8px; } }
.player { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 1rem; min-width: 0; }
.player .pname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 190px; }
.player.waiting { color: var(--muted); font-weight: 700; }
.player.waiting .av { animation: breathe 1.4s ease-in-out infinite; }
.av {
  --pc: var(--muted);
  display: inline-grid; place-items: center; flex: 0 0 auto;
  width: 30px; height: 30px; border-radius: 50%; font-size: 17px; line-height: 1;
  background: color-mix(in srgb, var(--pc) 14%, var(--card)); box-shadow: 0 0 0 2px var(--pc);
}
.av.ghost { box-shadow: none; border: 2px dashed var(--muted); color: var(--muted); font-weight: 800; font-size: 0.9rem; }
.vs { font-family: var(--font-display); color: var(--muted); font-weight: 600; }

.settings h3 { font-size: 1.05rem; margin: 18px 0 10px; color: var(--muted); }
.topics-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.topics-head h3 { margin: 0; }
.picked { font-weight: 800; font-size: 0.9rem; color: var(--accent); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.carousel { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 8px; }
.icon-btn.nav { width: 34px; height: 34px; font-size: 1.4rem; line-height: 1; padding-bottom: 3px; }
.icon-btn:disabled { opacity: 0.35; cursor: default; }
.topics { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; min-height: 0; }
@media (min-width: 560px) { .topics { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
/* phones: cards take the full width, the ‹ › arrows sit under them either side of the page dots */
@media (max-width: 559px) {
  .carousel { grid-template-columns: auto minmax(0, 1fr) auto; grid-template-areas: "g g g" "p . n"; row-gap: 0; }
  .carousel .topics { grid-area: g; }
  #topicPrev { grid-area: p; margin-top: 6px; }
  #topicNext { grid-area: n; margin-top: 6px; }
  .settings .dots-row { margin: -34px 0 14px; height: 34px; align-items: center; pointer-events: none; }
  .topic { min-height: 84px; }
}
@media (min-width: 980px) { .you-card .swatches { gap: 7px; } .you-card .swatch { width: 30px; height: 30px; } }
.topic {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: left;
  padding: 10px 11px; border-radius: 16px; border: 1.5px solid var(--line); background: var(--card-2);
  color: var(--ink); cursor: pointer; font-family: var(--font-body);
  transition: transform 0.12s, border-color 0.15s, background 0.15s;
  min-width: 0; min-height: 92px;
}
.topic:hover { transform: translateY(-2px); }
.topic .emoji { font-size: 1.5rem; line-height: 1.2; }
.topic .title { font-weight: 800; font-size: 0.92rem; line-height: 1.2; overflow-wrap: anywhere; }
.topic .sub { font-size: 0.74rem; color: var(--muted); font-weight: 700; }
.topic.on { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, var(--card)); box-shadow: 0 0 0 2px var(--accent) inset; }
.topic.pick-own { border-style: dashed; background: transparent; }
.dots-row { display: flex; justify-content: center; gap: 6px; margin: 10px 0 4px; }
.pdot { width: 7px; height: 7px; border-radius: 50%; background: var(--line); transition: background 0.2s, transform 0.2s; }
.pdot.on { background: var(--accent); transform: scale(1.25); }
.topic-tools { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-top: 6px; }
.topic-tools .btn.small { padding: 7px 12px; font-size: 0.84rem; }
.pick-box { margin-top: 10px; display: flex; flex-direction: column; gap: 8px; }
.pick-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 6px; max-height: 300px; overflow-y: auto; padding: 2px; }
.pick-item {
  display: grid; grid-template-columns: auto minmax(0, 1fr); grid-template-rows: auto auto; column-gap: 8px; align-items: center;
  text-align: left; padding: 7px 10px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--card-2);
  color: var(--ink); font-family: var(--font-body); cursor: pointer;
}
.pick-item .emoji { grid-row: span 2; font-size: 1.3rem; }
.pick-item .title { font-weight: 800; font-size: 0.9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pick-item .sub { font-size: 0.72rem; color: var(--muted); font-weight: 700; }
.pick-item.on { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent) inset; }
.custom-box { margin-top: 12px; }
.hint { font-size: 0.86rem; color: var(--muted); margin: 6px 2px 0; }

.seg { display: flex; flex-wrap: wrap; gap: 8px; }
.seg-btn {
  font: 700 0.92rem var(--font-body); color: var(--ink);
  padding: 9px 14px; border-radius: 999px; border: 1.5px solid var(--line); background: var(--card-2); cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.seg-btn.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.seg-diff { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.seg-diff .seg-btn { border-radius: 16px; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 9px 6px; }
.seg-btn .sl { font-family: var(--font-display); font-weight: 600; font-size: 1rem; }
.seg-btn .ss { font-size: 0.7rem; font-weight: 700; opacity: 0.85; text-align: center; line-height: 1.3; }

.summary { display: flex; flex-direction: column; gap: 12px; align-items: center; text-align: center; }
.sum-topic { display: flex; align-items: center; gap: 10px; font-family: var(--font-display); font-size: 1.5rem; font-weight: 600; }
.sum-topic .emoji { font-size: 2rem; }
.sum-row { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.pill { background: var(--card-2); border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; font-weight: 700; font-size: 0.9rem; }

.start-bar { display: flex; flex-direction: column; align-items: center; gap: 8px; padding-bottom: 8px; }
.start-bar .msg { color: var(--muted); text-align: center; margin: 0; }
.start-bar .btn { min-width: 200px; }

/* ---------- game ---------- */
.game { padding-top: 8px; max-width: 1240px; }
.hud {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 6px;
  margin-bottom: 10px;
}
.hud .opp { justify-content: flex-end; }
.hud .mid { text-align: center; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 3px; }
.hud-topic { display: none; font-weight: 800; font-size: 0.85rem; color: var(--muted); max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hud-meta { display: flex; gap: 6px; align-items: center; justify-content: center; font-size: 0.72rem; font-weight: 800; color: var(--muted); white-space: nowrap; }
.hud-meta .arrows { letter-spacing: 0.04em; font-size: 0.8rem; color: var(--ink); opacity: 0.75; }
.progress { width: 128px; height: 6px; border-radius: 99px; background: var(--line); overflow: hidden; display: flex; }
.progress .pm, .progress .po { display: block; height: 100%; width: 0; transition: width 0.35s ease; }
.progress .po { margin-left: auto; }

.pl { --pc: var(--muted); display: flex; align-items: center; gap: 6px; min-width: 0; font-weight: 800; }
.pl .pn { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; font-size: 0.9rem; display: none; }
.pl .av { width: 32px; height: 32px; font-size: 18px; }
.pl .ct {
  display: inline-flex; flex-direction: column; align-items: center; gap: 1px;
  font-family: var(--font-display); font-weight: 700; line-height: 1; min-width: 3.4ch; text-align: center;
  background: var(--card); border: 1.5px solid color-mix(in srgb, var(--pc) 55%, var(--line)); border-radius: 12px; padding: 4px 8px 3px; box-shadow: var(--shadow);
}
.pl .cp { font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.pl .cn { font-family: var(--font-body); font-size: 0.6rem; font-weight: 800; color: var(--muted); white-space: nowrap; }
.pl .cn:empty { display: none; }
/* phones: the score box never shrinks below its contents; the progress bar gives up the room */
@media (max-width: 819px) {
  .pl .ct { flex: none; padding: 4px 6px 3px; }
  .pl .av { width: 30px; height: 30px; font-size: 17px; }
  .progress { width: 96px; }
  .hm-kind { display: none; }
}
.hud-act { justify-self: end; display: flex; align-items: center; gap: 6px; }
.pause-btn { width: 36px; height: 36px; font-size: 0.95rem; }
.pause-btn[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.hint-btn {
  justify-self: end; display: inline-flex; align-items: center; gap: 3px;
  height: 36px; padding: 0 10px 0 8px; border-radius: 999px; cursor: pointer;
  font: 800 0.95rem var(--font-body); color: var(--ink);
  background: color-mix(in srgb, var(--gold) 16%, var(--card)); border: 1.5px solid color-mix(in srgb, var(--gold) 55%, var(--line));
}
.hint-btn .hi-ic { font-size: 1rem; }
.hint-btn .hi-n { min-width: 1ch; font-variant-numeric: tabular-nums; }
.hint-btn:disabled { opacity: 0.45; cursor: default; }
.hm-kind { color: var(--leaf); }
@keyframes bump { 40% { transform: scale(1.35); } }
.timer { font-family: var(--font-display); font-weight: 600; font-size: 1.45rem; line-height: 1; font-variant-numeric: tabular-nums; }
.timer.urgent { color: var(--accent); animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.08); } }
.icon-btn {
  width: 38px; height: 38px; border-radius: 50%; border: 1.5px solid var(--line); background: var(--card);
  color: var(--ink); font-size: 1rem; cursor: pointer; display: inline-grid; place-items: center; flex: 0 0 auto;
  font-family: var(--font-body); font-weight: 800;
}

/* header tools: a popover behind ⋯ on phones, an inline row on wide screens */
.icon-btn.more { width: 34px; height: 34px; font-size: 1.2rem; }
.tools {
  display: none;
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 25;
  flex-direction: column; gap: 2px; padding: 6px; min-width: 230px;
  background: var(--card); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow);
}
.tools.open { display: flex; animation: rise 0.18s ease; }
.tool {
  display: flex; align-items: center; gap: 10px; width: 100%;
  font: 700 0.95rem var(--font-body); color: var(--ink); text-align: left;
  background: transparent; border: 0; border-radius: 10px; padding: 9px 10px; cursor: pointer;
}
.tool:hover { background: var(--card-2); }
.tool .ti { width: 22px; text-align: center; font-size: 1.05rem; }
.tool[aria-pressed="false"] .ti { opacity: 0.55; }

@media (min-width: 820px) {
  .hud { grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); grid-template-areas: "me mid opp" "tools tools tools"; row-gap: 8px; }
  .hud .me { grid-area: me; }
  .hud .mid { grid-area: mid; }
  .hud .opp { grid-area: opp; }
  .hud-topic { display: block; }
  .pl .pn { display: block; }
  .pl .av { width: 40px; height: 40px; font-size: 22px; }
  .pl .ct { padding: 5px 12px 4px; }
  .pl .cp { font-size: 1.45rem; }
  .pl .cn { font-size: 0.68rem; }
  .hud-act { grid-area: opp; }
  .hint-btn { height: 40px; padding: 0 14px 0 12px; font-size: 1.05rem; }
  .pause-btn { width: 40px; height: 40px; }
  .timer { font-size: 1.7rem; }
  .progress { width: 200px; height: 7px; }
  .icon-btn.more { display: none; }
  .tools {
    grid-area: tools; display: flex; position: static; flex-direction: row; justify-content: center; flex-wrap: wrap;
    gap: 6px; padding: 0; min-width: 0; background: none; border: 0; box-shadow: none;
  }
  .tool { width: auto; padding: 6px 12px; border: 1.5px solid var(--line); border-radius: 999px; background: var(--card); font-size: 0.82rem; }
  .tool .ti { width: auto; font-size: 0.95rem; }
  #btnMute .tl, #btnMusic .tl, #btnHelp .tl, #btnFull .tl, #btnLeaveGame .tl, #btnRainbow .tl, #btnSettings .tl { display: none; }
  #btnHelp .ti { font-weight: 800; }
}
@media (min-width: 1100px) {
  .hud { grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr) auto; grid-template-areas: "me mid opp tools"; }
  .tools { flex-wrap: nowrap; }
}

/* small line under the header: room code (host) and the ping chip (both) */
.net-row { grid-column: 1 / -1; position: relative; display: flex; justify-content: center; align-items: center; gap: 6px; flex-wrap: wrap; min-width: 0; }
/* room code during play: the partner can join any time, even mid-round */
.invite-chip {
  display: inline-flex; align-items: stretch;
  border: 1.5px dashed color-mix(in srgb, var(--accent) 45%, var(--line)); border-radius: 999px; background: var(--card);
  font: 700 0.78rem var(--font-body); color: var(--muted); overflow: hidden;
}
.invite-chip button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 4px 10px; }
.invite-chip .ic-share b { color: var(--ink); letter-spacing: 0.08em; font-weight: 800; }
.invite-chip .ic-copy { border-left: 1px solid var(--line); padding: 4px 10px 4px 8px; color: var(--ink); }
.invite-chip button:hover { background: var(--card-2); }

/* "⚡ 34 ms": green < 80, amber < 200, red above */
.ping-chip {
  --pg: var(--leaf);
  font: 800 0.78rem var(--font-body); font-variant-numeric: tabular-nums; white-space: nowrap; cursor: pointer;
  color: var(--pg); background: color-mix(in srgb, var(--pg) 12%, var(--card));
  border: 1.5px solid color-mix(in srgb, var(--pg) 50%, var(--line)); border-radius: 999px; padding: 4px 10px;
}
.ping-chip.amber { --pg: #b7791f; }
.ping-chip.bad { --pg: #d64545; }
.ping-chip:hover { background: color-mix(in srgb, var(--pg) 20%, var(--card)); }
.ping-info {
  /* centred without transform, so the pop-in animation (which uses transform) can't push it off-screen */
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; margin: 0 auto; z-index: 26;
  width: min(280px, calc(100vw - 32px)); box-sizing: border-box; padding: 10px 12px; text-align: left;
  background: var(--card); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow);
  font-size: 0.82rem; animation: rise 0.18s ease;
}
.pi-row { display: flex; justify-content: space-between; gap: 10px; padding: 3px 0; }
.pi-k { color: var(--muted); font-weight: 700; }
.pi-v { font-weight: 800; text-align: right; font-variant-numeric: tabular-nums; }
.pi-note { margin: 6px 0 0; color: var(--muted); font-size: 0.75rem; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) .ping-chip.amber { --pg: #f0b552; }
  :root:not([data-theme]) .ping-chip.bad { --pg: #ff7b7b; }
}
:root[data-theme="dark"] .ping-chip.amber, :root[data-theme="midnight"] .ping-chip.amber { --pg: #f0b552; }
:root[data-theme="dark"] .ping-chip.bad, :root[data-theme="midnight"] .ping-chip.bad { --pg: #ff7b7b; }

.game-main { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; justify-items: center; }
@media (min-width: 820px) {
  .game-main { grid-template-columns: auto 300px; justify-content: center; align-items: start; justify-items: stretch; }
  .game-main .words { position: sticky; top: 16px; max-height: calc(100vh - 32px); overflow-y: auto; }
  .words { padding: 10px 12px; }
  .hm-diff { display: none; }
}
.board-wrap { width: 100%; display: flex; justify-content: center; }

.board {
  --cell: 28px;
  position: relative;
  width: 336px; height: 336px;
  background: var(--cell-bg);
  border-radius: 14px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  cursor: pointer;
}
.marks { position: absolute; inset: 1px; width: calc(100% - 2px); height: calc(100% - 2px); overflow: visible; pointer-events: none; }
.cells { position: absolute; inset: 1px; display: grid; pointer-events: none; outline: none; }
.cells .row { display: contents; }
/* keyboard cursor: only visible while the grid has focus */
.cells:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.cells:focus-visible .cell.kbcur { outline: 3px solid var(--ink); outline-offset: -3px; border-radius: 6px; background: color-mix(in srgb, var(--accent) 18%, transparent); }
/* pause: an opaque cover so nobody can study the grid while the clock is stopped */
.pause-cover {
  position: absolute; inset: 0; z-index: 6; border-radius: inherit;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: 16px; text-align: center;
  background: var(--card);
}
.pause-cover[hidden] { display: none; }
.board.is-paused .fx { visibility: hidden; }
.pz-title { margin: 0; font-family: var(--font-display); font-weight: 600; font-size: 2rem; }
.pz-sub { margin: 0 0 6px; color: var(--muted); font-weight: 700; }
.cell {
  display: grid; place-items: center;
  font-family: var(--font-display); font-weight: 500;
  font-size: calc(var(--cell) * 0.5);
  line-height: 1;
  color: var(--letter);
}
.fx { position: absolute; inset: 0; pointer-events: none; overflow: visible; }

/* found-word capsules: each player's fills share one group at low opacity, so overlaps don't darken */
.fills { opacity: var(--cap-fill); }
.cap-fill { fill: var(--pc); stroke: none; }
.cap-line { fill: none; stroke: var(--pc); stroke-width: 1.5px; vector-effect: non-scaling-stroke; opacity: 0.9; }
.cap-flash { fill: var(--pc); opacity: 0; animation: capFlash 0.6s ease-out; }
@keyframes capFlash { 0% { opacity: 0.9; } 55% { opacity: 0.75; } 100% { opacity: 0; } }
/* an optimistic find the other player won after all: shrinks away */
.cap-reject { fill: var(--pc); fill-opacity: 0.45; stroke: var(--pc); stroke-width: 1.5px; vector-effect: non-scaling-stroke; }
.rej { transform-box: fill-box; transform-origin: center; animation: capReject 0.7s ease-in forwards; }
@keyframes capReject { 0% { opacity: 1; } 30% { opacity: 1; transform: scale(1.06); } 100% { opacity: 0; transform: scale(0.2); } }
.cap-hi { fill: var(--pc); fill-opacity: 0.22; stroke: var(--pc); stroke-width: 3px; vector-effect: non-scaling-stroke; animation: hiPulse 0.5s ease-in-out 3; }
@keyframes hiPulse { 50% { fill-opacity: 0.5; } }
.cap-sel { fill: var(--pc); fill-opacity: 0.28; stroke: var(--pc); stroke-width: 2px; vector-effect: non-scaling-stroke; }
.cap-sel.bad { fill: var(--muted); stroke: var(--muted); animation: wiggle 0.26s; }
@keyframes wiggle { 25% { transform: translateX(-0.08px); } 75% { transform: translateX(0.08px); } }

.cap-hint { fill: var(--gold); fill-opacity: 0.35; stroke: var(--gold); stroke-width: 3px; vector-effect: non-scaling-stroke; animation: hintPulse 0.65s ease-in-out 4; }
@keyframes hintPulse { 50% { fill-opacity: 0.75; } }

/* "+90" over a found word, and the combo badge */
.pop {
  position: absolute; z-index: 6; transform: translate(-50%, -50%);
  font: 700 1.05rem var(--font-display); color: var(--ink);
  background: var(--card); border: 1.5px solid var(--line); border-radius: 999px; padding: 2px 9px;
  box-shadow: var(--shadow); white-space: nowrap; pointer-events: none;
  animation: popUp 1.25s ease-out forwards;
}
.pop.minus { color: var(--muted); }
@keyframes popUp {
  0% { transform: translate(-50%, -30%) scale(0.6); opacity: 0; }
  15% { transform: translate(-50%, -70%) scale(1.08); opacity: 1; }
  70% { opacity: 1; }
  100% { transform: translate(-50%, -190%) scale(1); opacity: 0; }
}
.combo-pop {
  position: absolute; left: 50%; top: 14%; z-index: 7; transform: translate(-50%, 0);
  display: flex; align-items: baseline; gap: 6px; pointer-events: none;
  font-family: var(--font-display); font-weight: 700; color: #fff; white-space: nowrap;
  padding: 6px 16px 7px; border-radius: 999px;
  background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 55%, var(--gold)));
  box-shadow: 0 8px 22px color-mix(in srgb, var(--accent) 40%, transparent);
  animation: comboIn 1.35s cubic-bezier(.2,1.4,.4,1) forwards;
}
.combo-pop.c3 { background: linear-gradient(135deg, var(--gold), var(--accent)); }
.combo-pop .cx { font-size: 1rem; }
.combo-pop .cn { font-size: 1.6rem; }
@keyframes comboIn {
  0% { transform: translate(-50%, 10px) scale(0.5) rotate(-6deg); opacity: 0; }
  18% { transform: translate(-50%, 0) scale(1.12) rotate(2deg); opacity: 1; }
  30% { transform: translate(-50%, 0) scale(1) rotate(0); }
  80% { opacity: 1; }
  100% { transform: translate(-50%, -14px) scale(0.96); opacity: 0; }
}

.spark {
  position: absolute; font-size: 16px; line-height: 1; font-weight: 800;
  transform: translate(-50%, -50%);
  animation: spark 0.85s ease-out forwards;
}
@keyframes spark {
  0% { transform: translate(-50%, -50%) scale(0.4); opacity: 1; }
  100% { transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(1.1); opacity: 0; }
}

/* first-time drag tutorial */
.tut {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 5;
  width: min(86%, 320px); padding: 16px 18px 14px; text-align: center; pointer-events: none;
  background: color-mix(in srgb, var(--card) 94%, transparent); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow);
  animation: rise 0.35s ease;
}
.tut p { margin: 10px 0 0; font-weight: 800; font-size: 0.95rem; }
.tut-track { position: relative; height: 26px; border-radius: 99px; background: color-mix(in srgb, var(--accent) 14%, transparent); }
.tut-dot {
  position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%;
  background: var(--accent); box-shadow: 0 0 0 6px color-mix(in srgb, var(--accent) 22%, transparent);
  animation: tutSlide 1.8s ease-in-out infinite;
}
@keyframes tutSlide { 0%, 12% { left: 3px; opacity: 0.2; } 20% { opacity: 1; } 75%, 88% { left: calc(100% - 23px); opacity: 1; } 100% { left: calc(100% - 23px); opacity: 0; } }

.words { width: 100%; padding: 12px 14px; }
.words h3 { font-size: 1rem; margin-bottom: 10px; }
.word-list { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.word {
  display: inline-flex; align-items: center; gap: 6px; max-width: 100%;
  padding: 4px 11px; border-radius: 999px; background: var(--card-2); border: 1.5px solid var(--line);
  font-weight: 700; font-size: 0.9rem; cursor: pointer; min-height: 30px;
}
.word .wt { display: flex; flex-direction: column; min-width: 0; line-height: 1.15; }
.word .wl { overflow-wrap: anywhere; letter-spacing: 0.04em; }
.word .wc { font-size: 0.7em; font-weight: 600; color: var(--muted); overflow-wrap: anywhere; letter-spacing: 0; }
.word .fav {
  display: inline-grid; place-items: center; width: 20px; height: 20px; margin-left: -6px; border-radius: 50%;
  font-size: 12px; line-height: 1; background: var(--card); box-shadow: 0 0 0 1.5px var(--pc);
}
.word.found { background: color-mix(in srgb, var(--pc) 13%, var(--card)); border-color: color-mix(in srgb, var(--pc) 55%, var(--line)); }
.word.found .wl { text-decoration: line-through; text-decoration-color: var(--pc); text-decoration-thickness: 2px; color: var(--muted); }
.word.just { animation: bump 0.45s ease; }
.word.hi { outline: 3px solid color-mix(in srgb, var(--pc, var(--accent)) 60%, transparent); outline-offset: 1px; animation: bump 0.45s ease; }
/* desktop: two columns of compact chips so a 20-word list fits beside the board without scrolling */
@media (min-width: 820px) {
  .word-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px; }
  .word { border-radius: 10px; padding: 3px 7px; gap: 5px; min-height: 0; font-size: 0.74rem; }
  .word .wc { font-size: 0.82em; }
  .word .fav { width: 16px; height: 16px; margin-left: -3px; font-size: 10px; flex: none; }
  .word .wl { letter-spacing: 0.02em; }
  .word.long .wl { font-size: 0.88em; letter-spacing: 0; }
}
@media (min-width: 1100px) { .game-main { grid-template-columns: auto 340px; } }

/* results */
.overlay {
  position: fixed; inset: 0; z-index: 30;
  display: grid; place-items: center; padding: 16px;
  background: color-mix(in srgb, var(--bg) 70%, transparent);
  -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
  animation: fadeIn 0.25s ease;
  overflow-y: auto;
}
.overlay.peek { background: transparent; backdrop-filter: none; -webkit-backdrop-filter: none; pointer-events: none; align-items: end; }
.overlay.peek .result > :not(.actions) { display: none; }
.overlay.peek .result { pointer-events: auto; padding: 12px; }
@keyframes fadeIn { from { opacity: 0; } }
.result { width: min(440px, 100%); text-align: center; animation: rise 0.35s cubic-bezier(.2,1.3,.5,1); }
@keyframes rise { from { transform: translateY(18px) scale(0.96); opacity: 0; } }
.eyebrow { margin: 0 0 6px; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.08em; font-weight: 800; color: var(--muted); }
.result-head { font-size: clamp(1.6rem, 7vw, 2.1rem); line-height: 1.15; overflow-wrap: anywhere; }
.cute { margin: 8px 0 16px; font-weight: 700; color: var(--muted); }
.scores { width: 100%; border-collapse: collapse; margin-bottom: 16px; font-weight: 700; }
.scores th, .scores td { padding: 7px 6px; border-bottom: 1px solid var(--line); }
.scores th { font-size: 0.9rem; }
.scores th .tav { --pc: var(--muted); display: inline-grid; place-items: center; width: 22px; height: 22px; margin-right: 6px; vertical-align: middle; border-radius: 50%; font-size: 13px; box-shadow: 0 0 0 1.5px var(--pc); }
.result-av { --pc: var(--accent); width: 64px; height: 64px; margin: 4px auto 8px; border-radius: 50%; display: grid; place-items: center; font-size: 36px; background: color-mix(in srgb, var(--pc) 14%, var(--card)); box-shadow: 0 0 0 3px var(--pc); animation: bump 0.6s ease 0.2s; }
.scores td.rl { text-align: left; color: var(--muted); }
.scores td.win { color: var(--accent); }
.scores tr.total td { border-bottom: 0; font-family: var(--font-display); font-size: 1.1rem; }
.result .actions { display: flex; flex-direction: column; gap: 8px; align-items: center; }
.result .actions .btn.big { min-width: 200px; }
.act-inline { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.scores td .tp { display: block; font-family: var(--font-display); font-size: 1.08rem; }
.scores td .tw { display: block; font-size: 0.72rem; color: var(--muted); font-weight: 700; }

/* solo results: score, breakdown, XP */
.big-score { display: flex; align-items: baseline; justify-content: center; gap: 6px; margin: -4px 0 4px; }
.bs-n { font-family: var(--font-display); font-weight: 700; font-size: clamp(2.4rem, 11vw, 3rem); line-height: 1; color: var(--accent); font-variant-numeric: tabular-nums; }
.bs-l { font-weight: 800; color: var(--muted); }
.pb-badge {
  display: inline-block; margin: 2px 0 8px; padding: 5px 12px; border-radius: 999px; font-weight: 800; font-size: 0.9rem;
  background: color-mix(in srgb, var(--gold) 20%, var(--card)); border: 1.5px solid color-mix(in srgb, var(--gold) 60%, var(--line));
  animation: bump 0.6s ease 0.3s;
}
.pb-note { margin: 0 0 8px; font-weight: 700; color: var(--muted); font-size: 0.9rem; }
.breakdown { width: 100%; border-collapse: collapse; margin: 4px 0 12px; font-weight: 700; font-size: 0.94rem; }
.breakdown td { padding: 6px 4px; border-bottom: 1px dashed var(--line); }
.breakdown .bl { text-align: left; color: var(--muted); }
.breakdown .bv { text-align: right; font-variant-numeric: tabular-nums; }
.breakdown tr.info td { font-size: 0.84rem; }
.breakdown tr.total td { border-bottom: 0; font-family: var(--font-display); font-size: 1.12rem; color: var(--ink); padding-top: 9px; }
.xp-gain { margin: 0 0 14px; padding: 10px 12px; border-radius: 16px; background: var(--leaf-soft); text-align: left; }
.xg-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 7px; flex-wrap: wrap; }
.xg-n { font-family: var(--font-display); font-weight: 700; font-size: 1.2rem; color: var(--leaf); }
.xg-l { font-weight: 800; font-size: 0.88rem; }
.xp-gain.up { animation: levelUp 0.9s ease 0.4s; box-shadow: 0 0 0 2px var(--leaf); }
.xp-gain.up .xg-l { color: var(--leaf); font-family: var(--font-display); font-weight: 600; font-size: 1.05rem; }
@keyframes levelUp { 30% { transform: scale(1.06); } 60% { transform: scale(0.98); } }
.new-badges { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin: -4px 0 14px; }
.badge-chip { padding: 4px 10px; border-radius: 999px; font-weight: 800; font-size: 0.82rem; background: var(--card-2); border: 1.5px solid var(--gold); animation: rise 0.4s ease both; }
.badge-chip:nth-child(2) { animation-delay: 0.1s; } .badge-chip:nth-child(3) { animation-delay: 0.2s; } .badge-chip:nth-child(4) { animation-delay: 0.3s; }

/* ---------- leaderboards ---------- */
.boards, .profile { max-width: 760px; display: flex; flex-direction: column; gap: 14px; }
.tabs { display: flex; gap: 6px; overflow-x: auto; padding: 2px; scrollbar-width: none; }
.tab {
  flex: none; font: 800 0.9rem var(--font-body); color: var(--ink); cursor: pointer;
  padding: 9px 14px; border-radius: 999px; border: 1.5px solid var(--line); background: var(--card);
}
.tab.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.board-tools { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.board-tools select { font: 700 1rem var(--font-body); color: var(--ink); background: var(--bg); border: 1.5px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.board-note { margin: 0 0 12px; padding: 9px 12px; border-radius: 12px; font-weight: 700; font-size: 0.88rem; }
.board-note.offline { background: var(--card-2); border: 1px dashed var(--line); color: var(--muted); }
.board-note.soft { padding: 0; color: var(--muted); }
.rank-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.rank { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 14px; background: var(--card-2); border: 1.5px solid transparent; min-width: 0; }
.rank.is-me { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 9%, var(--card)); }
.rk { width: 1.8em; text-align: center; font-family: var(--font-display); font-weight: 700; color: var(--muted); flex: none; }
.rank:nth-child(1) .rk { color: var(--gold); }
.rn { display: flex; flex-direction: column; min-width: 0; flex: 1 1 auto; }
.rname { font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rsub { font-size: 0.76rem; font-weight: 700; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.you-tag { flex: none; font-size: 0.7rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.06em; color: var(--accent-ink); background: var(--accent); border-radius: 999px; padding: 2px 7px; }
.rs { flex: none; font-family: var(--font-display); font-weight: 700; font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.empty { text-align: center; padding: 10px 0; }

.h2h { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: 8px; padding: 12px; border-radius: 16px; background: var(--card-2); }
.h2h + .h2h { margin-top: 8px; }
.h2h-side { display: flex; flex-direction: column; align-items: center; gap: 3px; min-width: 0; text-align: center; }
.h2h-side .av { width: 40px; height: 40px; font-size: 22px; }
.h2h-name { font-weight: 800; font-size: 0.86rem; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.h2h-wins { font-family: var(--font-display); font-weight: 700; font-size: 2rem; line-height: 1; }
.h2h-pts { font-size: 0.76rem; font-weight: 700; color: var(--muted); }
.h2h-mid { display: flex; flex-direction: column; align-items: center; gap: 2px; text-align: center; }
.h2h-vs { font-family: var(--font-display); font-weight: 600; color: var(--muted); }
.h2h-meta { font-size: 0.72rem; font-weight: 700; color: var(--muted); }

/* ---------- profile ---------- */
.profile-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }
@media (min-width: 760px) { .profile-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } .prof-you { grid-row: span 2; } }
.prof-you { display: flex; flex-direction: column; gap: 14px; }
.lvl-row.big .lvl-badge { font-size: 1rem; padding: 6px 11px; }
.lvl-row.big .xpbar { height: 11px; }
.sec-title { font-size: 1.05rem; margin-bottom: 10px; display: flex; gap: 8px; align-items: baseline; }
.sec-title .muted { font-family: var(--font-body); font-size: 0.85rem; font-weight: 700; }
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
@media (min-width: 420px) { .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (min-width: 760px) { .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.stat { display: flex; flex-direction: column; gap: 2px; padding: 9px 10px; border-radius: 14px; background: var(--card-2); min-width: 0; }
.stat .sv { font-family: var(--font-display); font-weight: 700; font-size: 1.3rem; line-height: 1.1; }
.stat .sl { font-size: 0.74rem; font-weight: 800; color: var(--muted); }
.badges { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.badge { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 2px; padding: 10px 6px; border-radius: 14px; background: var(--card-2); border: 1.5px dashed var(--line); min-width: 0; }
.badge .be { font-size: 1.6rem; line-height: 1.2; filter: grayscale(1); opacity: 0.4; }
.badge .bn { font-weight: 800; font-size: 0.8rem; line-height: 1.2; color: var(--muted); }
.badge .bd { font-size: 0.66rem; font-weight: 700; color: var(--muted); line-height: 1.25; }
.badge.on { border-style: solid; border-color: color-mix(in srgb, var(--gold) 60%, var(--line)); background: color-mix(in srgb, var(--gold) 10%, var(--card)); }
.badge.on .be { filter: none; opacity: 1; }
.badge.on .bn { color: var(--ink); }
.cloud-card > div > .muted { margin: 0 0 12px; line-height: 1.45; }
.cloud-form { display: flex; flex-direction: column; gap: 10px; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field-l { font-weight: 800; font-size: 0.84rem; color: var(--muted); }
.field input { width: 100%; min-width: 0; font: 600 1rem var(--font-body); color: var(--ink); background: var(--bg); border: 1.5px solid var(--line); border-radius: 14px; padding: 10px 12px; }
.field input:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
.field input[type="password"] { letter-spacing: 0.25em; }
.field input[type="password"]::placeholder { letter-spacing: normal; }
.pin-pair { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
.fine { margin: -2px 0 0; font-size: 0.78rem; font-weight: 700; color: var(--muted); }
.cloud-form .btn { align-self: flex-start; }
.cloud-form .msg { margin: 0; }
.cloud-form .msg:empty { display: none; }
.cloud-who { display: flex; align-items: center; gap: 10px; margin: 0 0 8px; font-size: 1.05rem; }
.cloud-ic { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 50%; background: var(--leaf-soft); font-size: 20px; flex: none; }
#btnSignOut.armed { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.danger p { margin-bottom: 10px; }
#btnReset.armed { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.settings h3.first { margin-top: 0; }
#modeBox { margin-bottom: 16px; }
.seg-mode { grid-template-columns: repeat(2, minmax(0, 1fr)); }

/* banner + toast */
.banner {
  position: sticky; top: 0; z-index: 40;
  background: var(--accent); color: var(--accent-ink);
  text-align: center; font-weight: 800; padding: 9px 16px; font-size: 0.92rem;
}
.toast {
  position: fixed; left: 50%; bottom: calc(22px + env(safe-area-inset-bottom)); z-index: 50;
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  background: var(--ink); color: var(--bg);
  padding: 10px 18px; border-radius: 999px; font-weight: 800; font-size: 0.95rem;
  box-shadow: var(--shadow); text-align: center;
}

/* help modal */
.modal { z-index: 45; }
.help { position: relative; width: min(480px, 100%); animation: rise 0.3s ease; }
.help h2 { font-size: 1.5rem; margin: 0 40px 10px 0; }
.help ol { margin: 0 0 12px; padding-left: 20px; display: flex; flex-direction: column; gap: 8px; line-height: 1.45; }
.help .close { position: absolute; top: 12px; right: 12px; width: 34px; height: 34px; }

/* Phones: the grid uses nearly the whole width (6px gutters instead of 16px), which gives Hard (15x15)
   cells about 2px more; the header and the word list keep their own side space. */
@media (max-width: 560px) {
  .screen.game { padding-left: 6px; padding-right: 6px; }
  .screen.game .hud { padding-left: 10px; padding-right: 10px; }
  .screen.game .words { margin-left: 10px; margin-right: 10px; }
  .board { border-radius: 10px; }
}
@media (max-width: 400px) {
  .card { padding: 14px; }
  .topbar-spacer { width: 44px; }
  .seg-diff .seg-btn .ss { font-size: 0.64rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* Two picks: what each player chose for the room */
.pick-duel { margin: -2px 2px 12px; line-height: 1.4; }

/* ===================== PC and laptop layout (K5) =====================
   Phones and tablets keep everything above. From 980px wide the home screen becomes a two-column showcase, the lobby
   uses its width, and from 1100px the game becomes a no-scroll stage: score/timer/tools in a left rail, the grid as
   large as the screen allows in the middle, the word list in a right rail. sizeBoard() in js/app.js sizes the grid. */
.home-main { display: flex; flex-direction: column; gap: 14px; }
.home-preview { display: none; }
@media (min-width: 980px) {
  /* home: brand, player card and buttons on the left; a live-looking teaser board on the right */
  .screen.home { max-width: 1120px; display: grid; grid-template-columns: minmax(0, 440px) minmax(0, 1fr); column-gap: 56px; align-items: center; align-content: center; min-height: 100vh; min-height: 100dvh; padding-top: 14px; padding-bottom: 14px; }
  .settings-mount { position: fixed; top: 14px; right: 18px; }
  .home-main { gap: 12px; }
  .home .logo-mark { width: 60px; height: 60px; margin-bottom: 2px; }
  .home .logo { font-size: 2.7rem; }
  .home .tagline { margin-top: 4px; }
  .home-preview { display: flex; justify-content: center; }
  .pv-card { width: min(100%, 540px); background: var(--card); border: 1px solid var(--line); border-radius: 28px; padding: 22px 24px 20px; box-shadow: var(--shadow); transform: rotate(1.4deg); transition: transform .35s cubic-bezier(.34, 1.56, .64, 1); }
  .home-preview:hover .pv-card { transform: rotate(0deg) scale(1.01); }
  .pv-kicker { margin: 0 0 12px; font-weight: 800; font-size: .8rem; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
  .pv-kicker span { color: var(--accent); }
  .pv-grid { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); background: var(--cell-bg); border: 1px solid var(--line); border-radius: 18px; padding: 10px; }
  .pv-grid i { font-style: normal; aspect-ratio: 1; display: grid; place-items: center; font-family: var(--font-display); font-weight: 500; font-size: clamp(1.1rem, 2.1vw, 1.7rem); color: var(--letter); }
  .pv-grid i.f { background: color-mix(in srgb, var(--pc) 24%, transparent); box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--pc) 55%, transparent); }
  .pv-grid .p-a { --pc: var(--accent); } .pv-grid .p-b { --pc: var(--leaf); }
  .pv-grid .p-a.p-s { border-radius: 99px 0 0 99px; } .pv-grid .p-a.p-e { border-radius: 0 99px 99px 0; }
  .pv-grid .p-b.p-s { border-radius: 99px 99px 0 0; } .pv-grid .p-b.p-e { border-radius: 0 0 99px 99px; }
  .pv-words { list-style: none; display: flex; flex-wrap: wrap; gap: 6px; margin: 14px 0 0; padding: 0; }
  .pv-words li { padding: 4px 12px; border-radius: 999px; background: var(--card-2); border: 1.5px solid var(--line); font-weight: 800; font-size: .85rem; letter-spacing: .04em; }
  .pv-words li.done { text-decoration: line-through; color: var(--muted); }
  .pv-facts { margin: 14px 0 0; font-weight: 700; color: var(--muted); font-size: .9rem; }
  .pv-facts b { color: var(--accent); }

  /* lobby: no empty third column in solo; a little tighter so the whole setup fits a 800px-high screen */
  .lobby-grid:not(:has(.col-side > :not([hidden]))) { grid-template-columns: 240px minmax(0, 1fr); }
  .col-side:not(:has(> :not([hidden]))) { display: none; }
  .screen.lobby { max-width: 1100px; gap: 10px; padding-top: 10px; padding-bottom: 12px; }
  .lobby .settings { padding: 14px 16px; }
  .lobby .settings h3 { margin: 12px 0 8px; }
  .lobby .settings h3.first { margin-top: 0; }
  .lobby .topic { min-height: 80px; padding: 8px 10px; }
  .lobby .topic:hover { box-shadow: 0 8px 18px -8px color-mix(in srgb, var(--accent) 45%, transparent); }
  .lobby .dots-row { margin: 6px 0 2px; }
  .lobby .start-bar { flex-direction: row; justify-content: center; align-items: center; gap: 16px; padding: 0; }
  .lobby .start-bar .msg { margin: 0; }
  .lobby .btn.big { padding: 11px 24px; }
  .btn:hover:not(:disabled), .topic:hover, .seg-btn:hover { cursor: pointer; }

  /* other screens: wider cards */
  .boards { max-width: 860px; }
}

/* the game stage (1100px and wider) */
@media (min-width: 1100px) {
  .screen.game { max-width: 1840px; padding: 12px 20px 12px; display: grid; grid-template-columns: 224px minmax(0, 1fr); column-gap: 14px; align-items: stretch; }
  .screen.game .hud {
    grid-column: 1; display: flex; flex-direction: column; align-items: stretch; gap: 12px; margin: 0; padding: 16px; min-height: 0; overflow: auto;
    background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  }
  .hud .mid { order: 1; padding: 4px 0 8px; border-bottom: 1px solid var(--line); gap: 6px; }
  .hud .me { order: 2; } .hud .opp { order: 3; } .hud-act { order: 4; } .hud .tools { order: 5; margin-top: auto; } .hud .net-row { order: 6; }
  .hud-topic { max-width: 100%; white-space: normal; text-align: center; line-height: 1.25; font-size: .95rem; }
  .hud .timer { font-size: 3rem; letter-spacing: .01em; }
  .hud .progress { width: 100%; height: 8px; }
  .hud-meta { flex-wrap: wrap; white-space: normal; }
  .hud .pl { padding: 8px 10px; border-radius: 16px; background: var(--card-2); border: 1.5px solid color-mix(in srgb, var(--pc) 45%, var(--line)); }
  .hud .opp { flex-direction: row-reverse; justify-content: flex-end; }
  .hud .pl .pn { flex: 1 1 auto; font-size: .95rem; }
  .hud .pl .ct { margin-left: auto; box-shadow: none; }
  .hud-act { justify-self: stretch; justify-content: center; }
  .hud .tools { justify-content: center; gap: 6px; }
  .game-main { grid-column: 2; min-height: 0; grid-template-columns: minmax(0, 1fr) 340px; gap: 14px; justify-content: stretch; align-items: stretch; }
  .game-main .board-wrap { align-self: center; }
  .game-main .words { position: static; max-height: none; overflow: auto; align-self: stretch; padding: 14px 14px; }
  .words h3 { font-size: 1.1rem; }
}
@media (min-width: 1700px) {
  .screen.game { grid-template-columns: 270px minmax(0, 1fr); }
  .game-main { grid-template-columns: minmax(0, 1fr) 380px; }
  .word { font-size: .86rem; padding: 4px 9px; }
}
@media (min-width: 1100px) {
  /* the tools become a tidy list at the foot of the rail, every button with its label */
  .hud .tools { flex-wrap: wrap; flex-direction: column; align-items: stretch; gap: 2px; padding-top: 8px; border-top: 1px solid var(--line); }
  .hud .tool { width: 100%; padding: 7px 10px; border: 0; border-radius: 10px; background: transparent; font-size: .9rem; }
  .hud .tool:hover { background: var(--card-2); }
  .hud .tool .ti { width: 22px; font-size: 1.05rem; }
  .hud .tool .tl, .hud #btnMute .tl, .hud #btnMusic .tl, .hud #btnHelp .tl, .hud #btnFull .tl, .hud #btnLeaveGame .tl, .hud #btnRainbow .tl, .hud #btnSettings .tl { display: inline; }
  /* profile: three columns */
  .profile { max-width: 1200px; }
  .profile-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); align-items: start; }
  .profile-grid .prof-you { grid-row: auto; }
}

@media (min-width: 980px) { .screen.lobby { min-height: 100vh; min-height: 100dvh; justify-content: center; } }
