:root {
  --bg: #0e1116;
  --bg2: #161b25;
  --ink: #eef2f8;
  --dim: #7d879b;
  --line: #242b39;
  --accent: #ffb703;
  --accent2: #4cc9f0;
  --green: #4d9e57;
  --amber: #c9a227;
  --tile: #1b2230;
  --tile-line: #2f394b;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background:
    radial-gradient(900px 620px at 15% -12%, #1a2230 0%, transparent 62%),
    radial-gradient(760px 520px at 100% 4%, #17222c 0%, transparent 58%),
    var(--bg);
  color: var(--ink);
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
}

h1, h2 { margin: 0; }

body.game-ladder {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
}

/* ================================================================= topbar */

.topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  flex: none;
}

/* The tagline reads as a subtitle to the mark, so it sits beneath the lockup
   rather than trailing off its baseline. */
.brand {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
}

/* The mark is the game itself: two words, exactly one tile changed. It says
   what the name says, works standalone as an icon, and leaves the wordmark
   free to be plain type rather than a letter in a box. */
.brand h1 {
  display: inline-flex;
  align-items: center;
  gap: 0.6em;
  font-size: clamp(15px, 2.1vw, 19px);
  font-weight: 700;
  color: var(--ink);
  line-height: 1;
  white-space: nowrap;
  letter-spacing: 0.01em;
}

.brand .mark {
  width: 2.9em;
  height: auto;
  flex: none;
  overflow: visible;
}

.brand .mark .mk-off { fill: #243043; stroke: #3a4a63; stroke-width: 1.1; }
.brand .mark .mk-on { fill: var(--green); }

.tag { font-size: 9.5px; letter-spacing: 1.9px; text-transform: uppercase; color: var(--dim); padding-left: 1px; }

.stats { display: flex; gap: 7px; margin-left: auto; }

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 66px;
  padding: 4px 11px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--bg2);
}

