/* ui.css — overlay UI styles (lane B, SPEC sections 4 and 7).
   Dark glass cards, warm white text, one accent color, system fonts, min 16 px,
   contrast >= 4.5:1, 44 px touch targets, visible focus rings, phone layout
   under 600 px, reduced-motion support. The overlay stays at the edges: the
   center of the screen is left free for the 3D scene. */

:root {
  --ui-glass: rgba(12, 10, 8, 0.62);
  --ui-glass-strong: rgba(12, 10, 8, 0.82);
  --ui-text: #f4ede2;
  --ui-text-dim: #d9cfc0;
  --ui-accent: #e8b75a;
  --ui-accent-ink: #1a1206;
  --ui-radius: 14px;
  --ui-font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* ---- shared overlay primitives ---- */

.ui-hud,
.ui-story,
.ui-infocard,
.ui-dialog,
.ui-story-lightbox {
  font-family: var(--ui-font);
  color: var(--ui-text);
  font-size: 16px;
  line-height: 1.45;
}

/* The hidden attribute must always win, even over class display rules. */
.ui-hud [hidden],
.ui-story [hidden],
.ui-infocard [hidden],
.ui-backdrop [hidden],
.ui-story-lightbox[hidden],
.ui-story-lightbox [hidden] {
  display: none !important;
}

.ui-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  min-width: 44px;
  padding: 8px 14px;
  border: 1px solid rgba(244, 237, 226, 0.28);
  border-radius: 10px;
  background: var(--ui-glass);
  color: var(--ui-text);
  font: inherit;
  font-size: 16px;
  cursor: pointer;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: background 160ms ease, border-color 160ms ease;
}

.ui-btn:hover {
  border-color: var(--ui-accent);
}

.ui-btn-primary {
  background: var(--ui-accent);
  border-color: var(--ui-accent);
  color: var(--ui-accent-ink);
  font-weight: 600;
}

.ui-btn-primary:hover {
  filter: brightness(1.06);
}

.ui-btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.ui-hud :focus-visible,
.ui-story :focus-visible,
.ui-infocard :focus-visible,
.ui-story-lightbox :focus-visible,
.ui-backdrop :focus-visible {
  outline: 3px solid var(--ui-accent);
  outline-offset: 2px;
}

/* ---- HUD ---- */

.ui-hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 10;
}

.ui-hud-tl {
  position: absolute;
  top: 12px;
  left: 14px;
  max-width: min(60vw, 420px);
  pointer-events: auto;
}

.ui-hud-title {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.55);
}

/* supervisor fix B3 #3: the step counter is small and gold, on the title line */
.ui-hud-step {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--ui-accent);
  white-space: nowrap;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.55);
}

.ui-hud-titleline {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.ui-hud-tr {
  position: absolute;
  top: 12px;
  right: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: auto;
}

.ui-hud-modes {
  display: flex;
  gap: 6px;
}

.ui-mode-btn[aria-pressed="true"],
.ui-lang-btn[aria-pressed="true"] {
  border-color: var(--ui-accent);
  color: var(--ui-accent);
  font-weight: 600;
}

.ui-lang-btn + .ui-lang-btn {
  margin-left: -6px;
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
}

.ui-lang-btn[aria-pressed="false"] + .ui-lang-btn[aria-pressed="false"]::before {
  content: "";
}

.ui-menu-btn,
.ui-hud-sheet {
  display: none;
}

/* ---- story card (bottom) ---- */

.ui-story {
  position: absolute;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  width: min(560px, calc(100vw - 24px));
  padding: 14px 16px 12px;
  /* supervisor fix B3 #6: a bit more transparent so the scene is felt behind */
  background: rgba(12, 10, 8, 0.55);
  border: 1px solid rgba(244, 237, 226, 0.16);
  border-radius: var(--ui-radius);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  pointer-events: auto;
  z-index: 10;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}

/* supervisor fix B3 #4: no floating collapse button on desktop; on phones it
   sits inside the card header (see the media query below). */
.ui-story-collapse {
  display: none;
}

.ui-story-collapsed .ui-story-live,
.ui-story-collapsed .ui-story-dots,
.ui-story-collapsed .ui-story-actions,
.ui-story-collapsed .ui-story-thumb {
  display: none;
}

.ui-story-realm {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ui-accent);
}

