/* Piction on the web.
 *
 * Mobile first, and the target is a 375x667 phone landing from a shared link:
 * photograph, board and keyboard all reachable without a scroll. Tile colours
 * are the app's own (lib/app/theme.dart) so a player who has both does not
 * think they are looking at a different game.
 */

:root {
  color-scheme: light dark;

  /* Tiles. Taken from AppColors in lib/app/theme.dart. */
  --correct: #478040;
  --present: #c9b458;
  --absent: #4e5254;

  /* Ground and ink. Light is the bare :root so an un-stamped document in a
     light OS resolves correctly without any media query firing. */
  --bg: #ffffff;
  --surface: #f3f4f6;
  --surface-2: #e7e9ee;
  --ink: #1f2937;
  --ink-dim: #686f7c;
  --line: #d7dae1;
  --key: #d3d6da;
  --key-ink: #1f2937;
  --focus: #2f6fd0;

  --radius: 10px;
  --gap: 5px;
  --tile: 46px;
  --maxw: 420px;
}

/* High-contrast tile colours, the web equivalent of the app's colourblind
   setting. Stamped on <html> and persisted per browser. */
:root[data-tiles="hc"] {
  --correct: #85c0f9;
  --present: #f5793a;
}

/* Dark, for everyone who has not explicitly chosen light. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121213;
    --surface: #1e1e1f;
    --surface-2: #2a2a2c;
    --ink: #f9fafb;
    --ink-dim: #9ca3af;
    --line: #35363a;
    --key: #818384;
    --key-ink: #ffffff;
    --focus: #8ab4f8;
  }
}

/* And again for an explicit dark choice over a light OS. */
:root[data-theme="dark"] {
  --bg: #121213;
  --surface: #1e1e1f;
  --surface-2: #2a2a2c;
  --ink: #f9fafb;
  --ink-dim: #9ca3af;
  --line: #35363a;
  /* #818384 with white text measures 3.81:1 and fails AA. This is 7.19:1. */
  --key: #565758;
  --key-ink: #ffffff;
  --focus: #8ab4f8;
}

/* The UA rule for [hidden] is `display: none`, and ANY author rule that sets
 * display outranks it. That silently disabled `hidden` on .help (an empty chip
 * row kept eating a gap) and on the photograph (a broken-image glyph and the raw
 * alt text rendered on every failure path). One rule, everywhere, so the next
 * element toggled by the attribute cannot be bitten by it. */
[hidden] { display: none !important; }

* { box-sizing: border-box; }

html, body { height: 100%; }

/* Set by fitToViewport() only when the page genuinely cannot fit, which is
   roughly below 460px of viewport height. Everywhere else the page is locked
   so the board does not bounce under a touch. */
body.scrollable {
  height: auto;
  min-height: 100%;
  overscroll-behavior: auto;
}
body.scrollable #main { min-height: 0; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  /* rem throughout below this, so a browser font-size preference is honoured.
     Every size used to be px, which made the accessibility setting inert. */
  font: 1rem/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  display: flex;
  flex-direction: column;
  overscroll-behavior: none;
}

.sr {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip-path: inset(50%); white-space: nowrap; border: 0;
}

.skip {
  position: absolute; left: -9999px; top: 0; z-index: 50;
  background: var(--bg); color: var(--ink); padding: 10px 14px;
}
.skip:focus { left: 8px; top: 8px; }

:where(button, a, [tabindex]):focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* ---------- top bar ---------- */

.topbar {
  flex: 0 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  padding: max(8px, env(safe-area-inset-top)) 16px 8px;
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: baseline; gap: 8px; min-width: 0; }

.mark {
  font-weight: 800;
  letter-spacing: 0.14em;
  font-size: 0.9375rem;
}

.num { color: var(--ink-dim); font-size: 0.8125rem; font-variant-numeric: tabular-nums; }

.iconbtn {
  flex: 0 0 auto;
  background: none; border: 1px solid var(--line); color: var(--ink-dim);
  width: 36px; height: 36px; border-radius: 50%;
  font-size: 1rem; line-height: 1; cursor: pointer;
}
.iconbtn[aria-pressed="true"] { color: var(--ink); border-color: var(--ink-dim); }

/* ---------- main column ---------- */

