/* ==========================================================================
   WebAR "Schrumpf-Reise" (Verortungen / Mobile Displays)
   styles.css — all styling for selection screen, AR overlay, pickers, HUD.

   Contract (per FROZEN spec §6/§7):
   - .hidden{display:none !important} is the ONLY region toggle.
   - #ar-container fixed fullscreen; MindAR injects <video>+<canvas> -> fill cover.
   - #ar-overlay pointer-events:none; only the HUD bar + buttons are interactive,
     so journey taps reach #ar-container beneath (center must stay clear).
   - Mobile-first, high contrast (bright room), tap targets >=44px (prefer 56px).
   ========================================================================== */

/* ---------- Design tokens ---------- */
:root {
  --bg: #0e0f12;
  --bg-elev: #1a1c22;
  --bg-elev-2: #23262e;
  --fg: #f5f6f8;
  --fg-muted: #aab0bb;
  --border: #353a45;
  --accent: #2f6df0;
  --accent-fg: #ffffff;
  --accent-soft: rgba(47, 109, 240, 0.18);
  --danger: #e23b4e;
  --hud-bg: rgba(12, 13, 16, 0.78);
  --tap-min: 44px;
  --tap-pref: 56px;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
    Arial, "Apple Color Emoji", "Segoe UI Emoji", sans-serif;
}

/* ---------- Base ---------- */
* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: var(--font);
  color: var(--fg);
  background: var(--bg);
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  /* avoid bounce/scroll fighting the camera on iOS */
  overscroll-behavior: none;
}

/* The ONLY region toggle — contractual class name */
.hidden {
  display: none !important;
}

/* ==========================================================================
   SELECTION SCREEN  (#selection-screen)
   Scrollable, padded, centered, max-width ~560px.
   ========================================================================== */
#selection-screen {
  position: relative;
  min-height: 100vh;
  min-height: 100dvh;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: 24px 18px calc(28px + env(safe-area-inset-bottom, 0px));
  padding-top: calc(24px + env(safe-area-inset-top, 0px));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.app-title,
#selection-screen h1 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.app-subtitle,
#selection-screen .subtitle {
  margin: 4px 0 0;
  color: var(--fg-muted);
  font-size: 0.95rem;
}

#selection-screen .lede {
  margin: 10px 0 0;
  color: var(--fg-muted);
  font-size: 0.95rem;
}

/* Generic section grouping (builder may wrap steps in <section>) */
#selection-screen section {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#selection-screen h2,
#selection-screen .section-label,
.field-label {
  margin: 0;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--fg-muted);
}

#selection-screen h3 {
  margin: 4px 0 0;
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--fg-muted);
}

#selection-screen .marker-hint,
#selection-screen .https-hint {
  margin: 0;
  color: var(--fg-muted);
  font-size: 0.85rem;
}

/* ---------- Photo picker (#photo-picker) ---------- */
#photo-picker {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}

#photo-picker button {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  min-height: var(--tap-pref);
  padding: 12px 12px;
  text-align: left;
  background: var(--bg-elev-2);
  color: var(--fg);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font: inherit;
  cursor: pointer;
  transition: border-color 0.12s ease, background 0.12s ease;
}

#photo-picker button .photo-btn-credit,
#photo-picker .credit {
  font-size: 0.72rem;
  color: var(--fg-muted);
  font-weight: 400;
}

#photo-picker button .photo-btn-label,
#photo-picker .photo-label {
  font-weight: 600;
  font-size: 0.92rem;
}

/* ---------- Photo upload (#photo-upload + #photo-upload-label) ---------- */
/* Hide the native file input; the <label> is the visible, styled control. */
#photo-upload {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

#photo-upload-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--tap-pref);
  padding: 12px 16px;
  background: var(--bg-elev-2);
  color: var(--fg);
  border: 2px dashed var(--border);
  border-radius: var(--radius-sm);
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.12s ease, background 0.12s ease, color 0.12s ease;
}

#photo-upload-label.active,
#photo-upload-label.is-selected {
  border-style: solid;
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--fg);
}

/* ---------- Mode toggle (#mode-journey / #mode-explorer) ---------- */
.mode-toggle,
.mode-switch {
  display: flex;
  gap: 8px;
}

#mode-journey,
#mode-explorer {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-height: var(--tap-pref);
  padding: 12px 10px;
  background: var(--bg-elev-2);
  color: var(--fg);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: border-color 0.12s ease, background 0.12s ease, color 0.12s ease;
}

#mode-journey .mode-sub,
#mode-explorer .mode-sub {
  font-weight: 400;
  font-size: 0.74rem;
  color: var(--fg-muted);
}

#mode-journey.is-selected,
#mode-explorer.is-selected {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-fg);
}

#mode-journey.is-selected .mode-sub,
#mode-explorer.is-selected .mode-sub {
  color: rgba(255, 255, 255, 0.85);
}

/* ---------- Explorer controls block (#explorer-controls) ---------- */
#explorer-controls {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ---------- Device / Context pickers (#device-picker / #context-picker) ---------- */
#device-picker,
#context-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

#device-picker button,
#context-picker button {
  flex: 1 1 auto;
  min-width: 96px;
  min-height: var(--tap-min);
  padding: 11px 12px;
  background: var(--bg-elev-2);
  color: var(--fg);
  border: 2px solid var(--border);
  border-radius: 999px;
  font: inherit;
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.12s ease, background 0.12s ease, color 0.12s ease;
}

/* ---------- Shared selected highlight ---------- */
.is-selected {
  border-color: var(--accent) !important;
  background: var(--accent-soft);
  color: var(--fg);
}

#device-picker button.is-selected,
#context-picker button.is-selected,
#photo-picker button.is-selected {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--fg);
}

