/* ==========================================================================
   UI TYPE & SURFACE LAW (Pong, 2026-07-06) — applies to ALL UI, including
   module-injected <style> blocks (migrate them to this law when touched):
   - Faces: Nunito for everything; Space Mono ONLY for telemetry (key hints,
     counts, coordinates, tiny uppercase labels).
   - Weights: 400 default · 600 names/emphasis · 800 for ONE heading per panel.
     Never 700-spam. When everything is bold, nothing is.
   - Italics are banned. No <em>/<i> styling anywhere.
   - Surfaces: no borders. Group with spacing and text color (primary /
     secondary / muted), not boxes. Panels are quiet dark glass + blur.
   - Clean > bulky. If a panel needs a border to read, its spacing is wrong.
   ========================================================================== */

@font-face {
  font-family: "Nunito";
  src: url("assets/fonts/nunito-var.woff2") format("woff2");
  font-weight: 400 900;
  font-display: swap;
}

@font-face {
  font-family: "Space Mono";
  src: url("assets/fonts/spacemono-400.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}

@font-face {
  font-family: "Space Mono";
  src: url("assets/fonts/spacemono-700.woff2") format("woff2");
  font-weight: 700;
  font-display: swap;
}

:root {
  color-scheme: dark;
  font-family: "Nunito", ui-rounded, "SF Pro Rounded", ui-sans-serif, system-ui, sans-serif;
  background: #030615;
  color: #f6f3ea;

  /* Type law tokens */
  --font-ui: "Nunito", ui-rounded, "SF Pro Rounded", ui-sans-serif, system-ui, sans-serif;
  --font-mono: "Space Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

  /* Brand palette */
  --neon-cyan:        #2bdfff;
  --neon-cyan-dim:    rgba(43, 223, 255, 0.42);
  --neon-cyan-glow:   rgba(43, 223, 255, 0.14);
  --neon-cyan-badge:  rgba(43, 223, 255, 0.08);
  --neon-cyan-border: rgba(43, 223, 255, 0.34);
  --neon-gold:        #ffc83b;
  --neon-gold-dark:   #c8930a;
  --neon-orange:      #e87040;

  /* Text hierarchy */
  --text-primary:   #f6f3ea;
  --text-secondary: #9ccfd8;
  --text-muted:     #7fa7b0;
  --text-white:     #ffffff;

  /* Surface / glass */
  --glass-bg:         rgba(15, 17, 23, 0.85);
  --glass-bg-deep:    rgba(10, 12, 18, 0.96);
  --glass-bg-light:   rgba(20, 24, 32, 0.72);
  --glass-border:     rgba(43, 223, 255, 0.15);
  --glass-border-mid: rgba(43, 223, 255, 0.22);
  --glass-glow:       0 14px 34px rgba(0,0,0,0.44), 0 0 18px rgba(43,223,255,0.14);

  /* Syntax highlight (MicroPython Code tab) */
  --syn-keyword:  #c792ea;
  --syn-string:   #c3e88d;
  --syn-number:   #f78c6c;
  --syn-comment:  #546e7a;
  --syn-builtin:  #82aaff;
  --syn-operator: #89ddff;
  --syn-default:  #eeffff;
}

* {
  box-sizing: border-box;
}

/* The italics ban — module styles opt back in never */
em,
i {
  font-style: normal;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow: hidden;
}

.app-shell {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  background: #030615;
}

.three-root {
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: none;
}

.three-root.dragging {
  cursor: grabbing;
}

.three-root canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.hud,
.controls {
  position: fixed;
  border-radius: 12px;
  background: rgba(4, 9, 28, 0.55);
  backdrop-filter: blur(14px);
}

.hud {
  z-index: 2;
}

/* Above base HUD chrome (z-index 2) so same-tier siblings can't crowd it on
   open, but below the mobile clear-screen/radial-toggle buttons (5) and the
   radial ring (6) — those two must always stay reachable over the modal. */
.controls {
  z-index: 4;
}

.hud {
  left: 24px;
  top: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  border-radius: 50%;
}

.hud-avatars {
  position: relative;
  width: 58px;
  height: 52px;
}

.avatar-container {
  border-radius: 50%;
  overflow: visible;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(4, 9, 28, 0.7);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.avatar-container:hover {
  transform: scale(1.05);
}

.player-avatar {
  position: absolute;
  left: 0;
  top: 2px;
  width: 44px;
  height: 44px;
  z-index: 2;
}

.pet-avatar {
  position: absolute;
  right: 0;
  bottom: 0px;
  width: 24px;
  height: 24px;
  z-index: 3;
  border: 1.5px solid rgba(4, 9, 28, 0.95);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
  background: rgba(4, 9, 28, 0.95);
}

.avatar-svg {
  width: 100%;
  height: 100%;
  display: block;
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 400;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: 19px;
  font-weight: 800;
  letter-spacing: 0.01em;
}

.readout {
  position: fixed;
  left: 24px;
  bottom: 16px;
  z-index: 2;
  display: flex;
  gap: 4px 14px;
  flex-wrap: wrap;
  max-width: 480px;
  background: rgba(4, 9, 28, 0.55);
  backdrop-filter: blur(14px);
  padding: 8px 16px;
  border-radius: 12px;
}

.readout span,
.controls span {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 0;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 400;
  font-variant-numeric: tabular-nums;
}

.reticle {
  position: fixed;
  left: 50%;
  top: 50%;
  z-index: 2;
  width: 18px;
  height: 18px;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.reticle::before,
.reticle::after {
  content: "";
  position: absolute;
  background: rgba(246, 243, 234, 0.82);
  box-shadow: 0 0 8px rgba(156, 207, 216, 0.45);
}

.reticle::before {
  left: 8px;
  top: 0;
  width: 2px;
  height: 18px;
}

.reticle::after {
  left: 0;
  top: 8px;
  width: 18px;
  height: 2px;
}

.controls {
  left: 50%;
  bottom: 22px;
  /* Shrinkable grid tracks keep long help labels inside the glass on narrower
     laptop viewports. Auto tracks use min-content widths and can bleed out. */
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-items: start;
  justify-content: center;
  width: min(980px, calc(100vw - 120px));
  max-width: min(980px, calc(100vw - 120px));
  gap: 16px 36px;
  padding: 14px 22px 12px;
  transform: translateX(-50%);
}

.controls-group {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.controls-group h3 {
  margin: 0 0 4px;
  font-family: "Space Mono", monospace;
  font-size: 10px;
  font-weight: 400;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--neon-gold, #ffc83b);
}

.controls span b {
  min-width: 0;
  font-family: "Space Mono", monospace;
  font-size: 11px;
  font-weight: 400;
  color: var(--text-primary, #dffcff);
}

.controls[hidden] {
  display: none;
}

.controls span {
  display: grid;
  grid-template-columns: clamp(72px, 8vw, 92px) minmax(0, 1fr);
  align-items: baseline;
  gap: 8px;
  min-width: 0;
  min-height: 19px;
  padding: 1px 0;
  font-family: var(--font-mono);
  font-size: 10px;
  line-height: 1.35;
  color: var(--text-muted);
  white-space: normal;
  overflow-wrap: anywhere;
}

/* Touch controls: hidden on fine-pointer machines, shown when the primary
   input is a thumb. Left stick walks (full tilt = sprint), right buttons jump;
   the rest of the screen keeps the existing drag-to-look and tap-to-select. */
.touch-stick,
.touch-jump,
.touch-boost {
  display: none;
  position: fixed;
  z-index: 3;
  background: rgba(4, 9, 28, 0.4);
  backdrop-filter: blur(10px);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.touch-stick {
  left: 22px;
  bottom: 78px;
  width: 118px;
  height: 118px;
  border-radius: 50%;
}

.touch-nub {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 52px;
  height: 52px;
  margin: -26px 0 0 -26px;
  border-radius: 50%;
  background: rgba(43, 223, 255, 0.28);
  box-shadow: 0 0 14px rgba(43, 223, 255, 0.25);
}

.touch-jump,
.touch-boost {
  right: 22px;
  border: none;
  border-radius: 50%;
  color: var(--text-secondary);
  font-family: var(--font-ui);
  font-weight: 600;
}

.touch-jump {
  bottom: 116px;
  width: 72px;
  height: 72px;
  font-size: 28px;
}

.touch-boost {
  bottom: 196px;
  width: 58px;
  height: 58px;
  right: 29px;
  color: var(--neon-cyan);
  font-size: 20px;
  background: rgba(43, 223, 255, 0.16);
  box-shadow: 0 0 18px rgba(43, 223, 255, 0.16);
}

.touch-action-rail {
  display: none;
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 66px);
  z-index: 3;
  transform: translateX(-50%);
  gap: 5px;
  max-width: calc(100vw - 172px);
  padding: 0;
  border-radius: 999px;
  background: transparent;
}

.touch-action-btn {
  width: 38px;
  height: 38px;
  border: none;
  border-radius: 50%;
  padding: 0;
  background: rgba(4, 9, 28, 0.42);
  backdrop-filter: blur(10px);
  color: var(--text-secondary);
  font-family: var(--font-ui);
  font-size: 15px;
  font-weight: 600;
  touch-action: manipulation;
}

.touch-danger {
  color: #ffb1c8;
  background: rgba(255, 84, 112, 0.12);
}

.touch-action-btn[hidden] {
  display: none !important;
}

/* Map fold, radial menu, clear-screen: mobile-only HUD de-clutter
   (docs/plans/mobile-ui-plan.md). Same touch-only pattern as the stick/jump:
   hidden by default, shown under (pointer: coarse) below. */
.touch-map-toggle,
.touch-radial-toggle,
.touch-clear-screen {
  display: none;
  position: fixed;
  z-index: 5; /* above .controls (4) — always reachable over the help modal */
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: rgba(4, 9, 28, 0.42);
  backdrop-filter: blur(10px);
  color: var(--text-secondary);
  font-family: var(--font-ui);
  font-size: 15px;
  font-weight: 600;
  touch-action: manipulation;
}

.touch-map-toggle {
  top: 22px;
  right: 24px;
}

.touch-map-toggle.map-hidden {
  display: none;
}

.touch-radial-toggle {
  top: 50%;
  right: 14px;
  transform: translateY(-50%);
}

.touch-clear-screen {
  top: 50%;
  left: 14px;
  transform: translateY(-50%);
}

.touch-clear-screen.active {
  color: var(--neon-cyan);
  background: rgba(43, 223, 255, 0.16);
}

.touch-radial-menu {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 6; /* above the radial-toggle button (5) that opens it */
  align-items: center;
  justify-content: center;
  background: rgba(2, 4, 12, 0.45);
  backdrop-filter: blur(2px);
}

.touch-radial-menu[hidden] {
  display: none;
}

.touch-radial-ring {
  position: relative;
  width: 1px;
  height: 1px;
}

.touch-radial-btn {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 42px;
  height: 42px;
  margin: -21px 0 0 -21px;
  border: none;
  border-radius: 50%;
  background: rgba(4, 9, 28, 0.72);
  backdrop-filter: blur(10px);
  color: var(--text-secondary);
  font-family: var(--font-ui);
  font-size: 16px;
  font-weight: 600;
  touch-action: manipulation;
}

.touch-radial-btn:nth-child(1) { transform: translate(0px, -78px); }
.touch-radial-btn:nth-child(2) { transform: translate(74px, -24px); }
.touch-radial-btn:nth-child(3) { transform: translate(46px, 63px); }
.touch-radial-btn:nth-child(4) { transform: translate(-46px, 63px); }
.touch-radial-btn:nth-child(5) { transform: translate(-74px, -24px); }

@media (pointer: coarse) {
  .touch-stick,
  .touch-jump,
  .touch-boost {
    display: block;
  }

  .touch-action-rail {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .touch-map-toggle:not(.map-hidden),
  .touch-radial-toggle,
  .touch-clear-screen {
    display: block;
  }

  .touch-radial-menu:not([hidden]) {
    display: flex;
  }

  /* Screen-clear: hide the map button, action rail, and readout/quest chip.
     Stick, jump, and boost stay — Pong's call, movement never disappears. */
  .touch-map-toggle.hud-cleared,
  .touch-action-rail.hud-cleared,
  .readout.hud-cleared {
    display: none;
  }

  /* Map fold: minimap + zone label default to hidden on mobile, tucked
     behind a small button in the same top-right corner they normally
     occupy. Desktop keeps the map always-on, untouched. */
  .minimap,
  .zone-label {
    transition: opacity 0.15s ease;
  }

  .minimap {
    pointer-events: auto;
    cursor: pointer;
  }

  .minimap.map-hidden,
  .zone-label.map-hidden {
    display: none;
  }

  .readout {
    left: 50%;
    right: auto;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 10px);
    transform: translateX(-50%);
    justify-content: center;
    width: min(360px, calc(100vw - 32px));
    max-width: none;
    gap: 6px 10px;
    padding: 7px 12px;
    text-align: center;
  }

  .readout span {
    min-height: 18px;
    font-size: 10.5px;
    line-height: 1.25;
  }

  #positionReadout,
  #lookReadout {
    display: none;
  }
}

.controls-toggle {
  position: fixed;
  right: 24px;
  bottom: 22px;
  z-index: 2;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: rgba(4, 9, 28, 0.55);
  backdrop-filter: blur(14px);
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}

.controls-toggle:hover {
  color: var(--neon-cyan);
}

@media (pointer: coarse) {
  /* Folded into the radial menu's "?" icon on mobile — no standalone button. */
  .controls-toggle {
    display: none;
  }
}

.station-panel[hidden] {
  display: none;
}

.station-panel {
  position: fixed;
  left: 24px;
  top: 96px;
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 180px;
  width: 280px;
  max-width: 280px;
  border-radius: 12px;
  padding: 14px 16px;
  background: rgba(4, 9, 28, 0.62);
  border: none;
  backdrop-filter: blur(14px);
}

.station-panel strong {
  color: var(--neon-gold);
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.01em;
}

.station-panel span {
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 400;
}

.station-panel .npc-line {
  max-width: 240px;
  color: var(--text-primary);
  font-weight: 400;
  line-height: 1.5;
  white-space: pre-wrap;
}

.panel-button {
  margin-top: 4px;
  border: none;
  border-radius: 8px;
  padding: 8px 10px;
  background: rgba(43, 223, 255, 0.14);
  color: var(--neon-cyan);
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.panel-button:hover:not(:disabled) {
  background: rgba(43, 223, 255, 0.24);
}

.panel-button:disabled {
  background: rgba(242, 193, 78, 0.12);
  color: var(--neon-gold);
  cursor: default;
}

.readout span[hidden] {
  display: none;
}

.quest-chip {
  color: var(--neon-gold) !important;
  font-weight: 600 !important;
}

.minimap {
  position: fixed;
  right: 24px;
  top: 22px;
  z-index: 2;
  width: 210px;
  height: 180px;
  border-radius: 12px;
  background: rgba(4, 9, 28, 0.3);
  border: 1px solid rgba(156, 207, 216, 0.16);
  backdrop-filter: blur(5px);
  pointer-events: none;
}

.zone-label {
  position: fixed;
  top: 208px; /* minimap top 22 + height 180 + 6 gap */
  right: 24px;
  z-index: 2;
  width: 210px; /* same width as the minimap: text hugs its bottom-left corner */
  text-align: left;
  font-family: "Space Mono", monospace;
  font-size: 10px;
  font-weight: 400;
  letter-spacing: 0.04em;
  color: rgba(223, 252, 255, 0.78);
  text-shadow: 0 1px 4px rgba(2, 4, 12, 0.8);
  pointer-events: none;
}

.moon-map {
  position: fixed;
  inset: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(2, 4, 12, 0.45);
  backdrop-filter: blur(2px);
  cursor: pointer;
}

.moon-map[hidden] {
  display: none;
}

.moon-map canvas {
  width: min(880px, 92vw);
  border-radius: 12px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
}

.load-status {
  position: fixed;
  left: 50%;
  top: 24px;
  transform: translateX(-50%);
  z-index: 10; /* Make sure it draws over normal HUD items */
  max-width: min(520px, 90vw);
  width: max-content;
  text-align: center;
  border-radius: 12px;
  padding: 10px 16px;
  background: rgba(4, 9, 28, 0.62);
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 400;
  line-height: 1.4;
  backdrop-filter: blur(14px);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

.load-status.ready {
  color: var(--text-muted);
}

.load-status.error {
  color: #ffb1c8;
  font-weight: 600;
}

.harvest-notice-toast {
  position: fixed;
  left: 24px;
  bottom: 72px; /* Positioned above bottom-left telemetry */
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: 8px;
  background: rgba(43, 223, 255, 0.12);
  border: 1px solid rgba(43, 223, 255, 0.25);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5), 0 0 15px rgba(43, 223, 255, 0.15);
  backdrop-filter: blur(14px);
  color: var(--neon-cyan, #2bdfff);
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.02em;
  transition: opacity 0.2s ease, transform 0.2s ease;
  transform-origin: left center;
}

.harvest-notice-toast[hidden] {
  display: none !important;
}

@media (max-width: 760px) {
  .hud {
    right: 16px;
    left: 16px;
    top: 16px;
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
  }

  .controls {
    right: 16px;
    left: 16px;
    width: auto;
    max-width: none;
    grid-template-columns: repeat(auto-fit, minmax(min(210px, 100%), 1fr));
    transform: none;
  }
}
