:root {
  --bg: #fbf7f2;
  --ink: #1a1a1a;
  --muted: #6b6b6b;
  --accent: #b35900;
  --line: #e8e3dc;
  --radius: var(--radius-lg, 10px);
  --cursor-radius: 6px;
  --game-focus: var(--border-focus, var(--accent));
  --serif: var(--font-serif, ui-serif, 'Iowan Old Style', 'Apple Garamond', Baskerville, 'Times New Roman', serif);
  --sans: var(--font-sans, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif);
  --mono: var(--font-mono, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15130f;
    --ink: #f4efe6;
    --muted: #8c8579;
    --accent: #e08a2a;
    --line: #2a2620;
  }
}

* { box-sizing: border-box; }

/* Several Pollen components declare explicit display values (.secondary,
   .perfect-stamp, .streak-chip). Keep the HTML hidden contract above those
   class rules so hidden UI cannot leak into normal play. */
[hidden] { display: none !important; }

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

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

header {
  text-align: center;
  padding: 1.1rem 1rem 0.15rem;
}

.wordmark {
  font-family: var(--serif);
  font-size: 2.75rem;
  margin: 0;
  letter-spacing: -0.02em;
  font-weight: 500;
  font-style: italic;
}

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

footer {
  text-align: center;
  padding: 1.25rem 1rem 1.75rem;
  font-size: 0.8rem;
  color: var(--muted);
}

footer .brand {
  font-family: var(--serif);
  font-style: italic;
}

.screen { display: none; }
.screen.active { display: block; animation: fadein 0.3s ease; }

@keyframes fadein {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ---------- intro ------------------------------------------------------- */
.intro-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 0 0.85rem;
  min-height: 1.6rem;
}

.puzzle-corner {
  font-family: var(--serif);
  font-style: italic;
  color: var(--muted);
  font-size: 0.95rem;
  letter-spacing: 0.02em;
}

.streak-chip {
  display: inline-block;
  background: var(--ink);
  color: var(--bg);
  padding: 0.18rem 0.65rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
}

.intro-rule {
  text-align: center;
  font-family: var(--serif);
  font-style: italic;
  color: var(--ink);
  margin: 20vh auto 0;
  max-width: 24rem;
  font-size: 1.35rem;
  line-height: 1.3;
}

.primary {
  display: block;
  margin: 1.25rem auto 0;
  background: var(--ink);
  color: var(--bg);
  border: none;
  border-radius: var(--radius);
  padding: 0.9rem 2.25rem;
  font-family: var(--sans);
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, transform 0.05s;
  min-width: 12rem;
}
.primary:hover { background: var(--accent); }
.primary:active { transform: translateY(1px); }
.primary:focus-visible {
  outline: 2px solid var(--game-focus);
  outline-offset: 3px;
}

.secondary {
  display: block;
  margin: 0.75rem auto 0;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.55rem 1.25rem;
  font-family: var(--sans);
  font-size: 0.88rem;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.secondary:hover { color: var(--ink); border-color: var(--ink); }

.round-header {
  text-align: center;
  margin-bottom: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  flex-wrap: wrap;
}

.round-counter {
  font-family: var(--serif);
  font-style: italic;
  font-size: 1rem;
  color: var(--muted);
}

.difficulty-chip {
  display: inline-block;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.16rem 0.55rem;
  color: var(--ink);
  background: color-mix(in srgb, var(--line) 42%, transparent);
  font-size: 0.74rem;
  font-weight: 650;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.big-swatch {
  width: 100%;
  aspect-ratio: 3.6 / 1;
  border-radius: var(--radius);
  background: var(--line);
  transition: opacity 0.4s ease;
  box-shadow: 0 1px 0 rgba(0,0,0,0.04);
}

.phase { display: none; }
.phase.visible { display: block; animation: fadein 0.25s ease; }

/* ---------- choice picker ------------------------------------------------ */

.choice-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.65rem;
  margin: 0.85rem 0 0;
}

.choice {
  display: block;
  min-width: 0;
  width: 100%;
  height: clamp(48px, 10vh, 68px);
  margin: 0;
  padding: 0;
  border: 2px solid transparent;
  border-radius: var(--radius);
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.08), 0 1px 3px rgba(0,0,0,0.08);
  cursor: pointer;
}

