:root {
  color-scheme: light;
  --paper: #f4eee1;
  --paper-card: #fbf7ee;
  --paper-shadow: rgba(45, 38, 28, 0.18);
  --ink: #1a1815;
  --ink-secondary: #524c40;
  --graphite: #7a7263;
  --grid-line: #d8cfba;
  --hatch-bg: #eee6d3;
  --accent-red: #b0352b;
  --accent-blue: #235d91;
  --accent-ochre: #b87d18;
  --font-sketch: "Courier New", Courier, "SF Mono", Menlo, ui-monospace, monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--paper);
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  position: fixed;
  inset: 0;
  font-family: var(--font-sketch);
  color: var(--ink);
  background-color: var(--paper);
  /* Subtle parchment grain & drafting grid background */
  background-image: 
    radial-gradient(circle at 50% 50%, rgba(255, 255, 255, 0.4) 0%, rgba(210, 198, 175, 0.45) 100%),
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 100% 100%, 32px 32px, 32px 32px;
}

#game {
  position: fixed;
  inset: 0;
  display: block;
  touch-action: none;
}

.top-bar {
  position: fixed;
  left: max(12px, env(safe-area-inset-left));
  top: max(12px, env(safe-area-inset-top));
  display: flex;
  gap: 8px;
  z-index: 10;
}

#sound-toggle,
#how-to-toggle {
  padding: 6px 12px;
  font: bold 11px var(--font-sketch);
  letter-spacing: 0.1em;
  color: var(--ink);
  background: var(--paper-card);
  border: 1.5px solid var(--ink);
  box-shadow: 2px 2px 0px var(--ink);
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 80ms ease, box-shadow 80ms ease;
}

#sound-toggle:hover,
#how-to-toggle:hover {
  background: #fff;
  transform: translate(-1px, -1px);
  box-shadow: 3px 3px 0px var(--ink);
}

#sound-toggle:active,
#how-to-toggle:active {
  transform: translate(1px, 1px);
  box-shadow: 1px 1px 0px var(--ink);
}

#sound-toggle:focus-visible,
#how-to-toggle:focus-visible {
  outline: 2px solid var(--accent-blue);
  outline-offset: 2px;
}

/* In-Game Contextual Onboarding Banner */
.hud-pill {
  position: fixed;
  bottom: max(28px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--paper-card);
  border: 2px solid var(--ink);
  box-shadow: 3px 3px 0px var(--ink);
  padding: 8px 18px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--accent-blue);
  pointer-events: none;
  z-index: 10;
  transition: opacity 180ms ease, transform 180ms ease;
  animation: floatPaper 2.2s ease-in-out infinite;
}

.hud-pill.hidden {
  opacity: 0;
  transform: translate(-50%, 12px);
}

@keyframes floatPaper {
  0%, 100% { transform: translate(-50%, 0); }
  50% { transform: translate(-50%, -3px); }
}

/* Fullscreen Overlay Dialog (Architectural Sketchbook Plate) */
#overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  text-align: center;
  z-index: 20;
  background: rgba(228, 220, 202, 0.85);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  transition: opacity 150ms ease;
}

#overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

/* Sketchbook Sheet Card */
.overlay-card.aero-spec {
  max-width: 500px;
  width: 100%;
  background: var(--paper-card);
  border: 2px solid var(--ink);
  /* Double ruled draft border */
  outline: 1px dashed var(--graphite);
  outline-offset: -5px;
  padding: clamp(16px, 3.2vw, 24px) clamp(16px, 3.2vw, 24px);
  box-shadow: 6px 7px 0px var(--paper-shadow), 0 12px 28px rgba(0, 0, 0, 0.12);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  position: relative;
}

.header-telemetry {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  border-bottom: 1.5px solid var(--ink);
  padding-bottom: 5px;
  margin-bottom: 2px;
}

.badge-tag {
  font-size: 9.5px;
  letter-spacing: 0.15em;
  color: var(--ink-secondary);
  text-transform: uppercase;
  font-weight: 700;
}

.badge-tag-status {
  font-size: 9.5px;
  letter-spacing: 0.14em;
  color: var(--accent-blue);
  display: flex;
  align-items: center;
  gap: 5px;
  font-weight: 700;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent-blue);
  border: 1px solid var(--ink);
}

