/* =============================================================================
 *  HIROSHI WORLD — style.css
 *  Clean page, retro pixel game screen, Pokémon-DS (Diamond·Pearl) textbox.
 *  No fake handheld shell — just the game.
 * ========================================================================== */
:root {
  --ds-blue: #2f6fd0; --ds-blue-lt: #bcd8f5; --ds-blue-dk: #1d4f9e;
  --paper: #fbfdff; --ink: #2a3a4a; --dim: #6f86a0;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

html, body {
  min-height: 100%;
  font-family: 'Press Start 2P', 'Courier New', monospace;
  background:
    radial-gradient(circle at 50% -10%, #2b2f3c, #14161d 70%),
    #14161d;
  color: #e7ecf5;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden; touch-action: manipulation; user-select: none;
  overscroll-behavior: none;            /* curb pull-to-refresh / swipe-nav */
  -webkit-tap-highlight-color: transparent;
}
/* Pin the page to the viewport so the keyboard can't scroll/pan it and leave
 * the layout shifted to one side when the chat input is focused on iOS. */
body { position: fixed; inset: 0; }

#app {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  /* A definite, keyboard-stable height. 100dvh tracks the mobile toolbars but
   * (unlike the visual viewport) does NOT shrink when the keyboard opens, so the
   * game never rescales / shifts mid-chat. 100vh is the fallback. */
  height: 100vh; height: 100dvh;
  padding: 10px 10px max(10px, env(safe-area-inset-bottom));
}

/* ---- title -------------------------------------------------------------- */
#titlebar { width: 100%; display: flex; align-items: center; justify-content: space-between; }
#title {
  font-size: 13px; letter-spacing: 2px; color: #ffd84d;
  text-shadow: 0 2px 0 #b8350f, 2px 0 0 #00000040;
}
#toggles button {
  font-family: inherit; font-size: 12px; cursor: pointer; line-height: 1;
  background: #232733; color: #cdd6e6; border: 1px solid #39405200;
  border-radius: 7px; padding: 5px 7px; margin-left: 6px;
}
#toggles button:hover { background: #2d3340; }
#toggles button.on { background: var(--ds-blue); color: #fff; }

/* ---- the game screen ---------------------------------------------------- */
#screen {
  --ps: 3;
  position: relative;
  border: 3px solid #0c0e14;
  border-radius: 5px;
  box-shadow: 0 12px 34px rgba(0,0,0,.5), inset 0 0 0 1px #ffffff14;
  background: #0c0e14;
  overflow: hidden; image-rendering: pixelated;
}
#game { display: block; image-rendering: pixelated; }

/* ---- overlay UI (DS Pokémon textbox / menu / chat) ---------------------- */
#overlay { position: absolute; inset: 0; pointer-events: none; }

#textbox, #menu, #chat {
  position: absolute; left: calc(var(--ps) * 6px); right: calc(var(--ps) * 6px);
  bottom: calc(var(--ps) * 6px);
  background: var(--paper); color: var(--ink);
  border: calc(var(--ps) * 1.5px) solid var(--ds-blue);
  border-radius: calc(var(--ps) * 3px);
  box-shadow:
    inset 0 0 0 calc(var(--ps) * 0.8px) var(--ds-blue-lt),
    0 calc(var(--ps) * 1px) 0 var(--ds-blue-dk),
    0 calc(var(--ps) * 2px) calc(var(--ps) * 3px) rgba(0,0,0,.35);
  padding: calc(var(--ps) * 6px) calc(var(--ps) * 7px);
  font-size: calc(var(--ps) * 6px); line-height: 1.65;
  pointer-events: auto;
}
#textbox { min-height: calc(var(--ps) * 40px); }
#textbox-text { white-space: pre-wrap; word-break: break-word; }
#textbox-arrow {
  position: absolute; right: calc(var(--ps) * 7px); bottom: calc(var(--ps) * 4px);
  color: var(--ds-blue); animation: blink .7s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

#menu {
  padding: calc(var(--ps) * 5px) calc(var(--ps) * 5px); font-size: calc(var(--ps) * 4px); line-height: 1.95;
  max-height: calc(var(--ps) * 150px); overflow-y: auto;
}
.menu-item { white-space: pre; padding: calc(var(--ps) * 1px) 0; overflow: hidden; text-overflow: ellipsis; }
.menu-item.sel { color: var(--ds-blue-dk); font-weight: bold; }
.menu-item:not(.sel) { color: var(--dim); }

