/* ═══ Frog Circuit — premium 8-bit UI ═══ */
:root {
  --water-deep: #07222e;
  --water-mid: #0e3b4d;
  --ink: #f4f7ee;
  --ink-dim: #9db8ad;
  --lime: #8fdb43;
  --forest: #2e7d32;
  --cyan: #55e0e8;
  --pink: #ff9ecf;
  --gold: #ffd24a;
  --danger: #ff5d6c;
  --panel: rgba(7, 28, 38, 0.92);
  --panel-edge: rgba(85, 224, 232, 0.25);
  --px-font: 'Press Start 2P', monospace;
  --body-font: 'DM Sans', system-ui, sans-serif;
}

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

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--water-deep);
  font-family: var(--body-font);
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

#game-root {
  position: fixed;
  inset: 0;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#game-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.hidden { display: none !important; }

/* ─── Screens ─── */
.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: max(20px, env(safe-area-inset-top)) 20px max(20px, env(safe-area-inset-bottom));
  text-align: center;
  z-index: 30;
}
.screen.active { display: flex; }
.screen.overlay { background: rgba(4, 16, 22, 0.82); backdrop-filter: blur(3px); }

.game-logo {
  font-family: var(--px-font);
  font-size: clamp(26px, 7vw, 44px);
  line-height: 1.35;
  color: var(--lime);
  text-shadow: 0 3px 0 #1a4a1e, 0 6px 0 rgba(0,0,0,.35), 0 0 24px rgba(143, 219, 67, .35);
  letter-spacing: 2px;
}
.tagline {
  font-family: var(--px-font);
  font-size: 9px;
  color: var(--cyan);
  letter-spacing: 1px;
  margin-top: 2px;
  text-shadow: 0 0 12px rgba(85,224,232,.5);
}
.title-art canvas {
  width: 144px; height: 108px;
  image-rendering: pixelated;
  filter: drop-shadow(0 6px 12px rgba(0,0,0,.45));
}

.screen-h {
  font-family: var(--px-font);
  font-size: clamp(14px, 4vw, 20px);
  color: var(--ink);
  letter-spacing: 1px;
  text-shadow: 0 2px 0 rgba(0,0,0,.5);
}

