/* LexiLink — styles
   One family, one surface level, feedback colours do the talking. */

:root {
  --font: ui-rounded, "SF Pro Rounded", "Segoe UI Variable Text", "Segoe UI", "Nunito", system-ui, -apple-system, sans-serif;

  --bg: #141821;
  --bg-2: #0f121a;
  --surface: #1d2331;
  --surface-2: #262d3d;
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.16);
  --text: #eef1f6;
  --text-2: #a4acbd;
  --text-3: #6d7588;
  --brand: #8b7cff;
  --brand-ink: #ffffff;
  --brand-soft: rgba(139, 124, 255, 0.16);
  --danger: #ff6b7a;

  --c-correct: #3fae6a;
  --c-present: #e3b341;
  --c-absent: #4a5160;
  --c-empty: transparent;
  --tile-ink: #ffffff;
  --tile-border: rgba(255, 255, 255, 0.18);
  --tile-border-filled: rgba(255, 255, 255, 0.42);
  --key-bg: #3a4254;
  --key-ink: #eef1f6;

  --radius-s: 8px;
  --radius: 14px;
  --radius-l: 22px;
  --shadow: 0 12px 40px -12px rgba(0, 0, 0, 0.55);
  --topbar-h: 56px;

  --ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);

  --cols: 5;
  --rows: 6;
  --tile: 58px;
  --gap: 6px;
}

:root[data-theme="light"] {
  --bg: #f3f5f9;
  --bg-2: #e9edf4;
  --surface: #ffffff;
  --surface-2: #f0f2f7;
  --line: rgba(20, 24, 33, 0.08);
  --line-strong: rgba(20, 24, 33, 0.18);
  --text: #171b26;
  --text-2: #5a6377;
  --text-3: #8a93a6;
  --brand: #6a5cf0;
  --brand-soft: rgba(106, 92, 240, 0.12);
  --c-correct: #4aa86a;
  --c-present: #d8a62f;
  --c-absent: #7b8499;
  --tile-border: rgba(20, 24, 33, 0.18);
  --tile-border-filled: rgba(20, 24, 33, 0.5);
  --key-bg: #d6dbe6;
  --key-ink: #171b26;
  --shadow: 0 12px 40px -14px rgba(23, 27, 38, 0.25);
}

:root[data-contrast="high"] {
  --c-correct: #f5793a;
  --c-present: #85c0f9;
  --tile-ink: #0b0d12;
}
:root[data-contrast="high"][data-theme="dark"] {
  --tile-ink: #0b0d12;
}
:root[data-contrast="high"] .tile[data-state="absent"],
:root[data-contrast="high"] .mini-cell[data-state="absent"],
:root[data-contrast="high"] .rcell[data-state="absent"],
:root[data-contrast="high"] .key[data-state="absent"] { color: #eef1f6; }

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { height: 100%; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  height: 100dvh;
  overflow: hidden; /* each .screen scrolls on its own so the top bar stays put */
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 50% -200px, var(--brand-soft), transparent 70%),
    var(--bg);
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
  overscroll-behavior-y: none;
  display: flex;
  flex-direction: column;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
[hidden] { display: none !important; }
svg { display: block; }
.only-light { display: none; }
:root[data-theme="light"] .only-light { display: block; }
:root[data-theme="light"] .only-dark { display: none; }

/* ---------- banner ---------- */
.banner {
  position: fixed; top: 0; left: 0; right: 0; z-index: 50;
  padding: calc(env(safe-area-inset-top) + 8px) 16px 8px;
  background: var(--c-present); color: #1a1500;
  font-weight: 600; font-size: 14px; text-align: center;
  display: flex; gap: 8px; align-items: center; justify-content: center;
}
.banner-dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; animation: pulse 1.2s infinite; }

