/* Catnnections
   ------------------------------------------------------------------------
   The game's own rules. Tokens, the page frame, the masthead, buttons, list
   rows and empty states come from ../shared/taskcat.css, which index.html
   loads first; this file only adds what the board, ladder and builder need.

   Palette note: the four difficulty hues do double duty — they colour the
   groups AND the rank ladder. That is a rhyme, not a collision: purple means
   "hardest" in both places. Form keeps them apart (tiles are squares, the
   ladder is a bar), so the two readings never compete for the same glyph.

   The player never sees a number. The bar and the rank name are the score.
*/

/* ---- Player masthead: the puzzle title beside the wordmark ------------ */

.puzzle-title {
  font-size: 15px;
  font-weight: 650;
  letter-spacing: -0.01em;
  text-align: right;
  line-height: 1.25;
}
.puzzle-byline { display: block; font-size: 12px; font-weight: 500; color: var(--ink-faint); }

/* ---- Rank ladder -------------------------------------------------------
   Quiet at rest, loud on change. The fill is linear in RANK, not in score,
   so the exponential thresholds at the top compress into equal segments and
   promotion keeps a steady rhythm all the way up.
   ------------------------------------------------------------------------ */

.ladder { margin-bottom: 18px; }

.ladder-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 6px;
  min-height: 20px;
}

.rank-name {
  font-size: 14px;
  font-weight: 750;
  letter-spacing: -0.01em;
  transition: color var(--dur) var(--ease);
}
.rank-name[data-tier='yellow'] { color: var(--yellow-ink); }
.rank-name[data-tier='green']  { color: var(--green-ink); }
.rank-name[data-tier='blue']   { color: var(--blue-ink); }
.rank-name[data-tier='purple'] { color: var(--purple-ink); }

.rank-note { font-size: 12px; color: var(--ink-faint); font-variant-numeric: tabular-nums; }

.track {
  position: relative;
  height: 12px;
  border-radius: 99px;
  background: var(--tile);
  border: 1px solid var(--line);
  overflow: hidden;
}

.track-fill {
  height: 100%;
  width: 0;
  border-radius: 99px;
  background: var(--yellow-fill);
  transition: width 620ms var(--ease), background-color var(--dur) var(--ease);
}
.track-fill[data-tier='yellow'] { background: var(--yellow-fill); }
.track-fill[data-tier='green']  { background: var(--green-fill); }
.track-fill[data-tier='blue']   { background: var(--blue-fill); }
.track-fill[data-tier='purple'] { background: var(--purple-fill); }

.track-ticks {
  position: absolute;
  inset: 0;
  display: flex;
  pointer-events: none;
}
.track-ticks i {
  flex: 1;
  border-right: 1px dashed var(--line-strong);
  opacity: 0.55;
}
.track-ticks i:last-child { border-right: 0; }

.ladder.surge .track-fill { animation: surge 620ms var(--ease); }
@keyframes surge {
  0%   { filter: brightness(1); }
  35%  { filter: brightness(1.35); }
  100% { filter: brightness(1); }
}

/* ---- Solved groups ----------------------------------------------------- */

.solved-list { display: grid; gap: var(--gap); margin-bottom: var(--gap); }

.solved {
  border-radius: var(--radius);
  padding: 12px 14px;
  text-align: center;
  color: #14161a;
  animation: land 420ms var(--ease);
}
.solved[data-tier='yellow'] { background: var(--yellow-fill); }
.solved[data-tier='green']  { background: var(--green-fill); }
.solved[data-tier='blue']   { background: var(--blue-fill); }
.solved[data-tier='purple'] { background: var(--purple-fill); }

