:root {
  --night: #020502;
  --forest: #071006;
  --forest-soft: #10220b;
  --leaf: #1f5e0b;
  --leaf-bright: #3c8b17;
  --bark: #5a2b09;
  --bark-light: #8b4c16;
  --gold: #e6c449;
  --cream: #fff0a4;
  --danger: #e73b20;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--night);
  touch-action: manipulation;
}

body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  color: var(--cream);
  background:
    radial-gradient(circle at 20% 0%, rgb(44 91 22 / 28%), transparent 34rem),
    linear-gradient(180deg, #081305, #020502 70%);
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
}

button,
canvas {
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
}

.page-shell {
  width: min(100%, 980px);
  margin: 0 auto;
  padding: clamp(14px, 3vw, 30px) clamp(12px, 3vw, 28px) calc(20px + env(safe-area-inset-bottom));
}

.masthead {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  margin: 0 auto 14px;
}

.eyebrow {
  margin: 0 0 3px;
  color: #7ea962;
  font-size: clamp(9px, 1.6vw, 12px);
  letter-spacing: .07em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(29px, 6vw, 48px);
  line-height: .9;
  letter-spacing: -.08em;
  text-shadow: 3px 4px 0 #1d1204;
}

h1 span:nth-child(odd) { color: #e44523; }
h1 span:nth-child(even) { color: #38a51c; }
h1 b { color: #f4d837; }

.top-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 7px;
}

.small-button,
.close-button {
  border: 1px solid var(--bark-light);
  color: var(--cream);
  background: linear-gradient(#18310e, #0a1707);
  box-shadow: inset 0 1px rgb(255 255 255 / 10%), 0 2px 0 #000;
  cursor: pointer;
}

.small-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 7px 11px;
  border-radius: 6px;
  font-size: 12px;
  line-height: 1;
  text-decoration: none;
}

.small-button:hover,
.small-button:focus-visible {
  border-color: var(--gold);
  outline: none;
  color: #fff;
}

.game-cabinet {
  position: relative;
  padding: clamp(9px, 1.8vw, 17px);
  overflow: hidden;
  border: 3px solid #2b1605;
  border-radius: 14px;
  background:
    linear-gradient(90deg, transparent 50%, rgb(255 220 104 / 4%) 50%) 0 0 / 6px 6px,
    linear-gradient(145deg, #81501b, #3d1c06 48%, #6e3a0d);
  box-shadow:
    inset 0 0 0 2px #a56724,
    inset 0 0 28px #170b02,
    0 16px 40px rgb(0 0 0 / 55%);
}

.game-cabinet::before,
.game-cabinet::after {
  content: "";
  position: absolute;
  z-index: 0;
  width: 90px;
  height: 24px;
  background: radial-gradient(ellipse, #287211 0 34%, #113808 36% 58%, transparent 60%) 0 0 / 30px 20px;
  opacity: .72;
  pointer-events: none;
}

.game-cabinet::before { top: -2px; left: 9%; transform: rotate(-3deg); }
.game-cabinet::after { right: 8%; bottom: 0; transform: rotate(181deg); }

.screen-wrap {
  position: relative;
  z-index: 1;
  width: 100%;
  aspect-ratio: 16 / 10;
  overflow: hidden;
  border: clamp(5px, 1vw, 9px) solid #020402;
  border-radius: 6px;
  background: #000;
  box-shadow: 0 0 0 2px #aa722a, inset 0 0 24px #000;
  touch-action: none;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  background: #000;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  outline: none;
  touch-action: none;
}

.dos-terminal {
  position: absolute;
  inset: 0;
  z-index: 4;
  padding: clamp(8px, 3.5%, 17px) clamp(9px, 4%, 20px);
  overflow: auto;
  color: #c8c8c8;
  background:
    repeating-linear-gradient(180deg, transparent 0 2px, rgb(255 255 255 / 2%) 2px 3px),
    #000;
  font: clamp(8px, 2.15vw, 16px)/1.2 ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  text-align: left;
  text-shadow: 0 0 .32em rgb(255 255 255 / 18%);
  touch-action: manipulation;
  -webkit-user-select: text;
  user-select: text;
  scrollbar-width: none;
}

.dos-terminal::-webkit-scrollbar { display: none; }
.dos-terminal[hidden] { display: none; }

.dos-output {
  margin: 0;
  white-space: pre-wrap;
}

.dos-prompt {
  display: flex;
  align-items: baseline;
  margin: 0;
  white-space: nowrap;
}

.dos-prompt label { flex: none; }

.dos-prompt input {
  min-width: 0;
  flex: 1;
  padding: 0;
  border: 0;
  border-radius: 0;
  outline: 0;
  color: #eee;
  background: transparent;
  font: inherit;
  text-transform: uppercase;
  caret-color: #fff;
  -webkit-user-select: text;
  user-select: text;
  appearance: none;
}

.dos-prompt input:disabled { opacity: 1; }

body[data-scene="dos"] .mobile-controls,
body[data-scene="dos"] .keyboard-hint {
  display: none;
}

.screen-message {
  position: absolute;
  inset: auto 8% 7%;
  z-index: 3;
  text-align: center;
  color: #fff5a3;
  font-size: clamp(10px, 2.3vw, 17px);
  font-weight: 800;
  line-height: 1.35;
  letter-spacing: .02em;
  text-shadow: 2px 2px #000, -1px -1px #000, 1px -1px #000, -1px 1px #000;
  pointer-events: none;
}

.screen-message:empty { display: none; }

.cabinet-strip {
  position: relative;
  z-index: 1;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 4px 0;
  color: #f5d86d;
  font-size: clamp(9px, 1.7vw, 12px);
  text-shadow: 1px 1px #000;
}

#status-label {
  color: #b2cc94;
  text-align: right;
}

.mobile-controls {
  display: none;
  grid-template-columns: minmax(130px, 1fr) minmax(90px, .6fr) minmax(74px, .45fr);
  align-items: center;
  gap: 14px;
  margin-top: 17px;
  touch-action: none;
}

.dpad {
  display: grid;
  grid-template: repeat(2, 54px) / repeat(3, 54px);
  justify-content: center;
}

.dpad button:nth-child(1) { grid-column: 2; grid-row: 1; }
.dpad button:nth-child(2) { grid-column: 1; grid-row: 2; }
.dpad button:nth-child(3) { grid-column: 2; grid-row: 2; }
.dpad button:nth-child(4) { grid-column: 3; grid-row: 2; }

.mobile-controls button {
  border: 2px solid #71400f;
  color: #ffe993;
  background: linear-gradient(145deg, #204611, #091b06);
  box-shadow: inset 0 2px rgb(255 255 255 / 8%), 0 4px 0 #020700;
  touch-action: none;
}

.dpad button {
  width: 52px;
  height: 52px;
  border-radius: 8px;
  font-size: 20px;
}

.mobile-controls button.is-pressed,
.mobile-controls button:active {
  transform: translateY(3px);
  box-shadow: inset 0 2px rgb(0 0 0 / 28%), 0 1px 0 #020700;
  filter: brightness(1.28);
}

.jump-button,
.enter-button {
  min-height: 72px;
  border-radius: 50%;
  font-weight: 800;
}

.enter-button {
  border-radius: 12px !important;
}

.jump-button small,
.enter-button small {
  display: block;
  margin-top: 4px;
  color: #8eb36e;
  font-size: 8px;
}

.keyboard-hint {
  margin: 11px 0 0;
  color: #789365;
  text-align: center;
  font-size: 11px;
}

dialog {
  width: min(92vw, 570px);
  max-height: min(85vh, 650px);
  padding: 0;
  overflow: auto;
  border: 2px solid var(--bark-light);
  border-radius: 10px;
  color: var(--cream);
  background: #071006;
  box-shadow: 0 20px 70px #000;
}

dialog::backdrop {
  background: rgb(0 0 0 / 78%);
  backdrop-filter: blur(3px);
}

.dialog-heading {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 17px;
  border-bottom: 1px solid #3c591d;
  background: #10220b;
}

.dialog-heading h2 { margin: 0; color: var(--gold); font-size: 18px; }
.close-button { width: 34px; height: 34px; border-radius: 50%; font-size: 22px; }
.dialog-body { padding: 17px; line-height: 1.55; font-size: 13px; }
.help-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 20px 0; }
.help-grid div { display: flex; align-items: center; gap: 7px; }
kbd { min-width: 28px; padding: 4px 6px; border: 1px solid #577c36; border-radius: 4px; color: #fff; background: #17300d; text-align: center; box-shadow: 0 2px #030; }
.help-note { color: #b6d098; }

@media (pointer: coarse), (max-width: 720px) {
  .mobile-controls { display: grid; }
  .keyboard-hint { display: none; }
}

@media (max-width: 540px) {
  .page-shell { padding-inline: 8px; }
  .masthead { align-items: center; }
  .eyebrow { display: none; }
  .small-button { min-height: 32px; padding: 6px 8px; }
  #sound-toggle span { display: none; }
  .game-cabinet { padding: 8px; border-radius: 10px; }
  .screen-wrap { border-width: 4px; }
  .cabinet-strip { padding-top: 10px; }
  .mobile-controls { gap: 7px; }
  .dpad { grid-template: repeat(2, 47px) / repeat(3, 47px); }
  .dpad button { width: 45px; height: 45px; }
  .jump-button, .enter-button { min-height: 64px; font-size: 11px; }
  .help-grid { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
}