/* ---------- top bar ---------- */
.topbar {
  height: calc(var(--topbar-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  flex: none;
}
.wordmark { display: inline-flex; align-items: center; gap: 9px; text-decoration: none; color: var(--text); justify-self: start; }
.mark { width: 28px; height: 28px; }
.wordmark-text { font-weight: 800; font-size: 20px; letter-spacing: -0.02em; }
@media (max-width: 480px) { body.in-room .wordmark-text { display: none; } }
.topbar-room { display: flex; align-items: center; gap: 12px; justify-self: center; }
.topbar-code { font-weight: 700; letter-spacing: 0.18em; color: var(--text-2); font-size: 14px; }
.topbar-timer { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--text); min-width: 3.5ch; text-align: right; }
.topbar-tools { display: flex; gap: 4px; justify-self: end; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; border: 0; background: transparent; color: var(--text-2);
  display: grid; place-items: center; transition: background .15s, color .15s;
}
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn[aria-pressed="true"] { color: var(--brand); background: var(--brand-soft); }

/* ---------- screens ---------- */
#main { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.screen {
  flex: 1; min-height: 0;
  animation: screen-in .35s var(--ease-out) both;
}
.screen.is-leaving { animation: screen-out .18s ease-in both; }
@keyframes screen-in { from { opacity: 0; transform: translateY(10px) scale(.995); } to { opacity: 1; transform: none; } }
@keyframes screen-out { to { opacity: 0; transform: translateY(-6px); } }

/* ---------- buttons & fields ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 0 18px; height: 46px; border-radius: var(--radius);
  border: 0; font-weight: 700; font-size: 16px; letter-spacing: 0.01em;
  transition: transform .12s var(--ease-out), background .15s, box-shadow .15s, opacity .15s;
  -webkit-tap-highlight-color: transparent;
}
.btn svg { width: 18px; height: 18px; }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: default; transform: none; }
.btn-primary { background: var(--brand); color: var(--brand-ink); box-shadow: 0 8px 24px -10px var(--brand); }
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn-secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--line); }
.btn-secondary:hover { border-color: var(--line-strong); }
.btn-block { width: 100%; }
.btn-lg { height: 54px; font-size: 17px; border-radius: 16px; }

.field { display: block; }
.field-label { display: block; font-size: 14px; font-weight: 600; color: var(--text-2); margin-bottom: 6px; }
.input {
  width: 100%; height: 50px; padding: 0 14px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line); color: var(--text);
  font-size: 17px; transition: border-color .15s, box-shadow .15s;
}
.input::placeholder { color: var(--text-3); }
.input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.input-code { text-transform: uppercase; letter-spacing: 0.35em; font-weight: 800; font-size: 24px; text-align: center; height: 60px; }
.input-code::placeholder { letter-spacing: 0.35em; font-weight: 600; }
.form-error { min-height: 1.4em; margin: 8px 0 0; color: var(--danger); font-size: 14px; font-weight: 600; text-align: center; }
.form-error:empty { margin: 0; }

/* ---------- settings control ---------- */
.settings { display: grid; gap: 16px; }
.setting { display: grid; gap: 8px; }
.setting-head { display: flex; justify-content: space-between; align-items: baseline; }
.setting-name { font-size: 14px; font-weight: 600; color: var(--text-2); }
.setting-value { font-size: 14px; color: var(--text-3); }
.segmented {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px;
  padding: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
}
.segmented button {
  height: 40px; border: 0; border-radius: 10px; background: transparent; color: var(--text-2);
  font-weight: 700; font-size: 16px; transition: background .15s, color .15s, transform .12s;
}
.segmented button[aria-checked="true"] { background: var(--brand); color: var(--brand-ink); }
.segmented button:hover:not([aria-checked="true"]) { background: var(--surface-2); color: var(--text); }
.stepper {
  display: grid; grid-template-columns: 48px 1fr 48px; align-items: center;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 4px; height: 50px;
}
.stepper button {
  height: 40px; border: 0; border-radius: 10px; background: transparent; color: var(--text); font-size: 22px; font-weight: 500;
  transition: background .15s;
}
.stepper button:hover:not(:disabled) { background: var(--surface-2); }
.stepper button:disabled { color: var(--text-3); cursor: default; }
.stepper output { text-align: center; font-weight: 800; font-size: 20px; font-variant-numeric: tabular-nums; }
.settings[aria-disabled="true"] { opacity: .55; pointer-events: none; }
.settings-summary { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; margin-bottom: 14px; }
.settings-summary span { background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; font-size: 14px; font-weight: 600; color: var(--text-2); }
.settings-summary strong { color: var(--text); }

