:root {
  --directional-text: 0.9rem;
  --answer-icon-size: 1.125rem;
  --icon-button-padding: 7px;
  --bg: oklch(.918 .035 62);
  --card: oklch(.965 .018 64);
  --tile: oklch(.992 .006 75);
  --ink: oklch(.31 .026 50);
  --muted: oklch(.745 .022 55);
  --accent: oklch(.575 .135 44);
  --accent-ink: oklch(.992 .012 75);
  --line: oklch(.85 .022 60);
  --label: oklch(.47 .028 50);
  --hairline: var(--line);
  /* Shared font convention: serif for game content, sans for anything
     directional (instructions, controls, etc). */
  --font-serif: "Roboto Serif", "Iowan Old Style", "Palatino Linotype", Palatino, Cambria, Georgia, serif;
  --font-sans: "Roboto", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body { overscroll-behavior-y: none; }

body {
  font-family: var(--font-sans);
  background: var(--bg);
}

/* Mirrors the prototype's outer wrapper: a min-height (not a forced height)
   so a short puzzle's background fills the screen without ever creating
   scrollable overflow — only a puzzle whose content is genuinely taller than
   the viewport scrolls, which is expected, not a bug.
   100vh resolves against the browser's LARGEST possible viewport (toolbar
   collapsed), not the shorter one actually visible while it's showing — that
   gap is exactly enough extra height to scroll the toolbar away even when the
   content itself fits. dvh tracks the real visible viewport; 100vh above is
   just the fallback for browsers that don't support dvh.
   flex-direction: column (not row) so BackToPortalBar can stack above
   .threads-board/.app--message as a sibling; align-items: center replaces
   the old justify-content: center to keep the same horizontal centering now
   that centering happens on the cross axis instead of the main axis. */
#root {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* Thin back-link to the portal landing page. See
   back-link-to-portal-design-spec.md for the full rationale. Rendered as a
   sibling of .threads-board/.app--message, above it, so it spans the full
   viewport width unconstrained by their own max-width/padding. */
.back-to-portal-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  width: 100%;
  padding: 6px 0;
  background: var(--tile);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 0.85rem;
  text-decoration: none;
  border-bottom: 1px solid var(--hairline);
}

.back-to-portal-bar:focus { outline: none; }
.back-to-portal-bar:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--tile), 0 0 0 4px var(--ink);
}

.app--message {
  max-width: 24rem;
  margin: 0 auto;
  padding: 1.5rem 1rem 3rem;
  font-family: var(--font-sans);
  color: var(--label);
  text-align: center;
}

.threads-board {
  width: 100%;
  max-width: 24rem;
  /* Bottom padding trimmed from the design's 3rem — that much was leaving
     puzzles with a long word (which need the shrink lever) taller than the
     visible viewport on phones whose browser chrome is showing. */
  padding: 16px 1rem 1.5rem;
}

.threads-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.wordmark {
  font-family: var(--font-serif);
  font-size: 1.1rem;
  font-weight: 400;
  letter-spacing: -0.01em;
  color: var(--ink);
}

.wordmark-btn {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  color: inherit;
  letter-spacing: inherit;
  cursor: default;
}
.wordmark-btn:not(:disabled) {
  cursor: pointer;
}
.wordmark-btn:focus { outline: none; }
.wordmark-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--ink);
  border-radius: 2px;
}

.wordmark-tm {
  font-size: 0.45em;
  vertical-align: super;
  margin-left: 0.05em;
  font-weight: 400;
  letter-spacing: 0;
}

/* Instructions trigger — circled bold "i" */
.instructions-trigger {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid var(--ink);
  background: transparent;
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease;
}
.instructions-trigger:hover {
  border-color: oklch(.15 .018 50);
  color: oklch(.15 .018 50);
}
.instructions-trigger:focus { outline: none; }
.instructions-trigger:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--ink);
}

.eyebrow {
  font-family: var(--font-sans);
  font-size: .6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .16em;
  color: var(--accent);
  text-align: center;
  margin-bottom: .25rem;
}

