:root {
  --bg: #f6f1e8;
  --surface: #fffaf2;
  --ink: #2a2620;
  --muted: #6f675b;
  --line: #e2d8c6;
  --glow: #e0a43c;
  --glow-soft: rgba(224, 164, 60, .22);
  --leaf: #5f9a6a;
  --petal: #e57a8a;
  --pot: #b8714a;
  --water: #5aa0d6;
  --bad: #c2523f;
  --radius: 16px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14161c;
    --surface: #1d2029;
    --ink: #ece7dd;
    --muted: #a39d92;
    --line: #2f3340;
    --glow: #f2bb57;
    --glow-soft: rgba(242, 187, 87, .2);
    --leaf: #78b884;
    --petal: #f08f9d;
    --pot: #c98560;
    --water: #78b6e6;
    --bad: #e2725f;
  }
}
:root[data-theme="dark"] {
  --bg: #14161c; --surface: #1d2029; --ink: #ece7dd; --muted: #a39d92; --line: #2f3340;
  --glow: #f2bb57; --glow-soft: rgba(242,187,87,.2); --leaf: #78b884; --petal: #f08f9d;
  --pot: #c98560; --water: #78b6e6; --bad: #e2725f;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
  overflow-x: hidden;
}
button { font: inherit; color: inherit; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: max(12px, env(safe-area-inset-top)) 16px 8px;
  max-width: 720px; margin: 0 auto;
}
.brand { font-weight: 700; letter-spacing: .04em; color: var(--muted); background: none; border: 0; padding: 6px 0; cursor: default; transition: color .6s, text-shadow .6s; }
.brand.found { color: var(--glow); text-shadow: 0 0 12px var(--glow-soft); }
.credits { margin-left: auto; margin-right: 16px; font-weight: 700; color: var(--glow); font-variant-numeric: tabular-nums; transition: transform .3s; }
.credits.bump { transform: scale(1.3); }
.hintbar { margin-top: auto; padding-top: 16px; display: flex; flex-direction: column; align-items: center; }
.hint-text { margin: 0 0 4px; max-width: 30em; min-height: 0; color: var(--ink); font-size: .95rem; }
.hint-text:not(:empty) { padding: 10px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
.hint-btn[disabled] { opacity: .45; cursor: default; }
.progress { display: flex; gap: 8px; list-style: none; margin: 0; padding: 0; }
.progress li { width: 10px; height: 10px; border-radius: 50%; background: var(--line); transition: background .4s; }
.progress li.done { background: var(--glow); }
.progress li.now { background: var(--glow); box-shadow: 0 0 0 4px var(--glow-soft); }

main { max-width: 720px; margin: 0 auto; padding: 0 16px 40px; }
.screen {
  display: none; position: relative;
  min-height: calc(100vh - 80px); min-height: calc(100dvh - 80px);
  flex-direction: column; align-items: center; text-align: center;
  padding-top: 16px;
  animation: fade .6s ease;
}
.screen[data-active] { display: flex; }
@keyframes fade { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

h1 { font-size: clamp(2.2rem, 8vw, 3.4rem); margin: 8px 0; letter-spacing: .02em; }
h2 { font-size: clamp(1.5rem, 5vw, 2rem); margin: 4px 0 8px; }
.eyebrow { margin: 0; color: var(--glow); font-weight: 700; font-size: .85rem; letter-spacing: .12em; text-transform: uppercase; }
.lede { max-width: 30em; font-size: 1.1rem; margin-bottom: 4px; }
.hint + .hint { margin-top: 0; }
.instr { max-width: 32em; color: var(--muted); margin: 0 0 16px; }
.hint { color: var(--muted); font-size: .9rem; }
.whisper { min-height: 1.6em; color: var(--muted); font-style: italic; margin: 16px 0 8px; transition: opacity .6s; }

.btn {
  border: 0; border-radius: 999px; padding: 14px 28px; margin: 8px; cursor: pointer;
  font-weight: 600; min-height: 48px; touch-action: manipulation;
}
.btn.primary { background: var(--glow); color: #2a1d06; }
.btn.ghost { background: transparent; border: 1.5px solid var(--line); color: var(--ink); }
.btn.small { padding: 8px 18px; min-height: 40px; font-size: .9rem; }
.btn:focus-visible, .hold-dot:focus-visible, .tile:focus-visible, .slot:focus-visible, .pot:focus-visible {
  outline: 3px solid var(--glow); outline-offset: 3px;
}
.hidden { display: none !important; }
.row { display: flex; flex-wrap: wrap; justify-content: center; }

.intro-orb {
  width: 120px; height: 120px; border-radius: 50%; margin-top: 6vh;
  background: radial-gradient(circle, var(--glow) 0 30%, var(--glow-soft) 31% 60%, transparent 61%);
  animation: breathe 5s ease-in-out infinite;
}
@keyframes breathe { 50% { transform: scale(1.12); opacity: .8; } }

/* Glints: hidden curiosity rewards */
.glint {
  position: absolute; width: 28px; height: 28px; border: 0; padding: 0; cursor: pointer;
  background: radial-gradient(circle, var(--muted) 0 2px, transparent 3px);
  opacity: .28; border-radius: 50%; touch-action: manipulation;
  transition: opacity .4s, transform .4s;
}
.glint:hover { opacity: .5; }
.glint.found {
  opacity: 1; transform: scale(1.4);
  background: radial-gradient(circle, var(--glow) 0 3px, var(--glow-soft) 4px 10px, transparent 11px);
}

/* Hold */
.hold-stage { position: relative; width: min(70vw, 260px); aspect-ratio: 1; margin: 8px 0; }
.ring { position: absolute; inset: 0; transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: var(--line); stroke-width: 6; }
.ring-fg { fill: none; stroke: var(--glow); stroke-width: 6; stroke-linecap: round;
  stroke-dasharray: 553; stroke-dashoffset: 553; transition: stroke-dashoffset .2s linear; }
.hold-dot {
  position: absolute; left: 50%; top: 50%; width: 46%; height: 46%; transform: translate(-50%, -50%);
  border-radius: 50%; border: 0; cursor: pointer; touch-action: none;
  background: radial-gradient(circle at 40% 35%, #fff6 0 10%, var(--glow) 40%, var(--glow-soft) 72%, transparent 73%);
  transition: transform .3s;
}
.hold-dot.held { transform: translate(-50%, -50%) scale(.92); animation: pulse 4s ease-in-out infinite; }
.hold-dot.slip { animation: slip .35s; }
@keyframes pulse { 50% { filter: brightness(1.2); } }
@keyframes slip { 25% { transform: translate(-46%, -50%); } 75% { transform: translate(-54%, -50%); } }

/* Trace */
.trace-wrap { position: relative; width: 100%; max-width: 640px; aspect-ratio: 4 / 3; max-height: 60vh;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
#trace-canvas { width: 100%; height: 100%; display: block; touch-action: none; cursor: crosshair; }
.trace-hud { position: absolute; left: 12px; top: 10px; font-size: .9rem; color: var(--muted); pointer-events: none; }

/* Riddle */
.riddle { margin: 0 0 12px; padding: 14px 18px; max-width: 30em; font-style: italic; font-size: 1.05rem;
  background: var(--surface); border-left: 4px solid var(--glow); border-radius: 8px; text-align: left; }
.timer { margin: 0 0 4px; font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums; }
.slots, .tiles { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin: 8px 0; max-width: 100%; }
.slot, .tile {
  width: clamp(34px, 9.5vw, 48px); height: clamp(42px, 11vw, 56px); border-radius: 10px;
  display: grid; place-items: center; font-weight: 700; font-size: clamp(1.1rem, 4vw, 1.4rem);
}
.slot { border: 2px dashed var(--line); background: transparent; cursor: pointer; padding: 0; }
.slot.filled { border-style: solid; border-color: var(--glow); background: var(--surface); }
.slot.over { border-color: var(--glow); background: var(--glow-soft); }
.slots.wrong { animation: slip .4s; }
.slots.right .slot { border-color: var(--leaf); color: var(--leaf); }
.tile { border: 0; background: var(--surface); box-shadow: 0 2px 0 var(--line); cursor: grab; touch-action: none; padding: 0; }
.tile.used { visibility: hidden; }
.tile.dragging { position: fixed; z-index: 50; cursor: grabbing; pointer-events: none; box-shadow: 0 8px 20px rgba(0,0,0,.25); }

/* Seed */
.pot { width: min(64vw, 240px); background: none; border: 0; padding: 0; cursor: pointer; touch-action: manipulation; }
.pot svg { width: 100%; height: auto; overflow: visible; }
.pot-body { fill: var(--pot); }
.pot-rim { fill: var(--pot); filter: brightness(1.12); }
.seedling { fill: #8a6a3e; }
.stem { fill: none; stroke: var(--leaf); stroke-width: 5; stroke-linecap: round; stroke-dasharray: 90; stroke-dashoffset: 90; transition: stroke-dashoffset 2.5s ease; }
.leaf { fill: var(--leaf); opacity: 0; transform-origin: 100px 110px; transform: scale(.2); transition: opacity 1.5s 1.5s, transform 1.5s 1.5s; }
.flower { opacity: 0; transform-origin: 100px 67px; transform: scale(.1) rotate(-30deg); transition: opacity 1.8s 2.8s, transform 1.8s 2.8s; }
.petal { fill: var(--petal); }
.core { fill: var(--glow); }
.plant.sprout .stem { stroke-dashoffset: 62; }
.plant.bloom .stem { stroke-dashoffset: 0; }
.plant.bloom .leaf { opacity: 1; transform: none; }
.plant.bloom .flower { opacity: 1; transform: none; }
.drop { fill: var(--water); animation: drop .9s ease-in forwards; }
@keyframes drop { from { transform: translateY(-40px); opacity: 1; } to { transform: translateY(40px); opacity: 0; } }

/* Orbit (balance) */
.space-wrap { position: relative; width: 100%; max-width: 640px; aspect-ratio: 4 / 3; max-height: 60vh;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
#orbit-canvas { width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
#orbit-canvas.aiming { cursor: grabbing; }

/* Pulsar (timing) */
.pulsar-stage { position: relative; width: min(70vw, 260px); aspect-ratio: 1; margin: 8px 0; --p: 0; }
.pulsar-ticks { position: absolute; inset: 0; overflow: visible; }
.pulsar-ticks circle { fill: var(--line); opacity: 0; transition: opacity .6s, fill .25s; }
.pulsar-stage.quiet .pulsar-ticks circle { opacity: 1; }
.pulsar-ticks circle.hit { fill: var(--glow); }
.pulsar-ticks circle.off { fill: var(--muted); opacity: .45; }
.pulsar {
  position: absolute; left: 50%; top: 50%; width: 52%; height: 52%; transform: translate(-50%, -50%);
  border-radius: 50%; border: 0; padding: 0; background: none; cursor: pointer; touch-action: manipulation;
}
.pulsar-core {
  position: absolute; inset: 0; border-radius: 50%; pointer-events: none;
  background: radial-gradient(circle at 42% 38%, #fff8 0 8%, var(--glow) 34%, var(--glow-soft) 66%, transparent 70%);
  transform: scale(calc(.78 + var(--p) * .3)); opacity: calc(.3 + var(--p) * .7);
}
.pulsar-stage.quiet .pulsar-core { transform: scale(.78); opacity: .22; }
.pulsar::after {
  content: ""; position: absolute; inset: 0; border-radius: 50%; border: 2px solid var(--glow);
  opacity: 0; pointer-events: none;
}
.pulsar.tap::after { animation: ripple .7s ease-out; }
.pulsar.slip { animation: slip .35s; }
@keyframes ripple { from { opacity: .8; transform: scale(.8); } to { opacity: 0; transform: scale(1.6); } }
.pulsar:focus-visible { outline: 3px solid var(--glow); outline-offset: 3px; }

/* Player name */
.player { margin-left: 10px; min-width: 0; max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  color: var(--muted); font-size: .85rem; }
.linkish { background: none; border: 0; padding: 8px 4px; margin-top: 4px; color: var(--muted); font-size: .9rem; cursor: pointer; touch-action: manipulation; }
.linkish span { color: var(--ink); font-weight: 600; }
.linkish:focus-visible, .name-opt:focus-visible { outline: 3px solid var(--glow); outline-offset: 3px; }
.intro-orb.small { width: 72px; height: 72px; margin-top: 4vh; }
.names { display: flex; flex-direction: column; gap: 12px; width: min(100%, 320px); margin: 16px 0 8px; }
.name-opt {
  border: 1.5px solid var(--line); background: var(--surface); border-radius: 999px; padding: 14px 20px; min-height: 52px;
  font-weight: 700; font-size: 1.1rem; cursor: pointer; touch-action: manipulation; transition: border-color .3s, box-shadow .3s;
  animation: fade .5s ease both;
}
.name-opt:nth-child(2) { animation-delay: .08s; }
.name-opt:nth-child(3) { animation-delay: .16s; }
.name-opt:hover { border-color: var(--glow); box-shadow: 0 0 0 4px var(--glow-soft); }
.names.busy { opacity: .55; transition: opacity .3s; }
.names:empty { min-height: 180px; }

/* Session log under the card */
.session-log { width: min(100%, 420px); margin: 4px 0 8px; text-align: left; }
.session-head { margin: 0 0 6px; color: var(--muted); font-size: .85rem; letter-spacing: .04em; }
.session-head b { color: var(--ink); }
.session-rows { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.session-rows li {
  display: grid; grid-template-columns: 1fr auto; column-gap: 12px; padding: 8px 2px; border-bottom: 1px solid var(--line);
  font-size: .92rem;
}
.session-rows .s-name { font-weight: 700; }
.session-rows .s-time { color: var(--muted); font-variant-numeric: tabular-nums; text-align: right; }
.session-rows .s-res { color: var(--ink); }
.session-rows .s-meta { color: var(--muted); text-align: right; font-size: .85rem; }

/* Card */
#card-canvas { width: min(100%, 420px); height: auto; border-radius: var(--radius); box-shadow: 0 10px 30px rgba(0,0,0,.18); margin: 8px 0; }

.toast {
  position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-size: .95rem;
  opacity: 0; pointer-events: none; transition: opacity .3s, transform .3s; max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
