:root {
  --bg: #060605;
  --panel: rgba(12, 11, 10, 0.96);
  --ink: #dfd7c5;
  --muted: #827b6d;
  --amber: #d49b4b;
  --rust: #c83e2b;
  --hairline: rgba(223, 215, 197, 0.16);
  --hairline-strong: rgba(223, 215, 197, 0.34);
  --mono: 'SFMono-Regular', 'Menlo', 'Consolas', monospace;
  --sans: 'Avenir Next', 'Helvetica Neue', system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 13px;
  -webkit-font-smoothing: antialiased;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
}

button:disabled {
  opacity: 0.35;
  cursor: default;
}

button:focus-visible,
a:focus-visible,
canvas:focus-visible {
  outline: 1px solid var(--amber);
  outline-offset: 4px;
}

kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 20px;
  padding: 0 5px;
  border: 1px solid var(--hairline-strong);
  border-radius: 1px;
  background: rgba(223, 215, 197, 0.05);
  color: var(--ink);
  font: 10px/1 var(--mono);
  letter-spacing: 0.04em;
}

.game-shell {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  isolation: isolate;
}

#scene {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  outline: none;
}

/* Subtle organic noise + deep vignette + horror danger/hit edges */
.grain,
.vignette,
.danger-edge,
.hit-flash {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.grain {
  z-index: 1;
  opacity: 0.045;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

.vignette {
  z-index: 1;
  box-shadow: inset 0 0 155px 42px rgba(3, 3, 2, 0.62);
}

.danger-edge {
  z-index: 2;
  opacity: 0;
  box-shadow: inset 0 0 120px 24px rgba(200, 62, 43, 0.42);
  transition: opacity 0.22s ease;
}

.danger-edge.on {
  opacity: 1;
}

.hit-flash {
  z-index: 3;
  opacity: 0;
  box-shadow: inset 0 0 165px 45px rgba(200, 62, 43, 0.85);
  transition: opacity 0.35s ease-out;
}

.hit-flash.on {
  opacity: 1;
  transition: none;
}

/* Archival Y2K corner ticks on tactical containers */
.corner-ticks {
  background-image:
    linear-gradient(var(--ink), var(--ink)), linear-gradient(var(--ink), var(--ink)),
    linear-gradient(var(--ink), var(--ink)), linear-gradient(var(--ink), var(--ink)),
    linear-gradient(var(--ink), var(--ink)), linear-gradient(var(--ink), var(--ink)),
    linear-gradient(var(--ink), var(--ink)), linear-gradient(var(--ink), var(--ink));
  background-repeat: no-repeat;
  background-size:
    5px 1px, 1px 5px,
    5px 1px, 1px 5px,
    5px 1px, 1px 5px,
    5px 1px, 1px 5px;
  background-position:
    left top, left top,
    right top, right top,
    left bottom, left bottom,
    right bottom, right bottom;
}

/* Top bar */
.hud-top {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 20px 28px;
  background: linear-gradient(180deg, rgba(6, 6, 5, 0.9) 0%, rgba(6, 6, 5, 0) 100%);
}

.hud-left {
  display: flex;
  align-items: center;
  gap: 14px;
  flex: 1 1 0;
  min-width: 0;
}

.brand {
  font: 600 12px/1 var(--mono);
  letter-spacing: 0.22em;
  color: var(--ink);
  white-space: nowrap;
}

.diff-badge {
  padding: 4px 8px;
  border: 1px solid var(--hairline-strong);
  background: rgba(12, 11, 10, 0.85);
  font: 600 10px/1 var(--mono);
  letter-spacing: 0.12em;
  color: var(--amber);
  white-space: nowrap;
  transition: opacity 0.35s ease, color 0.2s ease, border-color 0.2s ease;
}

.diff-badge[data-diff='hard'] {
  color: var(--amber);
  border-color: rgba(212, 155, 75, 0.55);
}

.diff-badge[data-diff='nightmare'] {
  color: var(--rust);
  border-color: rgba(200, 62, 43, 0.65);
}

.mode-switch {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--hairline);
  background: rgba(10, 9, 8, 0.84);
  transition: opacity 0.35s ease;
}

.mode-switch button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  font-size: 11px;
  color: var(--muted);
  transition: color 0.16s ease, background 0.16s ease;
  white-space: nowrap;
}

.mode-switch kbd {
  height: 17px;
  min-width: 17px;
  padding: 0 4px;
  font-size: 9px;
  border-color: rgba(223, 215, 197, 0.16);
  color: var(--muted);
}

