:root {
  --night: #100e0c;
  --sheet: #f3eee4;
  --bg: var(--sheet);
  --ink: #1b1612;
  --muted: #5e564c;
  --faint: #7a7166;
  --line: rgba(27, 22, 18, 0.14);
  --hot: #e23d2b;
  --gold: #8c6239;
  --dusk: #3d5c6e;
  --moss: #4d5c45;
  --clay: #7a4638;
  --blush: #a85b4a;
  --paper: #f7f3eb;
  --display: "Bricolage Grotesque", "Avenir Next", sans-serif;
  --serif: "Newsreader", Georgia, serif;
  --sans: "Bricolage Grotesque", "Avenir Next", sans-serif;
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  color-scheme: light;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html {
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--sans);
  font-weight: 420;
  font-size: 16px;
  line-height: 1.45;
  color: var(--ink);
  background:
    radial-gradient(900px 420px at 15% -10%, rgba(226, 61, 43, 0.18), transparent 55%),
    var(--night);
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

button:disabled { cursor: default; }

:focus { outline: none; }

:focus-visible {
  outline: 2px solid var(--hot);
  outline-offset: 3px;
}

::selection {
  background: #f0b2a8;
  color: var(--ink);
}

.kicker {
  margin: 0 0 12px;
  font-size: 0.72rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}

.text-btn {
  appearance: none;
  border: 0;
  background: none;
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 6px;
  color: var(--muted);
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  white-space: nowrap;
}

.text-btn:hover { color: var(--ink); }

.shell {
  width: min(1080px, 100%);
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.billboard {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(9.5rem, 16rem);
  column-gap: clamp(16px, 3vw, 40px);
  align-items: end;
  padding: max(22px, env(safe-area-inset-top)) max(22px, env(safe-area-inset-right)) 78px max(22px, env(safe-area-inset-left));
  color: var(--sheet);
}

.billboard-top {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.billboard .text-btn { color: rgba(243, 238, 228, 0.72); }
.billboard .text-btn:hover { color: var(--sheet); }

.mark {
  font-size: 0.72rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgba(243, 238, 228, 0.62);
}

.word {
  margin: clamp(18px, 4vh, 48px) 0 6px;
  font-family: var(--display);
  font-weight: 720;
  font-size: clamp(5.4rem, 12.4vw, 11.6rem);
  line-height: 0.74;
  letter-spacing: -0.07em;
}

.word span { display: block; }

.word .hot {
  padding-left: 0.42em;
  color: var(--hot);
}

.billboard-note {
  margin: 0 0 14px;
  justify-self: end;
  max-width: 11ch;
  text-align: right;
  font-family: var(--serif);
  font-style: italic;
  font-size: clamp(1.25rem, 2vw, 1.7rem);
  line-height: 1.12;
  color: rgba(243, 238, 228, 0.82);
}

.sheet {
  margin-top: -42px;
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--sheet);
  color: var(--ink);
  border-radius: 32px 32px 0 0;
  box-shadow: 0 -28px 70px rgba(0, 0, 0, 0.35);
  padding: 12px max(22px, env(safe-area-inset-right)) max(28px, env(safe-area-inset-bottom)) max(22px, env(safe-area-inset-left));
}

.folio { display: flex; flex-direction: column; }

.game-row {
  position: relative;
  isolation: isolate;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  grid-template-areas: "idx copy meta";
  align-items: center;
  gap: 8px 18px;
  width: 100%;
  padding: 20px 6px;
  border: 0;
  border-top: 1px solid var(--line);
  background: transparent;
  text-align: left;
  overflow: hidden;
}

.folio .game-row:last-child { border-bottom: 1px solid var(--line); }

.game-row::after {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--ink);
  transform: scaleX(0);
  transform-origin: left center;
  transition: transform 0.45s var(--ease);
  z-index: -1;
}

.game-index {
  grid-area: idx;
  font-family: var(--display);
  font-weight: 720;
  font-size: clamp(1.8rem, 3vw, 2.35rem);
  letter-spacing: -0.06em;
  line-height: 1;
  color: var(--hot);
}

.game-copy {
  grid-area: copy;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  transition: transform 0.45s var(--ease);
}

.game-name {
  font-family: var(--display);
  font-weight: 560;
  font-size: clamp(1.55rem, 2.4vw, 2.05rem);
  line-height: 1;
  letter-spacing: -0.045em;
}

.game-blurb {
  font-family: var(--serif);
  font-style: italic;
  font-size: 1.02rem;
  color: var(--muted);
  text-wrap: pretty;
}

.game-meta {
  grid-area: meta;
  display: flex;
  align-items: center;
  gap: 14px;
}

.game-best {
  color: var(--faint);
  font-size: 0.78rem;
  letter-spacing: 0.01em;
  text-align: right;
  max-width: 12rem;
}

.game-go {
  width: 42px;
  height: 42px;
  flex: none;
  display: grid;
  place-items: center;
  border: 1px solid var(--ink);
  border-radius: 50%;
  font-size: 1.05rem;
  line-height: 1;
}

@media (hover: hover) {
  .game-row:hover { color: var(--sheet); }
  .game-row:hover::after { transform: scaleX(1); }
  .game-row:hover .game-copy { transform: translateX(12px); }
  .game-row:hover .game-blurb,
  .game-row:hover .game-best { color: rgba(243, 238, 228, 0.7); }
  .game-row:hover .game-go {
    background: var(--sheet);
    color: var(--ink);
    border-color: var(--sheet);
  }
}

.game-row:active { color: var(--sheet); }
.game-row:active::after { transform: scaleX(1); }
.game-row:active .game-blurb,
.game-row:active .game-best { color: rgba(243, 238, 228, 0.7); }
.game-row:active .game-go {
  background: var(--sheet);
  color: var(--ink);
  border-color: var(--sheet);
}

.colophon {
  margin-top: auto;
  padding-top: 22px;
  color: var(--faint);
  font-family: var(--serif);
  font-style: italic;
  font-size: 0.95rem;
}

.play {
  width: min(680px, calc(100% - 20px));
  margin: 10px auto;
  min-height: calc(100dvh - 20px);
  display: flex;
  flex-direction: column;
  padding: 6px max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  background: var(--sheet);
  border-radius: 28px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.38);
}