#main {
  flex: 1 1 auto;
  display: flex; flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 100%;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 10px 16px 0;
  min-height: 0;
}

/* In portrait this is transparent: a column that passes the available height
   through to the board and keyboard. The landscape rule at the bottom turns it
   into a real second column. */
.game-col {
  flex: 0 0 auto;
  display: flex; flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-width: 0;
}

/* ---------- the photograph ---------- */

/* The photograph absorbs whatever height the fixed-size board, status and
 * keyboard leave over. Sizing it with aspect-ratio instead pushed the sixth row
 * off a 390x844 phone and put the status line on top of the board. Everything
 * else is measured; the picture gets the remainder. */
.photo {
  flex: 1 1 auto;
  margin: 0;
  width: 100%;
  /* min-height is set by sizeBoard() in app.js from the real remainder. A
     constant here fought the board's own floor and the keyboard lost. */
  min-height: 0;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
  position: relative;
}

.photo img {
  display: block;
  width: 100%; height: 100%;
  object-fit: cover;
}

.photo-skeleton {
  position: absolute; inset: 0;
  background: linear-gradient(100deg, var(--surface) 30%, var(--surface-2) 50%, var(--surface) 70%);
  background-size: 300% 100%;
  animation: sweep 1.4s ease-in-out infinite;
}
@keyframes sweep { to { background-position: -200% 0; } }

/* ---------- the standing instruction ---------- */

.prompt {
  flex: 0 0 auto;
  margin: 0;
  font-size: 0.8125rem;
  color: var(--ink-dim);
  text-align: center;
}
.prompt b { color: var(--ink); font-weight: 600; }

.photo-retry {
  flex: 0 0 auto;
  display: flex; justify-content: center;
  width: 100%;
}

/* ---------- the result bar, which replaces the keyboard ---------- */

.resultbar {
  flex: 0 0 auto;
  width: 100%; max-width: var(--maxw);
  margin: 0 auto;
  padding: 10px 6px max(10px, env(safe-area-inset-bottom));
  display: flex; align-items: center; gap: 12px;
}

