:root {
  /* Wordle's own light-mode canvas: white surfaces, near-black ink, no
     brand hue — the accent role that used to be a cryptic-crossword gold
     is now the same near-black Wordle itself uses for its UI chrome. */
  --page-bg: #FFFFFF;
  --ink: #FFFFFF;
  --ink-border: #D3D6DA;
  --paper: #FFFFFF;
  --paper-border: #D3D6DA;
  --text: #1A1A1B;
  --text-dim: #787C7E;
  --accent: #46474A;
  --accent-strong: #1A1A1B;
  --cell-black: #121213;
  /* Fixed mid-gray fill (doesn't flip with theme) for anything filled
     solid with white text on top — the active cell, badges, buttons.
     Deliberately lighter than --cell-black so the one interactive,
     currently-typed cell never reads as a blocked grid square. */
  --active-fill: #54565A;
  /* Wordle's actual palette — correct/present/absent — used for tile fills
     and keyboard-key status, same green/yellow/gray as the real game. */
  --wordle-green: #6AAA64;
  --wordle-yellow: #C9B458;
  --wordle-gray: #787C7E;
  --wordle-tile-text: #FFFFFF;
  --solved-bg: var(--wordle-green);
  --solved-text: var(--wordle-tile-text);
  /* Bonus cells solve to the same green as everything else, like Wordle's
     single "correct" color — a monochrome ring is the only thing marking
     them as bonus, not a separate hue. */
  --bonus-bg: var(--wordle-green);
  --bonus-text: var(--wordle-tile-text);
  --bonus-border: #1A1A1B;
  --kbd-bg: #D3D6DA;
  --kbd-text: #1A1A1B;
  --active-bg: #F4F4F5;
  --locked-text: #B7B7B7;
  --error: #D3455B;
  --fail-bg: var(--error);
  --fail-text: #FFFFFF;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    /* Wordle's own dark-mode canvas. */
    --page-bg: #121213;
    --ink: #121213;
    --ink-border: #3A3A3C;
    --paper: #121213;
    --paper-border: #3A3A3C;
    --text: #D7DADC;
    --text-dim: #818384;
    --accent: #A6A6AA;
    --accent-strong: #FFFFFF;
    --cell-black: #000000;
    --active-fill: #54565A;
    --wordle-green: #538D4E;
    --wordle-yellow: #B59F3B;
    --wordle-gray: #3A3A3C;
    --wordle-tile-text: #FFFFFF;
    --solved-bg: var(--wordle-green);
    --solved-text: var(--wordle-tile-text);
    --bonus-bg: var(--wordle-green);
    --bonus-text: var(--wordle-tile-text);
    --bonus-border: #D7DADC;
    --kbd-bg: #818384;
    --kbd-text: #D7DADC;
    --active-bg: #1F1F21;
    --locked-text: #565758;
    --error: #E86B85;
    --fail-bg: var(--error);
    --fail-text: #FFFFFF;
  }
}

:root[data-theme="dark"] {
  --page-bg: #121213;
  --ink: #121213;
  --ink-border: #3A3A3C;
  --paper: #121213;
  --paper-border: #3A3A3C;
  --text: #D7DADC;
  --text-dim: #818384;
  --accent: #A6A6AA;
  --accent-strong: #FFFFFF;
  --cell-black: #000000;
  --active-fill: #54565A;
  --wordle-green: #538D4E;
  --wordle-yellow: #B59F3B;
  --wordle-gray: #3A3A3C;
  --wordle-tile-text: #FFFFFF;
  --solved-bg: var(--wordle-green);
  --solved-text: var(--wordle-tile-text);
  --bonus-bg: var(--wordle-green);
  --bonus-text: var(--wordle-tile-text);
  --bonus-border: #D7DADC;
  --kbd-bg: #818384;
  --kbd-text: #D7DADC;
  --active-bg: #1F1F21;
  --locked-text: #565758;
  --error: #E86B85;
  --fail-bg: var(--error);
  --fail-text: #FFFFFF;
}

* { box-sizing: border-box; }

body {
  background: var(--page-bg);
  color: var(--text);
  font-family: -apple-system, "Avenir Next", "Segoe UI", system-ui, sans-serif;
  margin: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0;
}