.solved-name {
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.solved-words {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
  opacity: 0.82;
  margin-top: 2px;
}
.solved-flag {
  display: inline-block;
  margin-left: 6px;
  font-size: 11px;
  font-weight: 700;
  opacity: 0.7;
}

@keyframes land {
  from { transform: scale(0.97); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}

/* ---- Board ------------------------------------------------------------- */

/* Offscreen ruler for tile text, so app.js can read a word's width in em.
   Measured at 9px, the same value as the font floor below, because a word's
   width in em is not constant across sizes — glyph advances grid-fit to whole
   pixels, making text ~10% relatively wider at 9px than at 100px. Measuring at
   the floor yields the widest em a word can have, so the fit errs small rather
   than wrapping. Weight 800 is the heaviest a tile renders (painted), so a fit
   survives a paint. Keep these declarations in step with .tile below — that is
   what makes the measurement match the tile instead of approximating it. */
.text-probe {
  position: absolute;
  left: -9999px;
  top: 0;
  visibility: hidden;
  white-space: pre;
  pointer-events: none;
  font-family: inherit;
  font-weight: 800;
  font-size: 9px; /* EM_PROBE in app.js, and the floor below — keep all three in step */
  letter-spacing: -0.01em;
  text-transform: uppercase;
}

.board {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--gap);
  margin-bottom: 18px;
  /* Makes 100cqw inside a tile mean "the board's width", which is what lets
     the tile text size itself without script measuring anything. */
  container-type: inline-size;
}

.tile {
  position: relative;
  aspect-ratio: 1 / 0.82;
  min-height: 62px;
  border: 2px solid transparent;
  border-radius: var(--radius);
  background: var(--tile);
  color: var(--ink);
  /* A long word shrinks to fit rather than breaking across two lines.
     --em is the word's real rendered width in em, measured in app.js; --avail
     is how much room a tile has for it, derived from the board's own inline
     size so it stays right at every width with no media query and no layout
     read from script. A font size of --avail / --em is exactly the size at
     which the word spans the tile, and min() keeps short words from being
     scaled UP to fill it. The floor stops a pathological entry from going
     unreadable; overflow-wrap below is the last resort past that. */
  /* 10px is the tile's own chrome (2px border + 3px padding, both sides); the
     extra 2px is slack, because sizing a word to exactly its container's width
     leaves sub-pixel rounding to decide whether it wraps. */
  --avail: calc((100cqw - 3 * var(--gap)) / 4 - 12px);
  --tile-font: clamp(11px, 3.2vw, 15px);
  font-weight: 700;
  font-size: max(9px, min(var(--tile-font), calc(var(--avail) / var(--em, 1))));
  line-height: 1.15; font-family: inherit;
  letter-spacing: -0.01em;
  text-transform: uppercase;
  cursor: pointer;
  padding: 4px 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  overflow-wrap: anywhere;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 140ms var(--ease), border-color 140ms var(--ease),
    transform 320ms cubic-bezier(0.34, 1.56, 0.64, 1);
}
@media (hover: hover) and (pointer: fine) {
  .tile:hover { background: var(--tile-hover); }
}
.tile:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }
/* Press: quick ease-in to a real squish. Release inherits the springier
   transition above, so it pops back with a little overshoot. */
.tile:active {
  transform: scale(0.9);
  transition: transform 90ms cubic-bezier(0.4, 0, 0.6, 1);
}

/* Painted = conviction. A ring and a wash, never the full fill — the
   saturated fill is reserved for groups that are actually won. */
.tile[data-paint] { font-weight: 800; }
.tile[data-paint='0'] { border-color: var(--yellow); background: var(--yellow-wash); }
.tile[data-paint='1'] { border-color: var(--green);  background: var(--green-wash); }
.tile[data-paint='2'] { border-color: var(--blue);   background: var(--blue-wash); }
.tile[data-paint='3'] { border-color: var(--purple); background: var(--purple-wash); }

.tile[aria-pressed='true'] {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--ground);
}

.tile.shake { animation: shake 380ms var(--ease); }
@keyframes shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(3px); }
  30%, 50%, 70% { transform: translateX(-5px); }
  40%, 60% { transform: translateX(5px); }
}

/* ---- Mistake dots ------------------------------------------------------
   Also the stake meter. A dot arms when the pending submission puts it at
   risk, so the size of the bet is shown by what it could cost — never by a
   projected score. The final group arms nothing, because nothing is at risk.
   ------------------------------------------------------------------------ */

.dots-row {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
  min-height: 26px;
}
.dots { display: flex; gap: 9px; }

.dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--ink-soft);
  border: 2px solid transparent;
  transition: background-color var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.dot[data-state='spent'] { background: transparent; border-color: var(--line-strong); }
.dot[data-state='armed'] {
  background: var(--danger);
  animation: arm 900ms ease-in-out infinite;
}
@keyframes arm {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.28); }
}

/* ---- Controls ---------------------------------------------------------- */

.controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 18px;
}

