/* GAMEBOYO — original console shell. Studio palette only: near-black body,
   ink text, one acid-green accent. No Nintendo purple, no borrowed logos. */
:root {
  --bg: #05060a;
  --panel: #0e0e14;
  --panel2: #16161c;
  --ink: #e8f0ee;
  --dim: #8a8a94;
  --line: #2a2a33;
  --acid: #7cff4f;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  overscroll-behavior: none;
}

#app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 16px;
}

#console {
  position: relative;
  background: linear-gradient(180deg, var(--panel), #0a0a0f);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 18px 18px 22px;
  outline: none;
  display: grid;
  grid-template-columns: minmax(84px, auto) 1fr minmax(84px, auto);
  grid-template-rows: auto auto;
  grid-template-areas: "dpad scr ab" ".    ss  .";
  gap: 14px 10px;
  align-items: center;
  justify-items: center;
  width: min(94vw, 1040px);
  box-shadow: 0 10px 40px rgba(0, 0, 0, .5);
}
#console:focus-visible { box-shadow: 0 0 0 2px var(--acid), 0 10px 40px rgba(0, 0, 0, .5); }

#wordmark {
  position: absolute;
  bottom: -2px;
  left: 50%;
  transform: translate(-50%, 100%);
  font-weight: 800;
  letter-spacing: .22em;
  font-size: 13px;
  color: var(--dim);
  padding-top: 6px;
}

/* The wrap hugs the canvas; shell.js's fitScreen() computes the integer
   scale from the *other*, canvas-independent boxes around it (the dpad/ab
   columns, the startsel row, the viewport) so sizing never feeds back into
   itself and gets stuck at 1x. */
#screen-wrap {
  grid-area: scr;
  position: relative;
  background: #000;
  border-radius: 6px;
  padding: 8px;
  border: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
}
#screen {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  touch-action: none;
  background: var(--bg);
}
#unfocused-hint {
  position: absolute;
  inset: 8px;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, .78);
  color: var(--acid);
  font-weight: 700;
  letter-spacing: .14em;
  font-size: clamp(11px, 2.6vmin, 15px);
  text-align: center;
  pointer-events: none;
  border-radius: 4px;
}
#console:not(:focus-within) #unfocused-hint { display: flex; }

/* Shoulders sit at the top corners of the body regardless of breakpoint. */
.shoulder {
  position: absolute;
  top: 8px;
  min-width: 46px;
  min-height: 44px;
  border-radius: 8px;
  background: var(--panel2);
  color: var(--dim);
  border: 1px solid var(--line);
  font: 700 12px/1 inherit;
  letter-spacing: .08em;
  touch-action: none;
}
.shoulder:active, .shoulder.is-down { background: #1f1f28; color: var(--acid); }
#l { left: 8px; }
#r { right: 8px; }

#dpad-wrap { grid-area: dpad; display: flex; align-items: center; justify-content: center; }
#dpad {
  position: relative;
  width: clamp(134px, 30vmin, 150px);
  height: clamp(134px, 30vmin, 150px);
  touch-action: none;
  background:
    linear-gradient(var(--panel2), var(--panel2)) center / 34% 100% no-repeat,
    linear-gradient(var(--panel2), var(--panel2)) center / 100% 34% no-repeat;
  border-radius: 8px;
}
#dpad::after {
  content: "";
  position: absolute; inset: 42%;
  background: #0a0a0f;
  border-radius: 3px;
}
#dpad .arrow {
  position: absolute;
  color: var(--dim);
  font-size: 16px;
  pointer-events: none;
}
#dpad .arrow.up { top: 6%; left: 50%; transform: translateX(-50%); }
#dpad .arrow.down { bottom: 6%; left: 50%; transform: translateX(-50%); }
#dpad .arrow.left { left: 6%; top: 50%; transform: translateY(-50%); }
#dpad .arrow.right { right: 6%; top: 50%; transform: translateY(-50%); }

#ab-wrap { grid-area: ab; display: flex; align-items: center; justify-content: center; gap: 12px; }
.round {
  width: clamp(46px, 12vmin, 58px);
  height: clamp(46px, 12vmin, 58px);
  border-radius: 50%;
  background: var(--panel2);
  color: var(--acid);
  border: 1px solid var(--line);
  font: 800 15px/1 inherit;
  touch-action: none;
}
#b { transform: translateY(10px); }
.round:active, .round.is-down { background: #1f1f28; box-shadow: 0 0 0 2px var(--acid) inset; }

#startsel {
  grid-area: ss;
  display: flex;
  gap: 14px;
}
.pill {
  min-width: 60px;
  min-height: 44px;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--panel2);
  color: var(--dim);
  border: 1px solid var(--line);
  font: 700 10px/1 inherit;
  letter-spacing: .1em;
  touch-action: none;
}
.pill:active, .pill.is-down { color: var(--acid); }

button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:focus-visible { outline: 2px solid var(--acid); outline-offset: 2px; }

#keymap {
  font-size: 12px;
  color: var(--dim);
  max-width: 760px;
  text-align: center;
  line-height: 1.6;
}
#keymap b { color: var(--ink); }

/* Portrait phones: reflow to screen-on-top, controls below, so the whole
   console fits without page scroll and buttons stay >= 44px. */
@media (max-aspect-ratio: 1/1) {
  #app { gap: 8px; padding: 8px; }
  #console {
    width: min(96vw, 420px);
    padding: 14px 10px 16px;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto auto;
    grid-template-areas: "scr scr" "dpad ab" "ss  ss";
    gap: 10px;
  }
  #screen-wrap { padding: 6px; }
  #dpad { width: clamp(134px, 32vmin, 150px); height: clamp(134px, 32vmin, 150px); }
  #wordmark { display: none; }
  #keymap { display: none; }
}

/* Very short viewports (landscape phones): trim vertical chrome further and
   size the screen from the scarce dimension (height), not width. */
@media (max-height: 420px) {
  #app { padding: 6px; gap: 4px; }
  #console { padding: 10px 44px 12px; gap: 6px 10px; }
  #wordmark { display: none; }
  #keymap { display: none; }
  .shoulder { top: 4px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}