/* ---------- home ---------- */
.screen-home {
  display: flex; flex-direction: column; align-items: center;
  padding: 16px max(16px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  gap: 24px; overflow-y: auto;
}
.home-hero { text-align: center; max-width: 520px; margin-top: 4vh; }
.hero-mark { width: 72px; height: 72px; margin: 0 auto 18px; filter: drop-shadow(0 10px 24px rgba(0,0,0,.25)); }
.hero-title { margin: 0; font-size: clamp(30px, 6vw, 44px); line-height: 1.05; letter-spacing: -0.03em; font-weight: 800; }
.hero-sub { margin: 14px auto 0; color: var(--text-2); max-width: 40ch; font-size: 16px; }
.home-form {
  width: 100%; max-width: 440px; display: grid; gap: 18px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-l);
  padding: 22px; box-shadow: var(--shadow);
}
.tabs { position: relative; display: grid; grid-template-columns: 1fr 1fr; background: var(--bg-2); border-radius: var(--radius); padding: 4px; }
.tab { position: relative; z-index: 1; height: 40px; border: 0; background: transparent; border-radius: 10px; color: var(--text-2); font-weight: 700; transition: color .15s; }
.tab.is-active { color: var(--text); }
.tab-ink {
  position: absolute; top: 4px; bottom: 4px; left: 4px; width: calc(50% - 4px);
  background: var(--surface-2); border-radius: 10px; transition: transform .25s var(--ease-out);
}
.tabs[data-active="join"] .tab-ink { transform: translateX(100%); }
.panel { display: grid; gap: 18px; }
.home-foot { color: var(--text-3); font-size: 13px; text-align: center; margin: 0; }

/* ---------- lobby ---------- */
.screen-lobby { overflow-y: auto; padding: 8px max(16px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); }
.lobby-grid { max-width: 920px; margin: 0 auto; display: grid; gap: 20px; grid-template-columns: 1fr; }
.lobby-label { margin: 0 0 10px; font-size: 14px; font-weight: 600; color: var(--text-2); }
.lobby-invite { text-align: center; padding: 20px 0 6px; }
.room-code {
  display: inline-flex; gap: 8px; margin-bottom: 18px;
}
.room-code span {
  width: 56px; height: 68px; display: grid; place-items: center;
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: 12px;
  font-size: 36px; font-weight: 800; letter-spacing: 0; box-shadow: var(--shadow);
  animation: pop-in .4s var(--ease-spring) both;
}
.room-code span:nth-child(2) { animation-delay: .05s } .room-code span:nth-child(3) { animation-delay: .1s } .room-code span:nth-child(4) { animation-delay: .15s }
@keyframes pop-in { from { transform: scale(.6); opacity: 0 } to { transform: none; opacity: 1 } }
.invite-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.lobby-hint { color: var(--text-3); font-size: 13px; margin: 12px 0 0; }
.lobby-players, .lobby-controls { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-l); padding: 18px; }
.player-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.player {
  display: grid; grid-template-columns: 38px 1fr auto; align-items: center; gap: 12px;
  padding: 8px 10px 8px 8px; border-radius: 12px; background: var(--bg-2);
  animation: pop-in .3s var(--ease-out) both;
}
.avatar {
  width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center;
  font-weight: 800; font-size: 16px; color: #fff; text-transform: uppercase;
  background: var(--av, var(--brand));
}
.player-name { font-weight: 700; display: flex; align-items: center; gap: 6px; min-width: 0; }
.player-name > span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.player-name svg { width: 16px; height: 16px; color: var(--c-present); flex: none; }
.player-meta { font-size: 13px; color: var(--text-3); }
.player-you { flex: none; white-space: nowrap; font-size: 12px; font-weight: 700; color: var(--brand); background: var(--brand-soft); padding: 2px 8px; border-radius: 999px; }
.player.is-offline { opacity: .5; }
.lobby-wait { text-align: center; }
.waiting { display: block; color: var(--text-2); margin: 6px 0 0; overflow-wrap: anywhere; }
.waiting strong { color: var(--text); overflow-wrap: anywhere; }
.pulse { display: inline-block; vertical-align: middle; margin: -2px 10px 0 0; width: 10px; height: 10px; border-radius: 50%; background: var(--brand); animation: pulse 1.4s infinite; }
@keyframes pulse { 0%, 100% { opacity: .35; transform: scale(.8) } 50% { opacity: 1; transform: scale(1) } }