/* The submit button gets hot as the stake grows. No number — heat. */
.btn-submit[data-stake='2'] { box-shadow: 0 0 0 3px color-mix(in oklab, var(--danger) 22%, transparent); }
.btn-submit[data-stake='3'] { box-shadow: 0 0 0 5px color-mix(in oklab, var(--danger) 32%, transparent); }
.btn-submit[data-stake='4'] {
  box-shadow: 0 0 0 7px color-mix(in oklab, var(--danger) 42%, transparent);
  animation: charged 1.1s ease-in-out infinite;
}
@keyframes charged {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.035); }
}

/* ---- Palette ----------------------------------------------------------- */

.palette {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 7px;
  border-radius: 99px;
  background: var(--surface);
  border: 1.5px solid var(--line);
  width: fit-content;
  margin: 0 auto 8px;
}

.swatch {
  position: relative;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 3px solid transparent;
  background: transparent;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: transform 140ms var(--ease), border-color 140ms var(--ease);
}
.swatch i {
  display: block;
  width: 27px;
  height: 27px;
  border-radius: 50%;
  transition: transform 140ms var(--ease);
}
.swatch[data-tier='0'] i { background: var(--yellow-fill); }
.swatch[data-tier='1'] i { background: var(--green-fill); }
.swatch[data-tier='2'] i { background: var(--blue-fill); }
.swatch[data-tier='3'] i { background: var(--purple-fill); }

.swatch[aria-checked='true'] { border-color: var(--ink); }
.swatch[aria-checked='true'] i { transform: scale(1.16); }
.swatch:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }
.swatch:disabled { cursor: default; }
.swatch:disabled i { transform: scale(0.72); opacity: 0.35; }

/* A solved colour is spent. The check says "done" rather than leaving a
   faded circle that just reads as broken. */
.swatch-check {
  position: absolute;
  width: 20px;
  height: 20px;
  color: var(--ink);
  pointer-events: none;
}

.swatch-count {
  position: absolute;
  bottom: -1px;
  right: -1px;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border-radius: 99px;
  background: var(--ink);
  color: var(--ground);
  font-weight: 700; font-size: 10px; line-height: 17px; font-family: inherit;
  text-align: center;
}
.swatch-count[data-state='complete'] { background: var(--green); }
.swatch-count[data-state='over'] { background: var(--danger); }

/* ---- Flash message ----------------------------------------------------- */

.flash {
  min-height: 22px;
  text-align: center;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.01em;
  color: var(--ink-soft);
  margin-bottom: 10px;
}
.flash[data-kind='missed'] { color: var(--danger); }
.flash[data-kind='landed'] { color: var(--green-ink); }
.flash[data-kind='repeat'] { color: var(--ink-faint); }

/* ---- Footer bar -------------------------------------------------------- */

.mode-switch {
  display: inline-flex;
  padding: 3px;
  border-radius: 99px;
  background: var(--tile);
  border: 1px solid var(--line);
}
.mode-switch button {
  min-height: 34px;
  padding: 0 13px;
  border: 0;
  border-radius: 99px;
  background: transparent;
  color: var(--ink-soft);
  font-weight: 650; font-size: 12.5px; line-height: 1; font-family: inherit;
  cursor: pointer;
}
.mode-switch button[aria-pressed='true'] {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
}
.mode-switch button:focus-visible { outline: 2px solid var(--ink); outline-offset: 1px; }

/* ---- Result ------------------------------------------------------------ */

.result {
  margin-top: 18px;
  padding: 18px;
  border-radius: var(--radius-lg);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  text-align: center;
  animation: land 420ms var(--ease);
}
.result-rank {
  font-size: 30px;
  font-weight: 820;
  letter-spacing: -0.03em;
  line-height: 1.1;
}
.result-rank[data-tier='yellow'] { color: var(--yellow-ink); }
.result-rank[data-tier='green']  { color: var(--green-ink); }
.result-rank[data-tier='blue']   { color: var(--blue-ink); }
.result-rank[data-tier='purple'] { color: var(--purple-ink); }
.result-sub { font-size: 13.5px; color: var(--ink-soft); margin-top: 4px; }
.result-grid {
  font-size: 21px;
  line-height: 1.22;
  letter-spacing: 2px;
  margin: 14px 0 4px;
}
.result-actions { display: flex; gap: 8px; justify-content: center; margin-top: 14px; flex-wrap: wrap; }