#overlay h1 {
  margin: 0;
  font-size: clamp(34px, 8vw, 54px);
  font-weight: 900;
  letter-spacing: 0.32em;
  padding-left: 0.32em;
  color: var(--ink);
  text-shadow: 2px 2px 0px rgba(184, 125, 24, 0.25);
  border-bottom: 2px solid var(--ink);
  width: 90%;
  padding-bottom: 4px;
}

#overlay p#overlay-body {
  margin: 0;
  font-size: clamp(12px, 2.7vw, 13.5px);
  line-height: 1.45;
  color: var(--ink-secondary);
  max-width: 44ch;
}

/* Vector Schematic (Architectural Blueprint Plate) */
.schematic-container {
  width: 100%;
  background: var(--paper);
  border: 1.5px solid var(--ink);
  padding: 6px 8px 3px 8px;
  margin: 2px 0;
  box-shadow: inset 1px 1px 3px rgba(0, 0, 0, 0.08);
}

.schematic-svg {
  width: 100%;
  max-height: 105px;
  display: block;
}

/* Sketch Tutorial Cards */
.aero-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
  width: 100%;
  margin: 2px 0;
  text-align: left;
}

@media (min-width: 440px) {
  .aero-grid {
    grid-template-columns: 1fr 1fr 1fr;
  }
}

.aero-card {
  background: var(--paper);
  border: 1.5px solid var(--ink);
  padding: 7px 8px;
  position: relative;
  box-shadow: 2px 2px 0px rgba(0, 0, 0, 0.1);
}

.card-step {
  font-size: 8.5px;
  color: var(--graphite);
  letter-spacing: 0.1em;
  font-weight: 700;
}

.card-icon {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.05em;
  margin: 2px 0;
  color: var(--ink);
}

.card-desc {
  font-size: 9.5px;
  line-height: 1.35;
  color: var(--ink-secondary);
}

/* Telemetry Spec Bar */
.telemetry-bar {
  display: flex;
  justify-content: space-around;
  width: 100%;
  background: var(--hatch-bg);
  padding: 4px 6px;
  font-size: 9px;
  border: 1px solid var(--ink);
}

/* Run Debrief Telemetry Grid */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  width: 100%;
  margin: 6px 0;
}

.stats-grid.hidden {
  display: none;
}

.stat-box {
  background: var(--paper);
  border: 1.5px solid var(--ink);
  padding: 8px 10px;
  box-shadow: 2px 2px 0px rgba(0, 0, 0, 0.1);
  text-align: left;
}

.stat-label {
  font-size: 8.5px;
  color: var(--graphite);
  font-weight: 700;
  letter-spacing: 0.1em;
  margin-bottom: 3px;
}

.stat-val {
  font-size: 14px;
  font-weight: 900;
  color: var(--ink);
  letter-spacing: 0.05em;
}

.tel-item {
  display: flex;
  gap: 4px;
}

.tel-label {
  color: var(--graphite);
}

.tel-val {
  color: var(--ink);
  font-weight: 800;
}

.aero-legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  font-size: 10px;
  color: var(--ink-secondary);
  padding: 2px 0;
  width: 100%;
}

.aero-legend b {
  color: var(--ink);
}

/* Hand-Drawn Blueprint CTA Button */
.aero-launch-btn {
  margin-top: 4px;
  width: 100%;
  padding: 12px 16px;
  background: var(--paper-card);
  border: 2px solid var(--ink);
  color: var(--ink);
  font: bold 13px var(--font-sketch);
  letter-spacing: 0.2em;
  cursor: pointer;
  box-shadow: 3px 3px 0px var(--ink);
  transition: transform 80ms ease, box-shadow 80ms ease, background 80ms ease;
  touch-action: manipulation;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.aero-launch-btn:hover {
  background: #fff;
  transform: translate(-1px, -1px);
  box-shadow: 4px 4px 0px var(--ink);
  color: var(--accent-blue);
}

.aero-launch-btn:active {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0px var(--ink);
}

.aero-launch-btn .btn-bracket {
  color: var(--accent-red);
  font-weight: 700;
}

.blink-action {
  animation: pulseSketch 1.6s ease-in-out infinite;
}

.noscript {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  margin: 0;
  background: var(--paper);
}

@keyframes pulseSketch {
  0%, 100% {
    box-shadow: 3px 3px 0px var(--ink);
    border-color: var(--ink);
  }
  50% {
    box-shadow: 4px 4px 0px var(--accent-blue);
    border-color: var(--accent-blue);
  }
}

@media (prefers-reduced-motion: reduce) {
  .blink-action,
  .hud-pill {
    animation: none;
  }
}

