/* ─────────────────────────────────────────────────────────────────────────
   Instrument Detective · "What Instrument Do You Hear?"
   Prodigies teal UI + Chroma-Note family accents. Nunito, self-hosted.
   ───────────────────────────────────────────────────────────────────────── */

:root {
  --teal: #009999;
  --teal-dark: #007a7a;
  --teal-deep: #005f5f;
  --navy: #143a52;
  --ink: #1f2d38;
  --paper: #fdf9ef;
  --paper-edge: #f0e8d6;
  --cream: #fff8e8;
  --red: #E72829;
  --orange: #F39422;
  --yellow: #FFD25B;
  --green: #6AB845;
  --blue: #2A57A9;
  --purple: #7B569E;
  --pink: #EA6BA3;
  --shadow: 0 10px 30px rgba(20, 58, 82, 0.18);
  --radius: 22px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: 'Nunito', system-ui, sans-serif;
  background: var(--paper);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

button { font-family: inherit; cursor: pointer; }
button:focus-visible, a:focus-visible, [tabindex]:focus-visible {
  outline: 3px solid var(--orange);
  outline-offset: 2px;
}

.app {
  position: fixed;
  inset: 0;
  top: 44px; /* below pk5 game bar */
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.screen { position: absolute; inset: 0; display: none; }
.screen.active { display: flex; }

/* ── Title screen ─────────────────────────────────────────────────────── */
.title-screen {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 24px;
  background:
    radial-gradient(1200px 500px at 50% -10%, rgba(0,153,153,0.16), transparent 60%),
    radial-gradient(900px 420px at 15% 110%, rgba(243,148,34,0.12), transparent 60%),
    radial-gradient(900px 420px at 85% 110%, rgba(123,86,158,0.12), transparent 60%),
    var(--paper);
  text-align: center;
  overflow: auto;
}
.title-kicker {
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 4px;
  text-transform: uppercase;
  color: var(--teal-dark);
  margin: 0;
}
.title-main {
  font-size: clamp(34px, 6vw, 64px);
  font-weight: 900;
  line-height: 1.04;
  color: var(--navy);
  margin: 0;
  max-width: 15ch;
}
.title-main .q { color: var(--teal); }
.title-sub {
  font-size: clamp(15px, 2.2vw, 19px);
  font-weight: 600;
  color: #4d6273;
  max-width: 46ch;
  margin: 0;
}
.title-detective {
  width: clamp(110px, 16vw, 170px);
  height: auto;
  filter: drop-shadow(0 10px 18px rgba(20,58,82,0.22));
}
.title-actions { display: flex; flex-direction: column; gap: 12px; align-items: center; margin-top: 6px; }
.btn {
  border: none;
  border-radius: 999px;
  font-weight: 900;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
}
.btn:active { transform: scale(0.96); }
.btn-primary {
  background: var(--teal);
  color: #fff;
  font-size: 22px;
  padding: 18px 58px;
  box-shadow: 0 8px 0 var(--teal-deep), var(--shadow);
}
.btn-primary:hover { background: #00a8a8; }
.btn-primary:active { box-shadow: 0 3px 0 var(--teal-deep); transform: translateY(4px); }
.btn-ghost {
  background: #fff;
  color: var(--teal-dark);
  border: 2.5px solid rgba(0,153,153,0.4);
  font-size: 15px;
  font-weight: 800;
  padding: 10px 26px;
}
.btn-ghost:hover { border-color: var(--teal); background: #f4fbfb; }
.title-ghost-row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }

/* ── Map select ───────────────────────────────────────────────────────── */
.select-screen {
  flex-direction: column;
  align-items: center;
  padding: 28px 20px 40px;
  overflow-y: auto;
  background: var(--paper);
}
.select-head { text-align: center; margin-bottom: 22px; }
.select-title { font-size: clamp(26px, 4vw, 38px); font-weight: 900; color: var(--navy); margin: 0 0 6px; }
.select-sub { font-size: 15px; font-weight: 600; color: #4d6273; margin: 0; }
.map-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 340px));
  gap: 22px;
  justify-content: center;
  width: 100%;
  max-width: 1150px;
}
.map-card {
  background: #fff;
  border: none;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  text-align: left;
  padding: 0;
  display: flex;
  flex-direction: column;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  position: relative;
}
.map-card:not(.locked):hover { transform: translateY(-4px); box-shadow: 0 16px 38px rgba(20,58,82,0.26); }
.map-card-thumb {
  height: 170px;
  background-size: cover;
  background-position: center 25%;
  position: relative;
}
.map-card.locked .map-card-thumb {
  background: repeating-linear-gradient(45deg, #e9e2d2, #e9e2d2 14px, #f2ecdd 14px, #f2ecdd 28px);
  display: flex; align-items: center; justify-content: center;
}
.map-card-lock { font-size: 40px; opacity: 0.55; }
.map-diff {
  position: absolute; top: 12px; left: 12px;
  background: rgba(255,255,255,0.94);
  border-radius: 999px;
  padding: 5px 14px;
  font-size: 12px; font-weight: 900; letter-spacing: 1px; text-transform: uppercase;
  color: var(--teal-dark);
}
.map-diff.d2 { color: var(--orange); }
.map-diff.d3 { color: var(--purple); }
.map-card-body { padding: 16px 18px 18px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.map-card-title { font-size: 21px; font-weight: 900; color: var(--navy); margin: 0; }
.map-card-sub { font-size: 13.5px; font-weight: 600; color: #5a6e7e; margin: 0; }
.map-card-progress { display: flex; align-items: center; gap: 10px; margin-top: auto; padding-top: 10px; }
.map-progress-track {
  flex: 1; height: 10px; border-radius: 99px; background: #ede6d5; overflow: hidden;
}
.map-progress-fill { height: 100%; border-radius: 99px; background: linear-gradient(90deg, var(--teal), #35c1b2); width: 0%; transition: width 0.4s ease; }
.map-progress-label { font-size: 12.5px; font-weight: 800; color: var(--teal-dark); white-space: nowrap; }
.map-card.locked { opacity: 0.85; cursor: default; }
.map-card.done .map-progress-fill { background: linear-gradient(90deg, var(--green), #8fd06f); }
.select-footer { margin-top: 26px; display: flex; gap: 12px; }

/* ── Investigation screen ─────────────────────────────────────────────── */
.invest-screen { flex-direction: column; background: #0d2231; }
.map-viewport {
  position: relative;
  flex: 1;
  overflow: hidden;
  touch-action: none;
  cursor: zoom-in; /* magnifying glass: zooming (pinch/wheel/buttons) is the next move */
  background: #0d2231;
}
.map-viewport.zoomed { cursor: grab; }
.map-viewport.zoomed.dragging { cursor: grabbing; }
.map-world {
  position: absolute;
  top: 0; left: 0;
  transform-origin: 0 0;
  will-change: transform;
}
.map-world img.map-img {
  display: block;
  width: 100%; height: 100%;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}
.map-world.freeze { transition: transform 0.85s cubic-bezier(0.22, 0.9, 0.3, 1); }

.map-target {
  position: absolute;
  background: transparent;
  border: none;
  border-radius: 18px;
  padding: 0;
  transform: translate(-50%, -50%);
  -webkit-tap-highlight-color: transparent;
}
.map-target:focus-visible { outline: 3px dashed #fff; outline-offset: -3px; }
.dev .map-target { outline: 2px solid rgba(0, 255, 170, 0.9); background: rgba(0,255,170,0.12); }
.dev .map-decoy { outline: 2px dashed rgba(255, 80, 80, 0.9); background: rgba(255,80,80,0.10); }
.dev .map-target::after, .dev .map-decoy::after {
  content: attr(data-dev);
  position: absolute; top: -18px; left: 0;
  font-size: 11px; font-weight: 800; color: #fff;
  background: rgba(0,0,0,0.65); padding: 1px 6px; border-radius: 6px;
  white-space: nowrap;
}

.hint-region {
  position: absolute;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  border: 4px dashed rgba(255, 210, 91, 0.95);
  background: radial-gradient(closest-side, rgba(255,210,91,0.18), rgba(255,210,91,0.02));
  pointer-events: none;
  animation: hintPulse 1.8s ease-in-out infinite;
}
@keyframes hintPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255,210,91,0.35); }
  50% { box-shadow: 0 0 0 18px rgba(255,210,91,0); }
}

.found-ring {
  position: absolute;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  border: 5px solid #fff;
  box-shadow: 0 0 0 6px rgba(0,153,153,0.65), 0 0 40px 10px rgba(255,255,255,0.45);
  pointer-events: none;
  animation: foundPop 0.55s cubic-bezier(0.2, 1.6, 0.4, 1);
}
@keyframes foundPop { from { transform: translate(-50%, -50%) scale(0.3); opacity: 0; } }

.wrong-ripple {
  position: absolute;
  width: 60px; height: 60px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  border: 4px solid rgba(255,255,255,0.9);
  pointer-events: none;
  animation: rippleOut 0.6s ease-out forwards;
}
@keyframes rippleOut { to { transform: translate(-50%, -50%) scale(2.4); opacity: 0; } }

/* Map controls (zoom) */
.map-controls {
  position: absolute;
  right: 14px; top: 14px;
  display: flex; flex-direction: column; gap: 8px;
  z-index: 5;
}
.map-ctl-btn {
  width: 46px; height: 46px;
  border-radius: 14px;
  border: none;
  background: rgba(255,255,255,0.95);
  color: var(--navy);
  font-size: 22px;
  font-weight: 900;
  box-shadow: 0 4px 14px rgba(0,0,0,0.28);
  display: flex; align-items: center; justify-content: center;
}
.map-ctl-btn:hover { background: #fff; }
.map-ctl-btn svg { width: 22px; height: 22px; }

/* Top-left round chip */
.round-chip {
  position: absolute;
  left: 14px; top: 14px;
  z-index: 5;
  background: rgba(255,255,255,0.95);
  border-radius: 999px;
  padding: 9px 18px;
  font-size: 13.5px;
  font-weight: 900;
  color: var(--navy);
  box-shadow: 0 4px 14px rgba(0,0,0,0.28);
  display: flex; align-items: center; gap: 10px;
}
.round-chip .stars { color: var(--orange); letter-spacing: 1px; }

/* ── Mystery dock ─────────────────────────────────────────────────────── */
.dock {
  position: relative;
  z-index: 6;
  background: #fff;
  border-top: 4px solid var(--teal);
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  box-shadow: 0 -8px 26px rgba(13, 34, 49, 0.35);
}
.dock-question {
  font-size: clamp(15px, 2.1vw, 20px);
  font-weight: 900;
  color: var(--navy);
  letter-spacing: 0.4px;
  flex: 1 1 220px;
  min-width: 180px;
}
.dock-question .q-mark { color: var(--teal); }
.dock-center { display: flex; align-items: center; gap: 10px; flex: 0 0 auto; }
.play-btn {
  position: relative;
  background: var(--teal);
  color: #fff;
  border: none;
  border-radius: 999px;
  font-size: 18px;
  font-weight: 900;
  padding: 14px 34px 14px 28px;
  display: flex; align-items: center; gap: 10px;
  box-shadow: 0 6px 0 var(--teal-deep);
}
.play-btn:hover { background: #00a8a8; }
.play-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 var(--teal-deep); }
.play-btn.playing { background: var(--orange); box-shadow: 0 6px 0 #b96d12; }
.play-btn .icon { width: 20px; height: 20px; }
.play-btn .eq { display: none; gap: 3px; align-items: flex-end; height: 18px; }
.play-btn.playing .eq { display: flex; }
.play-btn.playing .icon-play { display: none; }
.eq span { width: 4px; background: #fff; border-radius: 2px; animation: eqBounce 0.7s ease-in-out infinite; }
.eq span:nth-child(1) { height: 8px; }
.eq span:nth-child(2) { height: 16px; animation-delay: 0.15s; }
.eq span:nth-child(3) { height: 11px; animation-delay: 0.3s; }
@keyframes eqBounce { 0%, 100% { transform: scaleY(0.5); } 50% { transform: scaleY(1); } }

.dock-btn {
  background: #fff;
  border: 2.5px solid #d9d2c0;
  color: var(--navy);
  border-radius: 999px;
  font-size: 14.5px;
  font-weight: 800;
  padding: 11px 20px;
  display: flex; align-items: center; gap: 7px;
}
.dock-btn:hover { border-color: var(--teal); color: var(--teal-dark); }
.dock-btn .icon { width: 17px; height: 17px; }
.dock-right { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.dock-progress { font-size: 13px; font-weight: 800; color: #5a6e7e; white-space: nowrap; }

/* Feedback bubble (wrong answer / hints) */
.bubble {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 12px);
  transform: translateX(-50%);
  width: min(560px, calc(100vw - 32px));
  background: var(--cream);
  border: 3px solid var(--yellow);
  border-radius: 18px;
  padding: 14px 44px 14px 18px;
  font-size: 15.5px;
  font-weight: 700;
  line-height: 1.45;
  color: var(--ink);
  box-shadow: 0 12px 30px rgba(13,34,49,0.35);
  z-index: 7;
  animation: bubbleIn 0.25s cubic-bezier(0.2, 1.4, 0.4, 1);
}
.bubble.hint { background: #eef9f9; border-color: var(--teal); }
.bubble .bubble-tag {
  display: inline-block;
  font-size: 11px; font-weight: 900; letter-spacing: 2px; text-transform: uppercase;
  color: var(--orange); margin-bottom: 4px;
}
.bubble.hint .bubble-tag { color: var(--teal-dark); }
/* A close button is the one control a stuck child needs to hit first time. */
.bubble-close {
  min-width: 44px;
  min-height: 44px;
  position: absolute; top: 8px; right: 8px;
  width: 30px; height: 30px;
  border: none; border-radius: 50%;
  background: rgba(20,58,82,0.08);
  color: var(--navy);
  font-size: 16px; font-weight: 900;
  display: flex; align-items: center; justify-content: center;
}
.bubble-replay {
  margin-top: 8px;
  background: var(--teal); color: #fff; border: none;
  border-radius: 999px; font-size: 13.5px; font-weight: 900;
  padding: 8px 18px;
}
@keyframes bubbleIn { from { opacity: 0; transform: translateX(-50%) translateY(10px); } }

/* ── Celebration overlay ──────────────────────────────────────────────── */
.celebrate {
  position: absolute; inset: 0;
  z-index: 20;
  display: none;
  align-items: flex-end;
  justify-content: center;
  padding: 18px;
  pointer-events: none;
}
.celebrate.show { display: flex; }
.celebrate-card {
  pointer-events: auto;
  background: #fff;
  border-radius: 24px;
  box-shadow: 0 24px 60px rgba(13,34,49,0.5);
  width: min(620px, 100%);
  padding: 20px 22px;
  border-top: 8px solid var(--fam-color, var(--teal));
  animation: cardUp 0.45s cubic-bezier(0.2, 1.3, 0.4, 1);
  margin-bottom: 6px;
}
@keyframes cardUp { from { opacity: 0; transform: translateY(40px) scale(0.96); } }
.celebrate-head { display: flex; align-items: center; gap: 14px; }
.celebrate-stamp {
  width: 64px; height: 64px; flex: 0 0 64px;
  border-radius: 50%;
  background: var(--fam-soft, #eef9f9);
  border: 3px solid var(--fam-color, var(--teal));
  display: flex; align-items: center; justify-content: center;
  animation: stampIn 0.5s cubic-bezier(0.2, 1.8, 0.4, 1) 0.15s backwards;
}
.celebrate-stamp svg { width: 36px; height: 36px; }
@keyframes stampIn { from { transform: scale(0) rotate(-30deg); } }
.celebrate-title { font-size: clamp(20px, 3vw, 26px); font-weight: 900; color: var(--navy); margin: 0; }
.celebrate-family {
  display: inline-block;
  margin-top: 4px;
  background: var(--fam-color, var(--teal));
  color: var(--fam-ink, #fff);
  border-radius: 999px;
  font-size: 12px; font-weight: 900; letter-spacing: 1.5px; text-transform: uppercase;
  padding: 4px 14px;
}
.celebrate-clue { font-size: 15px; font-weight: 700; color: #40566a; line-height: 1.5; margin: 12px 0 0; }
.celebrate-actions { display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.celebrate-actions .btn-primary { font-size: 17px; padding: 13px 34px; flex: 1; min-width: 170px; }
.celebrate-actions .dock-btn { flex: 0 0 auto; }

/* Map-complete variant */
.celebrate-card.map-done { text-align: center; border-top-color: var(--orange); }
.celebrate-card.map-done .celebrate-title { font-size: clamp(24px, 4vw, 32px); }
.stamp-row { display: flex; justify-content: center; gap: 6px; font-size: 30px; margin: 10px 0 2px; }

/* Confetti stars */
.confetti {
  position: absolute;
  width: 14px; height: 14px;
  pointer-events: none;
  z-index: 21;
  animation: confettiFall 1.4s ease-in forwards;
}
@keyframes confettiFall {
  0% { opacity: 1; transform: translate(0, 0) rotate(0deg) scale(1); }
  100% { opacity: 0; transform: translate(var(--cx), var(--cy)) rotate(540deg) scale(0.4); }
}

/* ── Notebook ─────────────────────────────────────────────────────────── */
.overlay {
  position: fixed; inset: 0;
  z-index: 40;
  background: rgba(13, 34, 49, 0.55);
  display: none;
  align-items: center; justify-content: center;
  padding: 20px;
}
.overlay.show { display: flex; }
.overlay-card {
  background: var(--paper);
  border-radius: 26px;
  box-shadow: 0 30px 80px rgba(0,0,0,0.45);
  width: min(860px, 100%);
  max-height: min(86vh, 720px);
  display: flex; flex-direction: column;
  overflow: hidden;
  animation: cardUp 0.35s cubic-bezier(0.2, 1.3, 0.4, 1);
}
.overlay-head {
  display: flex; align-items: center; gap: 12px;
  padding: 18px 22px 12px;
}
.overlay-title { font-size: 24px; font-weight: 900; color: var(--navy); margin: 0; flex: 1; }
.overlay-sub { font-size: 13.5px; font-weight: 700; color: #5a6e7e; padding: 0 22px 12px; margin: 0; }
.overlay-close {
  width: 40px; height: 40px;
  border: none; border-radius: 50%;
  background: rgba(20,58,82,0.08);
  color: var(--navy); font-size: 19px; font-weight: 900;
}
.overlay-body { overflow-y: auto; padding: 4px 22px 24px; }

.notebook-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(215px, 1fr));
  gap: 14px;
}
.notebook-card {
  background: #fff;
  border-radius: 18px;
  padding: 14px 16px;
  border-left: 6px solid var(--fam-color, #ccc);
  box-shadow: 0 4px 14px rgba(20,58,82,0.10);
  display: flex; flex-direction: column; gap: 6px;
}
.notebook-card.undiscovered {
  background: repeating-linear-gradient(45deg, #f4efe2, #f4efe2 10px, #faf6ea 10px, #faf6ea 20px);
  border-left-color: #d9d2c0;
  color: #a09a8a;
}
.notebook-card-name { font-size: 16.5px; font-weight: 900; color: var(--navy); }
.notebook-card.undiscovered .notebook-card-name { color: #a09a8a; }
.notebook-card-family { font-size: 11px; font-weight: 900; letter-spacing: 1.5px; text-transform: uppercase; color: var(--fam-color, #999); }
.notebook-card-clue { font-size: 13px; font-weight: 600; color: #5a6e7e; line-height: 1.4; }
.notebook-card-play {
  align-self: flex-start;
  margin-top: 4px;
  background: var(--fam-soft, #eef9f9);
  color: var(--navy);
  border: 2px solid var(--fam-color, var(--teal));
  border-radius: 999px;
  font-size: 12.5px; font-weight: 900;
  padding: 6px 16px;
  display: flex; align-items: center; gap: 6px;
}
.notebook-card-play .icon { width: 13px; height: 13px; }

/* ── Settings ─────────────────────────────────────────────────────────── */
.settings-row {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  background: #fff; border-radius: 16px; padding: 14px 18px; margin-bottom: 12px;
  box-shadow: 0 3px 10px rgba(20,58,82,0.08);
}
.settings-label { font-size: 15.5px; font-weight: 800; color: var(--navy); }
.settings-note { font-size: 12.5px; font-weight: 600; color: #7a8a97; margin-top: 2px; }
input[type="range"].vol { width: 170px; accent-color: var(--teal); }
.toggle { position: relative; width: 56px; height: 32px; flex: 0 0 56px; }
.toggle input { opacity: 0; width: 100%; height: 100%; position: absolute; margin: 0; cursor: pointer; }
.toggle-track {
  position: absolute; inset: 0; border-radius: 99px;
  background: #d9d2c0; transition: background 0.15s;
  pointer-events: none;
}
.toggle input:checked + .toggle-track { background: var(--teal); }
.toggle-thumb {
  position: absolute; top: 4px; left: 4px;
  width: 24px; height: 24px; border-radius: 50%;
  background: #fff; box-shadow: 0 2px 6px rgba(0,0,0,0.25);
  transition: left 0.15s;
  pointer-events: none;
}
.toggle input:checked ~ .toggle-thumb { left: 28px; }
.danger-btn {
  background: #fff; border: 2.5px solid #e5b5b5; color: #b03434;
  border-radius: 999px; font-size: 13.5px; font-weight: 800; padding: 9px 20px;
}
.danger-btn:hover { border-color: #d06060; background: #fdf4f4; }

/* ── Toast ────────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  top: 58px; left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  background: var(--navy);
  color: #fff;
  font-size: 14px; font-weight: 800;
  border-radius: 999px;
  padding: 10px 24px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}
.toast.show { opacity: 1; }

/* ── Reduced motion ───────────────────────────────────────────────────── */
.reduce-motion *, .reduce-motion *::before, .reduce-motion *::after {
  animation-duration: 0.01s !important;
  transition-duration: 0.01s !important;
}
@media (prefers-reduced-motion: reduce) {
  .map-world.freeze { transition-duration: 0.01s; }
}

/* ── Small screens ────────────────────────────────────────────────────── */
@media (max-width: 720px) {
  .dock { gap: 8px; padding: 10px 10px calc(10px + env(safe-area-inset-bottom)); }
  .dock-question { flex-basis: 100%; text-align: center; font-size: 15px; }
  .dock-center { flex: 1; justify-content: center; }
  .play-btn { font-size: 16px; padding: 12px 22px; }
  .dock-btn { font-size: 13px; padding: 10px 14px; }
  .dock-right { margin-left: 0; flex: 1; justify-content: center; }
  .map-controls { right: 10px; top: 10px; }
  .map-ctl-btn { width: 42px; height: 42px; }
  .round-chip { left: 10px; top: 10px; font-size: 12px; padding: 7px 13px; }
}