@media (min-width: 760px) {
  .lobby-grid { grid-template-columns: 1fr 1fr; align-items: start; margin-top: 16px; }
  .lobby-invite { grid-column: 1 / -1; }
}

/* ---------- game ---------- */
.screen-game {
  display: grid;
  grid-template-rows: auto 1fr auto;
  grid-template-columns: 1fr;
  grid-template-areas: "opp" "board" "keys";
  gap: 6px;
  padding: 0 0 max(8px, env(safe-area-inset-bottom));
  overflow: hidden;
}
.opponents { grid-area: opp; min-width: 0; }
.opponents-scroll {
  display: flex; gap: 8px; overflow-x: auto; padding: 4px 12px 6px; scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.opponents-scroll::-webkit-scrollbar { display: none; }
.opponents:empty, .opponents.is-empty { display: none; }

.opp {
  flex: none; display: grid; grid-template-columns: auto 1fr; gap: 8px; align-items: center;
  padding: 6px 10px 6px 6px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line);
  min-width: 128px; transition: border-color .3s, box-shadow .3s;
}
.opp.is-solved { border-color: var(--c-correct); box-shadow: 0 0 0 1px var(--c-correct) inset; }
.opp.is-failed { opacity: .7; }
.opp.is-offline { opacity: .45; }
.opp-info { min-width: 0; }
.opp-name { font-weight: 700; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 110px; }
.opp-status { font-size: 12px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.opp.is-solved .opp-status { color: var(--c-correct); font-weight: 700; }
.mini {
  display: grid; grid-template-columns: repeat(var(--cols), var(--mini, 7px)); gap: 2px;
}
.mini-cell { width: var(--mini, 7px); height: var(--mini, 7px); border-radius: 1.5px; background: var(--line-strong); transition: background .25s; }
.mini-cell[data-state="correct"] { background: var(--c-correct); }
.mini-cell[data-state="present"] { background: var(--c-present); }
.mini-cell[data-state="absent"] { background: var(--c-absent); }

.board-area {
  grid-area: board; min-height: 0; min-width: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 4px 12px;
}
.board {
  display: grid; gap: var(--gap);
  grid-template-rows: repeat(var(--rows), var(--tile));
}
.row { display: grid; grid-template-columns: repeat(var(--cols), var(--tile)); gap: var(--gap); }
.row.is-shake { animation: shake .5s var(--ease-out); }
@keyframes shake {
  10%, 90% { transform: translateX(-2px) } 20%, 80% { transform: translateX(3px) }
  30%, 50%, 70% { transform: translateX(-5px) } 40%, 60% { transform: translateX(5px) }
}
.tile {
  width: var(--tile); height: var(--tile);
  display: grid; place-items: center;
  border-radius: max(6px, calc(var(--tile) * 0.14));
  border: 2px solid var(--tile-border);
  font-weight: 800; font-size: calc(var(--tile) * 0.52); line-height: 1; text-transform: uppercase;
  color: var(--text); background: var(--c-empty);
  transition: border-color .12s;
  user-select: none;
}
.tile.is-filled { border-color: var(--tile-border-filled); animation: tile-pop .12s var(--ease-out); }
@keyframes tile-pop { 0% { transform: scale(.85) } 60% { transform: scale(1.08) } 100% { transform: scale(1) } }
.tile[data-state="correct"], .tile[data-state="present"], .tile[data-state="absent"] { border-color: transparent; color: var(--tile-ink); }
.tile[data-state="correct"] { background: var(--c-correct); }
.tile[data-state="present"] { background: var(--c-present); }
.tile[data-state="absent"] { background: var(--c-absent); }
.tile.is-flip { animation: flip .55s ease-in-out both; animation-delay: var(--d, 0ms); }
@keyframes flip { 0% { transform: rotateX(0) } 50% { transform: rotateX(-90deg) } 100% { transform: rotateX(0) } }
.tile.is-bounce { animation: bounce .7s var(--ease-out) both; animation-delay: var(--d, 0ms); }
@keyframes bounce {
  0%, 20% { transform: translateY(0) } 40% { transform: translateY(-28%) } 55% { transform: translateY(4%) }
  70% { transform: translateY(-12%) } 85% { transform: translateY(2%) } 100% { transform: translateY(0) }
}
.board-status { min-height: 20px; margin-top: 6px; font-size: 14px; color: var(--text-2); text-align: center; font-weight: 600; }
.board-status.is-win { color: var(--c-correct); }

/* keyboard */
.keyboard {
  grid-area: keys; display: grid; gap: 6px;
  padding: 0 max(6px, env(safe-area-inset-right)) 0 max(6px, env(safe-area-inset-left));
  width: 100%; max-width: 560px; margin: 0 auto;
  --key-h: clamp(40px, 6.8vh, 58px);
}
.krow { display: flex; gap: 5px; justify-content: center; }
.key {
  flex: 1 1 0; height: var(--key-h); min-width: 0; border: 0; border-radius: 8px;
  background: var(--key-bg); color: var(--key-ink); font-weight: 700; font-size: clamp(14px, 2.2vh, 18px);
  text-transform: uppercase; display: grid; place-items: center;
  transition: background .25s, transform .08s, color .25s;
  -webkit-tap-highlight-color: transparent; user-select: none;
}
.key:active { transform: scale(.94); filter: brightness(1.15); }
.key.is-wide { flex: 1.55 1 0; font-size: 12px; letter-spacing: .04em; }
@media (max-width: 380px) { .key.is-wide { font-size: 11px; letter-spacing: 0; } .krow { gap: 4px; } }
.key svg { width: 22px; height: 22px; }
.krow .kspace { flex: .5 1 0; }
.key[data-state="correct"] { background: var(--c-correct); color: var(--tile-ink); }
.key[data-state="present"] { background: var(--c-present); color: var(--tile-ink); }
.key[data-state="absent"] { background: var(--c-absent); color: var(--text-2); }
:root[data-theme="light"] .key[data-state="absent"] { color: #fff; }
.keyboard.is-locked .key { opacity: .5; pointer-events: none; }

@media (max-height: 700px) {
  .screen-game.is-tall .mini { --mini: 5px; gap: 1.5px; }
  .screen-game.is-tall .opp { padding: 4px 8px 4px 5px; }
  .screen-game.is-tall .keyboard { --key-h: clamp(38px, 6vh, 50px); gap: 4px; }
  .screen-game.is-tall .board-status { display: none; }
}

@media (min-width: 900px) {
  .screen-game {
    grid-template-columns: 1fr 280px;
    grid-template-rows: 1fr auto;
    grid-template-areas: "board opp" "keys opp";
    gap: 8px 16px;
    padding: 8px 16px max(16px, env(safe-area-inset-bottom)) 16px;
  }
  .opponents { overflow-y: auto; padding: 0; }
  .opponents-scroll { flex-direction: column; overflow: visible; padding: 0; gap: 10px; }
  .opp { min-width: 0; padding: 10px 12px 10px 10px; }
  .opp-name { max-width: none; font-size: 14px; }
  .mini { --mini: 10px; gap: 3px; }
  .keyboard { --key-h: 56px; }
  .screen-game.is-solo { grid-template-columns: 1fr; grid-template-areas: "board" "keys"; }
}

/* ---------- results ---------- */
.screen-results { overflow-y: auto; padding: 8px max(16px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); }
.results-head { text-align: center; padding: 16px 0 8px; }
.results-eyebrow { margin: 0 0 10px; color: var(--text-2); font-weight: 600; }
.results-word { display: inline-flex; gap: 6px; --n: 5; }
.results-word span {
  /* never wider than the viewport allows for an --n letter word (set by app.js) */
  width: min(clamp(38px, 10vw, 56px), calc((100vw - 40px - (var(--n) - 1) * 6px) / var(--n)));
  aspect-ratio: 5 / 6; display: grid; place-items: center;
  background: var(--c-correct); color: var(--tile-ink); border-radius: 10px;
  font-weight: 800; font-size: clamp(16px, 5.5vw, 34px); text-transform: uppercase;
  animation: flip .55s ease-in-out both; animation-delay: calc(var(--i) * 80ms);
}
.results-you { margin: 14px 0 0; font-size: 17px; font-weight: 600; }
.results-grid { max-width: 920px; margin: 10px auto 0; display: grid; gap: 22px; }
.section-h { font-size: 15px; font-weight: 700; color: var(--text-2); margin: 0 0 10px; }
.ranking, .scoreboard { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.rank {
  display: grid; grid-template-columns: 34px minmax(0, 1fr) auto; gap: 12px; align-items: start; min-width: 0;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-l); padding: 12px;
  animation: pop-in .35s var(--ease-out) both; animation-delay: calc(var(--i) * 60ms);
}
.rank.is-winner { border-color: var(--c-correct); }
.rank-pos { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; font-weight: 800; background: var(--bg-2); color: var(--text-2); }
.rank.is-winner .rank-pos { background: var(--c-correct); color: var(--tile-ink); }
.rank-body { min-width: 0; }
.rank-name { font-weight: 700; display: flex; align-items: center; gap: 6px; min-width: 0; }
.rank-name > span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.rank-name .you { flex: none; white-space: nowrap; font-size: 12px; color: var(--brand); font-weight: 700; }
.rank-sub { font-size: 13px; color: var(--text-3); }
.rank-board { margin-top: 8px; display: grid; gap: 3px; }
.rank-board .rrow { display: flex; gap: 3px; }
.rank-board .rcell {
  width: clamp(16px, 4vw, 24px); height: clamp(16px, 4vw, 24px); border-radius: 4px; display: grid; place-items: center;
  font-size: clamp(9px, 2.4vw, 13px); font-weight: 800; text-transform: uppercase; color: var(--tile-ink); background: var(--c-absent);
}
.rcell[data-state="correct"] { background: var(--c-correct); }
.rcell[data-state="present"] { background: var(--c-present); }
.rank-time { font-size: 14px; font-weight: 700; color: var(--text-2); font-variant-numeric: tabular-nums; white-space: nowrap; }
.score { display: grid; grid-template-columns: 34px 1fr auto; align-items: center; gap: 12px; padding: 6px 4px; }
.score .avatar { width: 34px; height: 34px; border-radius: 10px; font-size: 14px; }
.score-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.score-wins { font-weight: 800; font-variant-numeric: tabular-nums; }
.results-host, .results-guest { margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--line); }
.results-host .settings { margin-bottom: 14px; }
.results-guest { text-align: center; }

@media (min-width: 760px) {
  .results-grid { grid-template-columns: 1.2fr 1fr; align-items: start; }
}

/* ---------- toasts ---------- */
.toasts {
  position: fixed; left: 50%; top: calc(var(--topbar-h) + env(safe-area-inset-top) + 6px); transform: translateX(-50%);
  display: grid; gap: 8px; z-index: 40; pointer-events: none; width: min(92vw, 420px); justify-items: center;
}
.toast {
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px;
  font-weight: 700; font-size: 15px; box-shadow: var(--shadow); max-width: 100%;
  animation: toast-in .25s var(--ease-spring) both;
}
.toast.is-out { animation: toast-out .25s ease-in both; }
.toast.is-good { background: var(--c-correct); color: var(--tile-ink); }
.toast.is-bad { background: var(--danger); color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-10px) scale(.95) } to { opacity: 1; transform: none } }
@keyframes toast-out { to { opacity: 0; transform: translateY(-6px) } }
@media (min-width: 900px) {
  .toasts { left: auto; right: 20px; top: auto; bottom: 20px; transform: none; justify-items: end; width: 360px; }
  @keyframes toast-in { from { opacity: 0; transform: translateY(10px) scale(.95) } to { opacity: 1; transform: none } }
  @keyframes toast-out { to { opacity: 0; transform: translateY(6px) } }
}