.stat.wide { min-width: 104px; }
.stat-label { font-size: 9px; letter-spacing: 1.5px; text-transform: uppercase; color: var(--dim); }
.stat-value { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-value.sm { font-size: 13px; letter-spacing: 0.4px; }

.controls { display: flex; align-items: center; gap: 8px; }

.btn {
  font-family: inherit;
  font-size: 13px;
  color: var(--ink);
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 8px 13px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
}

.btn:hover { border-color: #3d4a61; background: #1d2431; }
.btn:active { transform: translateY(1px); }
.btn.ghost { width: 34px; padding: 8px 0; text-align: center; font-weight: 700; }
.btn.small { font-size: 12px; padding: 6px 12px; }
.btn.small em { font-style: normal; color: var(--dim); font-size: 10px; }

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #1a1405;
  font-weight: 700;
}

.btn.primary:hover { background: #ffc333; border-color: #ffc333; }
.btn.ok { background: var(--green); border-color: var(--green); color: #eafaec; }

/* ================================================================== board */

.ladder-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: 0 16px;
}

.board {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 8px;
  padding: 10px 0;
}

/* The rungs are the whole game, so they get all the vertical room and shrink
 * gracefully as the ladder grows rather than scrolling out of view. */
.ladder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(3px, 0.9vh, 7px);
  width: 100%;
  min-height: 0;
}

.rung {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: clamp(3px, 0.8vw, 6px);
  width: 100%;
  max-width: 330px;
  flex: 0 1 auto;
  min-height: 0;
}

.gl {
  font-style: normal;
  display: block;
  transform: translateX(var(--dx, 0));
}

.lt {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  min-height: 0;
  max-height: clamp(34px, 7.2vh, 58px);
  border: 2px solid var(--tile-line);
  border-radius: 7px;
  font-size: clamp(15px, 3.4vh, 26px);
  font-weight: 800;
  background: var(--tile);
  color: var(--ink);
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

/* endpoints anchor the puzzle */
.rung.start .lt { background: #243043; border-color: #3a4a63; }
.rung.end .lt { background: transparent; border-color: var(--accent); color: var(--accent); }

.rung.played .lt { background: #1f2a38; border-color: #34425a; }

/* Green means the letter agrees with the target in that position — the same
   thing green means in every other word game. It is NOT "the letter I just
   changed"; that reading made players think a letter was locked in when the
   target did not contain it at all. */
/* Scoped to .rung so it outranks `.rung.played .lt`, which sets its own
   background — an unscoped `.lt.match` loses the specificity race and paints
   nothing at all. */
.rung .lt.match { background: var(--green); border-color: var(--green); color: #f0fbf1; }

/* The swapped letter gets a quiet dot instead of a colour, so tracing your
   route never competes with reading your progress. */
.rung .lt.changed { position: relative; }
.rung .lt.changed::after {
  content: '';
  position: absolute;
  bottom: 4px;
  left: 50%;
  transform: translateX(-50%);
  width: 4px; height: 4px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.45;
}

.rung.landed .lt { animation: land 0.34s cubic-bezier(.2,1.4,.4,1) backwards; }
.rung.landed .lt:nth-child(2) { animation-delay: 0.03s; }
.rung.landed .lt:nth-child(3) { animation-delay: 0.06s; }
.rung.landed .lt:nth-child(4) { animation-delay: 0.09s; }
.rung.landed .lt:nth-child(5) { animation-delay: 0.12s; }

@keyframes land { from { transform: translateY(-9px) scale(0.9); opacity: 0; } }

/* win flourish: a quick lift across the solved word, left to right */
.rung.solved .lt { animation: solved 0.5s cubic-bezier(.2,1.5,.35,1) backwards; }
.rung.solved .lt:nth-child(2) { animation-delay: 0.06s; }
.rung.solved .lt:nth-child(3) { animation-delay: 0.12s; }
.rung.solved .lt:nth-child(4) { animation-delay: 0.18s; }
.rung.solved .lt:nth-child(5) { animation-delay: 0.24s; }

@keyframes solved {
  0%   { transform: translateY(0) scale(1); }
  40%  { transform: translateY(-10px) scale(1.06); }
  100% { transform: translateY(0) scale(1); }
}

/* The draft row is prefilled with the word you're on, so it must not read as
   another played rung. Carried-over letters recede; only your edit and the
   aimed cell come forward. */
.rung.typing { margin-top: 3px; }

.rung.typing .lt {
  background: transparent;
  border-style: dashed;
  border-color: #333e52;
  color: #67718a;
  cursor: pointer;
}

.rung.typing .lt.changed {
  border-style: solid;
  border-color: var(--accent);
  background: rgba(255, 183, 3, 0.10);
  color: var(--accent);
}

.rung.typing .lt.caret {
  border-style: solid;
  border-color: var(--accent2);
  color: var(--ink);
  box-shadow: 0 0 0 3px rgba(76, 201, 240, 0.25);
}

/* green means the same thing on every row */
.rung.typing .lt.match {
  border-style: solid;
  background: var(--green);
  border-color: var(--green);
  color: #f0fbf1;
}

@keyframes tap { from { transform: scale(0.86); } }

.rung.typing.bounce { animation: bounce 0.36s ease; }

@keyframes bounce {
  20% { transform: translateX(-7px); }
  45% { transform: translateX(6px); }
  70% { transform: translateX(-3px); }
}

.msg {
  margin: 0;
  min-height: 18px;
  font-size: 12.5px;
  letter-spacing: 0.4px;
  color: #d99a9a;
  text-align: center;
}

.msg.good { color: #86c98e; }

/* ================================================================ keypad */

/* A physical keyboard makes the on-screen one redundant clutter — and unlike
   Wordle's, it carries no letter-state information to justify the space. Show
   it only where there is nothing to type with. */
.pad { flex: none; padding-bottom: max(10px, env(safe-area-inset-bottom)); }
.keys { display: none; }

@media (hover: none) and (pointer: coarse) {
  .keys { display: flex; }
}

/* nothing left to type once the puzzle is done */
body.done .keys { display: none; }


}

.pad-tools { display: flex; justify-content: center; gap: 8px; margin-bottom: 10px; }

.keys { flex-direction: column; gap: 6px; }
.krow { display: flex; justify-content: center; gap: 5px; }

.key {
  font-family: inherit;
  flex: 1 1 auto;
  max-width: 42px;
  height: clamp(40px, 6.4vh, 52px);
  border: 0;
  border-radius: 7px;
  background: #2b3444;
  color: var(--ink);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.12s, transform 0.08s;
  touch-action: manipulation;
}

.key:hover { background: #364256; }
.key:active { transform: translateY(1px); background: #435268; }
.key.wide { max-width: 62px; font-size: 11.5px; letter-spacing: 0.6px; }

/* ================================================================ overlay */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(6, 8, 12, 0.8);
  backdrop-filter: blur(5px);
  display: grid;
  place-items: center;
  z-index: 100;
  padding: 18px;
  animation: fade 0.2s ease;
}

/* author display:grid would otherwise beat the UA rule for [hidden] */
.overlay[hidden] { display: none; }

@keyframes fade { from { opacity: 0; } }

.modal {
  background: linear-gradient(180deg, #1a212d 0%, #141a24 100%);
  border: 1px solid #2f3a4d;
  border-radius: 18px;
  padding: 28px 30px;
  max-width: 520px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 30px 70px rgba(0, 0, 0, 0.62);
  animation: pop 0.3s cubic-bezier(.2,1.2,.4,1);
}

@keyframes pop { from { transform: scale(0.9); opacity: 0; } }

.modal h2 { font-size: 26px; letter-spacing: 0.5px; margin-bottom: 6px; }
.modal .verdict { font-size: 13.5px; color: var(--dim); margin: 0 0 4px; line-height: 1.55; }

.chain {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin: 18px 0 4px;
}

.chain span {
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 1.2px;
  padding: 5px 8px;
  border-radius: 6px;
  background: #232c3b;
  color: var(--ink);
}

.chain i { color: var(--dim); font-style: normal; font-size: 12px; }
.chain.small span { font-size: 11px; padding: 4px 6px; background: transparent; color: #97a2b8; }

.modal .scoreline { display: flex; gap: 24px; margin: 18px 0 14px; flex-wrap: wrap; }
.modal .scoreline div { display: flex; flex-direction: column; gap: 3px; }
.modal .scoreline span:first-child { font-size: 9.5px; letter-spacing: 1.5px; text-transform: uppercase; color: var(--dim); }
.modal .scoreline span:last-child { font-size: 23px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* miniature ladder inside the help sheet — the rule is easier shown than told */
.demo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  margin: 18px 0 8px;
}

.demo .rung { max-width: 232px; gap: 5px; }
.demo .lt { max-height: 42px; font-size: 18px; border-width: 2px; border-radius: 6px; }
.demo-cap { margin: 0 0 4px; text-align: center; font-size: 11.5px; color: var(--dim); }

.countdown {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin: 0 0 18px;
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 183, 3, 0.05);
}

.countdown span { font-size: 10px; letter-spacing: 1.6px; text-transform: uppercase; color: var(--dim); }
.countdown b { font-size: 20px; font-variant-numeric: tabular-nums; color: var(--accent); }

.best { margin-bottom: 18px; }
.best summary { font-size: 12px; color: var(--dim); cursor: pointer; letter-spacing: 0.4px; }
.best summary:hover { color: var(--ink); }

.modal ol { padding-left: 20px; margin: 14px 0; line-height: 1.7; font-size: 14px; color: #ccd4e4; }
.modal ol b { color: var(--accent); }
.modal .fineprint { font-size: 12px; color: var(--dim); line-height: 1.6; border-top: 1px solid var(--line); padding-top: 14px; }
.modal .fineprint em { color: #97a2b8; font-style: normal; }

.modal-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.wide-btn { width: 100%; margin-bottom: 10px; }

/* Direct post targets. Secondary to the main Share button — on mobile the
   native sheet is better than any of these, so they sit quietly underneath. */
.targets {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.targets-label {
  font-size: 10px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--dim);
  margin-right: 2px;
}

.target {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--bg2);
  color: #97a2b8;
  transition: color 0.15s, border-color 0.15s, background 0.15s, transform 0.1s;
}

.target svg { width: 16px; height: 16px; fill: currentColor; }
.target:hover { color: var(--ink); border-color: #3d4a61; background: #1d2431; }
.target:active { transform: translateY(1px); }

/* on the board it is an unobtrusive row, not a section */
.targets-board {
  justify-content: center;
  border-top: 0;
  padding-top: 0;
  margin: 10px 0 0;
}
.modal-actions .btn { flex: 1 1 auto; min-width: 128px; }

/* ============================================================ responsive */

@media (max-width: 620px) {
  .topbar { gap: 8px; padding: 9px 12px; }
  .brand h1 { font-size: 15px; letter-spacing: 1px; }
  .tag { font-size: 8.5px; letter-spacing: 1.5px; }
  .stats { order: 3; width: 100%; margin-left: 0; justify-content: space-between; gap: 5px; }
  .stat { flex: 1; min-width: 0; padding: 3px 6px; }
  .stat-value { font-size: 16px; }
  .ladder-main { padding: 0 10px; max-width: 460px; }
  .modal { padding: 22px 18px; }
  .modal-actions .btn { min-width: 0; }
  .key { max-width: none; }
}

/* ======================================================== accessibility */

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

/* Visible focus everywhere, but only for keyboard users. */
:focus-visible {
  outline: 3px solid var(--accent2);
  outline-offset: 2px;
}

.modal:focus { outline: none; }

/* Respect the OS setting. The tile animations are decorative; the game reads
   identically without them, so drop them rather than shortening them. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
  .rung.landed .lt { animation: none !important; }
}

/* Fingers need ~44px; a mouse does not. The share button is the most
   important control in the game on the device where sharing actually
   happens, and it was 28px tall. */
@media (hover: none) and (pointer: coarse) {
  .btn.small { min-height: 44px; padding: 10px 16px; font-size: 13px; }
  .target { width: 44px; height: 44px; }
  .target svg { width: 19px; height: 19px; }
  .btn.ghost { width: 44px; min-height: 44px; }
  .modal-actions .btn { min-height: 46px; }
  .targets { gap: 10px; }
