/* Slap! styles. Self-contained (system fonts, no external requests). */
:root {
  color-scheme: light dark;
  --bg: #fbf8f3;
  --surface: #ffffff;
  --surface-2: #f4efe6;
  --ink: #16223b;
  --ink-2: #3b4661;
  --muted: #5b6475;
  --line: #e5ddcf;
  --btn: #16223b;
  --btn-ink: #ffffff;
  --focus: #16223b;
  --face: #1f2233;
  --gate: rgba(251, 248, 243, 0.8);
  --shadow: 0 1px 2px rgba(22, 34, 59, 0.06), 0 10px 28px rgba(22, 34, 59, 0.08);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --display: ui-rounded, "SF Pro Rounded", "Arial Rounded MT Bold", "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1522;
    --surface: #172033;
    --surface-2: #1d2841;
    --ink: #eef1f7;
    --ink-2: #c9d0dd;
    --muted: #9aa4b6;
    --line: #2b3752;
    --btn: #eef1f7;
    --btn-ink: #0f1522;
    --focus: #f3d38a;
    --gate: rgba(15, 21, 34, 0.8);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 12px 30px rgba(0, 0, 0, 0.35);
  }
}

/* Sound pack palettes: accent (blob), deep (words/text), tints (stage), particles. */
[data-pack="ouch"]    { --accent: #ff7a59; --deep: #b83a1f; --tint: #fff2ec; --tint-2: #ffdccf; --p1: #ff7a59; --p2: #ffbf2e; --p3: #ff8fab; }
[data-pack="drums"]   { --accent: #f4b740; --deep: #8a5a0e; --tint: #fff7e6; --tint-2: #ffe7b8; --p1: #f4b740; --p2: #16223b; --p3: #e8603c; }
[data-pack="zaps"]    { --accent: #8a7dff; --deep: #4a3dd1; --tint: #f3f1ff; --tint-2: #dfdaff; --p1: #8a7dff; --p2: #1fc7b6; --p3: #a3d900; }
[data-pack="squeaks"] { --accent: #f58bb4; --deep: #b3336b; --tint: #fff1f7; --tint-2: #ffd9e8; --p1: #f58bb4; --p2: #5cc2ff; --p3: #ffc53d; }
@media (prefers-color-scheme: dark) {
  [data-pack="ouch"]    { --deep: #ffb39c; --tint: #1d1a26; --tint-2: #3a2430; }
  [data-pack="drums"]   { --deep: #ffd683; --tint: #1c1d22; --tint-2: #3a3222; --p2: #eef1f7; }
  [data-pack="zaps"]    { --deep: #c0b8ff; --tint: #171a33; --tint-2: #2c2a5c; }
  [data-pack="squeaks"] { --deep: #ffb8d4; --tint: #1d1a29; --tint-2: #3b2338; }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 16px/1.6 var(--font);
  overflow-x: hidden;
}
a { color: inherit; text-underline-offset: 3px; text-decoration-color: var(--accent); text-decoration-thickness: 2px; }
a:hover { color: var(--deep); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; border-radius: 6px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }
.skip { position: absolute; left: 12px; top: -60px; z-index: 50; background: var(--btn); color: var(--btn-ink); padding: 10px 14px; border-radius: 10px; }
.skip:focus { top: 10px; }
.small { font-size: 0.875rem; line-height: 1.5; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }
kbd { font: 600 0.78rem/1 ui-monospace, Menlo, Consolas, monospace; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; padding: 2px 5px; background: var(--surface); color: var(--ink); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 10px 18px; border-radius: 14px;
  border: 1.5px solid var(--line); background: var(--surface); color: var(--ink);
  font: 650 1rem/1.1 var(--font); cursor: pointer; text-decoration: none;
  -webkit-tap-highlight-color: transparent; touch-action: manipulation;
}
.btn:hover { border-color: var(--ink-2); }
.btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.btn-primary { background: var(--btn); border-color: var(--btn); color: var(--btn-ink); }
.btn-primary:hover { background: var(--ink-2); border-color: var(--ink-2); }
.btn-ghost { background: transparent; }
.btn-sm { min-height: 44px; padding: 7px 13px; font-size: 0.92rem; border-radius: 11px; }
.btn[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #16223b; }

/* Header */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; max-width: 1160px; margin: 0 auto; padding: 10px 16px; }
.brand { display: inline-flex; align-items: center; gap: 8px; text-decoration: none; font-weight: 650; font-size: 0.98rem; min-height: 44px; }
.brand svg { width: 24px; height: 24px; color: var(--accent); }
.brand b { font-weight: 650; color: var(--muted); }

/* Intro */
.app { max-width: 1160px; margin: 0 auto; padding: 0 16px; }
.intro { padding: 2px 0 14px; }
h1 { margin: 0; font-weight: 800; }
.h1-big { display: block; font: 800 clamp(2.7rem, 11vw, 4.4rem)/0.95 var(--display); letter-spacing: -0.02em; }
.h1-sub { display: block; margin-top: 8px; font: 650 clamp(1.05rem, 4vw, 1.35rem)/1.3 var(--font); color: var(--ink-2); }
.lede { margin: 8px 0 0; color: var(--muted); max-width: 60ch; font-size: 0.95rem; line-height: 1.5; }

/* Challenge link banner */
.beat { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px; margin: 0 0 14px; padding: 12px 14px; border-radius: 16px; background: var(--surface); border: 1.5px solid var(--accent); box-shadow: var(--shadow); }
.beat[hidden] { display: none; }
.beat p { margin: 0; }
.beat-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Layout */
.play { display: grid; gap: 18px; align-items: start; }
@media (min-width: 900px) {
  .play { grid-template-columns: minmax(0, 1.5fr) minmax(300px, 1fr); gap: 24px; }
}

/* Stage */
.stage {
  position: relative; overflow: hidden; isolation: isolate;
  height: clamp(300px, 56vh, 600px); height: clamp(300px, 56svh, 600px);
  border-radius: 28px; border: 1px solid var(--line);
  background: radial-gradient(circle at 50% 52%, var(--tint-2) 0%, var(--tint) 62%);
  box-shadow: var(--shadow);
  transition: background-color 0.3s;
}
@media (min-width: 900px) { .stage { height: clamp(420px, 66vh, 620px); } }
.pad {
  position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; padding: 0; border: 0;
  background: transparent; color: inherit; border-radius: inherit; cursor: pointer; font: inherit;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
.pad:focus-visible { outline: 3px solid var(--focus); outline-offset: -7px; border-radius: 24px; }
.pad svg { display: block; width: 100%; height: 100%; overflow: visible; }
.rings circle { fill: none; stroke: var(--accent); stroke-width: 1.4; opacity: 0.32; vector-effect: non-scaling-stroke; }
.rings .ring-outer { stroke-dasharray: 3 7; opacity: 0.4; }
.shadow { fill: #16223b; opacity: 0.1; }
@media (prefers-color-scheme: dark) { .shadow { fill: #000; opacity: 0.35; } }
.body, .fill-accent { fill: var(--accent); transition: fill 0.3s; }
.shine { fill: #fff; opacity: 0.4; }
.fill-face { fill: var(--face); }
.stroke-face { stroke: var(--face); }
.glint { fill: #fff; }
.cheek { fill: #ff4d6d; opacity: 0.28; transition: opacity 0.2s; }
.ear-in { fill: #ffd0e1; }
.tongue { fill: #ff6b81; }
.bulb { fill: #c7f000; stroke: var(--face); stroke-width: 2; }
.plaster { fill: #ffe0bd; stroke: #d69a61; stroke-width: 1.2; }
.plaster-pad { fill: #f5c89a; }
.blob { transform-box: fill-box; transform-origin: 50% 100%; }
.acc, .face { display: none; }
[data-pack="ouch"] .acc-ouch, [data-pack="drums"] .acc-drums, [data-pack="zaps"] .acc-zaps, [data-pack="squeaks"] .acc-squeaks { display: inline; }
.blob[data-face="idle"] .face-idle, .blob[data-face="squint"] .face-squint, .blob[data-face="oh"] .face-oh,
.blob[data-face="ouch"] .face-ouch, .blob[data-face="star"] .face-star { display: inline; }
.blob:not([data-face="idle"]) .cheek { opacity: 0.6; }
.eyes ellipse, .eyes circle { transform-box: fill-box; transform-origin: 50% 50%; }
@media (prefers-reduced-motion: no-preference) {
  .blob[data-face="idle"] { animation: breathe 3.6s ease-in-out infinite; }
  .eyes { animation: blink 5s infinite; transform-box: fill-box; transform-origin: 50% 50%; }
}
@keyframes breathe { 50% { transform: scale(1.018, 0.985); } }
@keyframes blink { 0%, 94%, 100% { transform: scaleY(1); } 96% { transform: scaleY(0.12); } }

.fx { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 2; }
.flash { position: absolute; inset: 0; background: var(--accent); opacity: 0; pointer-events: none; z-index: 2; }

/* HUD */
.hud { position: absolute; inset: 0; pointer-events: none; z-index: 3; }
.hud-label { display: block; font: 750 0.7rem/1 var(--font); letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); }
.hud-num { display: block; font: 800 clamp(1.9rem, 7vw, 2.5rem)/1.05 var(--display); font-variant-numeric: tabular-nums; margin-top: 4px; }
.hud-hits { position: absolute; top: 16px; left: 18px; }
.hud-combo { position: absolute; top: 16px; right: 18px; text-align: right; }
.hud-combo .hud-num { color: var(--deep); }
.hud-combo[hidden], .hud-clock[hidden] { display: none; }
.hud-tier { display: block; font: 750 0.8rem/1.2 var(--display); color: var(--deep); text-transform: lowercase; min-height: 1em; }
.hud-clock { position: absolute; top: 16px; left: 50%; transform: translateX(-50%); text-align: center; }
.hud-bottom { position: absolute; left: 18px; right: 18px; bottom: 14px; text-align: center; }
.hint { margin: 0; font-size: 0.88rem; line-height: 1.35; color: var(--ink-2); text-wrap: balance; }
.bar { height: 8px; border-radius: 99px; background: rgba(22, 34, 59, 0.1); overflow: hidden; margin: 0 auto 8px; max-width: 420px; }
@media (prefers-color-scheme: dark) { .bar { background: rgba(255, 255, 255, 0.12); } }
.bar[hidden] { display: none; }
.bar span { display: block; height: 100%; background: var(--deep); transform-origin: 0 50%; transform: scaleX(1); }

/* Start gate and result card */
.gate, .result {
  position: absolute; inset: 0; z-index: 5; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; padding: 24px; text-align: center; background: var(--gate);
  -webkit-backdrop-filter: blur(7px); backdrop-filter: blur(7px);
}
.gate[hidden], .result[hidden] { display: none; }
.btn-start { min-height: 64px; padding: 14px 30px 14px 24px; font-size: 1.2rem; border-radius: 999px; box-shadow: var(--shadow); }
.btn-start svg { width: 26px; height: 26px; }
.gate-note { margin: 0; max-width: 34ch; font-size: 0.92rem; line-height: 1.45; color: var(--ink-2); }
.result { gap: 6px; }
.result p { margin: 0; }
.result-num { font: 800 clamp(3.2rem, 14vw, 4.6rem)/1 var(--display); font-variant-numeric: tabular-nums; }
.result-unit { display: block; font: 650 1rem/1.3 var(--font); color: var(--muted); margin-top: 4px; }
.result-line { font-weight: 650; color: var(--deep); min-height: 1.6em; margin: 4px 0 10px !important; }
.result-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.result-x { position: absolute; top: 10px; right: 10px; width: 44px; height: 44px; border-radius: 12px; border: 0; background: transparent; color: var(--ink); font-size: 1.8rem; line-height: 1; cursor: pointer; }
.result-x:hover { background: var(--surface-2); }

/* Under-stage actions */
.actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px; margin-top: 12px; }
.best { margin: 0; color: var(--muted); font-size: 0.95rem; white-space: nowrap; }
/* Narrow screens: button on its own row, best score centred under it, so the layout doesn't shift when the label changes. */
@media (max-width: 520px) {
  .actions #chBtn { flex: 1 1 100%; }
  .best { flex: 1 1 100%; text-align: center; }
}
.best b { color: var(--ink); font: 800 1.25rem/1 var(--display); font-variant-numeric: tabular-nums; margin: 0 2px; }
#chBtn.is-on { background: var(--surface); color: var(--ink); border-color: var(--ink-2); }

/* Settings panel */
.panel { display: grid; gap: 16px; }
.group { margin: 0; padding: 16px; border: 1px solid var(--line); border-radius: 20px; background: var(--surface); min-width: 0; }
fieldset.group > legend, .group-title {
  float: left; width: 100%; margin: 0 0 10px; padding: 0;
  font: 750 0.75rem/1.2 var(--font); letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted);
}
.packs { clear: both; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pack { position: relative; display: block; cursor: pointer; }
.pack input, .seg input { position: absolute; opacity: 0; width: 1px; height: 1px; margin: 0; }
.pack-tile {
  display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; column-gap: 10px; align-items: center;
  min-height: 64px; padding: 10px 12px; border-radius: 14px; border: 1.5px solid var(--line); background: var(--bg);
  transition: border-color 0.15s, background-color 0.15s;
}
.pack-tile svg { grid-row: 1 / 3; width: 26px; height: 26px; fill: none; stroke: var(--ink-2); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.pack-name { font-weight: 700; line-height: 1.2; }
.pack-sub { font-size: 0.78rem; color: var(--muted); line-height: 1.25; }
.pack[data-p="ouch"] { --c: #ff7a59; } .pack[data-p="drums"] { --c: #f4b740; } .pack[data-p="zaps"] { --c: #8a7dff; } .pack[data-p="squeaks"] { --c: #f58bb4; }
.pack:hover .pack-tile { border-color: var(--c); }
.pack input:checked + .pack-tile { border-color: var(--c); background: var(--tint); box-shadow: inset 0 0 0 1.5px var(--c); }
.pack input:checked + .pack-tile svg { stroke: var(--ink); fill: var(--c); fill-opacity: 0.35; }
.pack input:focus-visible + .pack-tile, .seg input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }

.sliders { display: grid; gap: 14px; }
.field { margin: 0; padding: 0; border: 0; min-width: 0; }
.field-head { display: flex; justify-content: space-between; align-items: baseline; }
.field label, .seg-field > legend { font-weight: 650; font-size: 0.95rem; padding: 0; }
.field output { font: 700 0.95rem/1 var(--display); font-variant-numeric: tabular-nums; color: var(--deep); }
.field p { margin: 4px 0 0; }
input[type="range"] { width: 100%; height: 36px; margin: 2px 0 0; accent-color: var(--deep); cursor: pointer; background: transparent; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 6px; padding: 4px; border-radius: 13px; background: var(--surface-2); }
.seg label { position: relative; display: block; cursor: pointer; }
.seg span { display: flex; align-items: center; justify-content: center; min-height: 44px; border-radius: 10px; font-weight: 650; font-size: 0.92rem; color: var(--ink-2); }
.seg input:checked + span { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(22, 34, 59, 0.15); }
@media (prefers-color-scheme: dark) { .seg input:checked + span { background: var(--line); } }

.inputs { display: grid; gap: 12px; }
.inputs .group-title { margin-bottom: 0; }
.way { display: grid; grid-template-columns: 12px 1fr; gap: 10px; align-items: start; }
.way p { margin: 0; }
.way-name { font-weight: 650; }
.way-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.way-body { min-width: 0; }
.way .small { margin-top: 2px; }
.dot { width: 10px; height: 10px; margin-top: 7px; border-radius: 50%; background: var(--line); box-shadow: inset 0 0 0 1.5px var(--muted); }
.dot.on { background: #2f9e6b; box-shadow: none; }
.dot.off { background: #d0643a; box-shadow: none; }
.meter { position: relative; height: 8px; border-radius: 99px; background: var(--surface-2); margin: 8px 0 4px; overflow: hidden; }
.meter[hidden] { display: none; }
.meter span { position: absolute; inset: 0; background: var(--deep); transform-origin: 0 50%; transform: scaleX(0); }
.meter i { position: absolute; top: 0; bottom: 0; left: 50%; width: 2px; background: var(--ink); opacity: 0.6; }

/* Text sections */
.learn { max-width: 760px; margin: 44px auto 0; }
.learn section { margin-bottom: 34px; }
.learn h2 { font: 800 clamp(1.4rem, 4.5vw, 1.75rem)/1.2 var(--display); margin: 0 0 12px; }
.learn h3 { font-size: 1.05rem; line-height: 1.35; margin: 22px 0 6px; }
.learn p { margin: 0 0 10px; color: var(--ink-2); }
.learn ol, .learn ul { margin: 0; padding-left: 1.3em; color: var(--ink-2); }
.learn li { margin-bottom: 10px; padding-left: 4px; }
.learn b { color: var(--ink); }

.foot { max-width: 1160px; margin: 20px auto 0; padding: 24px 16px 40px; border-top: 1px solid var(--line); display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px 20px; color: var(--muted); font-size: 0.92rem; }
.foot p { margin: 0; }
.foot a { color: var(--ink-2); }

.toast {
  position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); z-index: 60;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--btn); color: var(--btn-ink); padding: 10px 16px; border-radius: 12px; font-weight: 650; font-size: 0.95rem;
  transition: opacity 0.2s, transform 0.2s; box-shadow: var(--shadow); max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
}
