/*
 * PathPlay base stylesheet.
 * Scenario palette is injected at runtime as CSS custom properties on :root
 * (see src/ui/ScreenManager.js applyPalette). Defaults below match the
 * engine default palette in DESIGN.md section 9.
 */
:root {
  --color-bg: #0d0d0d;
  --color-primary: #e8c96d;
  --color-accent: #4fc3f7;
  --color-text: #f5f5f5;
  --color-locked: #5a5a5a;

  /* Layout constants. Target viewport is 600x900 portrait (DESIGN.md section 9). */
  --stage-w: 600px;
  --stage-h: 900px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  /* --app-height is set from window.innerHeight in index.html so the stage
   * matches the VISIBLE viewport, excluding Android Chrome's dynamic URL bar.
   * dvh / vh are progressive fallbacks if that script doesn't run. */
  height: 100vh;
  height: 100dvh;
  height: var(--app-height, 100dvh);
  background: #000;
  color: var(--color-text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* The stage is the fixed portrait canvas everything renders into. */
#stage {
  position: relative;
  width: var(--stage-w);
  height: var(--stage-h);
  max-width: 100vw;
  max-height: var(--app-height, 100dvh);
  background: var(--color-bg);
  overflow: hidden;
}

/* On real phones, fill the visible viewport instead of letterboxing. */
@media (max-width: 620px), (max-height: 920px) {
  #stage {
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    height: var(--app-height, 100dvh);
    --stage-w: 100vw;
    --stage-h: var(--app-height, 100dvh);
  }
}

#boot {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-primary);
  font-size: 18px;
  letter-spacing: 0.1em;
}

/* A screen is one full-stage view managed by ScreenManager. */
.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
}
.screen.is-active { display: flex; }

/* Shared button styling. */
.btn {
  appearance: none;
  border: 1px solid var(--color-primary);
  background: transparent;
  color: var(--color-primary);
  font-size: 16px;
  font-weight: 600;
  padding: 14px 18px;
  border-radius: 10px;
  cursor: pointer;
  width: 100%;
  text-align: left;
  transition: background 0.15s ease, color 0.15s ease;
}
.btn:hover { background: var(--color-primary); color: var(--color-bg); }
.btn:disabled,
.btn.is-locked {
  border-color: var(--color-locked);
  color: var(--color-locked);
  cursor: not-allowed;
  background: transparent;
}
.btn--primary {
  background: var(--color-primary);
  color: var(--color-bg);
  text-align: center;
}
.btn--primary:disabled {
  background: var(--color-locked);
  color: #000;
  border-color: var(--color-locked);
}

/* ---- Start overlay ---------------------------------------------------- */
.start-overlay {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 28px;
  background: radial-gradient(circle at 50% 30%, #1a1a1a, var(--color-bg));
}
.start-card { text-align: center; max-width: 460px; }
.start-title { color: var(--color-primary); font-size: 30px; margin-bottom: 14px; line-height: 1.2; }
.start-desc { color: var(--color-text); opacity: 0.85; font-size: 17px; margin-bottom: 28px; line-height: 1.5; }

/* ---- Map screen ------------------------------------------------------- */
.map-screen { padding: 24px 20px; gap: 18px; }
.map-header { text-align: center; }
.leg-indicator {
  display: inline-block;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 13px;
  font-weight: 700;
  color: var(--color-accent);
  border: 1px solid var(--color-accent);
  border-radius: 999px;
  padding: 5px 14px;
  margin-bottom: 16px;
}
.map-title { font-size: 13px; opacity: 0.6; text-transform: uppercase; letter-spacing: 0.1em; }
.waypoint-name { font-size: 26px; font-weight: 700; color: var(--color-primary); margin-top: 4px; }

.map-field {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  background:
    radial-gradient(circle at 50% 85%, rgba(79,195,247,0.10), transparent 60%),
    repeating-linear-gradient(0deg, rgba(255,255,255,0.03) 0 1px, transparent 1px 40px),
    repeating-linear-gradient(90deg, rgba(255,255,255,0.03) 0 1px, transparent 1px 40px);
  border-radius: 16px;
}
.player-dot {
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--color-accent);
  box-shadow: 0 0 0 6px rgba(79,195,247,0.25);
}
.map-line {
  position: absolute;
  width: 2px; height: 140px;
  top: calc(50% - 150px);
  background: linear-gradient(var(--color-primary), transparent);
  opacity: 0.5;
}
.map-marker {
  appearance: none;
  background: transparent;
  border: none;
  color: var(--color-primary);
  font-size: 54px;
  line-height: 1;
  cursor: default;
}
.map-marker.is-tappable {
  cursor: pointer;
  animation: marker-pulse 1.6s ease-in-out infinite;
}
@keyframes marker-pulse {
  0%, 100% { transform: scale(1); filter: drop-shadow(0 0 2px var(--color-primary)); }
  50% { transform: scale(1.12); filter: drop-shadow(0 0 12px var(--color-primary)); }
}
.distance-readout { font-size: 15px; opacity: 0.8; }