.step1__instruction {
  font-family: var(--font-sans);
  font-size: var(--directional-text);
  color: var(--label);
  text-align: center;
  margin-bottom: 1.125rem;
}

.step1__footer {
  text-align: center;
  min-height: 1.25rem;
  margin-top: .75rem;
  font-family: var(--font-sans);
  font-size: .9375rem;
  font-weight: 700;
  color: var(--accent);
}

/* Word card */
.word-card {
  background: var(--card);
  border-radius: 1rem;
  padding: 9.4px .875rem 11px;
  margin-bottom: .5rem;
  transition: background 0.35s ease;
}

.word-card--solved { background: oklch(.940 .020 62); }
.word-card--shaking { animation: shake 0.4s ease; }
.word-card--solved .word-card__source { opacity: 0.52; }

/* Step 1 chrome fade — when .step1--leaving, everything disappears except the
   solution tiles so they can linger before the flying-overlay takes over. */
.step1--leaving .word-card { background: transparent; }

.word-card__source { transition: opacity 0.3s ease; }
.step1--leaving .word-card__source { opacity: 0; }

.word-card__answer-label { transition: opacity 0.2s ease; }
.step1--leaving .word-card__answer-label { opacity: 0; }

.step1__instruction,
.step1__footer { transition: opacity 0.25s ease; }
.step1--leaving .step1__instruction,
.step1--leaving .step1__footer { opacity: 0; }

.word-card__source {
  position: relative;
  display: flex;
  gap: .25rem;
  justify-content: center;
  margin: 0 auto;
  /* Allow vertical page scroll to still start on this row; horizontal
     movement is claimed by the drag-select gesture instead of native panning. */
  touch-action: pan-y;
}

/* Grid (not flex) so the solution tiles center on the card regardless of the
   label's width — the label and the trailing spacer form two equal columns
   that balance around the centered middle column. */
.word-card__answer {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: .625rem;
  margin-top: .5rem;
}

.word-card__answer-label {
  font-family: var(--font-sans);
  font-size: .875rem;
  color: var(--label);
  white-space: nowrap;
  justify-self: end;
}

.word-card__solution {
  display: inline-flex;
  gap: .3125rem;
  justify-self: center;
}

/* Letter tiles — source (clickable) */
.source-tile {
  width: 1.95rem;
  height: 2.4rem;
  border-radius: 0;
  font-family: var(--font-serif);
  font-size: 1.35rem;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  z-index: 1;
  border: 0;
  transition: all .14s ease;
  user-select: none;
}
/* Invisible hit-slop: extends the tappable area into half the gap on each
   side, without changing the painted tile size — fixes "fat finger"
   mis-taps between adjacent letters on touch devices. */
.source-tile::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: calc(-1 * var(--hit-slop, 0px));
  right: calc(-1 * var(--hit-slop, 0px));
}
.source-tile[data-state="available"] {
  background: var(--tile);
  color: var(--ink);
  cursor: pointer;
}
.source-tile[data-state="available"]:active {
  background: rgba(0, 0, 0, 0.5);
  color: var(--accent-ink);
}
.source-tile[data-state="selected"] {
  background: var(--accent);
  color: var(--accent-ink);
  cursor: pointer;
}
.source-tile:disabled {
  cursor: default;
}
.source-tile[data-state="skipped"] {
  background: transparent;
  color: var(--muted);
  cursor: default;
}

/* Solution tiles — read-only, smaller than source tiles */
.solution-tile {
  width: 1.375rem;
  height: 1.6875rem;
  border-radius: 0;
  font-family: var(--font-serif);
  font-size: .9375rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .3s ease, color .3s ease;
}
.solution-tile[data-state="empty"] {
  border: 1.5px solid var(--line);
}
.solution-tile[data-state="filled"] {
  background: var(--tile);
  color: var(--ink);
}
.solution-tile[data-state="success"] {
  background: var(--accent);
  color: var(--accent-ink);
}
.solution-tile[data-state="solved"] {
  background: var(--tile);
  color: var(--ink);
}