.crown {
  display: inline-block;
  margin-top: 8px;
  padding: 4px 11px;
  border-radius: 99px;
  background: var(--purple-fill);
  color: #14161a;
  font-weight: 800; font-size: 11px; line-height: 1.6; font-family: inherit;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

/* ---- Caps ---------------------------------------------------------------
   Every string that belongs to the PUZZLE — its title, its group names, its
   words — renders upper case, in the builder and on the board alike. It used
   to be uppercase in some places and as-typed in others, so a puzzle written
   in Title Case shouted in the word grid and then whispered its own words
   back in the solved list (Aaron, 2026-09-19: "both pages should force
   all-caps for all text").

   This is a DISPLAY rule, not a storage one: the stored document keeps what
   the author typed, matching stays case-insensitive through `compareKey` in
   puzzle.js, and every puzzle already saved is fixed by the same stylesheet.
   The one string left alone is the author's own name in the byline — that
   names a person rather than the puzzle, and caps there reads as shouting it.
   Placeholders are exempt everywhere: they are the app talking, not content.
   ------------------------------------------------------------------------ */
.puzzle-title,
.solved-name,
.solved-words,
.tile,
#f-title,
.group-head input,
.word-grid input,
.builder-paste,
#my-puzzles .puzzle-row a { text-transform: uppercase; }

.puzzle-byline,
#f-title::placeholder,
.group-head input::placeholder,
.word-grid input::placeholder,
.builder-paste::placeholder { text-transform: none; }

/* ---- Builder ----------------------------------------------------------- */

.builder-intro { margin-bottom: 20px; }
.builder-intro h1 {
  font-size: 25px;
  font-weight: 820;
  letter-spacing: -0.03em;
  margin: 0 0 4px;
}
.builder-intro p { margin: 0; color: var(--ink-soft); font-size: 14.5px; }

.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-bottom: 5px;
}

input[type='text'], textarea {
  width: 100%;
  padding: 11px 13px;
  border-radius: var(--radius);
  border: 1.5px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-weight: 500; font-size: 16px; line-height: 1.4; font-family: inherit;
  transition: border-color 140ms var(--ease);
}
input[type='text']:focus, textarea:focus {
  outline: none;
  border-color: var(--ink);
}
input::placeholder, textarea::placeholder { color: var(--ink-faint); }
/* 16px, not 14: iOS Safari force-zooms a focused field whose font is smaller,
   and the zoom is what drags the page around when you tap a box (Aaron,
   2026-09-19). The floor applies to every focusable field on both pages. */
textarea { resize: vertical; min-height: 92px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 16px; }

.group-card {
  border-radius: var(--radius);
  border: 1.5px solid var(--line);
  border-left-width: 6px;
  background: var(--surface);
  padding: 13px;
  margin-bottom: 10px;
}
.group-card[data-tier='0'] { border-left-color: var(--yellow); }
.group-card[data-tier='1'] { border-left-color: var(--green); }
.group-card[data-tier='2'] { border-left-color: var(--blue); }
.group-card[data-tier='3'] { border-left-color: var(--purple); }

.group-head {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 9px;
}
.group-rank {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--ink-faint);
  white-space: nowrap;
}
.group-head input { flex: 1; }

.word-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 7px; }
@media (min-width: 460px) { .word-grid { grid-template-columns: repeat(4, 1fr); } }

.word-grid input { padding: 9px 10px; font-size: 16px; }

.problems { margin: 14px 0; padding: 0; list-style: none; }
.problems li {
  font-size: 13px;
  padding: 7px 11px;
  border-radius: 8px;
  margin-bottom: 5px;
  background: color-mix(in oklab, var(--danger) 10%, var(--surface));
  color: var(--danger);
  font-weight: 600;
}
.problems li[data-kind='warning'] {
  background: color-mix(in oklab, var(--yellow) 16%, var(--surface));
  color: var(--ink);
}

.saved-link {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 12px;
  padding: 11px 13px;
  border-radius: var(--radius);
  background: var(--green-wash);
  border: 1.5px solid var(--green);
}
.saved-link code {
  flex: 1;
  font: 500 12.5px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
  overflow-wrap: anywhere;
}

@media (prefers-reduced-motion: reduce) {
  /* The generic damping lives in ../shared/taskcat.css. These two keep the
     game's state changes legible once nothing moves: armed dots switch to a
     ring instead of a pulse; the charged submit button keeps its glow but
     stops breathing. */
  .dot[data-state='armed'] { outline: 2px solid var(--danger); outline-offset: 2px; }
  .btn-submit[data-stake='4'] { box-shadow: 0 0 0 7px color-mix(in oklab, var(--danger) 55%, transparent); }
}
