/* Word Grid web version. The colours are the Android app's (ui/theme/Theme.kt). */
:root {
  --ink: #12141c;
  --on: #eceaf2;
  --muted: #b9b7c6;
  --surface: #1b1e29;
  --surface-high: #232634;
  --outline: #4a4e60;
  --primary: #f2a541;
  --on-primary: #1a1205;
  --highlight: #5cc8b0;
  --tile: #f3e9d2;
  --tile-text: #1e1b16;
  --good: #4cc38a;
  --warn: #f2c14e;
  --bad: #f0605d;
  --me: rgba(242, 165, 65, 0.2);
  --dot: #2e9e6b;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html {
  background: var(--ink);
  color: var(--on);
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation; /* no double-tap zoom */
}
body {
  margin: 0;
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
  padding: var(--safe-top) env(safe-area-inset-right, 0px) var(--safe-bottom) env(safe-area-inset-left, 0px);
  -webkit-tap-highlight-color: transparent;
}
#app { max-width: 520px; margin: 0 auto; }
button, input { font: inherit; color: inherit; }
h1, h2, h3, p { margin: 0; }
[hidden] { display: none !important; }
.noscript { padding: 32px; }

/* Screens and the bar across the top */
.screen { min-height: calc(100vh - var(--safe-top) - var(--safe-bottom)); min-height: calc(100dvh - var(--safe-top) - var(--safe-bottom)); display: flex; flex-direction: column; }
.screen.fixed { height: calc(100vh - var(--safe-top) - var(--safe-bottom)); height: calc(100dvh - var(--safe-top) - var(--safe-bottom)); min-height: 0; overflow: hidden; }
.topbar { display: flex; align-items: center; gap: 4px; min-height: 60px; padding: 4px 8px 4px 12px; position: sticky; top: 0; z-index: 5; background: var(--ink); }
.topbar .titles { flex: 1; min-width: 0; padding-left: 4px; }
.topbar .title { font-size: 1.3rem; font-weight: 700; }
.topbar .title.brand { color: var(--primary); }
.topbar .subtitle { font-size: 0.8rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-button { width: 44px; height: 44px; border: 0; border-radius: 50%; background: transparent; display: grid; place-items: center; cursor: pointer; flex: none; }
.icon-button:hover { background: var(--surface-high); }
.icon-button svg { width: 24px; height: 24px; fill: var(--on); }
.content { padding: 0 16px 24px; display: flex; flex-direction: column; gap: 12px; }
.game-host { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.card form { display: flex; flex-direction: column; gap: 8px; }

/* Cards, buttons and text */
.card { background: var(--surface); border-radius: 16px; padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.card h2 { font-size: 1.1rem; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.tiny { font-size: 0.75rem; }
.accent { color: var(--primary); }
.good { color: var(--good); }
.warn { color: var(--warn); }
.bad { color: var(--bad); }
.bold { font-weight: 700; }
.semi { font-weight: 600; }
.button { display: block; width: 100%; border: 0; border-radius: 28px; padding: 14px 16px; background: var(--primary); color: var(--on-primary); font-weight: 700; font-size: 1.1rem; cursor: pointer; text-align: center; text-decoration: none; }
.button:disabled { opacity: 0.5; cursor: default; }
.button.outline { background: transparent; color: var(--primary); border: 1px solid var(--outline); font-size: 1rem; padding: 10px 16px; font-weight: 600; }
.text-button { border: 0; background: transparent; color: var(--primary); font-weight: 600; padding: 8px 4px; cursor: pointer; text-decoration: none; align-self: flex-start; }
.text-button.end { align-self: flex-end; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.button-pair { display: flex; gap: 8px; }
.button-pair .button { flex: 1; }
.tabs { display: flex; border-bottom: 1px solid var(--outline); margin: 0 0 12px; position: sticky; top: 60px; z-index: 4; background: var(--ink); }
.tab { flex: 1; border: 0; background: transparent; color: var(--muted); padding: 12px 8px; font-weight: 600; cursor: pointer; border-bottom: 3px solid transparent; }
.tab.on { color: var(--primary); border-bottom-color: var(--primary); }
.switch-row { flex-direction: row; align-items: center; gap: 12px; cursor: pointer; }
.switch-row .grow { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.switch { appearance: none; -webkit-appearance: none; width: 52px; height: 32px; border-radius: 16px; background: var(--surface-high); border: 2px solid var(--outline); position: relative; cursor: pointer; flex: none; margin: 0; transition: background 0.15s; }
.switch::after { content: ""; position: absolute; top: 4px; left: 4px; width: 20px; height: 20px; border-radius: 50%; background: var(--outline); transition: transform 0.15s, background 0.15s; }
.switch:checked { background: var(--primary); border-color: var(--primary); }
.switch:checked::after { transform: translateX(20px); background: var(--on-primary); }
.switch:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.history-row { width: 100%; border: 0; text-align: left; cursor: pointer; background: var(--surface) !important; padding: 10px 14px; }
.history-row .name { display: flex; align-items: center; gap: 8px; }
.history-row .big-score { font-size: 1.3rem; }
.tag { font-size: 0.7rem; font-weight: 700; color: var(--warn); }
.more { align-self: center; }
.chip { border: 1px solid var(--outline); background: transparent; border-radius: 8px; padding: 6px 14px; cursor: pointer; font-size: 0.9rem; font-weight: 600; }
.chip.on { background: rgba(242, 165, 65, 0.22); border-color: transparent; color: var(--primary); }
.banner { background: rgba(240, 96, 93, 0.2); padding: 6px 16px; font-size: 0.85rem; }
.card .banner { border-radius: 8px; padding: 8px; }
.center-box { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; padding: 32px; text-align: center; }
.spinner { width: 40px; height: 40px; border-radius: 50%; border: 4px solid var(--surface-high); border-top-color: var(--primary); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.field { width: 100%; padding: 14px; border-radius: 8px; border: 1px solid var(--outline); background: transparent; font-size: 1.05rem; }
.field:focus { outline: 2px solid var(--primary); border-color: transparent; }
.label { font-size: 0.85rem; color: var(--muted); }
.code { font-family: ui-monospace, Menlo, Consolas, monospace; word-break: break-all; background: var(--surface-high); padding: 10px; border-radius: 8px; user-select: all; -webkit-user-select: all; }
ul.bullets { margin: 0; padding-left: 1.1rem; color: var(--muted); display: flex; flex-direction: column; gap: 6px; }

/* Sign-up screen */
.welcome { padding: 32px; display: flex; flex-direction: column; gap: 16px; justify-content: center; min-height: calc(100dvh - var(--safe-top) - var(--safe-bottom)); }
.welcome h1 { font-size: 2.6rem; color: var(--primary); }
.welcome form { display: flex; flex-direction: column; gap: 12px; }
.tip { background: var(--surface); border-radius: 12px; padding: 12px 14px; font-size: 0.9rem; color: var(--muted); }
.tip b { color: var(--on); }

/* Player and leaderboard rows */
.rows { display: flex; flex-direction: column; gap: 4px; }
.row { display: flex; align-items: center; gap: 8px; background: var(--surface-high); border-radius: 10px; padding: 8px 12px; }
.results .row, .lb .row { background: var(--surface); }
.row.me { background: var(--me) !important; }
.row .rank { width: 36px; flex: none; font-weight: 700; }
.row .main { flex: 1; min-width: 0; }
.row .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.row .sub { font-size: 0.75rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .sub.accent { color: var(--primary); }
.row .count { font-size: 0.85rem; color: var(--muted); flex: none; }
.row .score { min-width: 48px; text-align: right; font-weight: 700; color: var(--primary); flex: none; }

/* The board. Sizes are in container units, so it scales with its width. */
.board { position: relative; width: 100%; aspect-ratio: 1 / 1; container-type: inline-size; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; flex: none; }
.board.live { touch-action: none; cursor: pointer; }
.board.tappable { cursor: pointer; }
.board .spin { position: absolute; inset: 0; transform: rotate(var(--turn, 0deg)); transition: transform 0.25s ease; }
.board .spin .tile { transform: rotate(calc(-1 * var(--turn, 0deg))); transition: transform 0.25s ease; }
.board svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.board .path { fill: none; stroke: var(--primary); stroke-width: 0.2; stroke-linecap: round; stroke-linejoin: round; }
.board.live .path { stroke: rgba(90, 51, 0, 0.45); stroke-width: 0.12; }
.board.static .path { stroke: var(--highlight); }
.board .grid { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(4, 1fr); grid-template-rows: repeat(4, 1fr); }
.tile { position: relative; margin: 1.75cqw; border-radius: 18%; background: var(--tile); color: var(--tile-text); display: flex; align-items: center; justify-content: center; font-weight: 700; line-height: 1; font-size: 28px; font-size: 10.5cqw; }
.tile.unused { background: #f59b92; }
.tile.once { background: #9fc6f7; }
.tile.fading { transition: background-color 0.6s ease; }
.tile.flash-good { background: #5ed696; }
.tile.flash-warn { background: #ffd84d; }
.tile.flash-bad { background: #ff6b5e; }
.tile.sel { background: var(--primary); }
.board.live .tile.sel { background: #ff9f1a; }
.board.live .tile { margin: 0.15cqw; }
.board.static .tile.sel { background: var(--highlight); }
.tile.focus { box-shadow: inset 0 0 0 1.5cqw var(--primary); }
.tile .val { position: absolute; right: 2cqw; bottom: 1cqw; font-size: 4.25cqw; opacity: 0.6; }
.tile .dots { position: absolute; top: 1.75cqw; right: 1.75cqw; display: flex; gap: 1.1cqw; }
.tile .dot { width: 2.25cqw; height: 2.25cqw; border-radius: 50%; background: var(--dot); }

/* Playing a round */
/* The board runs edge to edge; everything else keeps a margin. */
.playing { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.playing > :not(.board-wrap) { padding-left: 16px; padding-right: 16px; }
.stats-row { display: flex; padding: 4px 0; }
.stat { flex: 1; text-align: center; }
.stat .label { font-size: 0.8rem; }
.stat .value { font-size: 1.6rem; font-weight: 700; line-height: 1.2; }
.wordline { height: 56px; display: flex; flex-direction: column; align-items: center; justify-content: center; flex: none; }
.wordline .word { font-size: 1.5rem; font-weight: 700; white-space: nowrap; }
.wordline .word.long { font-size: 1.25rem; }
.wordline .extra { font-size: 1rem; font-weight: 700; color: var(--primary); }
.shake { animation: shake 0.3s; }
@keyframes shake { 17% { transform: translateX(-12px); } 33% { transform: translateX(12px); } 50% { transform: translateX(-8px); } 67% { transform: translateX(8px); } 83% { transform: translateX(-4px); } }
.board-wrap { display: flex; justify-content: center; flex: none; }
.board-wrap .board { width: min(100%, max(240px, 100vh - 330px)); width: min(100%, max(240px, 100dvh - var(--safe-top) - var(--safe-bottom) - 330px)); }
.boxes { display: flex; gap: 8px; padding-top: 8px; flex: none; align-items: center; }
.rotate-button { width: 44px; height: 44px; flex: none; border: 0; border-radius: 50%; background: #3b3a52; display: grid; place-items: center; cursor: pointer; }
.rotate-button svg { width: 24px; height: 24px; fill: var(--on); }
.rotate-button:active { background: #4a4966; }
.box { flex: 1; display: flex; align-items: center; gap: 6px; background: var(--surface-high); border-radius: 8px; padding: 5px 10px; border: 2px solid transparent; text-align: left; min-width: 0; }
button.box { cursor: pointer; }
.box.active { border-color: var(--primary); }
.legend { display: flex; gap: 14px; padding-top: 6px; font-size: 0.8rem; color: var(--muted); flex: none; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.swatch.unused { background: #f59b92; }
.swatch.once { background: #9fc6f7; }
.box.done { background: rgba(76, 195, 138, 0.2); }
.box .label { font-size: 0.75rem; }
.box .what { font-weight: 600; font-size: 0.9rem; }
.box.done .what, .box.done .pts { color: var(--good); }
.box .grow { flex: 1; min-width: 0; }
.box .pts { font-weight: 700; color: var(--primary); }
.found-head { display: flex; align-items: baseline; gap: 8px; padding-top: 10px; font-weight: 600; font-size: 0.95rem; }
.found { flex: 1; min-height: 0; overflow-y: auto; padding: 6px 0 12px; }
.found-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 6px; }
.found-word { display: flex; gap: 6px; align-items: center; background: var(--surface-high); border-radius: 8px; padding: 6px 10px; font-size: 0.9rem; }
.found-word .w { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.found-word .p { color: var(--primary); font-weight: 600; font-size: 0.85rem; }

/* Results */
.results { flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 0 16px; }
.results-head { display: flex; align-items: center; gap: 8px; padding: 6px 0 8px; flex: none; }
.results-head h2 { font-size: 1.3rem; }
.results-head .grow { flex: 1; min-width: 0; }
.results-head .next { color: var(--primary); font-weight: 600; font-size: 0.95rem; text-align: right; }
.results-body { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.results-top { display: flex; gap: 12px; flex: none; }
.results-top .board { width: 150px; }
.results-side { flex: 1; min-width: 0; min-height: 150px; display: flex; flex-direction: column; justify-content: center; gap: 2px; }
.results-side .big { font-size: 1.5rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.results-side .big.long { font-size: 1.15rem; }
.results-list { flex: 1; min-height: 0; overflow-y: auto; padding: 12px 0 24px; display: flex; flex-direction: column; gap: 4px; }
.section-title { font-weight: 600; font-size: 0.95rem; padding: 6px 0 4px; display: flex; align-items: center; gap: 8px; }
.section-title .grow { flex: 1; }
.word-row { display: flex; align-items: center; gap: 8px; background: var(--surface); border-radius: 8px; padding: 8px 12px; cursor: pointer; border: 0; width: 100%; text-align: left; }
.word-row.sel { background: rgba(92, 200, 176, 0.25); }
.word-row.nobody > * { opacity: 0.5; }
.word-row .tick { width: 18px; color: var(--good); font-weight: 700; flex: none; }
.word-row .w { flex: 1; font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.word-row .who { font-size: 0.8rem; color: var(--muted); flex: none; }
.word-row .p { width: 40px; text-align: right; font-weight: 700; color: var(--primary); flex: none; }
.your-round { background: var(--surface); border-radius: 12px; padding: 12px; margin-bottom: 8px; display: flex; flex-direction: column; gap: 8px; }
.mini-stats { display: flex; gap: 8px; }
.mini { flex: 1; background: var(--surface-high); border-radius: 8px; padding: 8px; text-align: center; }
.mini .value { font-size: 1.25rem; font-weight: 700; color: var(--primary); }
.mini .label { font-size: 0.7rem; white-space: nowrap; }
.detail { display: flex; font-size: 0.85rem; gap: 8px; }
.detail .k { width: 110px; flex: none; color: var(--muted); }
.detail .v { font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row { display: flex; align-items: center; gap: 8px; font-size: 0.85rem; }
.bar-row .k { width: 72px; flex: none; }
.bar { flex: 1; height: 10px; border-radius: 5px; background: var(--surface-high); overflow: hidden; }
.bar > div { height: 100%; background: var(--primary); border-radius: 5px; }
.bar-row .n { width: 64px; flex: none; color: var(--muted); }

/* Stats */
.big-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.big-stat { background: var(--surface-high); border-radius: 10px; padding: 12px; }
.big-stat .value { font-size: 1.6rem; font-weight: 700; color: var(--primary); line-height: 1.2; }
.big-stat .label { font-size: 0.8rem; color: var(--muted); }
.chart { position: relative; height: 150px; }
.chart svg { display: block; }
.chart .top { position: absolute; top: 0; left: 0; font-size: 0.7rem; color: var(--muted); }
.chart-axis { display: flex; justify-content: space-between; font-size: 0.7rem; color: var(--muted); }
.best-board { display: flex; align-items: center; gap: 16px; }
.best-board .board { width: 130px; }
.big-number { font-size: 1.6rem; font-weight: 700; color: var(--primary); }
.word-stat { display: flex; align-items: center; gap: 8px; padding: 4px 0; }
.word-stat .grow { flex: 1; min-width: 0; }
.word-stat .w { font-size: 1.25rem; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.word-stat .right { text-align: right; }