/* Weave SVG */
.weave {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  width: 100%;
  height: 2rem;
  overflow: visible;
}
.weave--down {
  height: 100%;
}
.weave__line {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: .85;
}
.weave--down .weave__line {
  opacity: .7;
}
.weave__dot {
  fill: var(--accent);
}

/* Step 2 */
.step2__instruction {
  font-family: var(--font-sans);
  font-size: var(--directional-text);
  line-height: 1.4;
  color: var(--label);
  text-align: center;
  margin-bottom: 1.5625rem;
}
.step2__clue-text,
.step2__clue {
  font-family: var(--font-serif);
  font-size: 1.25rem;
}
.step2__clue-text {
  color: var(--ink);
}
.step2__clue {
  color: var(--accent);
  font-weight: 600;
}

.step2__answer-area {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: .625rem;
  margin-bottom: 1.5rem;
}

.step2__answer {
  display: flex;
  gap: .4375rem;
}

.answer-tile {
  width: 1.875rem;
  height: 2.25rem;
  border-radius: 0;
  font-family: var(--font-serif);
  font-size: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
}
.answer-tile[data-state="empty"] {
  border: 1.5px solid var(--line);
}
.answer-tile[data-state="filled"] {
  background: var(--accent);
  color: var(--accent-ink);
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  18%       { transform: translateX(-7px); }
  36%       { transform: translateX(7px); }
  54%       { transform: translateX(-4px); }
  72%       { transform: translateX(4px); }
}

.step2__threads {
  margin: 0 auto;
  /* The swipe-to-select gesture is itself vertical (row to row), unlike Step
     1's horizontal drag, so it can't coexist with native vertical scroll the
     way pan-y does there — claim the gesture outright. */
  touch-action: none;
}

.step2__threads--shaking {
  animation: shake 0.4s ease;
}

.step2__threads--fading {
  opacity: 0;
  transition: opacity 0.4s ease;
  pointer-events: none;
}

@keyframes answer-celebrate {
  0%   { transform: scale(1);   animation-timing-function: cubic-bezier(0.34, 1.56, 0.64, 1); }
  50%  { transform: scale(1.6); animation-timing-function: ease-out; }
  100% { transform: scale(1); }
}

.step2__answer--celebrating {
  animation: answer-celebrate 1.1s;
}

.step2__solved-area {
  margin-top: 1.875rem;
  margin-bottom: 2.5rem;
  text-align: center;
}

.step2__solved {
  font-family: var(--font-sans);
  font-size: 1rem;
  font-weight: 500;
  color: var(--ink);
}

.step2__hint-tally {
  font-family: var(--font-sans);
  font-size: .875rem;
  color: var(--label);
  margin-top: .375rem;
}

.step2__share {
  display: flex;
  justify-content: center;
  margin-top: 2rem;
}

.share-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 18px;
  font-family: var(--font-sans);
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--accent);
  background: none;
  border: 1.5px solid var(--accent);
  border-radius: 999px;
  cursor: pointer;
  opacity: 0.85;
  transition: opacity 0.15s;
}
@media (hover: hover) {
  .share-button:hover { opacity: 1; }
}
.share-button:focus { outline: none; }
.share-button:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 3px;
}

.share-modal-text {
  display: block;
  width: 240px;
  max-width: 100%;
  padding: 8px 10px;
  font-family: var(--font-sans);
  font-size: 0.85rem;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
}

.step2__cross-promo {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.step2__cross-promo-caption {
  width: 100%;
  margin-top: 36px;
  font-family: var(--font-sans);
  font-size: 0.875rem;
  color: var(--label);
  text-align: center;
}

/* Each link is only as wide as it needs to be, not the row's full width — so
   a short tagline wraps within that narrower box and stays centered under
   its icon. One link's width matches its icon's width exactly, so it sits
   flush with the row's outer edge; the other link is wider than its icon
   (see its own comment below), so it sits a bit inset from the edge.
   `justify-content: space-between` anchors both to the row's outer edges
   rather than centering them within the full row width. */
.step2__cross-promo-row {
  width: 100%;
  display: flex;
  justify-content: space-between;
  margin-top: 12px;
}

.step2__cross-promo-link {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-align: center;
  text-decoration: none;
}
.step2__cross-promo-link:focus { outline: none; }
.step2__cross-promo-link:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 3px;
  border-radius: 2px;
}

