* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: linear-gradient(110deg, #263a4d, #131c27);
  color: #f6f5e9;
  font-family: Arial, Helvetica, sans-serif;
}
main { max-width: 960px; margin: auto; padding: 12px max(12px, env(safe-area-inset-right)) 24px max(12px, env(safe-area-inset-left)); }
header, footer, .guide { font: 13px/1.6 Verdana, sans-serif; }
header { display: flex; justify-content: space-between; align-items: center; padding: 5px 3px 14px; }
header span { letter-spacing: .14em; font-weight: bold; color: #ffca59; }
a { color: white; }
.console { border: 2px outset #bfc6c8; background: #263749; box-shadow: 4px 5px 0 #0e1721; }
.title { padding: 12px 16px; background: linear-gradient(105deg, #253947, #142330); border-bottom: 5px solid #ef9c30; }
h1 { font: bold italic clamp(23px, 4.5vw, 40px)/1.05 Arial, sans-serif; text-transform: uppercase; margin: 5px 0; }
.title p { margin: 0; color: #ccd4d8; font-size: 13px; }
.toolbar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: #182635; border-bottom: 1px solid #4c5e6c; }
button, select, summary { font: 700 14px/1.2 Arial, sans-serif; }
button { color: #162131; border: 2px outset #f7efce; border-radius: 5px; background: #e6e5d9; cursor: pointer; padding: 10px 12px; min-height: 44px; }
button:focus-visible, a:focus-visible, select:focus-visible, summary:focus-visible { outline: 3px solid #57cfff; outline-offset: 2px; }
button:active, button.held { border-style: inset; transform: translateY(1px); }
.toolbar button { background: #304759; border-color: #5b7181; color: #edf4f4; font-size: 12px; }
#crt span { color: #ffda82; margin-left: 4px; }
.options { margin-left: auto; position: relative; }
summary { cursor: pointer; padding: 12px 2px; font-size: 12px; }
.options-panel { position: absolute; right: 0; top: 100%; z-index: 5; display: grid; gap: 8px; width: 210px; padding: 12px; background: #182635; border: 1px solid #627482; box-shadow: 0 6px 16px #0008; }
.options-panel button { display: flex; align-items: center; justify-content: space-between; }
kbd { font: 12px monospace; opacity: .7; margin-left: 8px; }
.cockpit { display: grid; grid-template-columns: 1fr 1fr; background: #101b25; }
.stage { grid-column: 1 / -1; display: grid; place-items: center; background: #080e14; min-width: 0; }
.stage iframe { width: min(100%, 78vh); aspect-ratio: 4/3; border: 0; display: block; }
#launch {
  display: grid;
  grid-template-columns: minmax(0, 230px) minmax(0, 300px);
  align-items: center;
  justify-content: center;
  gap: 28px;
  width: 100%;
  padding: 28px;
  background: radial-gradient(ellipse at center, #344758, #10171e 72%);
}
#launch img { display: block; width: 100%; height: auto; border: 2px inset #aaa; }
.launch-settings { display: grid; gap: 16px; min-width: 0; width: 100%; }
.setting-field { display: grid; gap: 8px; min-width: 0; }
#launch label { font-size: 14px; color: #e0e7ec; }
#memory-mode, #draw-distance {
  appearance: none;
  -webkit-appearance: none;
  display: block;
  width: 100%;
  min-width: 0;
  height: 46px;
  padding: 0 36px 0 12px;
  border: 1px solid #8c9da9;
  border-radius: 5px;
  background-color: #e6e5d9;
  background-image: linear-gradient(45deg, transparent 50%, #263749 50%), linear-gradient(135deg, #263749 50%, transparent 50%);
  background-position: calc(100% - 18px) 20px, calc(100% - 13px) 20px;
  background-size: 5px 5px;
  background-repeat: no-repeat;
  color: #162131;
  font: 16px Arial, sans-serif;
  line-height: normal;
}
.advanced-settings { border-top: 1px solid #4c5e6c; }
.advanced-settings summary { font-weight: normal; font-size: 13px; padding: 12px 0; }
.advanced-settings .setting-field { padding-bottom: 4px; }
#memory-help { margin: 0; color: #bfcdd6; font-size: 12px; line-height: 1.5; }
#play { width: 100%; background: #ffca51; font-size: 18px; padding: 12px 16px; min-height: 48px; }
.console:not(.playing) .stage { grid-column: 1 / -1; }
.controls { display: none; }
[data-key] { touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
#message { margin: 0; padding: 12px; font-size: 13px; line-height: 1.5; color: #ffda82; border-top: 1px solid #435563; }
.guide { margin: 12px 1px; }
footer { color: #b6c1cd; margin-top: 12px; }
.console:fullscreen { overflow-y: auto; width: 100%; background: #101b25; border: 0; }
.console:fullscreen .title { display: none; }
@media (pointer: coarse), (max-width: 700px) {
  .playing .controls { display: grid; gap: 8px; padding: 12px; }
  .steering { grid-template-columns: 1fr 1fr; align-items: end; padding-right: 6px; }
  .steering button { height: 86px; display: grid; place-content: center; gap: 6px; background: linear-gradient(#455c6d, #2a3f50); border-color: #7e94a3; color: #fff; }
  .arrow { font-size: 26px; line-height: 1; }
  .pedals { grid-template-columns: 1fr 1fr; padding-left: 6px; }
  .pedals button { height: 62px; }
  .pedals .siren { grid-column: 1 / -1; height: 44px; background: #739ab8; border-color: #b9d4e5; color: #10273a; }
  .pedals .brake { background: #cf7768; border-color: #ffb5a7; color: #23130e; }
  .pedals .gas { background: #ffca51; border-color: #ffe7a1; }
  .controls button.held { background: #fff0bb; color: #172735; border-color: #ffca51; }
  .guide { display: none; }
}
@media (pointer: coarse) and (orientation: landscape) and (max-height: 600px) {
  main { max-width: none; padding-top: 4px; }
  header { padding: 0 3px 4px; }
  header span, .title p, footer { display: none; }
  .title { padding: 4px 12px; border-bottom-width: 3px; }
  h1 { font-size: 20px; margin: 2px 0; }
  .toolbar { padding: 4px 12px; }
  .toolbar button, summary { min-height: 36px; padding-top: 8px; padding-bottom: 8px; }
  .cockpit { grid-template-columns: minmax(100px, 1fr) minmax(0, 4fr) minmax(116px, 1fr); align-items: center; }
  .stage { grid-column: 2; grid-row: 1; }
  .stage iframe { width: min(100%, calc((100dvh - 150px) * 4 / 3)); }
  .steering { grid-column: 1; grid-row: 1; padding: 8px; gap: 6px; }
  .steering button { min-width: 0; padding: 6px; height: 80px; font-size: 11px; }
  .pedals { grid-column: 3; grid-row: 1; padding: 8px; gap: 6px; }
  .pedals button { padding: 6px; height: 70px; font-size: 12px; }
  #message { padding: 4px 12px; font-size: 11px; }
  .console:fullscreen .stage iframe { width: min(100%, calc((100dvh - 90px) * 4 / 3)); }
}
.cockpit { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
#launch, .stage iframe, .controls { min-width: 0; max-width: 100%; }
.toolbar { flex-wrap: wrap; }
@media (pointer: coarse) and (orientation: landscape) and (max-height: 600px) {
  .cockpit { grid-template-columns: minmax(112px, 1fr) minmax(0, 4fr) minmax(130px, 1fr); }
}

.skip-opening { display: flex; align-items: center; gap: 8px; min-height: 36px; }
.skip-opening input { width: 18px; height: 18px; accent-color: #ffca51; }
.pedals .siren { font-size: 12px; }

@media (max-width: 600px) {
  #launch { grid-template-columns: minmax(0, 1fr); gap: 20px; padding: 24px 20px; justify-items: center; }
  #launch img { width: 170px; max-width: 65%; }
  .launch-settings { max-width: 340px; }
}
@media (pointer: coarse) and (orientation: landscape) and (max-height: 600px) {
  #launch { grid-template-columns: minmax(0, 160px) minmax(0, 320px); gap: 24px; padding: 20px; }
}
.console:not(.playing) .options { display: none; }

.startup-status { display: flex; align-items: center; gap: 12px; padding: 14px; background: #233f50; border-bottom: 2px solid #ffca51; }
.startup-copy { flex: 1; min-width: 0; }
.startup-copy strong { font-size: 14px; color: #ffda82; }
.startup-copy p { font-size: 12px; line-height: 1.5; color: #e1e9ed; margin: 6px 0; }
#startup-elapsed { font: 13px monospace; font-variant-numeric: tabular-nums; }
#startup-dismiss { min-height: 44px; padding: 8px; background: #304759; border-color: #5b7181; color: #edf4f4; font-size: 12px; }
.startup-spinner { flex-shrink: 0; width: 22px; height: 22px; border: 3px solid #718999; border-top-color: #ffca51; border-radius: 50%; animation: startup-spin 1s linear infinite; }
@keyframes startup-spin { to { transform: rotate(360deg); } }
.startup-error .startup-spinner { animation: none; border-color: #ef9c80; }
@media (prefers-reduced-motion: reduce) { .startup-spinner { animation: none; border-style: dotted; } }
@media (max-width: 400px) { .startup-status { gap: 8px; padding: 10px; flex-wrap: wrap; } .startup-copy { flex-basis: calc(100% - 38px); } #startup-elapsed { margin-left: 30px; } }