.ui-story-thumb {
  float: left;
  width: 96px;
  height: 96px;
  margin: 2px 12px 6px 0;
  padding: 0;
  border: 1px solid rgba(244, 237, 226, 0.28);
  border-radius: 10px;
  overflow: hidden;
  cursor: zoom-in;
  background: var(--ui-glass);
}

.ui-story-thumb:hover {
  border-color: var(--ui-accent);
}

.ui-story-thumb-img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* lightbox for the full step image (opened from the story thumbnail) */

.ui-story-lightbox {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(4, 3, 2, 0.8);
  z-index: 30;
  padding: 16px;
}

.ui-story-lightbox-inner {
  margin: 0;
  max-width: min(860px, 100%);
  display: flex;
  flex-direction: column;
}

.ui-story-lightbox-img {
  display: block;
  max-width: 100%;
  max-height: calc(100dvh - 130px);
  width: auto;
  height: auto;
  border-radius: 8px;
}

.ui-story-lightbox-credit {
  margin-top: 8px;
  font-size: 13px;
  color: var(--ui-text-dim);
}

.ui-story-lightbox-close {
  position: absolute;
  top: 14px;
  right: 14px;
}

.ui-story-title {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
}

.ui-story-text {
  margin: 6px 0 0;
  color: var(--ui-text);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.ui-story-dots {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.ui-story-dot {
  width: 26px;
  height: 26px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid rgba(244, 237, 226, 0.4);
  background: transparent;
  cursor: pointer;
}

.ui-story-dot-active {
  background: var(--ui-accent);
  border-color: var(--ui-accent);
}

.ui-story-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.ui-story-actions .ui-btn {
  flex: 0 0 auto;
}

/* ---- info card (hotspots) ---- */

.ui-infocard {
  position: absolute;
  top: 84px;
  left: 14px;
  width: min(360px, calc(100vw - 28px));
  padding: 14px 16px;
  background: var(--ui-glass);
  border: 1px solid rgba(244, 237, 226, 0.16);
  border-radius: var(--ui-radius);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 12;
}

.ui-infocard-close {
  position: absolute;
  top: 8px;
  right: 8px;
  min-width: 44px;
  min-height: 44px;
  padding: 6px;
}

.ui-infocard-title {
  margin: 0;
  padding-right: 40px;
  font-size: 18px;
  font-weight: 700;
  color: var(--ui-accent);
}

.ui-infocard-text {
  margin: 8px 0 0;
}

.ui-infocard-img {
  display: block;
  width: 100%;
  height: auto;
  margin-top: 10px;
  border-radius: 8px;
}

.ui-infocard-credit {
  margin: 8px 0 0;
  font-size: 13px;
  color: var(--ui-text-dim);
}

.ui-infocard-source {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  margin-top: 2px;
  color: var(--ui-accent);
  font-size: 16px;
  text-decoration: underline;
}

.ui-infocard-source:hover {
  filter: brightness(1.1);
}

/* ---- modal dialogs (quiz, help) ---- */

.ui-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(4, 3, 2, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  padding: 16px;
}

.ui-backdrop[hidden] {
  display: none;
}

.ui-dialog {
  position: relative;
  width: min(480px, 100%);
  max-height: min(86dvh, 720px);
  overflow: auto;
  padding: 16px 18px 18px;
  background: var(--ui-glass-strong);
  border: 1px solid rgba(244, 237, 226, 0.2);
  border-radius: var(--ui-radius);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.ui-dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.ui-dialog-title {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  color: var(--ui-accent);
}

.ui-dialog-close {
  flex: 0 0 auto;
  min-width: 44px;
  min-height: 44px;
  padding: 6px;
}

/* ---- quiz ---- */

.ui-quiz-progress {
  margin: 4px 0 0;
  font-size: 14px;
  color: var(--ui-text-dim);
}

.ui-quiz-question {
  margin: 12px 0 0;
  font-size: 19px;
  font-weight: 600;
}

.ui-quiz-answers {
  display: flex;
  gap: 10px;
  margin-top: 14px;
}

.ui-quiz-answer {
  flex: 1 1 0;
  min-height: 56px;
  font-size: 18px;
}

.ui-quiz-feedback {
  margin: 12px 0 0;
}

.ui-quiz-score {
  margin: 8px 0 0;
  font-size: 18px;
  font-weight: 700;
}

.ui-quiz-verdict {
  margin: 6px 0 0;
  color: var(--ui-accent);
}

.ui-quiz-next,
.ui-quiz-retry {
  margin-top: 14px;
  width: 100%;
}

/* ---- help sheet ---- */

.ui-help-list {
  margin: 12px 0 0;
  padding: 0 0 0 18px;
  display: grid;
  gap: 10px;
}

.ui-help-mode {
  color: var(--ui-accent);
}

.ui-help-notes {
  margin-top: 16px;
  border-top: 1px solid rgba(244, 237, 226, 0.16);
  padding-top: 10px;
}

.ui-help-note {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--ui-text-dim);
}

/* ---- phone layout (under 600 px) ---- */

@media (max-width: 599px) {
  .ui-hud-tr {
    display: none;
  }

  .ui-menu-btn {
    display: inline-flex;
    position: absolute;
    top: 12px;
    right: 14px;
    pointer-events: auto;
    font-size: 20px;
  }

  .ui-hud-sheet {
    display: block;
    position: absolute;
    top: 64px;
    right: 14px;
    width: min(260px, calc(100vw - 28px));
    padding: 12px;
    background: var(--ui-glass-strong);
    border: 1px solid rgba(244, 237, 226, 0.2);
    border-radius: var(--ui-radius);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    pointer-events: auto;
  }

  .ui-hud-sheet[hidden] {
    display: none;
  }

  .ui-hud-sheet-modes,
  .ui-hud-sheet .ui-btn {
    width: 100%;
    margin-top: 6px;
  }

  .ui-hud-sheet .ui-hud-modes {
    flex-direction: column;
    margin-bottom: 6px;
  }

  .ui-story {
    bottom: 10px;
    padding: 10px 12px;
  }

  /* step thumbnail is hidden on phones (card B2) */
  .ui-story-thumb {
    display: none;
  }

  .ui-story-collapsed .ui-story-title {
    font-size: 16px;
  }

  .ui-story-collapse {
    display: inline-flex;
    position: absolute;
    top: 4px;
    right: 4px;
    min-width: 44px;
    min-height: 44px;
  }

  .ui-story-title {
    padding-right: 48px; /* room for the in-card collapse button */
  }

  .ui-infocard {
    top: auto;
    bottom: 76px;
    max-height: 46dvh;
    overflow: auto;
  }

  .ui-quiz-answers {
    flex-direction: column;
  }
}

/* ---- reduced motion ---- */

@media (prefers-reduced-motion: reduce) {
  .ui-btn,
  .ui-story,
  .ui-infocard,
  .ui-dialog,
  .ui-backdrop,
  .ui-story-lightbox {
    transition: none;
    animation: none;
    scroll-behavior: auto;
  }
}

/* ---- card B3: intro gate + boot reveal ---- */

/* The gate itself: shown after loading:done, centered near the bottom
   (SPEC 6.1). .ui-hidden keeps it invisible until loading:done; .ui-fading
   fades it out on intro:done. Reduced motion makes both instant. */
.ui-intro {
  position: absolute;
  left: 50%;
  bottom: 56px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  z-index: 15;
  pointer-events: auto;
  font-family: var(--ui-font);
  color: var(--ui-text);
  opacity: 1;
  transition: opacity 400ms ease;
}

.ui-intro-start {
  min-width: 220px;
  font-size: 18px;
  padding: 12px 22px;
}

.ui-intro-skip {
  font-size: 14px;
  color: var(--ui-text-dim);
  background: transparent;
  border-color: transparent;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}

.ui-intro.ui-hidden,
.ui-intro.ui-fading {
  opacity: 0;
}

/* Before intro:done only the gate is visible; HUD, story card and info card
   fade in (400 ms) when mountIntro removes "ui-root-waiting" from the root. */
.ui-root-waiting .ui-hud,
.ui-root-waiting .ui-story,
.ui-root-waiting .ui-infocard {
  opacity: 0;
  pointer-events: none;
}

.ui-hud,
.ui-story,
.ui-infocard {
  transition: opacity 400ms ease;
}

/* .ui-reduced is set by src/ui/motion.js on the overlay root: it kills every
   UI transition and animation (no fade, no auto animation) in one place. */
.ui-reduced *,
.ui-reduced *::before,
.ui-reduced *::after {
  transition: none !important;
  animation: none !important;
  scroll-behavior: auto !important;
}

/* supervisor fix B3 #2: the footer line sits bottom-left (12 px, 60% opacity),
   below the overlay cards so it is never drawn under one. On phones it is
   hidden here and shown inside the menu sheet instead (hud.js). */
footer {
  font-size: 12px;
  color: rgba(244, 237, 226, 0.6);
  z-index: 5;
}

/* supervisor fix B3 #5: all top-right buttons keep one 44 px height */
.ui-hud-tr .ui-btn {
  white-space: nowrap;
}

/* ---- credits page (card B3) ---- */

/* The credits page is a plain scrolling document; it links ONLY this file, so
   it carries its own base styles (main.css stays canvas-only). */
body.credits-page {
  margin: 0;
  padding: 24px 16px 48px;
  background: #0c0a08;
  color: var(--ui-text);
  font-family: var(--ui-font);
  font-size: 16px;
  line-height: 1.55;
  overflow: auto;
}

.credits-wrap {
  max-width: 860px;
  margin: 0 auto;
}

.credits-page h1 {
  color: var(--ui-accent);
  font-size: 26px;
  margin: 0 0 8px;
}

.credits-page h2 {
  color: var(--ui-accent);
  font-size: 20px;
  margin: 30px 0 8px;
}

.credits-page a {
  color: var(--ui-accent);
  text-decoration: underline;
}

.credits-page :focus-visible {
  outline: 3px solid var(--ui-accent);
  outline-offset: 2px;
}

.credits-lang {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
  margin: 0 0 18px;
}

.credits-list {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  display: grid;
  gap: 12px;
}

.credits-list li {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 10px 12px;
  background: rgba(12, 10, 8, 0.55);
  border: 1px solid rgba(244, 237, 226, 0.16);
  border-radius: 10px;
}

.credits-thumb {
  width: 120px;
  height: 80px;
  object-fit: cover;
  border-radius: 6px;
  flex: 0 0 auto;
  background: rgba(244, 237, 226, 0.08);
}

.credits-row {
  min-width: 0;
}

.credits-title {
  font-weight: 600;
}

.credits-meta {
  font-size: 14px;
  color: var(--ui-text-dim);
}

.credits-meta a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
}

.credits-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  color: var(--ui-text-dim);
  overflow-wrap: anywhere;
}

.credits-note {
  font-size: 14px;
  color: var(--ui-text-dim);
  margin: 10px 0 0;
}

.credits-back {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  margin-top: 32px;
}

.credits-footer {
  margin: 18px 0 0;
  font-size: 12px;
  color: rgba(244, 237, 226, 0.6);
}

/* ---- credits page: model / software / sources sections (card C2) ---- */

/* Same look as the existing photo list, but the model/software/source entries
   carry no thumbnail: text rows only. */
.credits-plain li {
  display: block;
}

.credits-item {
  overflow-wrap: anywhere; /* phone layout: long Commons URLs never overflow */
}

.credits-page h3 {
  color: var(--ui-accent);
  font-size: 17px;
  margin: 22px 0 6px;
}

.credits-item .credits-title a {
  overflow-wrap: anywhere;
}