/* One wordmark is a single row of tiles; the other is a staircase of the
   same tile unit across three rows. Sizing both icons to the same height
   would make the single-row icon's tiles dwarf the staircase icon's, so
   instead each is sized so the staircase icon's middle "U N G" row of tiles
   (278/908 of its image height) renders at the same height as the
   single-row icon's tile row (277/317 of its image height) — chosen at a
   32px height for the single-row icon, which is why the staircase icon ends
   up taller overall (91px) despite matching tile size.
   The single-row icon has no such middle row — its one row of tiles sits
   near the very top of its image (starting ~2px in) — so top-aligning both
   links (the row's default behavior) leaves the single-row icon's tiles
   level with the staircase icon's *top* tile, not its "U N G" row. Nudging
   the single-row link down by the "U N G" row's own offset (~31px, minus
   the single-row icon's ~2px of built-in top padding) brings the two tile
   rows level. */
.step2__cross-promo-link--forage { width: 108px; margin-top: 29px; }
/* 140px (not the 71px icon width) so "Find the 5 words that form a ladder"
   wraps across ~2 lines instead of 4 — the icon, narrower than this box,
   centers within it via .step2__cross-promo-link's align-items: center, same
   as the tagline below it. The pair sits a bit inset from the row's right
   edge as a result, but reads as one centered unit instead of the icon
   hugging the edge while the wider tagline sits off-center under it. */
.step2__cross-promo-link--rungs { width: 140px; }

.step2__cross-promo-icon {
  display: block;
}
.step2__cross-promo-icon--forage { width: 108px; height: 32px; }
.step2__cross-promo-icon--rungs { width: 71px; height: 91px; }

.step2__cross-promo-tagline {
  width: 100%;
  margin: 0;
  text-align: center;
  font-family: var(--font-sans);
  font-size: 0.9rem;
  color: var(--label);
}

@keyframes toast-fadein {
  from { opacity: 0; transform: translateX(-50%) translateY(-10px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.toast {
  position: fixed;
  top: 1.25rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  background: var(--ink);
  color: var(--accent-ink);
  padding: 0.625rem 1.25rem;
  border-radius: 0.5rem;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.2);
  font-family: var(--font-sans);
  font-size: 0.9rem;
  font-weight: 600;
  white-space: nowrap;
  pointer-events: none;
  opacity: 1;
  animation: toast-fadein 0.3s ease-out;
  transition: opacity 0.5s ease;
}

.toast--leaving {
  opacity: 0;
  pointer-events: none;
}

.step2__row {
  height: 2.75rem;
  margin-bottom: .625rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .375rem;
  position: relative;
  z-index: 1;
}

.meta-tile {
  width: 1.875rem;
  height: 2.125rem;
  border-radius: 0;
  font-family: var(--font-serif);
  font-size: 1.125rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0;
  user-select: none;
  position: relative;
}
/* Invisible hit-slop: extends the tappable area into half the gap on each
   side, without changing the painted tile size — fixes "fat finger"
   mis-taps between adjacent letters on touch devices. */
.meta-tile::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: calc(-1 * var(--hit-slop, 0px));
  right: calc(-1 * var(--hit-slop, 0px));
}
.meta-tile[data-state="available"] {
  background: var(--tile);
  color: var(--ink);
  cursor: pointer;
}
.meta-tile[data-state="selected"] {
  background: var(--accent);
  color: var(--accent-ink);
  cursor: pointer;
  animation: tile-select .14s ease;
}

@keyframes tile-select {
  from {
    background: var(--tile);
    color: var(--ink);
  }
}

/* Instructions modal */
@keyframes modal-backdrop-in {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes modal-panel-in {
  from { opacity: 0; transform: scale(0.9); }
  to { opacity: 1; transform: scale(1); }
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.5);
  animation: modal-backdrop-in 0.15s ease-out;
}

.modal-panel {
  position: relative;
  background: #fff;
  border-radius: 0.75rem;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
  max-width: 24rem;
  width: 100%;
  margin: 0 1rem;
  padding: 1.5rem;
  font-family: var(--font-sans);
  font-size: var(--directional-text);
  animation: modal-panel-in 0.15s ease-out;
}

/* Confirm modals (restart) */
.expand-row-modal {
  max-width: 18rem;
}

.expand-row-message {
  font-family: var(--font-sans);
  font-size: 0.95rem;
  color: #374151;
  line-height: 1.55;
  margin-bottom: 1.25rem;
  text-align: center;
}

.expand-row-buttons {
  display: flex;
  gap: 0.625rem;
  justify-content: center;
}

.expand-row-btn {
  padding: 0.45rem 1.1rem;
  border-radius: 6px;
  font-family: var(--font-sans);
  font-size: var(--directional-text);
  font-weight: 400;
  cursor: pointer;
  border: 2px solid var(--ink);
  background: transparent;
  color: var(--ink);
  transition: background 0.15s;
}

@media (hover: hover) {
  .expand-row-btn:hover {
    background: rgba(26, 26, 26, 0.08);
  }
}

.instructions-close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  background: transparent;
  border: 0;
  padding: 0;
  color: #6b7280;
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  transition: color 0.15s ease;
}
.instructions-close:hover {
  color: #374151;
}