.mode-switch button:hover {
  color: var(--ink);
}

.mode-switch button[aria-pressed='true'] {
  background: rgba(212, 155, 75, 0.16);
  color: var(--amber);
}

.mode-switch button[aria-pressed='true'] kbd {
  border-color: rgba(212, 155, 75, 0.5);
  color: var(--amber);
}

/* Center corridor progress filament */
.corridor-track {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
  transition: opacity 0.35s ease;
}

.route-filament {
  position: relative;
  width: clamp(82px, 12vw, 172px);
  height: 2px;
  background: rgba(223, 215, 197, 0.16);
}

.route-fill {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 0%;
  background: var(--rust);
}

.route-pip {
  position: absolute;
  top: 50%;
  left: 0%;
  width: 6px;
  height: 6px;
  background: var(--ink);
  transform: translate(-50%, -50%) rotate(45deg);
}

.route-pct {
  font: 11px/1 var(--mono);
  letter-spacing: 0.08em;
  color: var(--muted);
  min-width: 32px;
}

/* Top-right utility actions */
.hud-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex: 1 1 0;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 31px;
  padding: 0 11px;
  border: 1px solid var(--hairline);
  background: rgba(10, 9, 8, 0.82);
  color: var(--muted);
  font: 11px/1 var(--mono);
  letter-spacing: 0.06em;
  transition: color 0.16s ease, border-color 0.16s ease;
}

.icon-btn svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

.icon-btn:hover:not(:disabled) {
  color: var(--ink);
  border-color: var(--hairline-strong);
}

.icon-square {
  width: 31px;
  padding: 0;
  justify-content: center;
}

#soundButton[aria-pressed='true'] {
  color: var(--ink);
}

#soundButton[aria-pressed='true'] .sound-icon-off,
#soundButton[aria-pressed='false'] .sound-icon-on {
  display: none;
}

#pauseButton .play-icon {
  display: none;
}

.game-shell.is-paused #pauseButton .pause-icon {
  display: none;
}

.game-shell.is-paused #pauseButton .play-icon {
  display: block;
}

/* Bottom-center ergonomic tactile cluster */
.hud-bottom {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 28px 24px;
  background: linear-gradient(0deg, rgba(6, 6, 5, 0.88) 0%, rgba(6, 6, 5, 0) 100%);
  pointer-events: none;
  transition: opacity 0.35s ease;
}

.run-hints {
  display: flex;
  align-items: center;
  gap: 18px;
  margin-bottom: 12px;
  font: 11px/1 var(--mono);
  color: var(--muted);
  transition: opacity 0.8s ease;
}

.run-hints.faded {
  opacity: 0;
}

.run-hints span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.tactile-cluster {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 10px 16px;
  border: 1px solid var(--hairline);
  background: rgba(10, 9, 8, 0.88);
  pointer-events: auto;
}

.health {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-right: 18px;
  border-right: 1px solid var(--hairline);
}

.health .pip {
  display: inline-flex;
  width: 14px;
  height: 14px;
  color: var(--rust);
  transition: color 0.25s ease, transform 0.25s ease;
}

.health .pip svg {
  width: 100%;
  height: 100%;
  fill: currentColor;
}

.health .pip.empty {
  color: rgba(223, 215, 197, 0.14);
  transform: scale(0.8);
}

.probe-control {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 184px;
}

.probe-control > button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 2px 0;
  color: var(--ink);
  font: 600 10px/1 var(--mono);
  letter-spacing: 0.14em;
}

.probe-control > button:hover:not(:disabled) {
  color: var(--amber);
}

.probe-control > button kbd {
  min-width: 50px;
  height: 20px;
  font-size: 9px;
  border-color: rgba(212, 155, 75, 0.45);
  color: var(--amber);
}

.charge-row {
  display: flex;
  gap: 5px;
}

.charge-row i {
  position: relative;
  display: block;
  flex: 1;
  height: 3px;
  background: rgba(223, 215, 197, 0.14);
  overflow: hidden;
}

.charge-row i > span {
  display: block;
  height: 100%;
  width: 100%;
  background: var(--amber);
  transition: width 0.08s linear;
}

.charge-row i.empty > span {
  background: rgba(212, 155, 75, 0.42);
}

/* Whisper toast for mode switches only */
.toast {
  position: absolute;
  left: 50%;
  top: 74px;
  transform: translateX(-50%);
  z-index: 6;
  padding: 6px 14px;
  border: 1px solid var(--hairline);
  background: rgba(10, 9, 8, 0.9);
  color: var(--amber);
  font: 11px/1.2 var(--mono);
  letter-spacing: 0.08em;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease;
  white-space: nowrap;
}

