/* Kern By Eye — v3.3
 *
 * v3.1 deltas vs v3 (Critic's HOLD @ 19/30):
 *   - STRUCTURAL FIX: master-ghost layer during drag.
 *       .ghost-glyph     → faint pre-rendered letters at the master positions
 *       .word.ghosts-visible .ghost-glyph → fade to ~14% ink while dragging
 *       .ghost-glyph.faded → hard fade to 0 on kiss-into-alignment
 *   - N1: gap-pulse on EVERY lock (reuses .gap-pulse from v3).
 *   - N2: lock-button scale-bounce (.primary.bounce, 160ms).
 *   - N3: standard-lock chord (audio-only; no CSS).
 *
 * v3 deltas vs v2 (Mei's direction):
 *   - Reveal section becomes a CARD, not a dual-stage page (CUT).
 *   - Next button demoted from chunky CTA to thin margin caret.
 *   - New polish primitives for the clean-read lock-release:
 *       .hit-stop  → freeze the stage for 120ms (L1)
 *       .kissing   → CSS transition on `left` to glide to master (L2)
 *       .gap-pulse → thin warm-black underline that fades (L3)
 *       .clean-stamp → caret-italic stamp drop in the margin (L4)
 *       #round-num.pop → 1-frame scale pop on advance (L7)
 *       .card-word-score.flip-clean → ◆ flip on clean-read cells (L6)
 *       .specimen-cell → typographic chrome on the share row (#3)
 *   - prefers-reduced-motion: reduce collapses L1-L3 to crossfade.
 *
 * Aesthetic carries v2: off-white #FAFAF7, one-typeface-per-word,
 * 1px italic buttons, baseline as the only guide.
 */