/* ---------- reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-delay: 0ms !important; transition-duration: .01ms !important; }
  .tile.is-flip { animation: none; }
}

.svg-defs { position: absolute; }

/* ---------- co-op ---------- */
.segmented.is-mode button { font-size: 15px; }
.board-status.is-turn { color: var(--brand); }
.opp.is-team { grid-template-columns: auto 1fr; padding: 6px 12px 6px 6px; }
.opp.is-team .avatar { width: 30px; height: 30px; border-radius: 9px; font-size: 13px; }
.opp.is-turn { border-color: var(--brand); box-shadow: 0 0 0 1px var(--brand) inset, 0 6px 18px var(--brand-soft); }
.opp.is-turn .opp-status { color: var(--brand); font-weight: 700; }
@media (prefers-reduced-motion: no-preference) {
  .opp.is-turn .avatar { animation: turn-pulse 1.6s ease-in-out infinite; }
}
@keyframes turn-pulse { 50% { transform: scale(1.08); } }
.rank-board.is-team .rrow { align-items: center; }
.rrow-by { margin-left: 8px; font-size: 12px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }

/* ---------- duel ---------- */
.tile[data-state="chosen"] { background: var(--brand); border-color: transparent; color: var(--brand-ink); }
.screen-game.is-choosing .board { margin-block: auto; }

