:root {
  color-scheme: dark;
  --black: #090b09;
  --ink: #111612;
  --pine: #17301f;
  --pine-light: #315d3d;
  --red: #d51f20;
  --red-dark: #721416;
  --snow: #eeeeea;
  --silver: #a8aaa6;
  --wood: #6b4127;
  --wood-dark: #2d1b12;
  --gold: #e6c44b;
}

* { box-sizing: border-box; }

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

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

body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  color: var(--snow);
  background:
    radial-gradient(circle at 50% -10%, rgba(49,93,61,.34), transparent 46%),
    repeating-linear-gradient(90deg, transparent 0 17px, rgba(255,255,255,.012) 18px),
    linear-gradient(#101611, #080a08 70%);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

button, input { font: inherit; }

button {
  color: var(--snow);
  border: 1px solid #806b45;
  border-radius: 7px;
  background: linear-gradient(#2b2c26, #151713);
  box-shadow: inset 0 1px rgba(255,255,255,.08), 0 2px 5px rgba(0,0,0,.45);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

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

.snow {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: .2;
  background-image:
    radial-gradient(circle, #fff 0 1px, transparent 1.4px),
    radial-gradient(circle, #fff 0 1px, transparent 1.4px);
  background-position: 0 0, 31px 47px;
  background-size: 83px 83px, 109px 109px;
  animation: snowfall 22s linear infinite;
}

@keyframes snowfall {
  to { background-position: 31px 166px, 0 211px; }
}

.app-shell {
  width: min(1050px, calc(100% - 24px));
  margin: 0 auto;
  padding: 18px 0 28px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin: 0 10px 10px;
}

.brand {
  color: var(--red);
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(18px, 3.2vw, 34px);
  font-style: italic;
  font-weight: 700;
  letter-spacing: -.035em;
  text-shadow: 0 2px #3b0809;
  white-space: nowrap;
}

.brand em { color: #f2473c; font-weight: inherit; }
.brand small {
  margin-left: 8px;
  color: var(--gold);
  font-family: ui-monospace, monospace;
  font-size: 10px;
  font-style: normal;
  letter-spacing: .12em;
}

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

.toolbar button { padding: 8px 11px; font-size: 12px; }

.cabinet {
  position: relative;
  padding: 16px;
  border: 1px solid #815336;
  border-radius: 19px;
  background:
    repeating-linear-gradient(90deg, rgba(255,255,255,.035) 0 2px, transparent 2px 8px),
    linear-gradient(135deg, #704429, #352117 55%, #5a351f);
  box-shadow:
    inset 0 0 0 3px #24150f,
    inset 0 0 0 5px #8c5a37,
    0 18px 50px rgba(0,0,0,.58);
}

.lights {
  position: absolute;
  z-index: 2;
  top: 7px;
  left: 8%;
  right: 8%;
  display: flex;
  justify-content: space-between;
}

.lights i {
  display: block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--red);
  box-shadow: 0 0 7px var(--red);
}

.lights i:nth-child(3n + 2) { background: #39a24d; box-shadow: 0 0 7px #39a24d; }
.lights i:nth-child(3n) { background: var(--gold); box-shadow: 0 0 7px var(--gold); }

.screen-bezel {
  padding: 13px;
  border: 2px solid #1c1f1c;
  border-radius: 13px;
  background: linear-gradient(145deg, #c1c1ba, #5d615d 38%, #1b1d1b 78%);
  box-shadow: inset 0 0 0 3px #343833, inset 0 0 15px #000;
}

.screen-wrap {
  position: relative;
  overflow: hidden;
  border: 3px solid #080a08;
  border-radius: 5px;
  background: #000;
  box-shadow: 0 0 0 2px #30352f, inset 0 0 22px #000;
}

#game {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 10;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  touch-action: none;
  cursor: crosshair;
  outline: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.glass {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(115deg, rgba(255,255,255,.055), transparent 26%),
    repeating-linear-gradient(0deg, rgba(255,255,255,.018) 0 1px, transparent 1px 3px);
  mix-blend-mode: screen;
}

.cabinet-footer {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 8px 0;
  color: #d5bd83;
  font-size: 11px;
}

.archive-note {
  margin: 10px 4px 0;
  color: #8f9b90;
  font-size: 11px;
  text-align: center;
}

.mobile-controls {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 28px;
  padding: 16px 4px 2px;
  padding: 16px max(4px, env(safe-area-inset-right)) max(2px, env(safe-area-inset-bottom)) max(4px, env(safe-area-inset-left));
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.touch-stick {
  --stick-x: 0px;
  --stick-y: 0px;
  position: relative;
  width: 124px;
  height: 124px;
  flex: 0 0 124px;
  overflow: hidden;
  border: 1px solid #756543;
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 50%, rgba(230,196,75,.08) 0 27%, transparent 28%),
    radial-gradient(circle at 40% 32%, #30332d, #151713 70%);
  box-shadow: inset 0 2px 7px rgba(255,255,255,.07), inset 0 -7px 15px rgba(0,0,0,.4), 0 4px 10px rgba(0,0,0,.4);
  cursor: grab;
  touch-action: none;
}

.touch-stick:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; }
.touch-stick.is-active { cursor: grabbing; border-color: var(--gold); }

.stick-direction {
  position: absolute;
  color: rgba(230,196,75,.42);
  font-size: 10px;
  line-height: 1;
  pointer-events: none;
}

.stick-up { top: 9px; left: 50%; transform: translateX(-50%); }
.stick-right { top: 50%; right: 9px; transform: translateY(-50%); }
.stick-down { bottom: 9px; left: 50%; transform: translateX(-50%); }
.stick-left { top: 50%; left: 9px; transform: translateY(-50%); }

.touch-stick-knob {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 48px;
  height: 48px;
  border: 1px solid #96805a;
  border-radius: 50%;
  background: radial-gradient(circle at 37% 30%, #56594f, #20231f 68%);
  box-shadow: inset 0 2px rgba(255,255,255,.1), 0 3px 8px rgba(0,0,0,.55);
  transform: translate(calc(-50% + var(--stick-x)), calc(-50% + var(--stick-y)));
  transition: transform 70ms ease-out, border-color 120ms ease;
  pointer-events: none;
}

.touch-stick.is-active .touch-stick-knob {
  border-color: var(--gold);
  transition: border-color 80ms ease;
}

.action-button {
  width: 76px;
  height: 76px;
  border-color: #ad3434;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 30%, #e63a34, #7c1114 72%);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .05em;
  transition: filter 120ms ease, opacity 120ms ease, transform 80ms ease;
}

.action-button.is-pressed { transform: translateY(2px) scale(.96); }
.action-button.is-unavailable { opacity: .58; filter: saturate(.45); }

dialog {
  width: min(520px, calc(100% - 28px));
  max-height: calc(100dvh - 28px);
  overflow: auto;
  color: var(--snow);
  border: 2px solid #8d6d43;
  border-radius: 12px;
  background: #101411;
  box-shadow: 0 24px 70px #000;
}

dialog::backdrop { background: rgba(0,0,0,.78); backdrop-filter: blur(3px); }
dialog h2 { margin: 4px 0 12px; color: var(--red); font-family: Georgia, serif; }
dialog p { color: #c7cdc7; line-height: 1.55; }

.dialog-close {
  float: right;
  width: 34px;
  height: 34px;
  font-size: 20px;
}

.help-grid {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 10px 14px;
  align-items: center;
}

kbd {
  padding: 4px 7px;
  color: var(--gold);
  border: 1px solid #625d4d;
  border-radius: 4px;
  background: #20231f;
  font-family: inherit;
  font-size: 11px;
}

.help-note { color: #95ad99; font-size: 12px; }

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 18px;
}

.dialog-actions button { padding: 9px 13px; }
.resume-button { border-color: #4d8358; }
#return-menu-button { border-color: #8d4242; }

@media (hover: none), (pointer: coarse), (max-width: 760px) {
  .app-shell { width: min(100% - 10px, 720px); padding-top: 8px; }
  .topbar { align-items: flex-start; margin-inline: 5px; }
  .toolbar { gap: 4px; }
  .toolbar button { padding: 7px 8px; font-size: 10px; }
  .cabinet { padding: 10px; border-radius: 13px; }
  .screen-bezel { padding: 7px; }
  .mobile-controls { display: flex; }
  .cabinet-footer { font-size: 9px; }
}

@media (max-width: 560px) {
  .topbar { display: block; }
  .brand { display: block; margin: 0 3px 8px; text-align: center; }
  .toolbar { justify-content: center; }
  .cabinet-footer span:first-child { display: none; }
  .cabinet-footer { justify-content: center; text-align: center; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; }
}