.choice.selected {
  border-color: var(--ink);
  box-shadow: 0 0 0 3px var(--bg), 0 0 0 5px var(--accent);
}

.choice:focus-visible {
  outline: 2px solid var(--game-focus);
  outline-offset: 2px;
}

#guess-swatch { margin-bottom: 0; }

@media (max-width: 520px) {
  html, body { min-height: 100svh; }
  header { padding-top: 0.45rem; }
  .wordmark { font-size: 2.05rem; }
  main { padding: 0.35rem 0.85rem 0.8rem; }
  .primary { margin-top: 0.85rem; padding: 0.75rem 1.75rem; }
  .choice-grid { gap: 0.5rem; }
  .choice { height: clamp(42px, 9vh, 58px); }
  footer { display: none; }
}

.reveal-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
  position: relative;
}

/* ---------- Mei's "Perfect" moment over-polish ----------
   When the round scores >= 95, body adds .perfect-moment for ~600ms.
   That triggers:
     - .hit-stop: a brief blanching/freeze on the screen (CSS filter)
     - .reveal-row.kiss: target + guess swatches overlap then separate
     - .perfect-stamp: serif italic word stamps in, then fades
   Polish concentrates on one event. Everything else is restraint.
*/

.reveal-cell {
  text-align: center;
  transition: transform 0.32s cubic-bezier(.18,.85,.32,1.1);
}

.reveal-row.kiss .reveal-cell:first-child {
  transform: translateX(46%);
}
.reveal-row.kiss .reveal-cell:last-child {
  transform: translateX(-46%);
}

/* hit-stop: brief desaturation + scale punch on the body, ~3 frames at 60fps */
body.hit-stop {
  animation: hitstop 0.2s ease;
}
@keyframes hitstop {
  0% { filter: none; }
  15% { filter: brightness(1.06) contrast(1.04); }
  30% { filter: brightness(1.02); }
  100% { filter: none; }
}

.perfect-stamp {
  /* Mei: "serif type stamps the tier name." Per round, the word is
     "Perfect" — Bloom/Petal/Bud/Seed are the run-level tier. */
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--serif);
  font-style: italic;
  font-size: 3.4rem;
  font-weight: 500;
  color: var(--accent);
  pointer-events: none;
  letter-spacing: -0.01em;
  text-shadow: 0 1px 0 rgba(0,0,0,0.04);
  animation: stampdrop 1.6s cubic-bezier(.18,.85,.32,1.1) forwards;
}
@keyframes stampdrop {
  0%   { opacity: 0; transform: scale(0.6) translateY(-12px); }
  18%  { opacity: 1; transform: scale(1.12) translateY(0); }
  32%  { opacity: 1; transform: scale(1.0) translateY(0); }
  78%  { opacity: 1; transform: scale(1.0); }
  100% { opacity: 0; transform: scale(1.0); }
}

.reveal-swatch {
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: var(--radius);
  background: var(--line);
}