.play-head {
  position: sticky;
  top: 10px;
  z-index: 2;
  width: min(100%, 560px);
  margin-inline: auto;
  padding-top: max(8px, env(safe-area-inset-top));
  background: var(--sheet);
  backdrop-filter: blur(10px);
}

.play-bar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
}

.play-bar h1 {
  font-family: var(--display);
  font-size: clamp(1.7rem, 4vw, 2.2rem);
  font-weight: 560;
  line-height: 1;
  letter-spacing: -0.045em;
  margin: 0;
  text-align: center;
}

.back { justify-self: start; }

.stat {
  justify-self: end;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.play-sub {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px 18px;
  flex-wrap: wrap;
  min-height: 52px;
  padding: 2px 0 12px;
}

.sub-left {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  min-height: 36px;
  color: var(--muted);
}

.play-tools {
  display: flex;
  gap: 16px;
  margin-left: auto;
}

.segment {
  display: inline-flex;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 999px;
}

.segment button {
  appearance: none;
  border: 0;
  background: transparent;
  border-radius: 999px;
  padding: 0 12px;
  min-width: 44px;
  min-height: 44px;
  color: var(--muted);
}

.segment button[aria-checked="true"] {
  background: var(--ink);
  color: var(--bg);
}

.moves { font-variant-numeric: tabular-nums; }

.lives {
  display: inline-flex;
  gap: 6px;
  align-items: center;
}

.lives i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  border: 1px solid currentColor;
  display: block;
}

.lives i.on { background: currentColor; }

.stage {
  flex: 1;
  display: grid;
  place-items: start center;
  width: 100%;
  padding: 4px 0 20px;
}

.playfield {
  width: min(100%, 640px);
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 18px;
}

.status {
  margin: 0;
  min-height: 1.4em;
  text-align: center;
  color: var(--muted);
}

