:root {
  --bg: #0b1a2a;
  --panel: #0f2338;
  --panel-2: #15314f;
  --ink: #e9f3ff;
  --muted: #8ea7bf;
  --accent: #ffd34d;
  --accent-2: #76e39b;
  --danger: #ff5a6a;
  --safe-ins: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: #000;
  color: var(--ink);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  overscroll-behavior: none;
  width: 100%;
  height: 100%;
  height: 100dvh;
}

#app {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background:
    radial-gradient(1200px 800px at 50% -10%, #16304a 0%, #0b1a2a 50%, #050a12 100%);
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#stage {
  position: relative;
  width: min(100vw, calc(100dvh * 528 / 760));
  height: calc(100vw * 760 / 528);
  max-height: 100dvh;
  display: block;
  background: #000;
}

/* Keep ratio for very wide screens */
@media (min-aspect-ratio: 528/760) {
  #stage {
    width: calc(100dvh * 528 / 760);
    height: 100dvh;
  }
}

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

#hud {
  position: absolute;
  left: 0; right: 0; top: 0;
  padding: 6px 8px;
  font-size: 12px;
  letter-spacing: 1px;
  color: var(--ink);
  pointer-events: none;
  z-index: 2;
  text-shadow: 0 1px 0 #000;
}
.hud-row { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 4px; }
.hud-cell { background: rgba(0,0,0,0.45); border-radius: 6px; padding: 2px 8px; min-width: 72px; text-align: center; }
.hud-cell.wide { flex: 1; }
.hud-label { display: block; color: var(--muted); font-size: 9px; }
#hud-score, #hud-high, #hud-level, #hud-lives, #hud-frogs { font-size: 13px; color: var(--accent); }
#hud-lives { color: var(--danger); }

.timebar {
  background: #000;
  height: 10px;
  border-radius: 4px;
  overflow: hidden;
  margin-top: 2px;
  border: 1px solid #1b3a5c;
}
#timefill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, var(--accent-2), var(--accent));
  transition: width 100ms linear, background 200ms;
}
#timefill.low { background: linear-gradient(90deg, #ffb84d, var(--danger)); }

#btn-pause {
  position: absolute;
  top: 2px;
  right: 6px;
  z-index: 3;
  background: rgba(0,0,0,0.45);
  color: var(--ink);
  border: 1px solid #1b3a5c;
  width: 32px; height: 32px;
  border-radius: 50%;
  font-size: 16px;
  cursor: pointer;
  display: grid; place-items: center;
}

#dpad {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 180px;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: 1fr 1fr 1fr;
  gap: 6px;
  padding: 12px;
  z-index: 2;
  pointer-events: none;
}
#dpad.hidden { display: none; }
.dbtn {
  pointer-events: auto;
  background: rgba(15,35,56,0.65);
  border: 2px solid #244a73;
  color: var(--ink);
  font-size: 24px;
  border-radius: 14px;
  touch-action: manipulation;
  user-select: none;
  display: grid; place-items: center;
}
.dbtn:active { background: rgba(118,227,155,0.3); border-color: var(--accent-2); }
.dbtn[data-dir="up"]    { grid-column: 2; grid-row: 1; }
.dbtn[data-dir="left"]  { grid-column: 1; grid-row: 2; }
.dbtn[data-dir="down"]  { grid-column: 2; grid-row: 3; }
.dbtn[data-dir="right"] { grid-column: 3; grid-row: 2; }

.overlay {
  position: absolute;
  inset: 0;
  background: rgba(5,10,18,0.78);
  display: grid;
  place-items: center;
  z-index: 5;
  padding: 20px;
}
.overlay.hidden { display: none; }
.panel {
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  border: 2px solid #2a537f;
  border-radius: 16px;
  padding: 20px;
  max-width: 420px;
  width: 100%;
  text-align: center;
  box-shadow: 0 10px 30px rgba(0,0,0,0.6), inset 0 1px 0 rgba(255,255,255,0.08);
}
.panel.hidden { display: none; }
.panel h1 {
  margin: 4px 0 12px;
  font-size: 36px;
  letter-spacing: 2px;
  color: var(--accent);
  text-shadow: 0 2px 0 #000, 0 4px 0 #76e39b55;
  line-height: 0.95;
}
.panel h2 {
  margin: 0 0 12px;
  font-size: 22px;
  color: var(--accent);
}
.panel p { color: var(--muted); margin: 6px 0 14px; font-size: 13px; }
.panel .tagline { color: var(--accent-2); }
.panel ul { text-align: left; padding-left: 20px; font-size: 13px; line-height: 1.5; color: var(--ink); }
.panel ul b { color: var(--accent); }
.panel .credit { font-size: 10px; color: var(--muted); margin-top: 12px; }

.panel button {
  display: block;
  width: 100%;
  margin: 8px 0;
  padding: 10px 14px;
  background: #1a3a5e;
  border: 2px solid #2a537f;
  color: var(--ink);
  font-family: inherit;
  font-size: 14px;
  border-radius: 10px;
  cursor: pointer;
  letter-spacing: 1px;
}
.panel button:active { transform: translateY(1px); }
.panel button.big {
  background: linear-gradient(180deg, #ffd34d, #e2a300);
  color: #000;
  border-color: #c89100;
  font-size: 18px;
  padding: 14px;
  text-shadow: 0 1px 0 #ffe88c;
  font-weight: 800;
}
.panel .row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin: 10px 0;
  padding: 6px 2px;
  border-bottom: 1px solid #1b3a5c;
  font-size: 13px;
}
.panel select, .panel input[type=checkbox] {
  background: #0a1a2a;
  color: var(--ink);
  border: 1px solid #2a537f;
  border-radius: 6px;
  padding: 4px 6px;
  font-family: inherit;
  font-size: 13px;
}
.panel input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--accent-2); }

#go-high { color: var(--accent); font-weight: bold; }
