:root {
  color-scheme: dark;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #f4f2de;
  background: #080f16;
  font-synthesis: none;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }
button, a, summary { -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { opacity: .4; cursor: default; }
button:focus-visible, a:focus-visible, summary:focus-visible, input:focus-visible {
  outline: 2px solid #f6d26d;
  outline-offset: 3px;
}
[hidden] { display: none !important; }

.game-stage { position: fixed; inset: 0; overflow: hidden; background: #080f16; }
#game {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  image-rendering: pixelated;
  touch-action: none;
  outline: none;
}
.toolbar {
  position: absolute;
  top: max(14px, env(safe-area-inset-top));
  right: max(14px, env(safe-area-inset-right));
  z-index: 5;
  display: flex;
  gap: 6px;
}
.toolbar button {
  min-height: 42px;
  padding: 0 13px;
  border: 1px solid #ffffff24;
  border-radius: 7px;
  background: #0a1929d9;
  box-shadow: 0 2px 12px #0003;
  font-size: 12px;
  font-weight: 650;
  backdrop-filter: blur(12px);
}
.toolbar button:hover:not(:disabled), .toolbar button[aria-expanded="true"] {
  background: #24394fee;
  border-color: #f6d26d80;
}
#menu-toggle { color: #f6d26d; }
.overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  padding: 28px 20px max(36px, env(safe-area-inset-bottom));
  background: linear-gradient(transparent 55%, #080f16e6);
  text-align: center;
}
.overlay p { font-size: 13px; line-height: 1.6; margin: 0 0 16px; text-shadow: 0 2px 8px #000; }
.overlay button {
  min-height: 52px;
  min-width: 190px;
  padding: 12px 28px;
  border: 1px solid #ffe8a4;
  border-radius: 6px;
  background: #f6d26d;
  box-shadow: 0 4px 0 #a57b25, 0 10px 28px #0005;
  color: #1b2730;
  font-weight: 750;
  font-size: 15px;
}
.overlay button:hover:not(:disabled) { background: #ffe59b; }
.overlay.is-error { justify-content: center; background: #080f16f5; }
.overlay.is-error h1 { font-size: clamp(20px, 4vw, 32px); }
.overlay.is-error p { max-width: 560px; overflow-wrap: anywhere; }
.pause-indicator {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  padding: 18px 30px;
  border: 1px solid #ffffff30;
  border-radius: 8px;
  background: #080f16e6;
  text-align: center;
  font-size: 22px;
  pointer-events: none;
}
.pause-indicator span { display: block; margin-top: 6px; font-size: 11px; color: #afc0cd; }
.menu-panel {
  position: absolute;
  top: max(64px, calc(env(safe-area-inset-top) + 50px));
  right: max(14px, env(safe-area-inset-right));
  z-index: 4;
  width: min(310px, calc(100% - 28px));
  max-height: calc(100% - 84px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  padding: 18px;
  overflow-y: auto;
  overscroll-behavior: contain;
  border: 1px solid #ffffff26;
  border-radius: 10px;
  background: #0b1928f5;
  box-shadow: 0 14px 48px #0008;
  touch-action: pan-y;
}
.menu-panel h2 { margin: 0 0 14px; font-size: 14px; font-weight: 650; color: #afc0cd; }
.game-commands { display: grid; gap: 6px; }
.game-commands button, .return-button, .native-menu button {
  min-height: 42px;
  padding: 10px 12px;
  border: 1px solid #ffffff1f;
  border-radius: 5px;
  background: #ffffff09;
  text-align: left;
  font-size: 13px;
}
.game-commands button:hover, .return-button:hover, .native-menu button:hover { background: #ffffff18; }
.return-button { display: block; width: 100%; margin-top: 6px; color: #afc0cd; }
details { margin-top: 14px; padding-top: 14px; border-top: 1px solid #ffffff1c; font-size: 12px; }
summary { cursor: pointer; }
details p { color: #afc0cd; line-height: 1.6; }
details a { display: block; color: #f6d26d; margin-top: 12px; }
dl { font-size: 11px; }
dl div { display: flex; justify-content: space-between; gap: 12px; margin: 12px 0; }
dd { margin: 0; color: #afc0cd; text-align: right; }
.native-menu {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 3;
  width: min(560px, calc(100% - 32px));
  max-height: calc(100% - 144px);
  padding: clamp(18px, 4vw, 32px);
  overflow-y: auto;
  overscroll-behavior: contain;
  border: 1px solid #ffffff30;
  border-radius: 10px;
  background: #0b1928f5;
  box-shadow: 0 0 0 100vmax #0007, 0 18px 70px #0008;
  touch-action: pan-y;
}
.native-menu h2 { margin: 0 0 18px; font-size: 20px; }
.native-menu p { white-space: pre-wrap; line-height: 1.75; color: #d1dce4; font-size: 13px; }
.native-menu button { display: block; width: 100%; margin: 8px 0; }
.native-menu label { display: block; margin-top: 18px; }
.native-menu input { display: block; width: 100%; margin-top: 12px; padding: 12px; border: 1px solid #ffffff50; border-radius: 4px; font: inherit; }
.touch-controls {
  position: absolute;
  bottom: max(16px, env(safe-area-inset-bottom));
  left: max(16px, env(safe-area-inset-left));
  right: max(16px, env(safe-area-inset-right));
  z-index: 1;
  display: none;
  justify-content: space-between;
  pointer-events: none;
}
.touch-controls > div { display: flex; gap: 8px; }
.touch-controls button {
  width: clamp(46px, 9vw, 62px);
  height: clamp(46px, 9vw, 62px);
  border: 1px solid #ffffff50;
  border-radius: 50%;
  background: #0a1929b3;
  color: #fff9df;
  font-size: 23px;
  backdrop-filter: blur(6px);
  touch-action: none;
  user-select: none;
  pointer-events: auto;
}
.touch-controls button:active { background: #f6d26d99; color: #080f16; }
.game-stage[data-started="false"] .touch-controls, .game-stage[data-screen="form"] .touch-controls { display: none; }
.notice {
  position: absolute;
  bottom: max(90px, calc(env(safe-area-inset-bottom) + 74px));
  left: 50%;
  transform: translateX(-50%);
  z-index: 6;
  width: max-content;
  max-width: calc(100% - 32px);
  margin: 0;
  padding: 12px 18px;
  border: 1px solid #f6d26d80;
  border-radius: 6px;
  background: #0b1928f5;
  font-size: 12px;
  line-height: 1.6;
}
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }

@media (pointer: coarse), (max-width: 760px), (max-height: 500px) {
  .touch-controls { display: flex; }
}
@media (max-width: 480px) {
  .toolbar { top: max(10px, env(safe-area-inset-top)); right: max(10px, env(safe-area-inset-right)); gap: 4px; }
  .toolbar button { min-height: 40px; padding: 0 10px; font-size: 11px; }
  .overlay p { font-size: 11px; }
}
