:root {
  --night: #080914;
  --ink: #f3ecdc;
  --dim: rgba(236, 226, 204, .58);
  --accent: #ff5a3d;
  --glass: rgba(240, 228, 204, .06);
  --edge: rgba(240, 228, 204, .16);
  --serif: "Instrument Serif", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --ease: cubic-bezier(.2, .8, .2, 1);
}

* { box-sizing: border-box; margin: 0; }

html, body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--night);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

body { position: fixed; inset: 0; }

/* ── the embroidered night cloth (painted by js/cloth.js) ── */
#cloth { position: absolute; inset: 0; width: 100%; height: 100%; transition: opacity .45s ease; }
#cloth.wash { opacity: 0; }
.vignette {
  position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(ellipse at 50% 45%, transparent 42%, rgba(0, 0, 0, .42) 100%);
}

#stage {
  position: absolute; inset: 0; width: 100%; height: 100%;
  touch-action: none; cursor: crosshair;
}

.grain {
  position: absolute; inset: 0; pointer-events: none; opacity: .11; mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ── wordmark ── */
.brand {
  position: absolute; left: max(22px, env(safe-area-inset-left)); top: max(18px, env(safe-area-inset-top));
  pointer-events: none;
}
.brand h1 { font: 400 clamp(26px, 4.2vw, 38px)/1 var(--serif); letter-spacing: -.01em; }
.brand em, .guide em { font-style: italic; color: var(--accent); }
.brand .by {
  display: inline-block; margin-top: 9px; pointer-events: auto;
  font: italic 400 15px/1 var(--serif); color: var(--dim); text-decoration: none;
  border-bottom: 1px solid transparent; transition: color .25s, border-color .25s;
}
.brand .by:hover, .brand .by:focus-visible { color: var(--ink); border-bottom-color: var(--accent); outline: none; }
.brand p { margin-top: 7px; font-size: 11px; letter-spacing: .22em; text-transform: uppercase; color: var(--dim); }

/* ── opening invitation ── */
.hint {
  position: absolute; left: 50%; top: 46%; transform: translate(-50%, -50%);
  width: min(88vw, 520px); text-align: center; pointer-events: none;
  transition: opacity .7s var(--ease), transform .9s var(--ease), filter .7s;
}
.hint h2 { font: 400 clamp(40px, 9vw, 76px)/1 var(--serif); letter-spacing: -.02em; }
.hint p { margin-top: 16px; font-size: clamp(14px, 2.4vw, 16px); line-height: 1.6; color: var(--dim); }
.hint-scribble { width: 132px; margin-bottom: 14px; overflow: visible; }
.hint-scribble path {
  fill: none; stroke: var(--accent); stroke-width: 3.2; stroke-linecap: round; stroke-linejoin: round;
  stroke-dasharray: 1; stroke-dashoffset: 1; filter: drop-shadow(0 0 8px rgba(255, 90, 61, .7));
  animation: scribble 3.6s var(--ease) infinite;
}
@keyframes scribble {
  0% { stroke-dashoffset: 1; opacity: 1; }
  60% { stroke-dashoffset: 0; opacity: 1; }
  85%, 100% { stroke-dashoffset: 0; opacity: 0; }
}
.started .hint { opacity: 0; transform: translate(-50%, -58%) scale(.96); filter: blur(6px); }

/* ── controls ── */
.dock {
  position: absolute; left: 50%; bottom: max(14px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  display: flex; gap: 6px; padding: 6px;
  background: var(--glass); border: 1px solid var(--edge); border-radius: 999px;
  backdrop-filter: blur(18px) saturate(160%); -webkit-backdrop-filter: blur(18px) saturate(160%);
  box-shadow: 0 10px 40px rgba(0, 0, 0, .55), inset 0 1px 0 rgba(255, 255, 255, .08);
}
.dock button {
  appearance: none; border: 0; cursor: pointer; white-space: nowrap;
  padding: 10px 16px; border-radius: 999px;
  font: 500 13.5px/1 var(--sans); letter-spacing: .01em; color: var(--ink);
  background: transparent; transition: background .25s, transform .25s var(--ease), color .25s;
}
.dock button:hover { background: rgba(240, 228, 204, .1); }
.dock button:active { transform: scale(.95); }
.dock button:focus-visible, .guide button:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
#surprise { background: rgba(255, 90, 61, .16); box-shadow: inset 0 0 0 1px rgba(255, 90, 61, .5); }
#surprise:hover { background: rgba(255, 90, 61, .3); }
.spark { display: inline-block; color: var(--accent); animation: spin 6s linear infinite; }
#sound { padding: 7px 11px; }
#sound svg { display: block; width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
#sound path:first-child { fill: currentColor; }
#sound .muted, #sound.off .waves { display: none; }
#sound.off .muted { display: inline; }
#sound.off { color: var(--dim); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── field guide ── */
.guide {
  position: absolute; right: max(14px, env(safe-area-inset-right)); top: max(14px, env(safe-area-inset-top));
  width: min(340px, calc(100vw - 28px)); max-height: calc(100% - 100px); overflow: auto;
  padding: 18px 18px 14px; border-radius: 22px;
  background: rgba(13, 14, 19, .8); border: 1px solid var(--edge);
  backdrop-filter: blur(22px) saturate(160%); -webkit-backdrop-filter: blur(22px) saturate(160%);
  box-shadow: 0 24px 70px rgba(0, 0, 0, .6), inset 0 1px 0 rgba(255, 255, 255, .07);
  opacity: 0; visibility: hidden; transform: translateY(-10px) scale(.97); transform-origin: top right;
  transition: opacity .3s, transform .45s var(--ease), visibility 0s .3s;
}
.guide.open { opacity: 1; visibility: visible; transform: none; transition: opacity .3s, transform .45s var(--ease); }
.guide header { display: flex; align-items: center; justify-content: space-between; }
.guide h2 { font: 400 28px/1 var(--serif); }
.guide header button {
  width: 32px; height: 32px; border-radius: 50%; border: 1px solid var(--edge); cursor: pointer;
  background: var(--glass); color: var(--ink); font-size: 18px; line-height: 1;
}
.guide > p { margin: 8px 0 14px; font-size: 13px; line-height: 1.5; color: var(--dim); }
.guide ul { list-style: none; padding: 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.guide li {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 4px 9px;
  border-radius: 14px; background: rgba(240, 228, 204, .04); border: 1px solid rgba(240, 228, 204, .08);
}
.guide.open li { animation: rise .5s var(--ease) both; animation-delay: calc(var(--i) * 18ms); }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }
.guide svg { width: 44px; height: 44px; }
.guide path {
  fill: none; stroke: hsl(calc(var(--i) * 23 + 320) 100% 76%); stroke-width: 1.7;
  stroke-linecap: round; stroke-linejoin: round;
  filter: drop-shadow(0 0 3px hsl(calc(var(--i) * 23 + 320) 100% 60% / .9));
}
.guide span { font-size: 10px; letter-spacing: .14em; text-transform: uppercase; color: var(--dim); }
.guide b { font: italic 400 17px/1.15 var(--serif); }

@media (max-width: 520px) {
  .dock button { padding: 10px 13px; font-size: 13px; }
  .brand p { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .spark, .hint-scribble path { animation: none; }
  .hint-scribble path { stroke-dashoffset: 0; }
}
