:root {
  color-scheme: dark;
  font-family: Arial, Helvetica, sans-serif;
  color: #edf7fb;
  background: #0a1b2d;
  --ink: #0a1b2d;
  --panel: #102b43;
  --line: #42647a;
  --lime: #c5e684;
  --muted: #bad0dd;
  --control-size: 46px;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 280px; }
button, input { font: inherit; }
a { color: #bce4fa; text-underline-offset: 3px; }
a:hover { color: #fff; }
button {
  min-height: 40px;
  border: 1px solid #6d93aa;
  border-radius: 5px;
  padding: 8px 13px;
  color: #f4faff;
  background: #254b65;
  cursor: pointer;
}
button:hover:not(:disabled) { background: #32617e; }
button:disabled { opacity: .5; cursor: default; }
button:focus-visible, a:focus-visible, summary:focus-visible {
  outline: 3px solid var(--lime);
  outline-offset: 4px;
}
.page {
  max-width: 1120px;
  margin: 0 auto;
  padding: 22px max(18px, env(safe-area-inset-right)) 20px max(18px, env(safe-area-inset-left));
}
.masthead { position: relative; padding-bottom: 19px; }
.back-link { display: inline-block; padding: 6px 0; font-size: 14px; }
.title-block { text-align: center; margin: 10px 0 15px; }
.edition, .release { margin: 0; color: var(--muted); font-size: 12px; letter-spacing: .1em; }
.edition { text-transform: uppercase; }
h1 { margin: 9px 0 8px; line-height: 1.06; }
.game-logo { display: block; width: min(100%, 420px); height: auto; margin: 0 auto; border-radius: 3px; }
h1 span { display: block; font-size: clamp(25px, 5vw, 43px); letter-spacing: -.035em; }
h1 strong { display: block; margin-top: 5px; color: var(--lime); font-size: clamp(21px, 4vw, 31px); letter-spacing: .035em; text-transform: uppercase; }
.compatibility { margin: 0; text-align: center; font-size: 13px; color: #d9d0f2; }
.game-panel { border: 1px solid var(--line); border-top: 3px solid var(--lime); background: var(--panel); border-radius: 8px; padding: 12px; }
.play-layout { display: grid; grid-template-areas: "stage"; justify-items: center; gap: 12px; }
.stage {
  grid-area: stage;
  position: relative;
  width: min(100%, 640px);
  aspect-ratio: 4 / 3;
  background: #000;
  overflow: hidden;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
#game { width: 100%; height: 100%; }
#game canvas { display: block; object-fit: contain; image-rendering: pixelated; }
.loading-placeholder { margin: 0; position: absolute; inset: 0; display: grid; place-content: center; color: var(--muted); font-size: 14px; }
.game-toolbar { display: flex; gap: 12px; align-items: center; justify-content: space-between; margin: 10px 0 0; }
.game-toolbar p { margin: 0; font-size: 13px; color: var(--muted); }
#touch-toggle { flex: 0 0 auto; font-size: 12px; min-height: 34px; padding: 6px 10px; }
#touch-toggle[aria-pressed="true"] { border-color: var(--lime); color: var(--lime); }
.touch-pad, .touch-system { display: none; }
.show-touch-controls .play-layout {
  grid-template-columns: 1fr 1fr;
  grid-template-areas: "stage stage" "left right" "system system";
}
.show-touch-controls .touch-pad { display: flex; align-items: center; flex-direction: column; gap: 9px; }
.show-touch-controls .touch-system { display: flex; gap: 20px; }
.touch-left { grid-area: left; }
.touch-right { grid-area: right; }
.touch-system { grid-area: system; }
[data-touch-controls], [data-touch-controls] button {
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  overscroll-behavior: contain;
}
[data-touch-controls] button { transition: background-color 60ms, border-color 60ms; }
[data-touch-controls] button[aria-pressed="true"] { border-color: var(--lime); background: #4e6570; box-shadow: inset 0 0 0 2px #c5e68455; }
.shoulder { width: 80px; min-height: 32px; padding: 4px; font-weight: bold; }
.dpad, .face-pad { display: grid; grid-template-columns: repeat(3, var(--control-size)); grid-template-rows: repeat(3, var(--control-size)); gap: 2px; }
.dpad button { padding: 0; min-height: 0; font-size: 23px; }
.dpad .diagonal { background: #19394f; border-color: #345a70; font-size: 17px; color: #bdd2df; }
.dpad-center { display: grid; place-items: center; align-self: stretch; justify-self: stretch; }
.dpad-center::before { content: ""; width: 18px; height: 18px; border-radius: 50%; background: #0b2234; border: 1px solid #345a70; }
.face { padding: 0; min-height: 0; border-radius: 50%; font-size: 31px; font-weight: bold; line-height: 1; }
.triangle { grid-area: 1 / 2; color: #9fe1c5; }
.square { grid-area: 2 / 1; color: #eeb3d5; }
.circle { grid-area: 2 / 3; color: #f6a8a5; }
.cross { grid-area: 3 / 2; color: #b1ccf7; }
.touch-system button { min-width: 75px; min-height: 34px; padding: 5px 12px; font-size: 12px; border-radius: 18px; }
.below-game { display: grid; grid-template-columns: 1fr 1fr; gap: 26px; margin: 21px 3px 0; }
.instructions, .saves { min-width: 0; font-size: 14px; line-height: 1.55; }
summary { cursor: pointer; color: var(--lime); font-weight: bold; padding: 2px 0; }
.instructions p, .saves p { color: var(--muted); margin: 10px 0; }
.saves h2 { margin: 0; font-size: 14px; color: var(--lime); }
.key-list { margin: 12px 0; display: grid; gap: 4px; }
.key-list > div { display: flex; gap: 15px; justify-content: space-between; border-bottom: 1px solid #234258; padding: 2px 0; }
.key-list dt, .key-list dd { margin: 0; }
kbd { font-family: inherit; color: #f3f8fb; }
.save-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 13px; }
.save-actions button { font-size: 13px; }
.saves .save-status { font-size: 12px; min-height: 1.55em; }
.save-status[data-error="true"] { color: #ffc1b9; }
.notice { border: 1px solid var(--line); padding: 15px; }
footer { margin: 27px 3px 0; padding-top: 15px; border-top: 1px solid #29475d; font-size: 11px; line-height: 1.65; color: #9cb9cc; }
footer p { margin: 4px 0; }

/* The game keeps the entire 4:3 image. Controls occupy separate grid cells. */
@media (orientation: landscape) and (min-width: 640px) {
  .show-touch-controls .play-layout {
    grid-template-columns: max-content minmax(0, 1fr) max-content;
    grid-template-areas: "left stage right" ". system .";
    gap: 9px;
    align-items: center;
  }
  .show-touch-controls .stage { width: min(100%, calc((100svh - 105px) * 4 / 3)); }
}
@media (orientation: landscape) and (max-height: 600px) {
  :root { --control-size: 40px; }
  .page { padding-top: 7px; }
  .masthead { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding-bottom: 7px; }
  .back-link { font-size: 12px; white-space: nowrap; }
  .title-block { margin: 0; text-align: left; }
  .edition, .release { display: none; }
  h1 { margin: 0; }
  .game-logo { width: 155px; }
  h1 span { font-size: 16px; }
  h1 strong { font-size: 15px; margin-top: 2px; }
  .compatibility { max-width: 145px; font-size: 11px; text-align: right; }
  .game-panel { padding: 7px; }
  .show-touch-controls .play-layout { grid-template-areas: "left stage right"; }
  .show-touch-controls .touch-system { grid-area: 1 / 1 / 2 / 2; align-self: end; gap: 4px; }
  .show-touch-controls .touch-left, .show-touch-controls .touch-right { align-self: start; padding-top: 3px; }
  .show-touch-controls .touch-system button { min-width: 58px; padding: 5px 7px; }
  .show-touch-controls .stage { width: min(100%, calc((100svh - 100px) * 4 / 3)); }
  .show-touch-controls .touch-left { padding-bottom: 38px; }
  .game-toolbar { margin-top: 6px; }
  .below-game { margin-top: 15px; }
}
@media (max-width: 560px) {
  .page { padding-top: 10px; padding-left: max(10px, env(safe-area-inset-left)); padding-right: max(10px, env(safe-area-inset-right)); }
  .title-block { margin-top: 6px; }
  .game-panel { padding: 7px; }
  .below-game { grid-template-columns: 1fr; gap: 19px; }
  .game-toolbar { gap: 7px; }
  .game-toolbar p { font-size: 12px; }
}
@media (max-width: 340px) {
  :root { --control-size: 41px; }
  .game-toolbar { flex-wrap: wrap; }
}

/* Large, independent thumb controls. The game keeps its entire 4:3 picture. */
:root { --face-size: 56px; --joystick-size: 140px; }
[hidden] { display: none !important; }
.keyboard-guide { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 18px; margin: 0 0 12px; font-size: 13px; line-height: 1.6; }
.keyboard-guide span { white-space: nowrap; }
kbd { display: inline-block; padding: 0 4px; border: 1px solid #55768a; border-radius: 3px; background: #16374e; font-weight: bold; }
.play-layout { position: relative; }
.show-touch-controls .play-layout { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); grid-template-areas: "stage stage" "left right"; }
.show-touch-controls .stage { width: min(100%, 640px); }
.show-touch-controls .touch-pad { gap: 8px; padding: 0; align-self: start; }
.shoulder { width: 100px; min-height: 44px; padding: 6px; }
.joystick { position: relative; width: var(--joystick-size); height: var(--joystick-size); flex: 0 0 auto; border-radius: 50%; border: 2px solid #6d93aa; background: radial-gradient(circle, #244d68 0 30%, #12344d 31% 63%, #0b2438 64%); box-shadow: inset 0 0 0 8px #091f3155; touch-action: none; overflow: hidden; }
.joystick-ring { position: absolute; inset: 15px; border: 1px solid #6d93aa66; border-radius: 50%; pointer-events: none; }
.joystick-stick { position: absolute; left: 50%; top: 50%; width: 64px; height: 64px; border-radius: 50%; border: 2px solid #bdd5e3; background: radial-gradient(circle at 40% 30%, #7296ac, #325872 70%); box-shadow: 0 4px 9px #0008; transform: translate(calc(-50% + var(--stick-x, 0px)), calc(-50% + var(--stick-y, 0px))); pointer-events: none; }
.joystick[data-active="true"] { border-color: var(--lime); }
.face-pad { display: block; position: relative; width: calc(var(--face-size) * 3); height: calc(var(--face-size) * 3); flex: 0 0 auto; }
.face { position: absolute; display: grid; place-items: center; width: var(--face-size); height: var(--face-size); min-height: var(--face-size); padding: 0; border-width: 2px; }
.face svg { display: block; width: 32px; height: 32px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; pointer-events: none; }
.face.triangle { left: var(--face-size); top: 0; }
.face.square { left: 0; top: var(--face-size); }
.face.circle { right: 0; top: var(--face-size); }
.face.cross { left: var(--face-size); bottom: 0; }
.show-touch-controls .touch-system { display: flex; gap: 6px; margin: 0; padding: 0; align-self: center; }
.touch-system button, .show-touch-controls .touch-system button { min-width: 64px; min-height: 44px; padding: 6px 8px; }
.show-touch-controls .keyboard-guide { display: none; }
.picture-control { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 17px; color: var(--lime); font-weight: bold; }
.picture-control select { min-height: 44px; max-width: 100%; padding: 7px 10px; color: #edf7fb; background: #16374e; border: 1px solid #6d93aa; border-radius: 5px; font: inherit; }
.picture-note, .picture-status { font-size: 12px; }
.ejs_menu_button { touch-action: manipulation; }
.startup-status { position: absolute; z-index: 5; top: 12px; left: 50%; transform: translateX(-50%); display: flex; gap: 10px; width: min(420px, calc(100% - 20px)); padding: 12px; background: #102b43f5; border: 1px solid #a2c879; border-radius: 6px; box-shadow: 0 3px 20px #0009; pointer-events: auto; }
.startup-status > div { min-width: 0; flex: 1; }
.startup-status strong { display: block; font-size: 14px; }
.startup-status p { margin: 6px 0; color: var(--muted); font-size: 12px; line-height: 1.45; }
.startup-status progress { display: block; width: 100%; height: 7px; accent-color: var(--lime); }
.startup-status button { margin-top: 8px; width: 100%; min-height: 44px; font-size: 13px; }
.activity-spinner { flex: 0 0 18px; width: 18px; height: 18px; margin-top: 1px; border: 2px solid #55768a; border-top-color: var(--lime); border-radius: 50%; animation: startup-spin 1s linear infinite; }
.startup-status[data-state="error"] { border-color: #f6a8a5; }
.startup-status[data-state="error"] .activity-spinner, .startup-status[data-state="gesture"] .activity-spinner { display: none; }
@keyframes startup-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .activity-spinner { animation-duration: 2.5s; } }

@media (orientation: landscape) and (max-height: 650px) {
  body.show-touch-controls { overflow: hidden; }
  .show-touch-controls .page { padding: 0; }
  .show-touch-controls .masthead { position: static; height: 0; margin: 0; padding: 0; }
  .show-touch-controls .title-block, .show-touch-controls .compatibility, .show-touch-controls .below-game, .show-touch-controls footer { display: none; }
  .show-touch-controls .back-link { position: fixed; z-index: 12; left: max(10px, env(safe-area-inset-left)); top: max(6px, env(safe-area-inset-top)); padding: 7px 4px; font-size: 12px; }
  .show-touch-controls .game-panel { border: 0; padding: 0; border-radius: 0; }
  .show-touch-controls .play-layout { position: fixed; z-index: 10; inset: 0; padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left)); grid-template-columns: minmax(140px, 1fr) auto minmax(168px, 1fr); grid-template-areas: "left stage right"; align-items: center; gap: 8px; background: var(--ink); }
  .show-touch-controls .stage { width: min(calc((100dvh - max(8px, env(safe-area-inset-top)) - max(8px, env(safe-area-inset-bottom))) * 4 / 3), calc(100dvw - max(8px, env(safe-area-inset-left)) - max(8px, env(safe-area-inset-right)) - 324px)); }
  .show-touch-controls .touch-pad { align-self: center; padding: 0; }
  .show-touch-controls .touch-system { align-self: center; }
  .show-touch-controls .game-toolbar { display: contents; }
  .show-touch-controls #game-status { position: fixed; z-index: 11; bottom: max(4px, env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); max-width: calc(100dvw - 320px); font-size: 10px; text-align: center; color: #d2e4ee; background: #0a1b2dcc; padding: 2px 5px; border-radius: 3px; pointer-events: none; }
  .show-touch-controls #touch-toggle { position: fixed; z-index: 12; left: max(8px, env(safe-area-inset-left)); bottom: max(8px, env(safe-area-inset-bottom)); width: 140px; min-height: 36px; padding: 6px; font-size: 12px; }
  .show-touch-controls .startup-status { top: max(12px, env(safe-area-inset-top)); width: min(420px, calc(100dvw - 320px)); }
  .show-touch-controls[data-boot-state="running"] #game-status { display: none; }
}
@media (orientation: landscape) and (max-height: 350px) {
  :root { --joystick-size: 120px; }
  .show-touch-controls .touch-pad { gap: 5px; }
}
@media (max-width: 340px) {
  :root { --face-size: 52px; --joystick-size: 112px; }
  .show-touch-controls .play-layout { gap: 10px 4px; }
}
@media (orientation: landscape) and (max-height: 650px) and (max-width: 700px) {
  :root { --face-size: 52px; --joystick-size: 112px; }
  .show-touch-controls .play-layout { grid-template-columns: minmax(112px, 1fr) auto minmax(156px, 1fr); }
  .show-touch-controls .stage { width: min(calc((100dvh - max(8px, env(safe-area-inset-top)) - max(8px, env(safe-area-inset-bottom))) * 4 / 3), calc(100dvw - max(8px, env(safe-area-inset-left)) - max(8px, env(safe-area-inset-right)) - 284px)); }
  .show-touch-controls #touch-toggle { width: 112px; }
}