/* The app is a fixed-height "screen": header/grid/clues scroll inside
   .scroll-area, while the keyboard and solved panel stay pinned at the
   bottom and are never scrolled out of view. */
.app {
  width: 100%;
  max-width: 400px;
  height: 100dvh;
  background: var(--ink);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
/* Only float the card with margin on screens tall enough to spare it —
   the padding must never be able to push the fixed-height card past the
   viewport, so subtract it from the height instead of adding it blind. */
@media (min-height: 860px) {
  body { padding: 28px 12px 40px; }
  .app { height: min(760px, calc(100dvh - 68px)); border-radius: 22px; box-shadow: 0 30px 60px -20px rgba(0,0,0,0.35), 0 2px 8px rgba(0,0,0,0.12); }
}

.scroll-area {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  /* Reserve space for the fixed pane (clue bar + keyboard) so its own
     content never ends up scrolled underneath it. The clue bar's height
     varies with clue length, so this tracks the pane's real measured
     height (set in app.js) rather than a guessed constant. */
  padding-bottom: var(--kbd-height, 220px);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px 12px;
  border-bottom: 1px solid var(--ink-border);
}
.logo {
  font-family: Iowan Old Style, "Palatino Linotype", Georgia, ui-serif, serif;
  font-size: 20px;
  font-weight: 700;
}
.logo em { font-style: normal; color: var(--accent); }
.topbar-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: "SF Mono", "IBM Plex Mono", ui-monospace, monospace;
  font-size: 12px;
  color: var(--text-dim);
}
.streak { font-weight: 600; color: var(--accent); }
.league { font-weight: 600; color: var(--wordle-green); }
.theme-toggle {
  background: none;
  border: 1px solid var(--ink-border);
  color: var(--text);
  border-radius: 999px;
  width: 26px;
  height: 26px;
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.puzzle-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 8px 18px 0;
  font-family: "SF Mono", "IBM Plex Mono", ui-monospace, monospace;
  font-size: 12px;
  color: var(--text-dim);
}
.puzzle-nav button:disabled { opacity: 0.35; cursor: default; }
.hidden { display: none !important; }

.tier-tabs {
  display: flex;
  gap: 8px;
  padding: 10px 18px 0;
}
.tier-tab {
  flex: 1;
  background: none;
  border: 1px solid var(--ink-border);
  color: var(--text-dim);
  border-radius: 999px;
  padding: 7px 10px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}
.tier-tab.active { background: var(--active-fill); color: var(--wordle-tile-text); border-color: var(--active-fill); }
.tier-tab.locked { color: var(--locked-text); cursor: not-allowed; }
.tier-tab .lock-icon { font-size: 10px; opacity: 0.7; }
.tier-tab:not(.locked) .lock-icon { display: none; }

.daily-status {
  text-align: center;
  padding: 6px 18px 0;
  font-family: "SF Mono", "IBM Plex Mono", ui-monospace, monospace;
  font-size: 11px;
  color: var(--text-dim);
}

.archive-banner { display: flex; justify-content: center; padding: 8px 18px 0; }
.archive-back-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  padding: 4px 8px;
}

.badge {
  margin: 10px 18px 0;
  display: none;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-family: "SF Mono", "IBM Plex Mono", ui-monospace, monospace;
  font-size: 11px;
  letter-spacing: 0.1em;
  color: var(--wordle-tile-text);
  background: var(--active-fill);
  border-radius: 999px;
  padding: 6px 14px;
  width: fit-content;
  margin-inline: auto;
  font-weight: 700;
}
.badge.show { display: flex; }

/* One dot per attempt in the shared 5-guess pool, filling in (fail color)
   as they're used up — a constant, glanceable reminder that a wrong guess
   costs something shared across the whole puzzle, not just this entry. */
.attempts-indicator { display: none; justify-content: center; gap: 6px; margin: 8px 18px 0; }
.attempts-indicator.show { display: flex; }
.attempt-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--kbd-bg);
  transition: background 0.2s ease;
}
.attempt-dot.used { background: var(--fail-bg); }