.hint {
  margin: -8px 0 0;
  text-align: center;
  color: var(--faint);
  font-size: 0.75rem;
  letter-spacing: 0.06em;
}

@media (pointer: coarse) {
  .hint { display: none; }
}

.board {
  width: min(100%, 560px);
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: clamp(8px, 1.5vw, 14px);
}

.game-row,
.card,
.pad,
.star,
.node,
.petal {
  user-select: none;
}

.card {
  appearance: none;
  position: relative;
  aspect-ratio: 3 / 4;
  padding: 0;
  border: 0;
  background: transparent;
  perspective: 900px;
  border-radius: 14px;
}

.card-inner {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transition: transform 0.55s var(--ease);
}

.card.is-up .card-inner,
.card.is-matched .card-inner { transform: rotateY(180deg); }

.card-face,
.card-back {
  position: absolute;
  inset: 0;
  border-radius: 14px;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.card-back {
  background:
    radial-gradient(circle at 50% 50%, transparent 0 16%, rgba(212, 180, 131, 0.95) 16.6% 17.8%, transparent 18.6%),
    #1c1915;
  box-shadow: 0 10px 24px rgba(28, 25, 21, 0.08);
}

.card-face {
  display: grid;
  place-items: center;
  background: var(--paper);
  color: var(--ink);
  transform: rotateY(180deg);
  border: 1px solid rgba(28, 25, 21, 0.08);
  box-shadow: 0 10px 24px rgba(28, 25, 21, 0.06);
}

.card-face svg { width: 46%; height: 46%; }

.card.is-matched .card-face {
  color: var(--gold);
  background: #f7f1e4;
}

.card svg { pointer-events: none; }

.echo-ring {
  position: relative;
  width: min(100%, 500px, max(168px, calc(100dvh - 160px)));
  aspect-ratio: 1;
}

.echo-core {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  pointer-events: none;
}

.echo-count {
  display: block;
  font-family: var(--serif);
  font-weight: 300;
  font-size: clamp(3.2rem, 8vw, 4.6rem);
  line-height: 0.85;
  letter-spacing: -0.04em;
}

.echo-word {
  display: block;
  margin-top: 4px;
  color: var(--faint);
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.pad {
  position: absolute;
  width: max(44px, 20%);
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  border: 1px solid rgba(28, 25, 21, 0.14);
  background: var(--paper);
  color: rgba(28, 25, 21, 0.55);
  display: grid;
  place-items: center;
  padding: 0;
  box-shadow:
    inset 0 -10px 16px rgba(28, 25, 21, 0.04),
    0 10px 18px rgba(28, 25, 21, 0.05);
  transition: background 0.15s linear, color 0.15s linear, border-color 0.15s linear;
}

.pad svg {
  width: 42%;
  height: 42%;
  pointer-events: none;
}

.pad.is-lit {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}

.pad.is-bad {
  background: var(--blush);
  color: #fff;
  border-color: var(--blush);
}

.sky,
.loom {
  width: min(100%, 440px, max(272px, calc(100dvh - 150px)));
  aspect-ratio: 1;
}

.sky {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 4px;
  padding: clamp(12px, 3vw, 18px);
  border-radius: 28px;
  background:
    radial-gradient(circle at 50% 40%, #2a2622, #141311 72%);
}

.star,
.node {
  appearance: none;
  position: relative;
  border: 0;
  background: transparent;
  padding: 0;
  min-width: 0;
  min-height: 0;
}

.star::after,
.node::after {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  border-radius: 50%;
}

.star::after {
  width: 28%;
  aspect-ratio: 1;
  border: 1px solid rgba(243, 239, 231, 0.38);
}

.star.is-on::after {
  width: 40%;
  background: #f4efe6;
  border-color: #f4efe6;
  box-shadow: 0 0 16px rgba(244, 239, 230, 0.35);
}

.star.is-bad::after {
  width: 40%;
  background: #c48b73;
  border-color: #c48b73;
  box-shadow: none;
}

.star.is-miss::after {
  width: 40%;
  background: #d4b483;
  border-color: #d4b483;
}

.sky :focus-visible { outline-color: #f4efe6; }

.loom {
  position: relative;
  border-radius: 28px;
  background: rgba(28, 25, 21, 0.04);
}

.loom svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.silk {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

.silk-show { stroke: var(--gold); stroke-width: 2.25px; }
.silk-walk { stroke: var(--ink); stroke-width: 2.25px; }

.loom-grid {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.node::after {
  width: 16px;
  height: 16px;
  border: 1px solid var(--ink);
  background: var(--paper);
}

.node.is-on::after { background: var(--ink); }
.node.is-bad::after { background: var(--blush); border-color: var(--blush); }

.playfield.is-bloom { width: min(100%, 440px); }

.orchard {
  width: min(100%, 420px);
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: clamp(3px, 1.1vw, 8px);
  padding: clamp(6px, 1.6vw, 12px);
  border-radius: 28px;
  background: rgba(28, 25, 21, 0.045);
  touch-action: none;
}

.petal {
  appearance: none;
  aspect-ratio: 1;
  min-width: 0;
  min-height: 0;
  padding: 0;
  border-radius: 16px;
  border: 1px solid rgba(28, 25, 21, 0.08);
  background: var(--paper);
  display: grid;
  place-items: center;
  transition: transform 0.16s var(--ease), opacity 0.2s var(--ease), scale 0.2s var(--ease);
}

.petal svg {
  width: 52%;
  height: 52%;
  pointer-events: none;
}

.petal[data-kind="0"] { color: var(--ink); }
.petal[data-kind="1"] { color: var(--gold); }
.petal[data-kind="2"] { color: var(--dusk); }
.petal[data-kind="3"] { color: var(--moss); }
.petal[data-kind="4"] { color: var(--clay); }

.petal.is-picked {
  border-color: var(--ink);
  box-shadow: inset 0 0 0 1.5px var(--ink);
}

.petal.is-gone {
  opacity: 0;
  scale: 0.45;
}

.end {
  text-align: center;
  max-width: 18em;
  padding: 12px 8px 8px;
}

.end h2 {
  margin: 0;
  font-family: var(--display);
  font-weight: 720;
  font-size: clamp(2.6rem, 7vw, 4.2rem);
  line-height: 0.92;
  letter-spacing: -0.05em;
  text-wrap: balance;
}

.end-note {
  margin: 12px 0 0;
  color: var(--muted);
}

.again {
  appearance: none;
  margin-top: 22px;
  border: 1px solid var(--ink);
  background: var(--ink);
  color: var(--bg);
  border-radius: 999px;
  padding: 12px 26px;
  min-height: 44px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-size: 0.72rem;
}

.again:hover { background: #2a251f; }

@media (max-width: 720px) {
  .billboard { grid-template-columns: 1fr; }
  .word { font-size: clamp(4.5rem, 22vw, 7.2rem); margin-bottom: 0; }
  .billboard-note {
    justify-self: start;
    text-align: left;
    max-width: 16ch;
    margin: 16px 0 0;
  }

  .game-row {
    grid-template-areas: "idx copy go" "idx best go";
    gap: 4px 12px;
    padding: 16px 2px;
  }

  .game-meta { display: contents; }
  .game-index { align-self: start; padding-top: 1px; }
  .game-best { grid-area: best; text-align: left; max-width: none; }
  .game-go { grid-area: go; align-self: center; }
  .sheet { border-radius: 26px 26px 0 0; }
}

@media (max-width: 380px) {
  .play {
    width: calc(100% - 12px);
    margin: 6px auto;
    border-radius: 20px;
  }

  .play-bar h1 { font-size: 1.45rem; }
  .word { font-size: 4.4rem; }
}

@media (max-height: 700px) and (max-width: 520px) {
  .card { aspect-ratio: 1 / 1; }
  .board { gap: 6px; }
}

@media (max-height: 480px) {
  .board { width: min(100%, 340px); }
  .orchard { width: min(100%, 340px); }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