.toast.show {
  opacity: 1;
}

.toast.danger {
  color: var(--rust);
  border-color: rgba(200, 62, 43, 0.55);
}

/* Title Screen */
.intro-overlay {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: flex;
  align-items: center;
  padding: 68px 7%;
  background: linear-gradient(90deg, rgba(6, 6, 5, 0.94) 0%, rgba(6, 6, 5, 0.78) 36%, rgba(6, 6, 5, 0.2) 64%, transparent 86%);
}

.intro-overlay[hidden] {
  display: none;
}

.intro-content {
  max-width: 420px;
}

.intro-eyebrow {
  display: block;
  font: 10px/1 var(--mono);
  letter-spacing: 0.24em;
  color: var(--rust);
  margin-bottom: 16px;
}

h1 {
  margin: 0 0 16px;
  font-family: var(--sans);
  font-weight: 700;
  font-size: clamp(52px, 5.2vw, 74px);
  line-height: 0.94;
  letter-spacing: -0.03em;
  color: var(--ink);
}

.intro-lead {
  margin: 0 0 22px;
  font-size: 13px;
  line-height: 1.6;
  color: #b4ab9a;
}

/* 3-Difficulty Picker */
.difficulty-block {
  margin-bottom: 22px;
}

.modal-diff {
  margin: 0 0 20px;
}

.diff-caption {
  display: block;
  font: 9px/1 var(--mono);
  letter-spacing: 0.18em;
  color: var(--muted);
  margin-bottom: 8px;
}

.difficulty-picker {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.difficulty-picker button {
  padding: 9px 8px;
  border: 1px solid var(--hairline);
  background: rgba(12, 11, 10, 0.85);
  color: var(--muted);
  font: 600 10px/1.1 var(--mono);
  letter-spacing: 0.08em;
  white-space: nowrap;
  transition: border-color 0.16s ease, color 0.16s ease, background 0.16s ease;
}

.difficulty-picker button:hover {
  color: var(--ink);
  border-color: var(--hairline-strong);
}

.difficulty-picker button[data-difficulty='normal'][aria-pressed='true'] {
  color: var(--ink);
  border-color: var(--ink);
  background: rgba(223, 215, 197, 0.1);
}

.difficulty-picker button[data-difficulty='hard'][aria-pressed='true'] {
  color: var(--amber);
  border-color: var(--amber);
  background: rgba(212, 155, 75, 0.14);
}

.difficulty-picker button[data-difficulty='nightmare'][aria-pressed='true'] {
  color: var(--rust);
  border-color: var(--rust);
  background: rgba(200, 62, 43, 0.16);
}

.diff-summary {
  margin: 9px 0 0;
  font: 11px/1.3 var(--mono);
  color: #a69d8d;
}

.intro-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  margin-bottom: 24px;
  font: 11px/1 var(--mono);
  color: var(--muted);
}

.intro-controls span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.primary-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 45px;
  padding: 0 22px;
  background: var(--ink);
  color: #090908;
  font: 700 12px/1 var(--mono);
  letter-spacing: 0.15em;
  text-transform: uppercase;
  transition: background 0.16s ease, color 0.16s ease, transform 0.1s ease;
}

.primary-btn:hover:not(:disabled) {
  background: var(--rust);
  color: var(--ink);
}

.primary-btn:active:not(:disabled) {
  transform: translateY(1px);
}

.ghost-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--hairline-strong);
  color: var(--ink);
  font: 11px/1 var(--mono);
  letter-spacing: 0.08em;
  transition: border-color 0.16s ease, color 0.16s ease;
}

.ghost-btn:hover:not(:disabled) {
  border-color: var(--amber);
  color: var(--amber);
}

.intro-note {
  margin: 11px 0 0;
  font-size: 11px;
  color: var(--muted);
}

/* Hide gameplay HUD on intro */
.game-shell.is-intro .diff-badge,
.game-shell.is-intro .mode-switch,
.game-shell.is-intro .corridor-track,
.game-shell.is-intro .hud-bottom {
  opacity: 0;
  pointer-events: none;
}

.game-shell.is-intro .hud-top {
  z-index: 7;
  background: none;
}

/* Pause & End Panels */
.center-overlay {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(4, 4, 3, 0.82);
}

.center-overlay[hidden] {
  display: none;
}

