/*
 * One stylesheet for all three games. The palette mirrors the Android app:
 * parchment and slate for the chrome, and each game keeps its own board
 * colours in both themes, the way a printed puzzle would.
 */
:root {
  --bg: #FBFAF7;
  --surface: #ECE8F2;
  --surface-2: #EFEDE7;
  --on-bg: #15181D;
  --muted: #4B4F57;
  --outline: #C7C4BC;
  --primary: #5B4BD6;
  --on-primary: #FFFFFF;
  --primary-container: #E4E0FB;
  --on-primary-container: #1E1554;
  --accent-container: #D6EDE5;
  --on-accent-container: #10352B;
  --danger: #B3261E;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/*
 * Dark is asked for, not merely detected: the resolved theme is written onto
 * <html> as data-theme by the inline script in index.html and then kept there by
 * Theme.kt, so a player can have the dark chrome at noon and the light one at
 * midnight. Behind a media query this could only ever agree with the system.
 */
:root[data-theme="dark"] {
  --bg: #10141A;
  --surface: #262C35;
  --surface-2: #1D222A;
  --on-bg: #ECEDEF;
  --muted: #B6BBC4;
  --outline: #444B55;
  --primary: #B9AEFF;
  --on-primary: #29206B;
  --primary-container: #3A2F86;
  --on-primary-container: #E4E0FB;
  --accent-container: #20493E;
  --on-accent-container: #D6EDE5;
  --danger: #FFB4AB;
  /* So the scrollbar, and the field a leaderboard name is typed into, are
     drawn dark to match rather than staying stubbornly light. */
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  /* dvh follows Safari's toolbar as it slides away; the percentage is the
     fallback for browsers that do not have it. */
  height: 100%;
  height: 100dvh;
  background: var(--bg);
  color: var(--on-bg);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}

.app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100%;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: calc(var(--safe-top) + 12px) 16px calc(var(--safe-bottom) + 16px);
}

h1 { font-size: 2rem; margin: 4px 0 2px; letter-spacing: -0.5px; }
h2 { font-size: 1.25rem; margin: 18px 0 6px; }
p.lede { color: var(--muted); margin: 0 0 14px; font-size: 0.95rem; }

.card {
  background: var(--surface);
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 12px;
}
.card.tap {
  cursor: pointer;
  display: block;
  width: 100%;
  text-align: left;
  font: inherit;
  color: inherit;
  border: none;
}
.link { color: var(--primary); font-weight: 600; }
.card.tap:active { filter: brightness(0.97); }
.card.feature { background: var(--primary-container); color: var(--on-primary-container); }

.row { display: flex; align-items: center; gap: 12px; }
.grow { flex: 1; min-width: 0; }
.sub { color: var(--muted); font-size: 0.85rem; margin-top: 2px; }
.card.feature .sub { color: inherit; opacity: 0.85; }
.title { font-weight: 600; font-size: 1.05rem; }
.title.big { font-size: 1.3rem; }

.badge {
  width: 44px; height: 44px; border-radius: 12px;
  display: grid; place-items: center;
  color: #fff; font-weight: 700; font-size: 1.2rem;
  flex: none;
}

button {
  font: inherit;
  border: none;
  border-radius: 999px;
  padding: 10px 20px;
  background: var(--primary);
  color: var(--on-primary);
  font-weight: 600;
  cursor: pointer;
}
button:active { filter: brightness(0.94); }
button[disabled] { opacity: 0.4; cursor: default; }
button.ghost {
  background: transparent;
  color: var(--primary);
  border: 1px solid var(--outline);
}
button.plain { background: transparent; color: var(--primary); padding: 8px 10px; }
button.wide { width: 100%; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; margin: 10px 0; }

/* A settings row: what it does on the left, the switch on the right. */
.rule { height: 1px; background: var(--outline); opacity: 0.7; margin: 12px 0; }
.setting { display: flex; align-items: center; gap: 12px; padding: 7px 0; }
.switch {
  flex: none; position: relative; width: 46px; height: 27px; padding: 0;
  border: 1px solid var(--outline); border-radius: 999px;
  background: var(--surface-2); cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease;
}
.switch > i {
  position: absolute; top: 2px; left: 2px; width: 21px; height: 21px;
  border-radius: 50%; background: var(--muted);
  transition: transform 140ms ease, background 140ms ease;
}
.switch[aria-pressed="true"] { background: var(--primary-container); border-color: transparent; }
.switch[aria-pressed="true"] > i { transform: translateX(19px); background: var(--primary); }
.chip {
  border: 1px solid var(--outline);
  background: transparent;
  color: var(--on-bg);
  border-radius: 10px;
  padding: 7px 14px;
  font-size: 0.9rem;
  font-weight: 500;
}
.chip.on { background: var(--accent-container); color: var(--on-accent-container); border-color: transparent; }