/* Compass rose + bearing arrow (real-mode navigation) */
.compass-rose {
  position: relative;
  width: 220px;
  height: 220px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.15);
  background:
    radial-gradient(circle at 50% 50%, rgba(94,200,176,0.10), transparent 70%);
  display: flex;
  align-items: center;
  justify-content: center;
}
/* The rotating compass card: turns by -heading so N points to true north. */
.rose-ring {
  position: absolute;
  inset: 0;
  transition: transform 0.2s ease-out;
}
.rose-tick {
  position: absolute;
  font-size: 13px;
  font-weight: 700;
  color: var(--color-locked);
}
.rose-n { top: 8px; left: 50%; transform: translateX(-50%); color: var(--color-accent); }
.rose-s { bottom: 8px; left: 50%; transform: translateX(-50%); }
.rose-e { right: 10px; top: 50%; transform: translateY(-50%); }
.rose-w { left: 10px; top: 50%; transform: translateY(-50%); }
.nav-arrow {
  font-size: 110px;
  line-height: 1;
  color: var(--color-primary);
  /* Glyph points up (North) at rotate(0); JS rotates it by the bearing. */
  transition: transform 0.2s ease-out;
}
.nav-arrow.is-live { color: var(--color-accent); }
.bearing-readout {
  font-size: 20px;
  font-weight: 700;
  color: var(--color-primary);
  font-variant-numeric: tabular-nums;
}
.compass-hint {
  font-size: 12px;
  color: var(--color-locked);
  text-align: center;
  max-width: 260px;
  line-height: 1.4;
}

.progress-strip { display: flex; gap: 10px; justify-content: center; padding-top: 4px; }
.pdot {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid var(--color-locked);
  background: transparent;
}
.pdot.is-half { background: linear-gradient(90deg, var(--color-primary) 50%, transparent 50%); border-color: var(--color-primary); }
.pdot.is-full { background: var(--color-primary); border-color: var(--color-primary); }
.pdot.is-target { box-shadow: 0 0 0 3px rgba(232,201,109,0.3); border-color: var(--color-accent); }

/* ---- AR screen -------------------------------------------------------- */
.ar-screen { overflow: hidden; }
.ar-backdrop { position: absolute; inset: 0; touch-action: none; }
.ar-video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
/* Camera denied: fall back to the sim panorama gradient so the view isn't blank. */
.ar-backdrop.ar-camera-failed {
  background:
    linear-gradient(180deg, #14233a 0%, #1d2f3f 45%, #2b2218 55%, #141008 100%);
}
.simar-backdrop {
  position: absolute;
  inset: 0;
  cursor: grab;
  background-image:
    linear-gradient(180deg, #14233a 0%, #1d2f3f 45%, #2b2218 55%, #141008 100%),
    repeating-linear-gradient(90deg, rgba(255,255,255,0.05) 0 2px, transparent 2px 120px);
  background-size: 100% 100%, 1440px 100%;
  background-repeat: no-repeat, repeat-x;
}
.simar-backdrop:active { cursor: grabbing; }

.ar-compass {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: linear-gradient(180deg, rgba(0,0,0,0.55), transparent);
  z-index: 5;
  pointer-events: none;
}
.compass-deg { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--color-text); }
.compass-card { color: var(--color-accent); font-weight: 700; letter-spacing: 0.1em; }

.ar-hotspots { position: absolute; inset: 46px 0 96px 0; z-index: 4; pointer-events: none; }
.hotspot {
  position: absolute;
  top: 45%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  background: transparent;
  border: none;
  cursor: pointer;
  pointer-events: auto;
  padding: 8px;
}
.hotspot-dot {
  width: 40px; height: 40px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; font-weight: 700; color: var(--color-bg);
  border: 3px solid;
}
.hotspot-label {
  font-size: 13px; font-weight: 600;
  padding: 3px 10px; border-radius: 999px;
  background: rgba(0,0,0,0.6);
}
.hotspot--outbound .hotspot-dot { border-color: var(--color-accent); background: rgba(79,195,247,0.25); color: var(--color-text); }
.hotspot--return .hotspot-dot { border-color: var(--color-primary); background: rgba(232,201,109,0.3); color: var(--color-text); }
.hotspot--outbound .hotspot-label { color: var(--color-accent); }
.hotspot--return .hotspot-label { color: var(--color-primary); }
.hotspot.is-resolved .hotspot-dot { background: var(--color-primary); color: var(--color-bg); opacity: 0.7; }
.hotspot.is-pulsing .hotspot-dot { animation: hotspot-pulse 0.9s ease-in-out infinite; }
@keyframes hotspot-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(232,201,109,0.5); }
  50% { box-shadow: 0 0 0 14px rgba(232,201,109,0); }
}