/* ---------- duel lifelines ---------- */
.tile[data-state="hidden"] {
  border-color: transparent; color: var(--text);
  background: repeating-linear-gradient(135deg, var(--surface-2) 0 6px, var(--surface) 6px 12px);
  position: relative;
}
.tile[data-state="hidden"]::after {
  content: '?'; position: absolute; top: 3px; right: 5px; font-size: calc(var(--tile, 56px) * .26);
  font-weight: 800; color: var(--brand); line-height: 1;
}
.mini-cell[data-state="hidden"] { background: repeating-linear-gradient(135deg, var(--line-strong) 0 2px, transparent 2px 4px); outline: 1px solid var(--brand); }
.rcell.is-fogged { box-shadow: 0 0 0 2px var(--brand); }
.lifelines {
  display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 8px;
  margin-top: 8px; min-height: 36px;
}
.lifelines[hidden] { display: none; }
.ll-btn {
  display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 12px; border-radius: 999px;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--text);
  font-weight: 700; font-size: 14px; touch-action: manipulation; transition: background .15s, border-color .15s, opacity .15s, transform .12s;
}
.ll-btn:hover:not(:disabled) { background: var(--surface-2); }
.ll-btn:active:not(:disabled) { transform: scale(.96); }
.ll-btn:disabled { cursor: default; }
.ll-btn.is-used { opacity: .38; text-decoration: line-through; }
.ll-btn.is-active { border-color: var(--brand); background: var(--brand-soft); color: var(--text); box-shadow: 0 0 0 1px var(--brand) inset; }
.ll-btn.is-cancel { padding: 0 10px; }
.ll-icon { font-size: 16px; line-height: 1; }
.ll-note { font-size: 14px; font-weight: 700; color: var(--text-2); }
.ll-warn {
  font-size: 13px; font-weight: 700; color: var(--c-present); padding: 4px 10px; border-radius: 999px;
  background: color-mix(in srgb, var(--c-present) 14%, transparent);
}
@media (prefers-reduced-motion: no-preference) { .ll-warn { animation: turn-pulse 1.4s ease-in-out infinite; } }
@media (max-width: 380px) { .ll-btn { height: 30px; padding: 0 9px; font-size: 13px; } .lifelines { gap: 6px; margin-top: 6px; } }
.ll-icon { width: 17px; height: 17px; flex: none; }
.ll-warn { display: inline-flex; align-items: center; gap: 5px; }