/* hover/active feedback (non-touch + tap) */
@media (hover: hover) {
  #photo-picker button:hover,
  #photo-upload-label:hover,
  #device-picker button:hover,
  #context-picker button:hover,
  #mode-journey:hover,
  #mode-explorer:hover {
    border-color: var(--accent);
  }
}

button:active {
  filter: brightness(0.92);
}

/* ---------- Start button (#start-btn) ---------- */
#start-btn {
  position: sticky;
  bottom: max(8px, env(safe-area-inset-bottom, 0px));
  min-height: 60px;
  width: 100%;
  padding: 16px 20px;
  background: var(--accent);
  color: var(--accent-fg);
  border: none;
  border-radius: var(--radius);
  font: inherit;
  font-size: 1.1rem;
  font-weight: 800;
  letter-spacing: 0.01em;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: background 0.12s ease, transform 0.08s ease;
}

#start-btn:active {
  transform: translateY(1px);
}

#start-btn:disabled {
  opacity: 0.6;
  cursor: default;
}

/* ==========================================================================
   AR CONTAINER  (#ar-container)  — MindAR camera mount
   ========================================================================== */
#ar-container {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: #000;
  z-index: 0;
  /* The parent #ar-overlay is pointer-events:none, and pointer-events INHERITS.
     Without this, the camera area receives no taps and the Schrumpf-Reise tap
     never fires. Re-enable here so taps on the camera reach the tap listener. */
  pointer-events: auto;
}

/* MindAR injects the camera <video> and the three.js <canvas> and gives them
   inline top/left/width/height for its own "cover" math. If the container was
   hidden at start() that math is wrong and pushes the video off-screen (only a
   corner shows). We override ALL of MindAR's inline positioning with !important
   so they truly fill the viewport; object-fit:cover keeps the camera aspect. */
#ar-container video,
#ar-container canvas {
  position: absolute !important;
  inset: 0 !important;
  top: 0 !important;
  left: 0 !important;
  width: 100% !important;
  height: 100% !important;
  max-width: none !important;
  max-height: none !important;
  transform: none !important;
  object-fit: cover !important;
}

/* ==========================================================================
   AR OVERLAY  (#ar-overlay) — HUD + controls floating above the camera.
   pointer-events:none so the clear center forwards taps to #ar-container.
   ========================================================================== */
#ar-overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  pointer-events: none; /* center stays tap-through for the Schrumpf-Reise */
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

/* Re-enable interaction only on the actual interactive chrome. */
#ar-overlay button,
#ar-overlay .ar-bar,
#ar-overlay #ar-explorer-controls {
  pointer-events: auto;
}

/* ---------- HUD bar (#hud) ---------- */
#hud {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  margin: 0 auto;
  padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top, 0px));
  width: 100%;
  max-width: 560px;
  text-align: center;
  background: linear-gradient(
    to bottom,
    var(--hud-bg) 0%,
    rgba(12, 13, 16, 0) 100%
  );
  pointer-events: none; /* the gradient itself is tap-through */
}

/* Top row: stage chip + exit button */
.hud-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  pointer-events: none;
}

/* Stage readout (#hud-stage) — legible chip in a bright room */
#hud-stage {
  display: inline-block;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--hud-bg);
  color: var(--fg);
  font-weight: 800;
  font-size: 1rem;
  letter-spacing: 0.01em;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
  pointer-events: none;
}

/* Hint line (#hud-hint) */
#hud-hint {
  display: inline-block;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(12, 13, 16, 0.62);
  color: var(--fg);
  font-size: 0.86rem;
  font-weight: 600;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
  pointer-events: none;
}

/* ---------- Bottom control region wrapper ---------- */
.ar-bottom,
#ar-overlay > .controls {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px 16px calc(14px + env(safe-area-inset-bottom, 0px));
}

/* ---------- Explorer live controls (#ar-explorer-controls) ---------- */
#ar-explorer-controls {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  max-width: 560px;
  margin: 12px auto 0;
  padding: 10px 12px;
  background: var(--hud-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

#ar-explorer-controls .ar-explorer-row,
#ar-explorer-controls .row,
#ar-explorer-controls > div {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

#ar-explorer-controls button {
  flex: 1 1 auto;
  min-width: 84px;
  min-height: var(--tap-min);
  padding: 10px 12px;
  background: var(--bg-elev-2);
  color: var(--fg);
  border: 2px solid var(--border);
  border-radius: 999px;
  font: inherit;
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.12s ease, background 0.12s ease, color 0.12s ease;
}

#ar-explorer-controls button.is-selected {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-fg);
}

/* ---------- Exit button (#exit-btn) ---------- */
#exit-btn {
  position: fixed;
  top: calc(10px + env(safe-area-inset-top, 0px));
  right: calc(10px + env(safe-area-inset-right, 0px));
  z-index: 20;
  min-width: var(--tap-min);
  min-height: var(--tap-min);
  padding: 0 16px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--hud-bg);
  color: var(--fg);
  border: 2px solid rgba(255, 255, 255, 0.25);
  border-radius: 999px;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  box-shadow: var(--shadow);
  pointer-events: auto;
}

#exit-btn:active {
  background: var(--danger);
  border-color: var(--danger);
}

/* ==========================================================================
   Responsive niceties
   ========================================================================== */
@media (min-width: 520px) {
  .app-title,
  #selection-screen h1 {
    font-size: 1.7rem;
  }
}

/* Landscape: keep the selection screen scrollable & the start button reachable */
@media (orientation: landscape) and (max-height: 480px) {
  #selection-screen {
    gap: 14px;
    padding-top: 14px;
  }
  #start-btn {
    position: static;
    box-shadow: none;
  }
}

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