#chat {
  bottom: calc(var(--ps) * 50px);
  display: flex; align-items: center;
  padding: calc(var(--ps) * 5px) calc(var(--ps) * 6px);
}
#chat-input {
  width: 100%; font-family: inherit;
  /* >=16px or iOS Safari auto-zooms into the field on focus and, because the
   * viewport blocks pinch-zoom, leaves the page stuck zoomed/panned afterwards. */
  font-size: max(16px, calc(var(--ps) * 5px));
  color: var(--ink); background: transparent; border: none; outline: none;
}
#chat-input::placeholder { color: var(--dim); }

/* ---- controls (Game-Boy pad — touch devices only) ----------------------- *
 * Hidden by default (desktop = keyboard). Shown via the (hover:none) query
 * below. Kept well inside the viewport edges so the phone's edge-swipe / back
 * gesture never steals the LEFT and A presses.                               */
#controls {
  width: 100%; max-width: 460px;
  display: none;                         /* shown on touch devices (see @media) */
  align-items: center; justify-content: space-between;
  padding: 4px max(26px, env(safe-area-inset-right)) 4px max(26px, env(safe-area-inset-left));
  touch-action: none;
}

/* D-pad — one dark cross, whole thing is a single touch surface */
#dpad {
  position: relative; touch-action: none;
  display: grid;
  grid-template-columns: repeat(3, 46px);
  grid-template-rows: repeat(3, 46px);
  filter: drop-shadow(0 4px 0 #05070c);
}
.pad {
  font-family: inherit; font-size: 14px; line-height: 1; color: #aeb8c8;
  background: linear-gradient(#3a4150, #232a36);
  border: none; pointer-events: none;    /* #dpad container handles the input */
  display: flex; align-items: center; justify-content: center;
}
#pad-up { grid-area: 1/2; border-radius: 9px 9px 0 0; }
#pad-left { grid-area: 2/1; border-radius: 9px 0 0 9px; }
#pad-mid { grid-area: 2/2; background: #2b323e; position: relative; }
#pad-mid::after { content: ''; position: absolute; inset: 33%; border-radius: 50%; background: #1b212b; }
#pad-right { grid-area: 2/3; border-radius: 0 9px 9px 0; }
#pad-down { grid-area: 3/2; border-radius: 0 0 9px 9px; }
.pad.active { background: var(--ds-blue); color: #fff; }

/* A / B — round, set diagonally like a real Game Boy (A upper-right) */
#ab { display: grid; grid-template-columns: auto auto; gap: 12px 16px; align-items: center; }
.round {
  width: 60px; height: 60px; border-radius: 50%;
  font-family: inherit; font-size: 16px; color: #fff;
  border: none; touch-action: none; cursor: pointer;
  background: radial-gradient(circle at 36% 30%, #4f96ec, #1d4f9e);
  box-shadow: 0 5px 0 #0c2f6b, inset 0 2px 2px #ffffff55;
}
#btn-a { grid-area: 1 / 2; }
#btn-b {
  grid-area: 2 / 1;
  background: radial-gradient(circle at 36% 30%, #ee7a70, #9e2a23);
  box-shadow: 0 5px 0 #6b160f, inset 0 2px 2px #ffffff55;
}
.round.active { transform: translateY(3px); box-shadow: inset 0 2px 5px rgba(0,0,0,.45); }

/* ---- meta --------------------------------------------------------------- */
#hint { font-family: system-ui, sans-serif; font-size: 11px; color: #6b7689; text-align: center; }
#footer { font-family: system-ui, sans-serif; font-size: 11px; }
#footer a { color: #5a86c8; text-decoration: none; }
#footer a:hover { text-decoration: underline; }

/* Touch devices (phones / tablets): show the Game-Boy pad, drop the keyboard
 * hint, and push the pad to the bottom of the stack for thumb reach. Laptops
 * with a trackpad report (hover:hover)+(pointer:fine) and keep the pad hidden. */
@media (hover: none), (pointer: coarse) {
  #app { gap: 8px; }
  #controls { display: flex; order: 5; }
  #hint { display: none; }
}

/* Narrow phones — shrink the pad a touch so everything fits */
@media (max-width: 380px) {
  #title { font-size: 10px; }
  #controls { max-width: 360px; padding-left: 18px; padding-right: 18px; }
  #dpad { grid-template-columns: repeat(3, 40px); grid-template-rows: repeat(3, 40px); }
  .round { width: 52px; height: 52px; }
}