.rb-btn {
  flex: 0 0 auto;
  height: 46px; padding: 0 20px;
  border: 0; border-radius: var(--radius);
  background: var(--correct); color: #fff;
  font-size: 0.9375rem; font-weight: 700; cursor: pointer;
}
:root[data-tiles="hc"] .rb-btn { color: #121213; }

.rb-next {
  flex: 1 1 auto;
  font-size: 0.8125rem; color: var(--ink-dim);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

/* ---------- help, chips ---------- */

.help {
  flex: 0 0 auto;
  display: flex; flex-wrap: wrap; gap: 6px;
  justify-content: center;
  width: 100%;
}
/* See the global [hidden] rule at the top of this file. */

.chip {
  margin: 0;
  font-size: 0.8125rem;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink-dim);
  border: 1px solid var(--line);
}
.chip.cat { text-transform: lowercase; letter-spacing: 0.02em; }
.chip.hint { color: var(--ink); }
.chip.nearmiss {
  border-color: var(--present);
  color: var(--ink);
  font-weight: 600;
}

/* ---------- board ---------- */

.board {
  flex: 0 0 auto;
  display: flex; flex-direction: column; gap: var(--gap);
  align-items: center;
  min-height: 0;
}

.row { display: flex; gap: var(--gap); }

.tile {
  width: var(--tile); height: var(--tile);
  display: grid; place-items: center;
  border: 2px solid var(--line);
  border-radius: 4px;
  font-size: calc(var(--tile) * 0.48);
  font-weight: 700;
  text-transform: uppercase;
  color: var(--ink);
  background: transparent;
  user-select: none;
}

.tile.filled { border-color: var(--ink-dim); }
.tile.correct { background: var(--correct); border-color: var(--correct); color: #fff; }
/* ⚠️ Near-black, NOT white. White on #c9b458 measures 2.07:1, which fails WCAG
   1.4.3 at any size, and this is the tile carrying the most information in the
   game: right letter, wrong place. Near-black on the same yellow is 9.05:1. */
.tile.present { background: var(--present); border-color: var(--present); color: #121213; }
.tile.absent  { background: var(--absent);  border-color: var(--absent);  color: #fff; }

/* High contrast swaps both hues for light ones, so correct joins present in
   taking near-black. Measured: present 6.85:1, correct 9.72:1. */
:root[data-tiles="hc"] .tile.correct { color: #121213; }

.row.invalid { animation: shake 0.42s cubic-bezier(.36,.07,.19,.97); }
@keyframes shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-7px); }
  40%, 60% { transform: translateX(7px); }
}

@media (prefers-reduced-motion: reduce) {
  .row.invalid { animation: none; outline: 2px solid var(--present); }
  .photo-skeleton { animation: none; }
  * { transition-duration: 0.01ms !important; }
}

/* ---------- status ---------- */

.status {
  flex: 0 0 auto;
  margin: 0; min-height: 1.3em;
  font-size: 0.8125rem; color: var(--ink-dim); text-align: center;
}

/* ---------- keyboard ---------- */

.keyboard {
  flex: 0 0 auto;
  width: 100%; max-width: var(--maxw);
  margin: 0 auto;
  padding: 6px 6px max(6px, env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 6px;
}

.krow { display: flex; gap: 5px; justify-content: center; }

.key {
  flex: 1 1 0;
  min-width: 0;
  height: clamp(40px, 6.2vh, 54px);
  border: 0; border-radius: 4px;
  background: var(--key); color: var(--key-ink);
  font-size: 0.875rem; font-weight: 600; text-transform: uppercase;
  cursor: pointer;
  touch-action: manipulation;
}
/* ENTER and DELETE share row 3 with seven letters. At 1.6 flex and 13px the
   ENTER label overflowed its key and collided with Z on a 375px phone. More
   width and the original 12px, with nowrap so it can never overlap again. */
.key.wide {
  flex: 1.9 1 0;
  font-size: 0.75rem;
  letter-spacing: 0.01em;
  white-space: nowrap;
  overflow: hidden;
  padding: 0 2px;
}
.key.correct { background: var(--correct); color: #fff; }
.key.present { background: var(--present); color: #121213; }
/* The 0.85 opacity here composited the grey down to 4.36:1, just under AA, for
   no visual gain. Full opacity is 7.90:1. */
.key.absent  { background: var(--absent);  color: #fff; }
:root[data-tiles="hc"] .key.correct { color: #121213; }
.key:disabled { cursor: default; }

/* Ten keys per row is fixed by the alphabet, so a key cannot get wider. Extend
   the touch target past the painted edge instead. Measured before this: 28.6 x
   41.3 on a 375x667 iPhone SE, against a 44pt minimum, with 5px gaps that put
   Q/W and N/M/DELETE centres ~35px apart. */
.key { position: relative; }
.key::after {
  content: "";
  position: absolute;
  inset: -4px -3px;
}

/* Both of these are single points of failure: the contrast toggle is the only
   route to a legible palette, and the close button is the only deliberate way
   out of the result sheet. Both measured under 44pt. */
.iconbtn, .sheet-close { position: relative; }
.iconbtn::after, .sheet-close::after {
  content: "";
  position: absolute;
  inset: 50%;
  width: 44px; height: 44px;
  transform: translate(-50%, -50%);
}

/* ---------- end sheet ---------- */

.sheet-scrim {
  position: fixed; inset: 0; z-index: 10;
  background: rgba(0, 0, 0, 0.55);
}

.sheet {
  position: fixed; z-index: 11;
  left: 0; right: 0; bottom: 0;
  margin: 0 auto;
  width: 100%; max-width: var(--maxw);
  background: var(--bg);
  border-top: 1px solid var(--line);
  border-radius: 20px 20px 0 0;
  padding: 22px 20px max(22px, env(safe-area-inset-bottom));
  text-align: center;

  /* ⛔ These three lines are a bug fix, not styling.
     Measured on the live page at 320x568: the sheet is 619px tall TODAY, and
     with the app call to action it reaches 889px. Without a ceiling and a
     scroller the sheet grows upward off the screen, taking the result, the
     answer word and the close button with it, and a phone has no Escape key
     to dismiss it. The player is stuck on a screen with no result on it. */
  max-height: calc(100vh - 12px);
  max-height: calc(100dvh - 12px);
  overflow-y: auto;
  overscroll-behavior: contain;

  box-shadow: 0 -8px 40px rgb(0 0 0 / 0.18);
}

/* The sheet is focused programmatically so the keyboard lands somewhere sane.
   Chrome still paints the focus-visible ring on that, which reads as an error
   state on a win screen. The close button and share button keep their rings. */
.sheet:focus,
.sheet:focus-visible { outline: none; }

.sheet-close {
  position: absolute; top: 8px; right: 10px;
  background: none; border: 0; color: var(--ink-dim);
  font-size: 1.625rem; line-height: 1; cursor: pointer;
}

.sheet-eyebrow {
  margin: 0; font-size: 0.8125rem; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--ink-dim);
}

.sheet-word {
  margin: 4px 0 8px;
  font-size: 2.125rem; font-weight: 800; letter-spacing: 0.06em;
  text-transform: uppercase;
}

.sheet-why { margin: 0 0 14px; color: var(--ink-dim); font-size: 0.875rem; }

.sheet-said {
  margin: 0 0 16px;
  font-size: 0.9375rem;
  padding: 10px 12px;
  background: var(--surface);
  border-radius: var(--radius);
}
.sheet-said:empty { display: none; }

.primary {
  width: 100%; height: 50px;
  border: 0; border-radius: var(--radius);
  background: var(--correct); color: #fff;
  font-size: 1rem; font-weight: 700; cursor: pointer;
}
:root[data-tiles="hc"] .primary { color: #121213; }

/* The streak is the reason to come back, so it is the second biggest thing on
   this sheet, not a 12px footnote pointing at a different product. */
.sheet-streak {
  margin: 0 0 4px;
  font-size: 1.0625rem; font-weight: 700;
}
.sheet-streak:empty { display: none; }

.sheet-next {
  margin: 0 0 16px;
  font-size: 0.8125rem; color: var(--ink-dim);
  font-variant-numeric: tabular-nums;
}
.sheet-next:empty { display: none; }

.sheet-foot { margin: 14px 0 0; font-size: 0.8125rem; color: var(--ink-dim); }
.sheet-foot a { color: inherit; }

/* ---------- the account offer, after the game and never before ---------- */

/* Separated by a rule rather than whitespace, because it is a different kind of
   thing from the result above it: the result is what happened, this is a choice.
   Colours come from the tokens so both themes and high contrast follow along. */
.sheet-account {
  margin: 14px 0 0;
  padding: 14px 0 0;
  border-top: 1px solid var(--line);
}

.sheet-account-why {
  margin: 0 0 10px;
  font-size: 0.8125rem;
  line-height: 1.45;
  color: var(--ink-dim);
}

.sheet-account-row {
  display: flex;
  gap: 8px;
}

/* Wraps rather than squashing. Two 44px-tall targets side by side fit a 320px
   screen, but only just, so give them room to stack if the font is scaled up. */
@media (max-width: 359px) {
  .sheet-account-row { flex-wrap: wrap; }
  .sheet-account-row .secondary { flex-basis: 100%; }
}

/* Quieter than .primary on purpose. Sharing is the thing being asked for on
   this sheet; the account is the thing being offered. */
.secondary {
  flex: 1 1 0;
  min-height: 44px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
}

.secondary:hover:not(:disabled) { background: var(--surface-2); }

/* A disabled pair means a popup is already open. Say so by looking inert, so a
   second press is visibly pointless rather than silently ignored. */
.secondary:disabled { opacity: 0.55; cursor: default; }

.sheet-account-note {
  margin: 10px 0 0;
  font-size: 0.8125rem;
  line-height: 1.45;
  color: var(--ink-dim);
}
.sheet-account-note:empty { display: none; }

/* ---------- a little more room when there is some ---------- */

@media (min-width: 480px) {
  :root { --maxw: 460px; }
}

/* Landscape phone. Stacking photograph, board and keyboard in 320-400px of
   height cannot work, so the picture takes one column and the game the other. */
@media (orientation: landscape) and (max-height: 500px) {
  #main {
    flex-direction: row;
    align-items: stretch;
    max-width: none;
    gap: 14px;
  }
  .photo { flex: 1 1 45%; min-height: 0 !important; align-self: center; height: 100%; }
  .game-col { display: flex; flex-direction: column; gap: 6px; flex: 1 1 55%; min-width: 0; }
  .keyboard, .resultbar { max-width: none; }
}


/* ===========================================================================
   WEB ARCADE
   Added with the two-a-day arcade. Everything here uses the existing tokens so
   the light and dark sets, and the high-contrast tile override, keep working.
   =========================================================================== */

/* The colour rule, taught before the first guess instead of after it. */
.legend-inline {
  display: flex; flex-wrap: wrap; gap: 4px 10px;
  justify-content: center; align-items: center;
  margin-top: 8px;
  font-size: 0.75rem; color: var(--ink-dim);
}
.legend-inline .lt {
  display: inline-grid; place-items: center;
  width: 18px; height: 18px; margin-right: 3px;
  border-radius: 4px;
  font-style: normal; font-size: 0.6875rem; font-weight: 700;
  color: #fff; vertical-align: -4px;
}
.legend-inline .lt.correct { background: var(--correct); }
.legend-inline .lt.present { background: var(--present); }
.legend-inline .lt.absent  { background: var(--absent); }

/* Disclosed up front, so the cap is never a surprise. Quiet on purpose: it is
   a fact the player should have, not a thing to worry about before they play. */
.cap-note {
  display: block; margin-top: 6px;
  font-size: 0.6875rem; letter-spacing: 0.02em;
  color: var(--ink-dim); opacity: 0.85;
}

/* The crowd fact. Reads as belonging, so it gets real weight; the source line
   is a footnote and must never compete with it. */
.sheet-crowd {
  margin: 14px 0 0;
  font-size: 0.9375rem; line-height: 1.4;
  color: var(--ink);
  text-wrap: balance;
}
.sheet-crowdsrc {
  margin: 4px 0 0;
  font-size: 0.6875rem; color: var(--ink-dim);
}

/* The install ask. Separated by a rule rather than shouted, because it appears
   after the first puzzle too and must not look like a wall at that point. */
.sheet-getapp {
  margin-top: 18px; padding-top: 16px;
  border-top: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 10px; align-items: center;
}
.getapp-why {
  margin: 0; max-width: 32ch;
  font-size: 0.875rem; line-height: 1.45; color: var(--ink-dim);
  text-wrap: balance;
}
.btn-store {
  display: inline-block;
  padding: 12px 22px;
  border-radius: 999px;
  background: var(--ink); color: var(--bg);
  font-weight: 650; font-size: 0.9375rem; letter-spacing: 0.01em;
  text-decoration: none;
  transition: transform 120ms ease, opacity 120ms ease;
}
.btn-store:hover { opacity: 0.88; }
.btn-store:active { transform: translateY(1px); }
.getapp-note { margin: 0; font-size: 0.6875rem; color: var(--ink-dim); }

/* The forward action in the result bar, so dismissing the sheet never leaves
   the player on a dead board. */
.rb-btn.rb-primary {
  background: var(--ink); color: var(--bg);
  border-color: var(--ink);
  font-weight: 650;
}

@media (prefers-reduced-motion: reduce) {
  .btn-store { transition: none; }
}


/* The page footer. Quiet by design: it must be findable without competing
   with the board, which is the only thing on screen that matters. Outside the
   #main flow so the viewport-fitting maths for the board is untouched. */
.pagefoot {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 18px 20px max(18px, env(safe-area-inset-bottom));
  text-align: center;
  border-top: 1px solid var(--line);
}
.pagefoot-note {
  margin: 0 auto;
  max-width: 44ch;
  font-size: 0.6875rem; line-height: 1.5;
  color: var(--ink-dim);
}
.pagefoot-links {
  margin: 8px 0 0;
  display: flex; flex-wrap: wrap; gap: 8px;
  justify-content: center; align-items: center;
  font-size: 0.75rem; color: var(--ink-dim);
}
.pagefoot-links a { color: inherit; text-decoration: underline; }
.pagefoot-links a:hover { color: var(--ink); }

/* The board already fills the viewport, so on a phone the footer would push it
   and reintroduce the scroll the layout works to avoid. Keep it reachable by
   scrolling rather than part of the first screen. */
@media (max-height: 700px) {
  .pagefoot { padding-top: 14px; }
}
