:root { color-scheme: dark; font: 14px/1.5 var(--font-ui); color: #f4ead4; background: #17283e; }
* { box-sizing: border-box; }
body { margin: 0; }
/* Reserve the controls' natural height; only the display yields space. */
main { width: 100%; height: 100vh; height: 100dvh; display: flex; flex-direction: column; }
.screen { flex: 0 1 75vw; min-height: 96px; container-type: size; background: #f4f1e9; }
canvas { display: block; margin: 0 auto; width: min(100cqw, calc(100cqh * 4 / 3)); height: auto; aspect-ratio: 4 / 3; image-rendering: pixelated; background: #f4f1e9; }
.console { display: flex; flex: 1 0 auto; flex-direction: column; align-items: center; padding: clamp(8px, 2dvh, 22px) 24px 0; text-align: center; background: linear-gradient(115deg, #233b56, #17283e 60%, #20354d); border-top: 3px solid #0d1827; box-shadow: inset 0 2px #637487; }
.console-heading { margin: 0; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .2em; }
.status { margin: 9px 0 0; min-height: 1.5em; color: #cfceca; font-size: 12px; }
.control-bay { flex: 1; width: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: clamp(10px, 2dvh, 20px); padding: clamp(10px, 2dvh, 20px) 0; }
.touch { display: none; }
.keyboard { margin: 0; color: #e4ddce; line-height: 2.3; font-size: 13px; }
kbd { display: inline-block; min-width: 25px; margin: 0 2px; border: 1px solid #718092; border-bottom-width: 3px; border-radius: 4px; padding: 0 6px; color: #f4ead4; font: inherit; line-height: 1.7; }
.toolbar { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; }
button, .back { -webkit-tap-highlight-color: transparent; font: inherit; cursor: pointer; touch-action: manipulation; }
button { border: 1px solid #778493; border-radius: 7px; min-height: 44px; padding: 8px 18px; color: #eee5d2; background: linear-gradient(#344b63, #24384e); box-shadow: 0 4px 0 #0b1523, 0 5px 6px #0b152380, inset 0 1px #ffffff24; transition: transform 80ms ease, box-shadow 80ms ease, filter 100ms ease; }
button:active:not(:disabled), button.pressed:not(:disabled) { transform: translateY(4px); box-shadow: 0 0 0 #0b1523, inset 0 2px 4px #0006; }
button:disabled { opacity: .45; cursor: default; }
@media (hover: hover) { button:hover:not(:disabled) { filter: brightness(1.12); } .back:hover { background: #eee1c7; } }
a:focus-visible, button:focus-visible, canvas:focus-visible { outline: 3px solid #ffc04a; outline-offset: -3px; }
.back { display: flex; flex-shrink: 0; align-items: center; justify-content: center; gap: 9px; width: calc(100% + 48px); min-height: 48px; padding: 12px 24px max(12px, env(safe-area-inset-bottom)); background: linear-gradient(#e9dcc2, #d9c8a8); color: #26364a; box-shadow: inset 0 2px #fff6; border-top: 2px solid #101b2b; text-decoration: none; font-size: 12px; font-weight: 700; letter-spacing: .08em; }
.back:focus-visible { outline-color: #243b56; }
#error { max-width: 620px; color: #ffe0ad; padding: 12px; border: 1px solid #e6a761; }
noscript { display: block; padding: 16px; text-align: center; }
@media (max-width: 760px), (pointer: coarse) {
  .keyboard { display: none; }
  .touch { display: flex; align-items: center; justify-content: center; gap: clamp(20px, 7vw, 44px); width: 100%; }
  .dpad { --key-size: clamp(44px, 7dvh, 58px); display: grid; grid-template: repeat(3, var(--key-size)) / repeat(3, var(--key-size)); gap: 5px; }
  .dpad button { padding: 0; border-radius: 9px; border-color: #748392; background: linear-gradient(#364b62, #24364d); font-size: 23px; color: #f0e6ce; box-shadow: 0 5px 0 #080f1a, 0 7px 9px #080f1a99, inset 0 2px #ffffff24; }
  .dpad .up { grid-area: 1 / 2; } .dpad .left { grid-area: 2 / 1; } .dpad .right { grid-area: 2 / 3; } .dpad .down { grid-area: 3 / 2; }
  .dpad button:active:not(:disabled), .dpad button.pressed:not(:disabled) { transform: translateY(5px); box-shadow: inset 0 2px 4px #0006; }
  .greet { width: 66px; height: 66px; padding: 0; border-radius: 50%; border-color: #ffc352; background: linear-gradient(#ffba32, #e99710); color: #33230b; font-size: 11px; font-weight: 700; box-shadow: 0 5px 0 #87500b, 0 7px 9px #080f1a99, inset 0 2px #ffe29a; }
  .toolbar button:first-child { background: linear-gradient(#ef7237, #cb481c); border-color: #ff9b64; color: #fff7ec; box-shadow: 0 4px 0 #79290f, 0 5px 6px #0b152380, inset 0 1px #ffffff45; }
  .toolbar button:active:not(:disabled) { box-shadow: inset 0 2px 4px #0006; }
  .toolbar { gap: 14px; }
  .toolbar button { font-size: 12px; }
}
@media (max-width: 350px) { .touch { gap: 18px; } .greet { width: 58px; height: 58px; } .toolbar { gap: 8px; } .toolbar button { padding-inline: 12px; } }
/* A landscape handset becomes a handheld console, without tiny controls. */
@media (min-width: 600px) and (max-height: 500px) {
  main { flex-direction: row; }
  .screen { flex: 1 1 0; min-width: 128px; min-height: 100%; display: grid; align-content: center; }
  .console { flex: 0 0 320px; min-width: 0; padding-inline: 16px; padding-top: max(8px, env(safe-area-inset-top)); }
  .back { width: calc(100% + 32px); }
  .status { margin-top: 6px; }
  .control-bay { gap: 10px; padding: 10px 0; }
  .touch { gap: 18px; }
  .toolbar { gap: 8px; }
  .toolbar button { padding-inline: 12px; }
}
@media (prefers-reduced-motion: reduce) { button { transition: none; } }