.bar { height: 4px; background: var(--outline); border-radius: 999px; overflow: hidden; margin-top: 8px; }
.bar > i { display: block; height: 100%; background: var(--primary); }

/* ---- play screen ---- */
.topbar { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.topbar .title { flex: 1; }
.iconbtn {
  background: transparent; color: var(--on-bg);
  padding: 8px 10px; border-radius: 10px; font-size: 1.1rem; font-weight: 400;
}
.stats { display: flex; justify-content: space-between; margin-bottom: 10px; }
.stat { text-align: center; }
.stat b { display: block; font-size: 1.05rem; }
.stat span { font-size: 0.7rem; letter-spacing: 0.08em; color: var(--muted); text-transform: uppercase; }

.board-wrap { display: grid; place-items: center; flex: 1; min-height: 0; }
canvas { max-width: 100%; height: auto; }

/*
 * Double tap must not zoom.
 *
 * `manipulation` is what stops it. The viewport meta used to claim that with
 * `user-scalable=no`, which both Safari and Chrome ignore on purpose, so it
 * never worked. Pinch to zoom still works, deliberately: taking it away breaks
 * the page for anyone who needs it.
 *
 * It cannot be declared on `body` alone, which is what it was and why iPhones
 * went on zooming after that was supposed to be fixed. Chrome intersects
 * touch-action down the ancestor chain, so one declaration up there covered
 * every square and button beneath it and the page behaved. WebKit does not
 * apply touch-action set on the document's own scrolling element, so on iOS
 * nothing below inherited anything: html, #app, .board-wrap and every button
 * all computed `auto`, and a second tap on a square was a zoom. Naming the
 * elements a finger actually lands on is the version both engines agree about.
 */
html, body { touch-action: manipulation; }
.app, .app * { touch-action: manipulation; }

/*
 * Touch on the board.
 *
 * `manipulation` was wrong here. It stops a double tap zooming, but it still
 * lets the browser treat a drag as a pan -- and the moment it decides that is
 * what is happening it cancels the pointer stream, so painting a run of crosses
 * stops halfway through. Safari claims a vertical drag far more eagerly than
 * Chrome, which is why this looked like a Safari bug rather than a missing
 * declaration. `none` says the board handles its own gestures.
 *
 * It outranks the rule above on specificity, and it is written after it as
 * well, so the board keeps `none` however this file is later rearranged.
 */
.board-wrap canvas { touch-action: none; }

.banner {
  background: var(--accent-container);
  color: var(--on-accent-container);
  border-radius: 14px;
  padding: 14px;
  margin-top: 12px;
  font-size: 0.95rem;
}
.banner .row { margin-top: 10px; gap: 8px; }
.actions { display: flex; gap: 8px; margin-top: 12px; }
.actions button { flex: 1; }
.note { text-align: center; color: var(--danger); min-height: 1.2em; font-size: 0.9rem; margin: 6px 0; }

/* ---- level grid ---- */
.levels { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 10px; }
.level {
  position: relative;
  aspect-ratio: 1;
  border-radius: 14px;
  background: var(--surface-2);
  display: grid; place-items: center; align-content: center;
  font-weight: 600;
  cursor: pointer;
  border: none; color: var(--muted); padding: 0;
}
.level small { display: block; font-weight: 500; font-size: 0.7rem; }
.level i {
  position: absolute; top: 5px; right: 5px;
  font-style: normal; font-size: 0.6rem; font-weight: 700;
  color: #fff; border-radius: 4px; padding: 1px 4px;
}

/* ---- wordspot ---- */
.wgrid { display: grid; gap: 5px; justify-content: center; }
.wrow { display: grid; gap: 5px; }
.wtile {
  aspect-ratio: 1;
  display: grid; place-items: center;
  border-radius: 6px;
  font-weight: 700;
  border: 2px solid transparent;
  color: var(--on-bg);
}
.wtile.empty { border-color: color-mix(in srgb, var(--outline) 60%, transparent); }
.wtile.typed { border-color: var(--muted); }
/* Word Spot is the one board made of elements rather than drawn on a canvas,
   so its three verdict colours come in as variables that BoardSkin.kt sets --
   the same shared values every other board is drawn from. */
.wtile.correct { background: var(--ws-correct, #3F8F5F); color: #fff; }
.wtile.present { background: var(--ws-present, #C29A2B); color: #fff; }
.wtile.absent  { background: var(--ws-absent, #6E7278); color: #fff; }

.keys { display: grid; gap: 5px; margin-top: 10px; }
.krow { display: flex; gap: 4px; justify-content: center; }
.key {
  flex: 1; min-width: 0; height: 46px;
  border-radius: 6px; border: none;
  background: var(--surface-2); color: var(--on-bg);
  font-weight: 600; font-size: 0.95rem; padding: 0;
}
.key.wide { flex: 1.6; font-size: 0.75rem; }
.key.correct { background: var(--ws-correct, #3F8F5F); color: #fff; }
.key.present { background: var(--ws-present, #C29A2B); color: #fff; }
.key.absent  { background: var(--ws-absent, #6E7278); color: #fff; }

/* ---- dialog ---- */
.scrim {
  position: fixed; inset: 0; background: rgba(0,0,0,0.45);
  display: grid; place-items: center; padding: 24px; z-index: 10;
}
.dialog {
  background: var(--primary-container); color: var(--on-primary-container);
  border-radius: 22px; padding: 22px; max-width: 340px; width: 100%;
  /* A grid item will not shrink below its content unless told it may. With a
     table in it, that content was wider than a 360px phone left room for, so
     the dialog overflowed to the right -- 24px of margin on the left and 4px
     on the right. It shrinks to the space now, and a table that still does
     not fit scrolls inside its own box. */
  min-width: 0;
}
/* The standings keep their columns but not the board screen's minimum width,
   which is wider than a dialog on a phone has. */
.dialog .srow { min-width: 0; }
/* Narrow phones: a little less around the dialog, and a little less inside
   it, so a table fits without scrolling. */
@media (max-width: 400px) {
  .scrim { padding: 16px; }
  .dialog { padding: 20px 18px; }
}
.dialog h3 { margin: 0 0 8px; font-size: 1.3rem; }
.dialog .row { justify-content: flex-end; margin-top: 18px; }

.center { text-align: center; color: var(--muted); padding: 40px 0; }

/* ---- patches legend ---- */
.legend { margin-top: 10px; text-align: center; }
.legend p { margin: 2px 0; color: var(--muted); font-size: 0.8rem; }

/* ---- game glyphs, rings and the streak ---- */
.badge .glyph { display: grid; place-items: center; }

.rings { display: flex; justify-content: space-evenly; margin-top: 10px; }
.ring { text-align: center; color: var(--on-bg); }
.ring-label { font-size: 0.72rem; color: var(--muted); margin-top: 3px; }
.ring-label.on { color: var(--on-bg); font-weight: 600; }
.ring-count { font-size: 0.72rem; color: var(--muted); }

/* Was a flex row when it only held a flame and a line of text. It now stacks
   that row above the six daily slots, so the card itself is a block. */
.card.streak {
  background: var(--primary-container); color: var(--on-primary-container);
}
.card.streak .sub { color: inherit; opacity: 0.8; }
.flame { display: grid; place-items: center; animation: breathe 1.6s ease-in-out infinite alternate; }
@keyframes breathe { from { transform: scale(0.92); } to { transform: scale(1.06); } }
@media (prefers-reduced-motion: reduce) { .flame { animation: none; } }

/* ---- the daily archive ---- */
.month { margin-bottom: 4px; }
.center { text-align: center; }
.iconbtn.off { opacity: 0.3; cursor: default; }
.weekdays { display: grid; grid-template-columns: repeat(7, 1fr); margin-bottom: 4px; }
.weekdays span { text-align: center; font-size: 0.72rem; color: var(--muted); }
.calendar { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.day {
  aspect-ratio: 1; border-radius: 10px; background: transparent;
  border: 1px solid var(--outline); color: var(--on-bg);
  font: inherit; font-size: 0.9rem; padding: 0; cursor: pointer;
}
.day.empty { border: none; cursor: default; }
.day.shut { border: none; color: var(--muted); opacity: 0.4; cursor: default; }
.day.done { border: none; color: #fff; font-weight: 700; }
.day.today { border: 2px solid var(--on-bg); font-weight: 700; }

/* ---- worked examples under the rules ---- */
.example { margin-top: 14px; }
.example-board { display: grid; place-items: center; margin: 10px 0; }
button.flush { padding-left: 0; padding-right: 0; }
/* Text, not a filled button: --danger is a light salmon in dark mode, meant to
   be read against a dark surface rather than filled behind white text. */
button.danger { background: transparent; color: var(--danger); font-weight: 600; }
.tappable { cursor: pointer; user-select: none; }

/* A submitted Word Spot row turns over, tile by tile. */
.wtile.flip { animation: turnover 260ms ease-in-out both; }
@keyframes turnover {
  0%   { transform: scaleY(1); }
  50%  { transform: scaleY(0.04); }
  100% { transform: scaleY(1); }
}
@media (prefers-reduced-motion: reduce) { .wtile.flip { animation: none; } }

/* ---- today's dailies, and the compact game rows ---- */
/* Rows of daily slots. How many rows, and how many in each, is decided in
   shared Kotlin so the phone and the browser agree; --slot-cols carries the
   widest row's count in, and every row lays out on it so a short row's tiles
   match the rest instead of stretching. */
.slots { display: flex; flex-direction: column; gap: 7px; margin-top: 14px; }
.slotrow { display: grid; grid-template-columns: repeat(var(--slot-cols, 5), 1fr); gap: 7px; }
.slotgap { visibility: hidden; }
.slot {
  height: 34px; border-radius: 9px; padding: 0; border: none;
  display: grid; place-items: center; opacity: 0.3;
}
.slot.done { opacity: 1; }
.card.tap.compact { padding: 12px 14px; }
.badge.small { width: 38px; height: 38px; border-radius: 11px; }
.packring { display: grid; place-items: center; flex: none; color: var(--on-bg); }

/* ---- the result on the solved dialog ---- */
.result {
  background: rgba(0, 0, 0, 0.10); border-radius: 12px;
  padding: 12px 14px; margin: 16px 0;
}
.result-head {
  font-size: 0.68rem; letter-spacing: 0.09em; opacity: 0.7;
  text-transform: uppercase; margin-bottom: 6px;
}
.result pre {
  margin: 0; font-size: 0.78rem; line-height: 1.5;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: pre-wrap; word-break: break-word;
}
.dialog .row.actions { justify-content: stretch; gap: 10px; margin-top: 0; }
.dialog .row.actions button { flex: 1; }
.dialog .row.streakline { justify-content: center; gap: 9px; margin-top: 14px; font-size: 0.9rem; }

/* ---- the masthead, with the share-the-game button ---- */
.masthead { align-items: flex-start; margin-bottom: 2px; }
.masthead-lede { margin-bottom: 8px; }
/* Every icon in the masthead reads as one set. Keyed to where they sit, not
   to the first one that happened to need it: as .iconbtn.share this caught
   share alone, so refresh -- which never carried that class -- came out in
   the body colour, at a looser padding, sitting half a line higher than the
   icons beside it. */
.masthead .iconbtn { color: var(--primary); padding: 6px 8px; flex: none; margin-top: 6px; }
.masthead .iconbtn:active { opacity: 0.6; }

/* ---- the daily board ------------------------------------------------------
   Sits inside the solved dialog, under the result and above the streak. It is
   the one part of the app that shows other people, so it is deliberately quiet:
   a heading, a few rows, and the player's own line picked out. */
.board-panel {
  margin-top: 14px;
}

.namefield {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  border-radius: 10px;
  /* --line, --card and --ink were never declared: this asked for three
     variables that do not exist, so the browser threw the whole declaration
     out and the field a name is typed into had no border, no background and
     whatever colour it inherited. */
  border: 1px solid var(--outline);
  background: var(--surface-2);
  color: var(--on-bg);
  font: inherit;
}

/* A restore code, shown to be copied off the screen by hand. */
.code {
  margin: 10px 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px dashed var(--outline);
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 1.1rem;
  letter-spacing: 0.08em;
  text-align: center;
  user-select: all;
}

/* A table with columns that line up, rather than a row of things shoved
   around by however long somebody's name is. --card and --dim were asked for
   here and have never been declared, so the background and the quiet grey
   were both thrown away by the browser; they are real tokens now.

   Narrow screens scroll it sideways instead of squeezing four numbers into
   nothing, which is why the rows carry a minimum width. */
.standings {
  background: var(--surface);
  border-radius: 12px;
  padding: 10px 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.srow {
  display: grid;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border-radius: 10px;
  min-width: 17rem;
}

/* Place and name, then whatever that board counts. The tracks are sized to
   fit a 360px phone without scrolling at all; the scroll is there for the
   narrower ones and for a name long enough to need it. */
.srow.daily { grid-template-columns: 1.4rem minmax(4.5rem, 1fr) 3.6rem 4.6rem; }
.srow.weekly { grid-template-columns: 1.4rem minmax(4rem, 1fr) 2.6rem 3.4rem 3.2rem; }

.srow.head {
  font-size: 0.66rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  padding-bottom: 0;
}

.srow .place {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.srow .who {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Numbers line up on the right and share a width, so a column of them reads
   as a column. */
.srow .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.srow .quiet { color: var(--muted); font-size: 0.78rem; }

/* Hints and slips: shown, never sorted by. A clean row says so in the accent
   colour, because it is worth noticing even when it did not win. */
.srow .clean { color: var(--primary); font-weight: 600; }

/* Your own row, so you can find yourself without reading the names. */
.srow.you {
  background: var(--primary-container);
  color: var(--on-primary-container);
  font-weight: 600;
}

/* ---- today's boards -------------------------------------------------------
   A row of game chips over one board. No swiping between them: a browser page
   already swipes, back and forward, and a second horizontal gesture on top is
   how you leave the page meaning to change game. */
.chips {
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  margin-bottom: 12px;
  scrollbar-width: none;
}

.chips::-webkit-scrollbar {
  display: none;
}

.chips .chip {
  white-space: nowrap;
  flex: 0 0 auto;
}

.chips .chip.on {
  background: var(--primary);
  color: var(--on-primary, #fff);
  border-color: var(--primary);
}

.boards-body {
  min-height: 120px;
}

/* A refusal worth reading, as against the quiet grey of an explanation. */
.sub.warn:not(:empty) { color: var(--danger); }

/* The rubber sits with the number keys but is not one of them. */
.key.erase { background: var(--surface-2); color: var(--muted); }


.whoami { margin-top: 18px; }

/* ---- rooms ----------------------------------------------------------------
   A batch is a row of numbered squares, filled in the game's colour once you
   have done them -- the phone's picture, at the phone's size. */
.tiles { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.tile {
  width: 48px; height: 48px; padding: 0;
  border-radius: 10px;
  border: 1px solid var(--outline);
  background: var(--surface);
  color: var(--on-bg);
  font-weight: 600; font-size: 1rem;
}
.tile.done { border-color: transparent; color: #fff; }

.label { font-size: 0.8rem; color: var(--muted); margin-top: 12px; }
.label + .chips { margin-top: 4px; }

/* How many puzzles: a short box for a number, beside what to do with it. */
.namefield.count { flex: none; width: 4.5em; text-align: center; font-size: 1.05rem; }
.release { align-items: center; gap: 10px; margin: 10px 0 2px; }

/* The name a room knows you by, on its own line above the cards. */
.namefield.alone { display: block; width: 100%; box-sizing: border-box; margin: 4px 0 14px; }

.member { padding: 6px 0; }
.member .you { font-weight: 700; }
.mono { font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; }
.card > .title.big + button.wide,
.card > .title.big + form { margin-top: 12px; }

/* Who you are in rooms: the name, or the field when there is none yet. */
.nameline { align-items: center; margin: 4px 0 14px; }
.card > .namefield.count { margin-bottom: 12px; }
.playtoday { margin: 4px 0 12px; }

/* Finished batches, folded into one row. The chevron turns when it opens. */
.card.folded .row { align-items: center; }
.chevron { display: grid; place-items: center; color: var(--muted); transition: transform 0.15s; }
.chevron.open { transform: rotate(180deg); }
.firstsolve { margin-bottom: 10px; }

/* Google draws its own button, so this only gives it somewhere to sit. */
.signin { margin: 10px 0 4px; min-height: 40px; }

/* A name you can press: the row's own name, which opens report-or-hide.
   Dotted rather than solid, so a leaderboard does not read as a page of
   links -- it is an affordance for the rare moment somebody needs it. */
.who.tappable {
  cursor: pointer;
  text-decoration: underline dotted;
  text-underline-offset: 3px;
  text-decoration-color: var(--outline);
}
.who.tappable:hover, .who.tappable:focus-visible {
  text-decoration-color: var(--primary);
}

/* The sign-in card on the hub. Marked out from the game cards because it is
   the one thing here that was not asked for, and should look like a thing
   you can dismiss rather than part of the furniture. */
.card.nudge {
  border: 1px solid var(--primary);
  background: var(--primary-container);
  color: var(--on-primary-container);
}
.card.nudge .sub { color: var(--on-primary-container); opacity: 0.85; }
