@font-face {
  /* Pixel-ish fallback stack only; no external font files required so the
     game still looks right when opened completely offline. */
  font-family: 'NokiaPixel';
  src: local('Courier New');
}

:root {
  --shell-dark: #2b2d26;
  --shell-mid: #46493d;
  --shell-light: #6b6f5c;
  --lcd-bg: #9aad55;
  --lcd-bg-dark: #8a9c48;
  --lcd-ink: #26311a;
  --lcd-ink-soft: #3b4a26;
  --key-shadow: rgba(0, 0, 0, 0.55);
  --accent: #cfd8b0;
  font-size: 16px;
}

* { box-sizing: border-box; }

.hidden { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
  background: #111;
  font-family: 'NokiaPixel', 'Courier New', Courier, monospace;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  touch-action: none;
}

.phone {
  position: relative;
  overflow: hidden;
  height: 100dvh;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: linear-gradient(160deg, var(--shell-mid), var(--shell-dark) 70%);
  border-left: 1px solid #55584a;
  border-right: 1px solid #1a1b16;
}

/* ===================== 70% SCREEN ===================== */

.screen-area {
  flex: 7 1 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(8px, 3vh, 20px) clamp(10px, 4vw, 24px) clamp(4px, 1.5vh, 10px);
}

.lcd {
  position: relative;
  width: 100%;
  height: 100%;
  background: radial-gradient(ellipse at 30% 20%, var(--lcd-bg) 0%, var(--lcd-bg-dark) 100%);
  border-radius: 10px;
  border: 3px solid #1c1d17;
  box-shadow:
    inset 0 0 0 2px #4a5a2c,
    inset 0 2px 14px rgba(0, 0, 0, 0.45),
    0 1px 0 rgba(255, 255, 255, 0.05);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.status-bar {
  flex: 0 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 10px 4px;
  font-size: 0.72rem;
  letter-spacing: 0.5px;
  color: var(--lcd-ink);
  font-weight: bold;
  border-bottom: 1px solid rgba(38, 49, 26, 0.25);
}

.screen-inner {
  flex: 1 1 auto;
  min-height: 0;
  position: relative;
  padding: 2px 6px 8px;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(154, 173, 85, 0.96);
  text-align: center;
  padding: 10px;
}

.overlay.hidden { display: none; }

.overlay-content.hidden { display: none; }

.overlay-content {
  color: var(--lcd-ink);
  width: 100%;
}

.logo {
  margin: 0 0 4px;
  font-size: clamp(1.4rem, 6vw, 2.1rem);
  letter-spacing: 4px;
}

.subtitle {
  margin: 0 0 12px;
  font-size: 0.75rem;
  letter-spacing: 1px;
}

.level-select {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin: 0 auto 14px;
  max-width: 300px;
}

.level-btn {
  font-family: inherit;
  font-size: 0.7rem;
  letter-spacing: 1px;
  padding: 8px 4px;
  background: transparent;
  border: 2px solid var(--lcd-ink);
  color: var(--lcd-ink);
  border-radius: 3px;
  cursor: pointer;
}

.level-btn.active {
  background: var(--lcd-ink);
  color: var(--lcd-bg);
}

.hint {
  font-size: 0.72rem;
  letter-spacing: 0.5px;
  margin: 4px 0 0;
}

.blink { animation: blink 1.1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }

.settings-group {
  margin: 0 auto 14px;
  max-width: 300px;
  text-align: left;
}

.settings-label {
  font-size: 0.62rem;
  letter-spacing: 1px;
  margin: 0 0 6px;
  opacity: 0.8;
}

.settings-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

/* Three control-mode options wrap to a second row rather than squeezing
   three columns into the same width as the two-option layout row above. */
.mode-options { grid-template-columns: 1fr 1fr; }
.mode-options .opt-btn:last-child { grid-column: 1 / -1; }

.opt-btn {
  font-family: inherit;
  font-size: 0.68rem;
  letter-spacing: 0.5px;
  padding: 9px 4px;
  background: transparent;
  border: 2px solid var(--lcd-ink);
  color: var(--lcd-ink);
  border-radius: 3px;
  cursor: pointer;
}

.opt-btn.active {
  background: var(--lcd-ink);
  color: var(--lcd-bg);
}

.settings-back { margin-top: 6px; }

/* ===================== 30% CONTROLS ===================== */

.controls-area {
  flex: 3 1 0;
  min-height: 0;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px clamp(16px, 6vw, 34px) max(10px, env(safe-area-inset-bottom));
}

/* Sized from the controls-area's own (already 100dvh-derived) height, not
   raw vh — vh alone ignores how much of that height the 70/30 split and
   padding actually leave, which clipped the pad on short/landscape screens.
   container queries (cqw/cqh) size each button from the *actual* box it
   sits in, so it stays square without the flex-basis/aspect-ratio fights
   that come from mixing flex-grow/shrink with a pinned cross-axis size. */
.dpad {
  container-type: size;
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: min(100%, 300px);
  width: 100%;
}

/* One-hand mode: full-width bars stacked top/bottom rather than a pair of
   squares docked to one side — a thumb from either hand can reach anywhere
   along the width, so it isn't handedness-specific like a side-docked pad
   would be. Plain flexbox (stretch cross-axis + flex:1 main-axis) is all
   that's needed here — no aspect-ratio, so none of the flex-basis fights
   that the square split-mode buttons need container queries to avoid. */
.dpad.stacked {
  flex-direction: column;
  align-items: stretch;
  justify-content: center;
  gap: clamp(8px, 2vh, 16px);
  width: 100%;
  max-width: 100%;
  height: min(100%, 280px);
}

.dbtn {
  flex: 0 0 auto;
  min-width: 0;
  min-height: 0;
  font-family: inherit;
  font-size: clamp(1.4rem, 6.5vh, 2.4rem);
  color: var(--accent);
  background: linear-gradient(160deg, #5b5f4d, #34362b 85%);
  border: 1px solid #1c1d17;
  border-radius: 14px;
  box-shadow:
    0 4px 0 var(--key-shadow),
    inset 0 1px 0 rgba(255, 255, 255, 0.12);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.05s ease;
}

.dbtn:active,
.dbtn.pressed {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--key-shadow), inset 0 1px 0 rgba(255, 255, 255, 0.12);
  background: linear-gradient(160deg, #6d715c, #3f4234 85%);
}

.dbtn.turn-left,
.dbtn.turn-right {
  width: min(46cqw, 96cqh);
  height: min(46cqw, 96cqh);
}

.dpad.stacked .dbtn.turn-left,
.dpad.stacked .dbtn.turn-right {
  width: auto;
  height: auto;
  flex: 1 1 0;
  min-height: 48px;
  font-size: clamp(1.2rem, 8cqh, 2rem);
}

/* Classic 4-button cross pad. A skewed middle track (giving the outer
   tracks more share) made up/down noticeably narrower than tall and
   left/right noticeably shorter than wide — reported as looking wrong.
   Equal thirds keep all four arm buttons perfectly square instead. */
.dpad4 {
  height: min(100%, 320px);
  aspect-ratio: 1 / 1;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: clamp(4px, 1vh, 8px);
}

.dpad4 .dbtn { min-width: 36px; min-height: 36px; }

.dpad4 .dbtn.up { grid-column: 2; grid-row: 1; }
.dpad4 .dbtn.left { grid-column: 1; grid-row: 2; }
.dpad4 .dbtn.right { grid-column: 3; grid-row: 2; }
.dpad4 .dbtn.down { grid-column: 2; grid-row: 3; }

.joystick {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  height: min(100%, 300px);
  width: 100%;
}

.joystick-ring {
  position: relative;
  height: 100%;
  aspect-ratio: 1 / 1;
  max-width: 100%;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #5b5f4d, #2c2e25 75%);
  border: 1px solid #1c1d17;
  box-shadow: inset 0 3px 10px rgba(0, 0, 0, 0.5), 0 3px 0 var(--key-shadow);
  touch-action: none;
  cursor: pointer;
}

.joystick-thumb {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 40%;
  height: 40%;
  border-radius: 50%;
  background: linear-gradient(160deg, var(--accent), #9aa87a);
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.4);
  transform: translate(-50%, -50%);
  transition: transform 0.15s ease;
  pointer-events: none;
}

.joystick-ring.dragging .joystick-thumb { transition: none; }

/* ===================== Dock (Pause / Sound / Settings / Menu) ===================== */

.dock-handle {
  position: absolute;
  top: 50%;
  right: 0;
  transform: translateY(-50%);
  width: 26px;
  height: 68px;
  border: 1px solid #1c1d17;
  border-right: none;
  border-radius: 10px 0 0 10px;
  background: linear-gradient(160deg, #5b5f4d, #34362b 85%);
  color: var(--accent);
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 20;
  box-shadow: -2px 0 6px rgba(0, 0, 0, 0.35);
}

.dock {
  position: absolute;
  top: 50%;
  right: 26px;
  /* translateX(100%) only clears the dock's own width — it still leaves the
     26px gap to the handle exposed, showing a sliver of the "closed" dock.
     The extra fixed offset covers that gap regardless of the dock's width
     (which varies with button label lengths / font-size breakpoints). */
  transform: translate(calc(100% + 40px), -50%);
  transition: transform 0.25s ease;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  background: linear-gradient(160deg, var(--shell-mid), var(--shell-dark) 85%);
  border: 1px solid #1c1d17;
  border-right: none;
  border-radius: 10px 0 0 10px;
  z-index: 15;
  box-shadow: -2px 0 10px rgba(0, 0, 0, 0.4);
}

.dock.open { transform: translate(0, -50%); }

.side-btn {
  min-width: 92px;
  font-family: inherit;
  font-size: 0.72rem;
  letter-spacing: 0.5px;
  color: var(--accent);
  background: linear-gradient(160deg, #5b5f4d, #34362b 85%);
  border: 1px solid #1c1d17;
  border-radius: 8px;
  padding: 10px 14px;
  box-shadow: 0 3px 0 var(--key-shadow), inset 0 1px 0 rgba(255, 255, 255, 0.12);
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  text-align: center;
  display: block;
}

.side-btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 var(--key-shadow);
}

@media (min-width: 480px) and (min-height: 700px) {
  :root { font-size: 18px; }
}