:root {
  --bg: #FAFAF7;
  --ink: #15130E;
  --muted: #6B675E;
  --line: #15130E;
  --line-faint: rgba(21, 19, 14, 0.18);
  --accent: #8A3B12;
  /* v3 — warm-black for the gap-pulse, slightly warmer than ink so the
     fading underline reads as ink-on-the-page, not as a UI dash. */
  --pulse: rgba(21, 19, 14, 0.78);

  --face-georgia: Georgia, 'Iowan Old Style', Charter, 'Times New Roman', serif;
  --face-garamond: 'EB Garamond', 'Apple Garamond', 'Garamond', 'Cormorant Garamond', Georgia, serif;
  --face-plex: 'IBM Plex Serif', 'Source Serif Pro', 'Charter', Georgia, serif;

  --serif: var(--face-georgia);
  --sans: var(--font-sans, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Inter', 'Helvetica Neue', sans-serif);
  --mono: var(--font-mono, ui-monospace, 'SF Mono', Menlo, monospace);
  --radius: var(--radius-sm, 4px);
  --game-focus: var(--border-focus, var(--accent));
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14130F;
    --ink: #F4F0E7;
    --muted: #908A7E;
    --line: #F4F0E7;
    --line-faint: rgba(244, 240, 231, 0.20);
    --accent: #DD9C5A;
    --pulse: rgba(244, 240, 231, 0.82);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 17px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: geometricPrecision;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

header {
  text-align: center;
  padding: 2.5rem 1rem 0.75rem;
}

.puzzle-no {
  font-family: var(--serif);
  font-size: 0.92rem;
  margin: 0;
  letter-spacing: 0.04em;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.puzzle-no .sep { padding: 0 0.1em; }

main {
  flex: 1;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 2rem 1.25rem 3rem;
}

footer {
  text-align: center;
  padding: 1.5rem 1rem 2rem;
  font-size: 0.78rem;
  color: var(--muted);
  font-family: var(--serif);
  font-style: italic;
}

.screen { display: none; }
.screen.active { display: block; animation: fade-in 0.35s ease; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.rules {
  font-size: 1.15rem;
  line-height: 1.7;
  text-align: center;
  margin: 4rem 0 2.5rem;
  color: var(--ink);
  font-family: var(--serif);
}

.meta {
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  margin-top: 2.25rem;
  font-style: italic;
  font-family: var(--serif);
}

.primary {
  display: block;
  margin: 1.75rem auto 0;
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 0;
  padding: 0.7rem 2.5rem;
  font-family: var(--serif);
  font-size: 0.98rem;
  font-style: italic;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  letter-spacing: 0.01em;
}
.primary:hover { background: var(--ink); color: var(--bg); }
.primary:disabled,
.primary.pre-drag {
  color: var(--muted);
  border-color: var(--line-faint);
  cursor: default;
  opacity: 0.72;
}
.primary:disabled:hover,
.primary.pre-drag:hover {
  background: transparent;
  color: var(--muted);
}
.primary:active { transform: translateY(1px); }
.primary:focus-visible { outline: 1px solid var(--game-focus); outline-offset: 3px; }

/* v3.1 — N2: lock-button scale-bounce on commit. Fires on every lock
   (clean OR standard). Reads as the verb being committed — the button is
   answering the press, not just consuming it. Animation re-triggers via
   class toggle in JS (`bounceLockButton()`). */
.primary.bounce {
  animation: primary-bounce 180ms cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes primary-bounce {
  0%   { transform: scale(1.00); }
  45%  { transform: scale(0.965); }
  100% { transform: scale(1.00); }
}
@media (prefers-reduced-motion: reduce) {
  .primary.bounce { animation: none; }
}

.round-header {
  text-align: center;
  margin-bottom: 1.75rem;
}

.round-counter {
  font-family: var(--serif);
  font-style: italic;
  font-size: 0.95rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.round-counter .dot,
.round-counter #rv-score { font-style: normal; }

.round-face { font-style: italic; }

/* L7 — round-counter 1-frame scale pop on advance. */
#round-num.pop {
  display: inline-block;
  animation: rc-pop 240ms ease-out;
}
@keyframes rc-pop {
  0%   { transform: scale(1); }
  35%  { transform: scale(1.22); color: var(--ink); }
  100% { transform: scale(1); }
}
@media (prefers-reduced-motion: reduce) {
  #round-num.pop { animation: none; }
}

/* ---------- stage ---------- */

.stage {
  position: relative;
  width: 100%;
  height: 280px;
  margin: 1.5rem 0 1.25rem;
  overflow: visible;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

/* L1 — hit-stop. Freezes the stage briefly before the reveal-card paints.
   Implementation: kill pointer events + suppress sub-pixel movement by
   pinning paint with `will-change`. The actual freeze is the JS timeout;
   this class makes the freeze visually legible by killing the cursor and
   any hover state during it. */
.stage.hit-stop {
  pointer-events: none;
  filter: contrast(1.02);
  transition: filter 60ms ease-out;
}
@media (prefers-reduced-motion: reduce) {
  .stage.hit-stop { filter: none; }
}

.baseline {
  position: absolute;
  left: 0; right: 0;
  bottom: 72px;
  height: 1px;
  background: var(--line-faint);
  pointer-events: none;
}

.word {
  position: relative;
  width: 100%;
  height: 100%;
}

.glyph {
  position: absolute;
  bottom: 72px;
  font-size: 160px;
  font-weight: 400;
  font-style: normal;
  line-height: 1;
  color: var(--ink);
  cursor: grab;
  transform: translate(-50%, 0);
  transform-origin: 50% 100%;
  font-kerning: none;
  font-feature-settings: "kern" 0;
  -webkit-font-feature-settings: "kern" 0;
  font-variant-ligatures: none;
  white-space: pre;
}

.glyph.dragging { cursor: grabbing; }

/* v3.1 — STRUCTURAL FIX: master-ghost layer.
   Ghost letters pre-rendered at the target (master) positions. Invisible
   by default; fade in to a faint ink wash while the player is dragging.
   The eye gets an optical target to aim at; the clean-read gate becomes
   skill rather than luck.

   Design choices:
   - Same face + same font-size as the live glyphs (so the alignment is
     pixel-true at the threshold).
   - Color held at 14% ink: visible enough to aim at, faint enough not to
     read as a second word competing for the eye.
   - No cursor, no pointer-events: this is a render layer, not interactive.
   - Sits BELOW the live glyphs in z-order (z-index 0 vs glyph's auto 1).
*/
.ghost-glyph {
  position: absolute;
  bottom: 72px;
  font-size: 160px;
  font-weight: 400;
  font-style: normal;
  line-height: 1;
  color: var(--ink);
  opacity: 0;
  transform: translate(-50%, 0);
  transform-origin: 50% 100%;
  font-kerning: none;
  font-feature-settings: "kern" 0;
  -webkit-font-feature-settings: "kern" 0;
  font-variant-ligatures: none;
  white-space: pre;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
  z-index: 0;
  transition: opacity 200ms ease-out;
}
.word.ghosts-visible .ghost-glyph {
  opacity: 0.14;
}
.ghost-glyph.faded {
  opacity: 0 !important;
  transition: opacity 220ms ease-out;
}
.glyph { z-index: 1; }

@media (prefers-reduced-motion: reduce) {
  .ghost-glyph { transition: opacity 80ms linear; }
}

/* L2 — kiss-into-alignment. CSS transition on `left` so the glyphs animate
   from their current positions to the master centers. 300ms ease-out is
   the rubric-fast "I see you" register, not the slow "let me explain"
   register. Stripped under prefers-reduced-motion. */
.glyph.kissing {
  transition: left 300ms cubic-bezier(0.22, 0.61, 0.36, 1);
}
@media (prefers-reduced-motion: reduce) {
  .glyph.kissing { transition: none; }
}

/* L3 — gap pulse on the worst-pair gap. Thin warm-black baseline underline
   that the CSS fades 200ms after JS appends it. Position is set inline
   (left+width) so it spans the gap. */
.gap-pulse {
  position: absolute;
  bottom: 64px;
  height: 2px;
  background: var(--pulse);
  opacity: 1;
  transition: opacity 220ms ease-out;
  pointer-events: none;
}
.gap-pulse.fading { opacity: 0; }
@media (prefers-reduced-motion: reduce) {
  .gap-pulse { display: none; }
}

@media (max-width: 560px) {
  .glyph { font-size: 110px; }
  .stage { height: 220px; }
  .baseline { bottom: 50px; }
  .glyph { bottom: 50px; }
  .gap-pulse { bottom: 44px; }
  .ghost-glyph { font-size: 110px; bottom: 50px; }
}

.hint {
  text-align: center;
  color: var(--muted);
  font-size: 0.82rem;
  margin: 2rem 0 0;
  font-style: italic;
  font-family: var(--serif);
}

/* ---------- reveal CARD (v3) ----------
   The reveal is no longer a page with two stages + a CTA. The kissed word
   stays on the round stage (L2). The card carries the prose. */

.reveal-card {
  position: relative;
  max-width: 38em;
  margin: 1.5rem auto 0;
  padding: 1.75rem 1.5rem 2.75rem;
  background: var(--bg);
  border: 1px solid var(--line-faint);

  /* L10 — paint-in. Card starts scaled-down + transparent; .active toggles. */
  opacity: 0;
  transform: scale(0.985);
  transition: opacity 220ms ease-out, transform 220ms cubic-bezier(0.22, 0.61, 0.36, 1);
}
.reveal-card.active {
  opacity: 1;
  transform: scale(1);
}
@media (prefers-reduced-motion: reduce) {
  .reveal-card { transition: opacity 120ms linear; transform: none; }
}

.reveal-card-label {
  font-family: var(--serif);
  font-style: italic;
  color: var(--muted);
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  margin: 0 0 0.5rem;
  text-align: left;
}

.reveal-card-score {
  text-align: center;
  font-family: var(--serif);
  font-size: 2.1rem;
  margin: 0 0 1.25rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}
.reveal-card-score-of {
  font-size: 0.95rem;
  color: var(--muted);
  font-style: italic;
}

/* The eye-language diagnostic. v2 read as noun-phrase with an em-dash:
   "The n — too tight against the r." v3 cuts the parenthetical em-readout. */
.diag {
  text-align: center;
  font-family: var(--serif);
  font-style: normal;
  font-size: 1.02rem;
  color: var(--ink);
  margin: 0.5rem 0 0.5rem;
  line-height: 1.5;
  max-width: 36em;
  margin-left: auto;
  margin-right: auto;
}

/* Pair-citation, longer prose. v3 long-presses the source. */
.pair-cite {
  text-align: center;
  font-family: var(--serif);
  font-style: italic;
  font-size: 0.88rem;
  color: var(--muted);
  margin: 0 0 0.55rem;
  line-height: 1.5;
  max-width: 38em;
  margin-left: auto;
  margin-right: auto;
  cursor: help;
  user-select: none;
  -webkit-user-select: none;
}

/* Source-citation tooltip — surfaces on long-press of .pair-cite. */
.cite-tip {
  text-align: center;
  font-family: var(--serif);
  font-style: italic;
  font-size: 0.74rem;
  color: var(--muted);
  margin: 0 0 0.4rem;
  letter-spacing: 0.01em;
  min-height: 1.2em;
  opacity: 0;
  transition: opacity 180ms ease-out;
}
.cite-tip.show { opacity: 1; }

/* L4 — serif "clean read" stamp drops into the right margin of the reveal
   card. Caret-italic, slightly skewed, fades in from above with a small
   rotation. Reads as a stamp, not a label. */
.clean-stamp {
  position: absolute;
  top: 1.1rem;
  right: 1rem;
  font-family: var(--serif);
  font-style: italic;
  color: var(--accent);
  font-size: 0.92rem;
  letter-spacing: 0.02em;
  opacity: 0;
  transform: translateY(-6px) rotate(-3deg);
  transition: opacity 200ms ease-out, transform 220ms cubic-bezier(0.34, 1.56, 0.64, 1);
  pointer-events: none;
  border-left: 2px solid var(--accent);
  padding-left: 0.55rem;
  line-height: 1.2;
}
.clean-stamp em { font-style: italic; }
.clean-stamp.show {
  opacity: 1;
  transform: translateY(0) rotate(-2deg);
}
@media (prefers-reduced-motion: reduce) {
  .clean-stamp { transition: opacity 120ms linear; transform: none; }
  .clean-stamp.show { transform: none; }
}

/* Next is a margin caret, not a CTA. Mei's #4: "the artifact is what the
   thumb lingers on, not the chrome." Demoted to a thin bottom-right glyph. */
.next-caret {
  position: absolute;
  right: 0.8rem;
  bottom: 0.6rem;
  background: transparent;
  border: 0;
  font-family: var(--serif);
  font-size: 1.6rem;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  padding: 0.35rem 0.5rem;
  transition: color 0.15s ease;
  letter-spacing: 0;
}
.next-caret:hover { color: var(--ink); }
.next-caret:focus-visible {
  outline: 1px solid var(--game-focus);
  outline-offset: 2px;
}

@media (max-width: 560px) {
  .reveal-card { padding: 1.5rem 1.1rem 2.5rem; }
  .clean-stamp { top: 0.8rem; right: 0.75rem; font-size: 0.84rem; }
  .next-caret { font-size: 1.45rem; }
}

/* ---------- finale + share card ---------- */

#finale h2, #already h2 {
  text-align: center;
  font-family: var(--serif);
  font-weight: 400;
  font-style: italic;
  font-size: 1.55rem;
  margin: 2rem 0 0.5rem;
}

.finale-score {
  text-align: center;
  font-family: var(--serif);
  font-size: 2.4rem;
  margin: 0.2rem 0 0.6rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}
.finale-score .of {
  font-size: 1rem;
  color: var(--muted);
  font-style: italic;
}

.streak {
  text-align: center;
  font-family: var(--serif);
  font-style: italic;
  font-size: 0.9rem;
  color: var(--accent);
  margin: 0 0 1.6rem;
  min-height: 1.3em;
}

.card {
  width: 100%;
  max-width: 480px;
  margin: 1rem auto 1.5rem;
  padding: 1.75rem 1.5rem 1.25rem;
  background: var(--bg);
  border: 1px solid var(--line-faint);
  position: relative;
}

.card-title {
  text-align: center;
  font-family: var(--serif);
  font-style: italic;
  color: var(--muted);
  font-size: 0.8rem;
  margin: 0 0 1.25rem;
  letter-spacing: 0.06em;
}

.card-words {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin: 0.5rem 0 1.1rem;
}

.card-word {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: baseline;
  gap: 0.75rem;
  border-bottom: 1px dotted var(--line-faint);
  padding: 0.15rem 0;
}

.card-word-text {
  font-size: 1.3rem;
  letter-spacing: 0.02em;
  font-kerning: normal;
  font-feature-settings: "kern" 1;
}

.card-word-score {
  font-family: var(--serif);
  font-style: italic;
  font-size: 1rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* L6 — share-cell flip on clean. The score cell shows ◆ alongside the
   number; the visible toggle reads as the round having flipped to "clean."
   We render `◆ N` rather than replacing N entirely so the score is still
   parseable in the share row. */
.card-word-score.flip-clean {
  color: var(--accent);
}
.card-word-score.flip-clean::before {
  content: '◆ ';
  font-style: normal;
  display: inline-block;
  animation: cell-flip 380ms cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
@keyframes cell-flip {
  0%   { transform: rotateY(180deg); opacity: 0; }
  100% { transform: rotateY(0);      opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .card-word-score.flip-clean::before { animation: none; }
}

/* v3 — thumbnail-recognizable share row (Mei's #3).
   A specimen-row per word: `T·a·r·t·a·n` rendered in the word's face.
   At 64px the row reads as TYPE. */
.card-specimen-row {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin: 0.6rem 0 0.9rem;
  align-items: center;
}
.specimen-cell {
  display: inline-block;
  font-size: 1.1rem;
  letter-spacing: 0.02em;
  color: var(--ink);
  font-feature-settings: "kern" 1;
  line-height: 1.3;
  text-align: center;
}
.specimen-cell.clean {
  color: var(--accent);
}

.card-meta {
  text-align: center;
  font-family: var(--serif);
  font-size: 0.95rem;
  color: var(--ink);
  margin: 0.5rem 0 0.25rem;
  letter-spacing: 0.04em;
}

.card-footer {
  text-align: center;
  margin: 0.75rem 0 0;
  font-family: var(--serif);
  font-style: italic;
  font-size: 0.72rem;
  color: var(--muted);
  letter-spacing: 0.04em;
}

.share-status {
  text-align: center;
  color: var(--muted);
  min-height: 1.4em;
  margin: 0.5rem 0 0;
  font-size: 0.85rem;
  font-style: italic;
  font-family: var(--serif);
}

.next-puzzle {
  text-align: center;
  color: var(--muted);
  font-size: 0.82rem;
  font-family: var(--serif);
  font-style: italic;
  font-variant-numeric: tabular-nums;
  margin-top: 2rem;
}

.fallback-share {
  background: transparent;
  border: 1px dotted var(--line-faint);
  padding: 0.75rem;
  font-family: var(--mono);
  font-size: 0.8rem;
  margin-top: 0.5rem;
  text-align: left;
  color: var(--ink);
}