.modal-panel {
  width: 470px;
  padding: 32px 34px;
  background: var(--panel);
  border: 1px solid var(--hairline-strong);
  box-shadow: 0 32px 100px rgba(0, 0, 0, 0.85);
}

.panel-eyebrow {
  display: block;
  font: 10px/1 var(--mono);
  letter-spacing: 0.2em;
  color: var(--rust);
  margin-bottom: 10px;
}

.modal-panel h2 {
  margin: 0 0 10px;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.panel-desc {
  margin: 0;
  font-size: 12px;
  line-height: 1.6;
  color: var(--muted);
}

.pause-keys {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 15px;
  margin: 18px 0 20px;
  padding: 13px 0;
  border-top: 1px solid var(--hairline);
  border-bottom: 1px solid var(--hairline);
  font: 11px/1 var(--mono);
  color: var(--muted);
}

.pause-keys span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.panel-stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.secondary-row {
  display: flex;
  gap: 10px;
}

.secondary-row .primary-btn {
  flex: 1.15;
  min-height: 40px;
}

.end-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin: 20px 0 20px;
  padding: 16px 0;
  border-top: 1px solid var(--hairline);
  border-bottom: 1px solid var(--hairline);
}

.end-stats strong {
  display: block;
  font: 500 21px/1.1 var(--mono);
  color: var(--ink);
}

.end-stats span {
  display: block;
  margin-top: 6px;
  font-size: 10px;
  color: var(--muted);
  letter-spacing: 0.04em;
}

.subtle-link {
  display: block;
  margin: 14px auto 0;
  font: 11px/1 var(--mono);
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 4px;
}

.subtle-link:hover {
  color: var(--amber);
}

/* Field Notes Dialog */
dialog {
  background: #0d0c0b;
  border: 1px solid var(--hairline-strong);
  color: var(--ink);
  padding: 28px 34px;
  max-width: 590px;
  width: 90%;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 32px 100px rgba(0, 0, 0, 0.9);
}

dialog::backdrop {
  background: rgba(3, 3, 2, 0.84);
}

.dialog-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font: 10px/1 var(--mono);
  letter-spacing: 0.2em;
  color: var(--rust);
  padding-bottom: 14px;
  border-bottom: 1px solid var(--hairline);
}

.dialog-head button {
  font-size: 22px;
  line-height: 1;
  color: var(--muted);
  padding: 2px 6px;
}

.dialog-head button:hover {
  color: var(--ink);
}

dialog h2 {
  margin: 20px 0 14px;
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

dialog p {
  margin: 0 0 12px;
  font-size: 12.5px;
  line-height: 1.7;
  color: #bfb7a7;
}

dialog strong {
  color: var(--ink);
  font-weight: 600;
}

.context-block {
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--hairline);
}

.context-block h3 {
  margin: 0 0 10px;
  font: 10px/1 var(--mono);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}

.ref-links {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
}

.ref-links a {
  font: 11px/1.3 var(--mono);
  color: var(--amber);
  text-decoration: underline;
  text-underline-offset: 4px;
}

.loading,
.webgl-error {
  position: absolute;
  inset: 0;
  z-index: 20;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font: 11px/1.6 var(--mono);
  letter-spacing: 0.18em;
  color: var(--muted);
}

.loading[hidden],
.webgl-error[hidden] {
  display: none;
}

@media (max-width: 1180px) {
  .hud-top {
    padding: 16px 20px;
    gap: 10px;
  }
  .hud-left {
    gap: 10px;
  }
  .brand {
    letter-spacing: 0.14em;
    font-size: 11px;
  }
  .diff-badge {
    padding: 4px 6px;
    font-size: 9px;
  }
  .mode-switch button {
    padding: 4px 6px;
    font-size: 10px;
    gap: 4px;
  }
  .icon-btn {
    padding: 0 8px;
    font-size: 10px;
  }
}

@media (max-width: 960px) {
  .mode-switch button span,
  .icon-btn span {
    display: none;
  }
  .mode-switch button {
    padding: 4px 6px;
  }
  .icon-btn {
    width: 31px;
    padding: 0;
    justify-content: center;
  }
}

@media (max-height: 700px) {
  .intro-overlay {
    padding: 46px 6%;
  }
  h1 {
    font-size: 50px;
    margin-bottom: 12px;
  }
  .intro-lead {
    margin-bottom: 14px;
  }
  .difficulty-block {
    margin-bottom: 14px;
  }
  .intro-controls {
    margin-bottom: 16px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
  .grain {
    display: none;
  }
}