.grid-area {
  padding: 14px 18px 6px;
  display: flex;
  justify-content: center;
}
#grid {
  width: min(360px, 92vw);
  aspect-ratio: 1;
  background: var(--paper);
  border-radius: 10px;
  display: grid;
  padding: 7px;
  gap: 3px;
}
.cell {
  position: relative;
  border: 1px solid var(--paper-border);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: Iowan Old Style, "Palatino Linotype", Georgia, ui-serif, serif;
  font-size: 17px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text);
  background: transparent;
  cursor: default;
  transition: background 0.12s ease, box-shadow 0.12s ease, color 0.12s ease;
}
.cell.black { background: var(--cell-black); border-color: var(--cell-black); }
.cell.fillable { cursor: pointer; background: var(--paper); }
/* Whole active word: a soft, unmistakable wash so you can see which run
   of cells you're currently filling in. */
.cell.active-entry { background: var(--active-bg); box-shadow: inset 0 0 0 1px var(--accent); }
/* The exact next cell to type into: fully inverted, not just a thin ring —
   a 1-2px outline disappears at this cell size, a solid fill doesn't. */
.cell.active-cell { background: var(--active-fill); color: var(--wordle-tile-text); box-shadow: inset 0 0 0 2px var(--accent-strong); }
.cell.solved { background: var(--solved-bg); color: var(--solved-text); }
.cell.bonus { box-shadow: inset 0 0 0 1.5px var(--bonus-border); }
.cell.bonus.solved { background: var(--bonus-bg); color: var(--bonus-text); }
.cell.bonus.active-cell { background: var(--active-fill); color: var(--wordle-tile-text); }
.cell.locked-hint { color: var(--locked-text); font-size: 12px; }
/* A revealed-on-fail cell — the answer to an entry the player never
   solved, shown once the shared attempt pool ran out. Distinct color from
   .solved so a failed grid still reads at a glance as "these ones you
   didn't get", not a second shade of success. */
.cell.failed { background: var(--fail-bg); color: var(--fail-text); cursor: default; }

/* Wordle-style per-letter reveal: on both a correct entry and a wrong
   guess's feedback, tiles flip and color one at a time, left to right,
   instead of every letter changing at once. --reveal-bg/--reveal-text are
   set inline per cell (green/yellow/gray for a wrong guess, the solved/
   bonus color for a correct one); animation-delay is set inline too, at
   REVEAL_STAGGER_MS * this cell's position in the word (app.js), so each
   tile's flip starts a beat after the one before it. The color itself only
   switches at the flip's edge-on midpoint, same as the real thing — a tile
   mid-delay still looks like a plain typed cell, not yet "revealed". */
.cell.reveal {
  animation: reveal-flip 0.45s ease both;
}
/* Without an explicit value at every early keyframe, a browser treats a
   property's first mention (here, at 50%) as the END of an interpolation
   that silently starts from 0% — the tile would visibly start blending
   toward its revealed color from the very first frame instead of staying
   blank until it's edge-on. Repeating the pre-reveal colors through 49.999%
   pins them flat for the whole first half, so the switch at 50% reads as
   the intended instant flip-reveal, not an early leak. */
@keyframes reveal-flip {
  0% { transform: rotateX(0deg); background: var(--paper); color: var(--text); }
  49.999% { transform: rotateX(89.9deg); background: var(--paper); color: var(--text); }
  50% { transform: rotateX(90deg); background: var(--reveal-bg); color: var(--reveal-text); }
  100% { transform: rotateX(0deg); background: var(--reveal-bg); color: var(--reveal-text); }
}
.entry-shake { animation: shake 0.35s ease; }
@keyframes shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(3px); }
  30%, 50%, 70% { transform: translateX(-5px); }
  40%, 60% { transform: translateX(5px); }
}
@media (prefers-reduced-motion: reduce) {
  .cell.reveal { animation: none; background: var(--reveal-bg); color: var(--reveal-text); }
  .entry-shake { animation: none; }
}
.cell .num {
  position: absolute;
  top: 2px;
  left: 3px;
  font-family: "SF Mono", "IBM Plex Mono", ui-monospace, monospace;
  font-size: 9px;
  font-weight: 700;
  color: var(--accent);
}
.cell.solved .num, .cell.reveal .num { color: var(--solved-text); opacity: 0.8; }
.cell.failed .num { color: var(--fail-text); opacity: 0.8; }
.cell.active-cell .num { color: var(--wordle-tile-text); opacity: 0.85; }

/* Lives inside the fixed .kbd pane now (pinned above the keys, same as the
   keys themselves) rather than scrolling away with the grid — the clue
   being typed should stay visible the whole time it's being typed. */