.ar-intro {
  position: absolute;
  inset: auto 0 96px 0;
  z-index: 6;
  margin: 0 18px;
  padding: 18px;
  background: rgba(10,10,10,0.88);
  border: 1px solid var(--color-accent);
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.ar-intro p { font-size: 16px; line-height: 1.5; }
.ar-intro-dismiss { width: auto; align-self: flex-end; padding: 10px 18px; }

.ar-actionbar {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 16px 18px calc(16px + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(0deg, rgba(0,0,0,0.7), transparent);
  z-index: 7;
}

/* ---- Dialogue overlay ------------------------------------------------- */
.dialogue-overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: none;
  align-items: flex-end;
  background: rgba(0,0,0,0.55);
}
.dialogue-overlay.is-open { display: flex; }
.dialogue-panel {
  width: 100%;
  max-height: 80%;
  overflow-y: auto;
  background: rgba(16,16,16,0.97);
  border-top: 2px solid var(--color-primary);
  border-radius: 18px 18px 0 0;
  padding: 24px 20px calc(24px + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.dialogue-title { color: var(--color-primary); font-size: 21px; }
.dialogue-body { font-size: 16px; line-height: 1.55; opacity: 0.92; }
.dialogue-image { width: 100%; border-radius: 10px; }
.choice-option { margin-top: 2px; }
.choice-locked-note { color: var(--color-locked); font-size: 14px; font-style: italic; }
.choice-locked-detail { color: var(--color-locked); font-size: 12px; opacity: 0.8; margin-top: -6px; }

/* ---- End screen ------------------------------------------------------- */
.end-screen {
  background-size: cover;
  background-position: center;
  justify-content: flex-end;
}
.end-screen.has-image::after {
  content: "";
  position: absolute; inset: 0;
  background: linear-gradient(0deg, rgba(0,0,0,0.92) 20%, rgba(0,0,0,0.3));
}
.end-content {
  position: relative;
  z-index: 2;
  padding: 28px 22px calc(28px + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-height: 100%;
  overflow-y: auto;
}
.end-title { color: var(--color-primary); font-size: 30px; line-height: 1.15; }
.end-body { font-size: 17px; line-height: 1.6; opacity: 0.92; }
.end-completeness { font-size: 14px; color: var(--color-accent); }
.end-score {
  align-self: flex-start;
  font-weight: 700;
  border: 1px solid var(--color-primary);
  color: var(--color-primary);
  border-radius: 999px;
  padding: 6px 16px;
}
.end-replay { margin-top: 8px; }

/* ---- Dev panel -------------------------------------------------------- */
.dev-root { position: absolute; right: 10px; bottom: 10px; z-index: 60; }
.dev-toggle {
  width: 44px; height: 44px; border-radius: 50%;
  background: rgba(0,0,0,0.7); color: var(--color-accent);
  border: 1px solid var(--color-accent); font-size: 20px; cursor: pointer;
}
.dev-panel {
  display: none;
  position: absolute;
  right: 0; bottom: 52px;
  width: 280px; max-height: 60vh; overflow-y: auto;
  background: rgba(0,0,0,0.92);
  border: 1px solid var(--color-accent);
  border-radius: 12px;
  padding: 12px;
}
.dev-panel.is-open { display: block; }
.dev-controls { display: flex; gap: 8px; margin-bottom: 10px; }
.dev-btn {
  flex: 1; font-size: 12px; padding: 8px;
  background: transparent; color: var(--color-accent);
  border: 1px solid var(--color-accent); border-radius: 8px; cursor: pointer;
}
.dev-json { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 11px; line-height: 1.4; white-space: pre-wrap; color: #b9e6ff; }

/* ---- Dialogue input + timer ------------------------------------------- */
.dialogue-prompt { font-size: 16px; font-weight: 600; color: var(--color-accent); }
.dialogue-input {
  width: 100%;
  background: #161616;
  color: var(--color-text);
  border: 1px solid #444;
  border-radius: 8px;
  padding: 12px;
  font-size: 16px;
}
.choice-timer {
  align-self: center;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--color-accent);
  border: 1px solid var(--color-accent);
  border-radius: 999px;
  padding: 4px 14px;
  margin-top: 4px;
}
.end-share { margin-top: 8px; }

/* ---- Codex / field notes overlay -------------------------------------- */
.codex-root { position: absolute; left: 10px; bottom: 10px; z-index: 60; }
.codex-toggle {
  width: 44px; height: 44px; border-radius: 50%;
  background: rgba(0,0,0,0.7); color: var(--color-primary);
  border: 1px solid var(--color-primary); font-size: 20px; cursor: pointer;
}
.codex-panel {
  display: none;
  position: absolute;
  left: 0; bottom: 52px;
  width: 290px; max-height: 64vh; overflow-y: auto;
  background: rgba(10,10,10,0.95);
  border: 1px solid var(--color-primary);
  border-radius: 12px;
  padding: 14px;
}
.codex-panel.is-open { display: block; }
.codex-header { color: var(--color-primary); font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; font-size: 13px; margin-bottom: 10px; }
.codex-empty { color: var(--color-locked); font-size: 13px; }
.codex-entry { margin-bottom: 10px; padding-bottom: 10px; border-bottom: 1px solid rgba(255,255,255,0.08); }
.codex-entry-label { color: var(--color-accent); font-weight: 600; font-size: 13px; }
.codex-entry-text { font-size: 13px; line-height: 1.4; opacity: 0.9; }
.codex-section { color: var(--color-primary); font-weight: 700; font-size: 12px; text-transform: uppercase; margin-top: 8px; }
.codex-items { font-size: 13px; opacity: 0.9; }