.reveal-label {
  font-family: var(--serif);
  font-style: italic;
  margin: 0.5rem 0 0.1rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.round-score {
  margin-top: 1.25rem;
  font-size: 1.1rem;
  color: var(--ink);
  font-family: var(--serif);
  font-style: italic;
  text-align: center;
}

.round-score span { font-style: normal; font-variant-numeric: tabular-nums; font-weight: 500; }

.recall-cue {
  margin: 0.3rem auto 0;
  color: var(--muted);
  font-size: 0.86rem;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* ---------- finale: tier word is the brag (Mei's dim-4 + dim-6 lift) ---- */

.tier-display {
  text-align: center;
  margin: 0.5rem 0 1rem;
}

.tier-name {
  font-family: var(--serif);
  font-style: italic;
  font-size: 3rem;
  font-weight: 500;
  margin: 0.5rem 0 0.25rem;
  letter-spacing: -0.02em;
  color: var(--ink);
  line-height: 1;
}

.tier-score {
  font-family: var(--serif);
  font-size: 1.05rem;
  margin: 0;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.streak-line {
  margin: 0.75rem 0 0;
  font-size: 0.92rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.tier-display--already {
  margin-top: 0;
}
.tier-display--already .tier-name-already {
  font-family: var(--serif);
  font-style: italic;
  font-size: 2rem;
  font-weight: 500;
  text-align: center;
  margin: 0.5rem 0 0.15rem;
}

#already h2 {
  font-family: var(--serif);
  font-size: 1.35rem;
  font-weight: 500;
  font-style: italic;
  text-align: center;
  margin: 0.5rem 0 0.75rem;
  color: var(--muted);
}

.already-score-line {
  text-align: center;
  margin: 0;
  color: var(--ink);
  font-size: 1.05rem;
  font-family: var(--serif);
  font-variant-numeric: tabular-nums;
}

.petal-result {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  margin: 1rem auto 1.5rem;
  flex-wrap: wrap;
}

.petal {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--line);
  display: inline-block;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.06);
  position: relative;
}

/* The Perfect petal (round score >= 95) gets a small flair ring. */
.petal.perfect::after {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 1.5px solid var(--accent);
  pointer-events: none;
  animation: petalpulse 1.8s ease-in-out infinite;
}
@keyframes petalpulse {
  0%, 100% { opacity: 0.35; transform: scale(1); }
  50%      { opacity: 0.85; transform: scale(1.04); }
}

.review-intro {
  margin: 0.25rem 0 0.55rem;
  text-align: center;
  color: var(--muted);
  font-family: var(--serif);
  font-style: italic;
  font-size: 0.95rem;
}

.round-review {
  display: grid;
  gap: 0.45rem;
  margin: 0 auto 1.25rem;
}

.review-row {
  display: grid;
  grid-template-columns: auto auto 1fr;
  align-items: center;
  gap: 0.65rem;
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--line) 22%, transparent);
}

.review-round {
  width: 1.45rem;
  height: 1.45rem;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: var(--ink);
  color: var(--bg);
  font-size: 0.78rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.review-swatches {
  display: flex;
  gap: 0.2rem;
}

.review-swatch {
  width: 2rem;
  height: 2rem;
  border-radius: 0.45rem;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.08);
}

.review-copy {
  min-width: 0;
  display: grid;
  gap: 0.08rem;
}

.review-copy strong {
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
}

.review-copy span {
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.25;
}

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

.share-note {
  display: block;
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 0.5rem;
}

.share-preview {
  display: inline-block;
  margin: 0 auto;
  padding: 0.75rem 1rem;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-family: var(--mono);
  font-size: 0.95rem;
  line-height: 1.5;
  color: var(--ink);
  white-space: pre;
  text-align: left;
  user-select: all;
  -webkit-user-select: all;
  box-shadow: 0 1px 0 rgba(0,0,0,0.03);
}

.next-puzzle {
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
  margin-top: 1.75rem;
}

.follow-cta {
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  margin-top: 1.75rem;
  line-height: 1.5;
}

.follow-cta a {
  color: inherit;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

.follow-cta a:hover,
.follow-cta a:focus-visible {
  color: var(--accent);
}

.follow-cta a:focus-visible {
  outline: 2px solid var(--game-focus);
  outline-offset: 3px;
  border-radius: 2px;
}

@media (max-width: 420px) {
  .wordmark { font-size: 2.25rem; }
  main { padding: 0.75rem 1rem 2rem; }
  .petal { width: 44px; height: 44px; }
  .tier-name { font-size: 2.5rem; }
  .perfect-stamp { font-size: 2.6rem; }
}