.active-clue {
  padding: 0 2px 10px;
  border-bottom: 1px solid var(--ink-border);
}
.active-clue .tag {
  font-family: "SF Mono", "IBM Plex Mono", ui-monospace, monospace;
  font-size: 11px;
  letter-spacing: 0.08em;
  font-weight: 700;
  color: var(--accent);
  display: block;
  margin-bottom: 4px;
}
.active-clue .clue-text { font-size: 14.5px; line-height: 1.4; }

/* Past attempts at the currently active entry, kept visible instead of
   vanishing after their flash — same idea as Wordle's stacked guess rows,
   just sized down to fit the pinned pane above the keyboard. Empty (no
   attempts yet) collapses to nothing via max-height so it costs no space
   until there's something to show. */
.guess-history {
  display: none;
  flex-direction: column;
  gap: 4px;
  max-height: 104px;
  overflow-y: auto;
}
.guess-history.show {
  display: flex;
  padding: 8px 0 2px;
  border-bottom: 1px solid var(--ink-border);
}
.history-row { display: flex; gap: 4px; justify-content: center; flex-shrink: 0; }
.history-tile {
  flex: 1;
  max-width: 26px;
  aspect-ratio: 1;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: Iowan Old Style, "Palatino Linotype", Georgia, ui-serif, serif;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--wordle-tile-text);
}
.history-tile.green { background: var(--wordle-green); }
.history-tile.yellow { background: var(--wordle-yellow); }
.history-tile.gray { background: var(--wordle-gray); }

#clue-list {
  list-style: none;
  margin: 0;
  padding: 0 18px;
}
.clue-heading {
  font-family: "SF Mono", "IBM Plex Mono", ui-monospace, monospace;
  font-size: 10px;
  letter-spacing: 0.14em;
  color: var(--text-dim);
  padding: 8px 0 4px;
}
#clue-list li {
  display: flex;
  gap: 8px;
  padding: 7px 6px;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.35;
  cursor: pointer;
  border-bottom: 1px solid var(--ink-border);
}
#clue-list li.active { background: var(--active-bg); }
#clue-list li.solved .txt { color: var(--text-dim); text-decoration: line-through; text-decoration-color: var(--text-dim); opacity: 0.75; }
#clue-list li.locked .txt { color: var(--locked-text); font-style: italic; }
#clue-list .num { font-family: "SF Mono", "IBM Plex Mono", ui-monospace, monospace; font-size: 12px; min-width: 14px; color: var(--text-dim); }

/* Truly pinned to the viewport, not just "last flex child" — that was
   reliable in a plain layout but not against mobile browsers whose chrome
   (URL bar, home indicator) resizes the viewport out from under a normal
   flex-flow element. Fixed positioning can't be pushed around by any of
   that. */