.instructions-title {
  font-size: 1.125rem;
  font-weight: 600;
  color: #111827;
  margin-bottom: 0.75rem;
}

.instructions-tm {
  font-weight: 400;
}

.instructions-body {
  font-size: var(--directional-text);
  color: #374151;
  line-height: 1.625;
}
.instructions-body p + p {
  margin-top: 0.75rem;
}
.instructions-body .word-card {
  margin-top: 0.75rem;
}

.instructions-footer {
  margin-top: 1rem;
  font-size: 0.75rem;
  color: #6b7280;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.instructions-feedback {
  color: #2563eb;
  text-decoration: underline;
}
.instructions-feedback:hover {
  color: #1e40af;
}

/* Flying tile overlay — solution-tile groups that travel from Step 1 positions
   to Step 2 row positions during the stage transition. */
.flying-tile-group {
  display: inline-flex;
  gap: 0.3125rem;
  transition: transform 450ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* Hint button */
.icon-button {
  background: none;
  border: none;
  cursor: pointer;
  padding: var(--icon-button-padding);
  width: calc(var(--answer-icon-size) + 2 * var(--icon-button-padding));
  height: calc(var(--answer-icon-size) + 2 * var(--icon-button-padding));
  box-sizing: border-box;
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.55;
  transition: opacity 0.15s;
  -webkit-tap-highlight-color: transparent;
}

@media (hover: hover) {
  .icon-button:hover { opacity: 1; }
}

.answer-actions {
  display: flex;
  align-items: center;
  gap: .5rem;
  justify-self: start;
}

.hint-glyph {
  font-family: var(--font-sans);
  font-size: var(--answer-icon-size);
  font-weight: 700;
}

.clear-button svg {
  width: var(--answer-icon-size);
  height: var(--answer-icon-size);
}

.clear-button--placeholder,
.hint-button--placeholder {
  visibility: hidden;
}

/* Hint modal */
.info-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}

.info-modal {
  background: var(--tile);
  padding: 32px 32px 24px;
  border-radius: 8px;
  width: fit-content;
  position: relative;
  font-family: var(--font-sans);
  font-size: var(--directional-text);
  color: var(--ink);
}

.info-modal-close {
  position: absolute;
  top: 6px;
  right: 6px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  color: var(--ink);
  opacity: 0.6;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}

@media (hover: hover) {
  .info-modal-close:hover { opacity: 1; }
}

.hint-content {
  text-align: center;
}