/* ---------- duel lifelines: reactive windows ---------- */
.lifelines .ll-btn { cursor: default; height: 30px; font-size: 13px; padding: 0 10px; }
.row.is-held .tile { border-color: var(--brand); animation: held-pulse 1.1s ease-in-out infinite; }
@keyframes held-pulse { 50% { border-color: var(--line-strong); } }
@media (prefers-reduced-motion: reduce) { .row.is-held .tile { animation: none; } }
.row.is-scrambled, .row.is-shielded { position: relative; }
.row.is-scrambled::after, .row.is-shielded::after {
  position: absolute; left: calc(100% + 6px); top: 50%; transform: translateY(-50%);
  font-size: 11px; font-weight: 800; color: var(--brand); letter-spacing: .02em;
}
.row.is-scrambled::after { content: 'MIXED'; }
.row.is-shielded::after { content: 'SAFE'; color: var(--c-correct); }
.keyboard.is-held .key { opacity: .5; }
.defend {
  grid-area: keys; z-index: 5; align-self: stretch; display: grid; align-content: center; gap: 10px;
  padding: 14px 14px calc(14px + env(safe-area-inset-bottom)); margin: 0 6px 6px;
  border-radius: 18px; background: var(--surface); border: 1px solid var(--brand);
  box-shadow: 0 -8px 30px rgba(0,0,0,.35), 0 0 0 1px var(--brand) inset;
  animation: defend-in .18s ease-out;
}
.defend[hidden] { display: none; }
@keyframes defend-in { from { transform: translateY(12px); opacity: 0; } }
.defend-h { text-align: center; font-weight: 800; font-size: 16px; }
.defend-sub { text-align: center; font-size: 14px; color: var(--text-2); margin-top: -4px; }
.defend-row { display: flex; justify-content: center; gap: 6px; }
.dtile {
  width: clamp(30px, 9vw, 44px); aspect-ratio: 1; border-radius: 8px; display: grid; place-items: center;
  font-weight: 800; font-size: clamp(15px, 4.4vw, 20px); text-transform: uppercase; color: var(--tile-ink);
  background: var(--c-absent); border: 0; padding: 0;
}
.dtile[data-state="correct"] { background: var(--c-correct); }
.dtile[data-state="present"] { background: var(--c-present); }
button.dtile { cursor: pointer; box-shadow: 0 0 0 2px var(--brand); animation: held-pulse 1s ease-in-out infinite; }
button.dtile:hover { transform: translateY(-2px); }
.defend-actions { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; }
.dbtn {
  display: inline-flex; align-items: center; gap: 6px; height: 42px; padding: 0 16px; border-radius: 12px;
  border: 1px solid var(--brand); background: var(--brand-soft); color: var(--text); font-weight: 800; font-size: 15px;
  touch-action: manipulation;
}
.dbtn:disabled { opacity: .35; text-decoration: line-through; }
.dbtn.is-ghost { background: transparent; border-color: var(--line-strong); }
.dbtn.is-primary { background: var(--brand); color: var(--brand-ink); }
.cd { height: 4px; border-radius: 2px; background: var(--line); overflow: hidden; }
.cd > span { display: block; height: 100%; background: var(--brand); transform-origin: left; animation: cd var(--ms) linear forwards; }
@keyframes cd { from { transform: scaleX(1); } to { transform: scaleX(0); } }
.rrow-mark { width: 14px; height: 14px; margin-left: 6px; color: var(--brand); align-self: center; flex: none; }
.defend { justify-self: center; width: min(560px, calc(100% - 12px)); box-sizing: border-box; }
/* Float the decision panel over the bottom of the game screen so it never resizes the board. */
.screen-game { position: relative; }
.defend {
  position: absolute; left: 50%; bottom: 0; transform: translateX(-50%);
  margin: 0 0 6px; max-height: calc(100% - 12px); overflow: auto;
}
@keyframes defend-in { from { transform: translate(-50%, 12px); opacity: 0; } to { transform: translate(-50%, 0); } }
.defend { grid-area: auto; }
@media (max-width: 400px) {
  .defend { gap: 8px; padding: 10px 10px calc(10px + env(safe-area-inset-bottom)); border-radius: 16px; }
  .defend-h { font-size: 15px; }
  .dbtn { height: 38px; padding: 0 11px; font-size: 14px; gap: 5px; }
  .defend-actions { gap: 6px; flex-wrap: nowrap; }
  .dtile { width: clamp(26px, 9vw, 40px); }
}
.dbtn { white-space: nowrap; }
@media (max-width: 380px) {
  .dbtn { padding: 0 9px; font-size: 13px; gap: 4px; }
  .dbtn .ll-icon { width: 15px; height: 15px; }
  .defend-actions { gap: 5px; }
}