.kbd {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 400px;
  z-index: 20;
  background: var(--ink);
  border-top: 1px solid var(--ink-border);
  box-sizing: border-box;
  padding: 12px 8px calc(16px + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.kbd-row { display: flex; justify-content: center; gap: 5px; }
.kbd-key {
  flex: 1; max-width: 32px; height: 40px; border-radius: 6px; border: none;
  background: var(--kbd-bg); color: var(--kbd-text);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600; text-transform: uppercase; cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
}
/* Wordle-style key status: best-known result across every guess so far,
   green beats yellow beats gray and none of them ever downgrade. */
.kbd-key.gray { background: var(--wordle-gray); color: var(--wordle-tile-text); }
.kbd-key.yellow { background: var(--wordle-yellow); color: var(--wordle-tile-text); }
.kbd-key.green { background: var(--wordle-green); color: var(--wordle-tile-text); }
.kbd-key.wide { max-width: 46px; font-size: 14px; }
/* The word is fully typed (often because crossing letters from other
   solved entries filled most of it in) but not yet checked — Enter pulses
   so it's obvious there's still a step left, instead of a complete-looking
   word just sitting there uncolored. */
.kbd-key.ready { background: var(--accent-strong); color: var(--wordle-tile-text); animation: ready-pulse 1s ease-in-out infinite; }
@keyframes ready-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}
@media (prefers-reduced-motion: reduce) {
  .kbd-key.ready { animation: none; }
}

.solved-panel { display: none; text-align: center; padding: 8px 20px 4px; }
.solved-panel.show { display: block; }
.solved-panel h2 {
  font-family: Iowan Old Style, "Palatino Linotype", Georgia, ui-serif, serif;
  font-size: 22px; margin: 4px 0 2px;
}
.solved-panel .time { font-family: "SF Mono", "IBM Plex Mono", ui-monospace, monospace; font-size: 12px; color: var(--text-dim); }
.bonus-line { font-family: "SF Mono", "IBM Plex Mono", ui-monospace, monospace; font-size: 11px; color: var(--accent); margin-top: 4px; }
.share-row { display: flex; gap: 6px; justify-content: center; padding: 12px 20px; }
.share-sq { width: 20px; height: 20px; border-radius: 5px; background: var(--kbd-bg); }
.share-sq.g { background: var(--wordle-green); }
.share-sq.y { background: var(--wordle-yellow); }
.share-sq.bonus-sq { background: var(--active-fill); }
.share-btn {
  background: var(--active-fill); color: var(--wordle-tile-text); border: none; border-radius: 999px;
  padding: 11px 26px; font-size: 14px; font-weight: 700; font-family: inherit; cursor: pointer;
  display: block; margin: 4px auto 6px;
}
.next-puzzle-btn {
  display: block;
  margin: 4px auto 18px;
  background: none;
  border: 1px solid var(--ink-border);
  color: var(--accent);
  border-radius: 999px;
  padding: 9px 20px;
  font-size: 13px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
}
.next-puzzle-btn:disabled { color: var(--text-dim); cursor: default; }

.fail-panel { display: none; text-align: center; padding: 8px 20px 4px; }
.fail-panel.show { display: block; }
.fail-panel h2 {
  font-family: Iowan Old Style, "Palatino Linotype", Georgia, ui-serif, serif;
  font-size: 22px; margin: 4px 0 2px; color: var(--fail-bg);
}
.fail-line {
  font-family: "SF Mono", "IBM Plex Mono", ui-monospace, monospace;
  font-size: 12px; color: var(--text-dim); margin-bottom: 10px;
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  background: var(--text);
  color: var(--ink);
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.menu-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 50;
  align-items: flex-start;
  justify-content: center;
  padding: 0;
}
.menu-overlay.show { display: flex; }
.menu-panel {
  width: 100%;
  max-width: 400px;
  max-height: 100dvh;
  overflow-y: auto;
  background: var(--ink);
  color: var(--text);
  box-shadow: 0 30px 60px -20px rgba(0, 0, 0, 0.45);
  padding: 18px 18px 28px;
  box-sizing: border-box;
}
.menu-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.menu-section {
  padding: 14px 0;
  border-top: 1px solid var(--ink-border);
}
.menu-section:first-of-type { border-top: none; padding-top: 0; }
.menu-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 14px;
}
.menu-heading {
  font-family: "SF Mono", "IBM Plex Mono", ui-monospace, monospace;
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 8px;
}
/* Sits in the menu rather than on the puzzle itself, so it never competes
   with the grid for attention. Full-width because it is the only control in
   its section — the pill shape matches .next-puzzle-btn. */
.coffee-btn {
  display: block;
  text-align: center;
  text-decoration: none;
  border: 1px solid var(--ink-border);
  color: var(--accent);
  border-radius: 999px;
  padding: 11px 20px;
  font-size: 13px;
  font-weight: 700;
  font-family: inherit;
}
.coffee-btn:hover { border-color: var(--accent); }

.menu-text { font-size: 13px; line-height: 1.55; color: var(--text-dim); margin: 0; }
.menu-text a { color: var(--accent); }
.menu-text strong { color: var(--text); }
.menu-puzzle-list {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
}
.menu-puzzle-list button {
  border: 1px solid var(--ink-border);
  background: none;
  color: var(--text);
  border-radius: 8px;
  padding: 8px 0;
  font-family: "SF Mono", "IBM Plex Mono", ui-monospace, monospace;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.menu-puzzle-list button.current { background: var(--active-fill); color: var(--wordle-tile-text); border-color: var(--active-fill); }
.menu-puzzle-list button.done { border-color: var(--wordle-green); color: var(--wordle-green); }
.menu-puzzle-list button.current.done { color: var(--wordle-tile-text); }