/* ─── Buttons ─── */
.btn-col { display: flex; flex-direction: column; gap: 10px; width: min(320px, 84vw); }
.btn {
  font-family: var(--px-font);
  font-size: 11px;
  padding: 15px 18px;
  border: 2px solid var(--panel-edge);
  border-radius: 10px;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  letter-spacing: 1px;
  transition: transform .08s ease, box-shadow .12s ease, background .12s ease;
  box-shadow: 0 4px 0 rgba(0,0,0,.35);
  text-decoration: none;
  display: block;
}
.btn:hover { transform: translateY(-1px); background: rgba(14, 59, 77, .95); }
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0,0,0,.35); }
.btn-primary {
  background: linear-gradient(180deg, #9fe45c, #5cab26);
  border-color: #c6f39a;
  color: #10300b;
  text-shadow: 0 1px 0 rgba(255,255,255,.35);
  box-shadow: 0 4px 0 #2a5d1f, 0 8px 18px rgba(143,219,67,.25);
}
.btn-primary:hover { background: linear-gradient(180deg, #adf06b, #69bd2e); }
.btn-text {
  background: transparent;
  border-color: transparent;
  box-shadow: none;
  color: var(--ink-dim);
  font-size: 10px;
  padding: 10px;
}
.btn-text:hover { color: var(--ink); background: rgba(255,255,255,.06); }
.back-a { text-align: center; }

.best-row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.best-chip {
  font-family: var(--px-font);
  font-size: 8px;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(255, 210, 74, .12);
  border: 1px solid rgba(255, 210, 74, .35);
  color: var(--gold);
}
.best-chip b { color: var(--ink); }

.footer-row {
  position: absolute;
  bottom: max(14px, env(safe-area-inset-bottom));
  left: 0; right: 0;
  display: flex;
  justify-content: space-between;
  padding: 0 18px;
  font-size: 12px;
  color: var(--ink-dim);
}
.back-link { color: var(--cyan); text-decoration: none; font-weight: 700; }
.back-link:hover { text-decoration: underline; }
.ver { opacity: .5; }

/* ─── Stage select ─── */
.chapter-list {
  width: min(420px, 92vw);
  max-height: 62vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 4px;
  scrollbar-width: thin;
}
.chapter {
  border: 2px solid var(--panel-edge);
  border-radius: 12px;
  background: var(--panel);
  padding: 12px;
}
.chapter-name {
  font-family: var(--px-font);
  font-size: 9px;
  letter-spacing: 1px;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: center;
}
.stage-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.stage-btn {
  position: relative;
  aspect-ratio: 1;
  border-radius: 10px;
  border: 2px solid rgba(255,255,255,.12);
  background: rgba(255,255,255,.05);
  color: var(--ink);
  font-family: var(--px-font);
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform .08s, border-color .12s;
}
.stage-btn:hover { transform: translateY(-2px); border-color: var(--cyan); }
.stage-btn.locked { opacity: .35; cursor: not-allowed; }
.stage-btn .medal-dot { position: absolute; bottom: 3px; right: 4px; font-size: 11px; }

/* ─── Help / settings ─── */
.help-cards {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: min(420px, 92vw);
  max-height: 60vh;
  overflow-y: auto;
}
.help-card {
  display: flex;
  gap: 12px;
  align-items: center;
  text-align: left;
  background: var(--panel);
  border: 2px solid var(--panel-edge);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 14px;
  line-height: 1.5;
}
.help-ico { font-size: 26px; flex: 0 0 auto; }
.c-gold { color: var(--gold); } .c-cyan { color: var(--cyan); } .c-pink { color: var(--pink); }

.settings-box {
  width: min(360px, 88vw);
  background: var(--panel);
  border: 2px solid var(--panel-edge);
  border-radius: 12px;
  padding: 8px 16px;
}
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 0;
  border-bottom: 1px solid rgba(255,255,255,.07);
  font-weight: 500;
  font-size: 15px;
  cursor: pointer;
}
.setting-row:last-child { border-bottom: none; }
.setting-row input[type="checkbox"] { position: absolute; opacity: 0; pointer-events: none; }
.toggle {
  width: 46px; height: 26px;
  border-radius: 999px;
  background: rgba(255,255,255,.14);
  position: relative;
  transition: background .15s;
  flex: 0 0 auto;
}
.toggle::after {
  content: '';
  position: absolute;
  top: 3px; left: 3px;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--ink);
  transition: transform .15s;
}
input:checked + .toggle { background: var(--lime); }
input:checked + .toggle::after { transform: translateX(20px); background: #10300b; }
.setting-row input[type="range"] { flex: 1; max-width: 150px; accent-color: var(--lime); }

/* ─── HUD ─── */
#hud { position: absolute; inset: 0; pointer-events: none; z-index: 20; }
.hud-top {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  left: 10px; right: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.hud-left, .hud-right { display: flex; gap: 8px; align-items: center; }
.icon-btn {
  pointer-events: auto;
  width: 44px; height: 44px;
  border-radius: 10px;
  border: 2px solid var(--panel-edge);
  background: var(--panel);
  color: var(--ink);
  font-size: 17px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.icon-btn:active { transform: translateY(1px); }
.hud-chip {
  font-family: var(--px-font);
  font-size: 9px;
  background: var(--panel);
  border: 2px solid var(--panel-edge);
  padding: 12px 12px;
  border-radius: 10px;
  letter-spacing: 1px;
}
.hud-score { color: var(--gold); min-width: 86px; text-align: right; }

.hud-combo {
  position: absolute;
  top: calc(max(10px, env(safe-area-inset-top)) + 56px);
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--px-font);
  font-size: 11px;
  color: var(--gold);
  text-shadow: 0 0 14px rgba(255, 210, 74, .6), 0 2px 0 rgba(0,0,0,.5);
  animation: comboPop .25s ease;
}
@keyframes comboPop { from { transform: translateX(-50%) scale(1.5); } to { transform: translateX(-50%) scale(1); } }

.hud-grade {
  position: absolute;
  top: 34%;
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--px-font);
  font-size: clamp(14px, 4.4vw, 22px);
  letter-spacing: 2px;
  text-shadow: 0 2px 0 rgba(0,0,0,.55);
  animation: gradeFloat .8s ease forwards;
  white-space: nowrap;
}
.hud-grade.g-perfect { color: var(--gold); }
.hud-grade.g-safe { color: var(--cyan); }
.hud-grade.g-edge { color: var(--pink); }
.hud-grade.g-miss { color: var(--danger); }
@keyframes gradeFloat {
  0% { opacity: 0; transform: translateX(-50%) translateY(10px) scale(.7); }
  18% { opacity: 1; transform: translateX(-50%) translateY(0) scale(1.08); }
  30% { transform: translateX(-50%) scale(1); }
  75% { opacity: 1; }
  100% { opacity: 0; transform: translateX(-50%) translateY(-16px); }
}

.hud-banner {
  position: absolute;
  top: 22%;
  left: 50%;
  transform: translateX(-50%);
  width: min(340px, 86vw);
  background: var(--panel);
  border: 2px solid var(--cyan);
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 14px;
  line-height: 1.45;
  box-shadow: 0 8px 24px rgba(0,0,0,.4), 0 0 18px rgba(85,224,232,.15);
  animation: bannerIn .3s ease;
}
@keyframes bannerIn { from { opacity: 0; transform: translateX(-50%) translateY(-8px); } }

.hud-hint {
  position: absolute;
  bottom: max(26px, calc(env(safe-area-inset-bottom) + 14px));
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--px-font);
  font-size: 9px;
  color: var(--ink-dim);
  letter-spacing: 1px;
  animation: hintPulse 1.6s ease-in-out infinite;
  white-space: nowrap;
}
@keyframes hintPulse { 0%,100% { opacity: .5; } 50% { opacity: 1; } }

/* ─── Results ─── */
.medal { font-size: 52px; filter: drop-shadow(0 4px 10px rgba(0,0,0,.4)); animation: medalDrop .45s cubic-bezier(.2,1.6,.4,1); }
@keyframes medalDrop { from { transform: scale(2.2); opacity: 0; } }
.result-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  width: min(340px, 86vw);
}
.res {
  background: var(--panel);
  border: 2px solid var(--panel-edge);
  border-radius: 10px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.res-label { font-family: var(--px-font); font-size: 7px; color: var(--ink-dim); letter-spacing: 1px; }
.res b { font-family: var(--px-font); font-size: 14px; color: var(--ink); }
.res-tally {
  display: flex;
  gap: 12px;
  font-family: var(--px-font);
  font-size: 8px;
  color: var(--ink-dim);
  flex-wrap: wrap;
  justify-content: center;
}
.res-tally .t-perfect { color: var(--gold); }
.res-tally .t-safe { color: var(--cyan); }
.res-tally .t-edge { color: var(--pink); }
.res-tally .t-miss { color: var(--danger); }
.over-reason { color: var(--ink-dim); font-size: 14px; max-width: 300px; }

.nn-nudge {
  background: var(--panel);
  border: 2px solid var(--gold);
  border-radius: 12px;
  padding: 14px;
  width: min(320px, 84vw);
  font-size: 14px;
}
.nudge-btns { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }

/* reduced motion */
@media (prefers-reduced-motion: reduce) {
  .hud-grade, .hud-combo, .medal, .hud-banner { animation: none; }
  .hud-hint { animation: none; opacity: .8; }
  .btn, .stage-btn { transition: none; }
}
body.reduced-motion .hud-grade, body.reduced-motion .hud-combo,
body.reduced-motion .medal, body.reduced-motion .hud-banner { animation: none; }
body.reduced-motion .hud-hint { animation: none; opacity: .8; }

@media (max-height: 620px) {
  .game-logo { font-size: 24px; }
  .title-art canvas { width: 96px; height: 72px; }
  .btn { padding: 11px 14px; }
}
