:root {
  --ink: #17202e;
  --paper: #ffffff;
  --muted: #5b6575;
  --accent: #ff6b3d;
  --gold: #ffd23f;
  --shadow: 0 12px 34px rgba(10, 20, 40, 0.28);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #9ad8ff;
  color: var(--ink);
  font-family: system-ui, "Segoe UI", Roboto, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.app {
  position: fixed;
  inset: 0;
  pointer-events: none;
}

.top {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  padding: 10px 14px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  pointer-events: none;
}

.lvl-name {
  font-weight: 800;
  font-size: clamp(16px, 3.6vw, 20px);
  color: #fff;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}

.lvl-sub,
.lvl-env {
  font-size: 13px;
  color: #fff;
  max-width: 62vw;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}

.chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
  pointer-events: auto;
}

.chip {
  background: rgba(10, 20, 40, 0.6);
  color: #fff;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.chip-star { color: var(--gold); }

.sound-btn {
  background: rgba(10, 20, 40, 0.6);
  color: #fff;
  border: 0;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  min-height: 30px;
}

.toast {
  position: absolute;
  top: 88px;
  left: 50%;
  transform: translate(-50%, -8px);
  opacity: 0;
  transition: opacity 0.25s ease, transform 0.25s ease;
  font-size: clamp(24px, 6vw, 44px);
  font-weight: 900;
  color: #fff;
  text-shadow: 0 4px 0 #0a1a2e, 0 0 18px rgba(0, 0, 0, 0.4);
  white-space: nowrap;
  pointer-events: none;
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.tone-hit { color: #7dffb0; }
.toast.tone-miss { color: #ffe7b3; }

.panel {
  position: absolute;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: min(100%, 780px);
  padding: 12px 14px calc(12px + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, 0.96);
  border-radius: 18px 18px 0 0;
  box-shadow: var(--shadow);
  pointer-events: auto;
}

.controls {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 10px;
  align-items: end;
}

.slider {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 13px;
  font-weight: 700;
}

.slider input { width: 100%; }

.slider-val {
  font-weight: 600;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.fire-btn,
.card button.primary {
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 14px;
  font-weight: 800;
  font-size: 17px;
  padding: 12px 18px;
  min-height: 48px;
  cursor: pointer;
}

.fire-btn:disabled { opacity: 0.45; cursor: default; }

.table-wrap {
  margin-top: 8px;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.trow {
  display: grid;
  grid-template-columns: 1.7fr 1fr 1fr;
  gap: 6px;
  padding: 3px 0;
  border-bottom: 1px solid #e7ebf2;
}

.thead { font-weight: 800; color: var(--muted); }
.td.real { font-weight: 800; color: #c2410c; }

.live {
  min-height: 18px;
  margin-top: 6px;
  font-size: 13px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.help {
  margin: 6px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.app:not(.playing) .top,
.app:not(.playing) .panel {
  visibility: hidden;
}

.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(8, 16, 30, 0.55);
  pointer-events: auto;
  z-index: 10;
}

.overlay[hidden] { display: none; }

.card {
  width: min(92vw, 540px);
  max-height: 90vh;
  overflow: auto;
  background: var(--paper);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 22px 24px;
}

.card h1 { margin: 0 0 8px; font-size: clamp(28px, 6vw, 40px); line-height: 1.1; }
.card h2 { margin: 0 0 10px; font-size: clamp(22px, 4.5vw, 30px); line-height: 1.15; }
.card p { margin: 8px 0; line-height: 1.45; }
.card .kicker {
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 12px;
  font-weight: 800;
  color: var(--accent);
}
.card .lead { font-size: 18px; font-weight: 700; }
.card .muted { color: var(--muted); font-size: 14px; }
.card .fact {
  background: #f3f6fb;
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 14px;
}
.card .learned { padding-left: 20px; line-height: 1.6; }

.stars {
  font-size: 40px;
  letter-spacing: 6px;
  margin: 4px 0 8px;
}
.stars .on { color: var(--gold); text-shadow: 0 2px 0 #c58d00; }
.stars .off { color: #d7dde7; }

.card button.primary { width: 100%; margin-top: 12px; }

button:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
}

@media (max-width: 640px) {
  .controls { grid-template-columns: 1fr 1fr; }
  .fire-btn { grid-column: 1 / -1; }
  .table-wrap { font-size: 12px; }
  .trow { grid-template-columns: 1.6fr 1fr 1fr; }
  .help,
  .lvl-env { display: none; }
  .panel { width: 100%; padding-left: 12px; padding-right: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .toast { transition: none; }
}
