/* RetroReverse Studio — the Retro-X viewer. Mobile-first: one slim top bar,
   full-bleed stage, popovers instead of side panels. */

:root {
  --bg: #0b0e14;
  --panel: #151a24;
  --panel2: #1c2331;
  --line: #2a3446;
  --text: #d7dfeb;
  --dim: #8a97ab;
  --accent: #6ea8ff;
  --bar-h: 44px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
  overflow: hidden;
}

/* ---- top bar ---- */
#topbar {
  position: fixed; inset: 0 0 auto 0; height: var(--bar-h);
  display: flex; align-items: center; gap: 6px;
  padding: 0 8px; z-index: 30;
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(6px);
  /* narrow (portrait) screens: the bar scrolls sideways; the edges fade out
     as the "there's more off-screen" cue (classes set from app.js) */
  overflow-x: auto; scrollbar-width: none;
}
#topbar::-webkit-scrollbar { display: none; }
#topbar > * { flex-shrink: 0; }
#topbar.fade-r, .modal-tabs.fade-r { mask-image: linear-gradient(90deg, #000 0, #000 calc(100% - 32px), transparent);
  -webkit-mask-image: linear-gradient(90deg, #000 0, #000 calc(100% - 32px), transparent); }
#topbar.fade-l, .modal-tabs.fade-l { mask-image: linear-gradient(90deg, transparent, #000 32px, #000 100%);
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 32px, #000 100%); }
#topbar.fade-l.fade-r, .modal-tabs.fade-l.fade-r {
  mask-image: linear-gradient(90deg, transparent, #000 32px, #000 calc(100% - 32px), transparent);
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 32px, #000 calc(100% - 32px), transparent);
}
.tb-btn {
  flex: 0 0 auto; width: 34px; height: 34px; padding: 6px;
  border: 0; border-radius: 8px; background: transparent; color: var(--dim);
  cursor: pointer;
}
.tb-btn:hover { background: var(--panel2); color: var(--text); }
.tb-btn.on { color: var(--accent); background: var(--panel2); }
.tb-btn svg { width: 100%; height: 100%; }
.tb-title {
  font-weight: 600; white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; max-width: 26vw; color: var(--text);
}
.tb-select {
  appearance: none; -webkit-appearance: none;
  background: var(--panel2) url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238a97ab' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E") no-repeat right 6px center / 14px;
  color: var(--text); border: 1px solid var(--line); border-radius: 8px;
  height: 32px; padding: 0 26px 0 10px; font: inherit; font-size: 13px;
  max-width: 40vw; text-overflow: ellipsis;
}
.tb-grow { flex: 1 1 auto; min-width: 60px; }
.tb-spacer { flex: 1 0 0; }

/* ---- landing ---- */
#landing {
  position: fixed; inset: var(--bar-h) 0 0 0; overflow-y: auto;
  padding: 26px clamp(12px, 4vw, 48px) 60px;
}
.landing-head { max-width: 900px; margin: 0 auto 22px; }
.landing-head h1 { margin: 0 0 6px; font-size: 26px; }
.landing-head p { margin: 0; color: var(--dim); max-width: 640px; }
.cards {
  display: grid; gap: 14px; max-width: 900px; margin: 0 auto;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
}
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 14px 16px; cursor: pointer; transition: border-color .15s, transform .15s;
}
.card:hover { border-color: var(--accent); transform: translateY(-2px); }
.card h2 { margin: 0 0 2px; font-size: 17px; display: flex; align-items: center; gap: 8px; }
.card h2 img { width: 28px; height: 28px; object-fit: contain; image-rendering: pixelated; }
.card .meta { color: var(--accent); font-size: 12px; margin-bottom: 8px; }
.card p { margin: 0; color: var(--dim); font-size: 13px;
  display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }

/* ---- stage ---- */
#stage { position: fixed; inset: var(--bar-h) 0 0 0; }
#stage.render2d canvas.pixi { image-rendering: pixelated; }
/* touch-action none: the viewers own their drag/pinch gestures — without it
   Android claims the touches for page gestures and pointercancels the pan */
#stage > canvas, #stage canvas.fill { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }
/* The XR shell's stage lives outside #stage — teardown() empties that, which
   would detach the presenting renderer's canvas — so it needs the rule too.
   Without it the canvas takes its drawing-buffer size as CSS pixels and
   overflows the window by the device pixel ratio. */
.xr-shell-host > canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }
#stage.dragging { cursor: grabbing; }
#screenfx { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 10; }

/* ---- popover (display options) ---- */
.popover {
  position: fixed; top: calc(var(--bar-h) + 6px); right: 8px; z-index: 40;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; min-width: 190px; max-height: 70vh; overflow-y: auto;
  box-shadow: 0 8px 30px rgba(0,0,0,.5);
}
.popover h4 { margin: 8px 0 4px; font-size: 11px; text-transform: uppercase;
  letter-spacing: .08em; color: var(--dim); }
.popover h4:first-child { margin-top: 0; }
.popover label { display: flex; align-items: center; gap: 8px; padding: 3px 0;
  cursor: pointer; font-size: 13px; }
.popover input { accent-color: var(--accent); }

/* ---- modal ---- */
.modal-back {
  position: fixed; inset: 0; z-index: 50; background: rgba(4,6,10,.65);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal {
  position: relative; background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 20px 22px; max-width: 720px; width: 100%;
  max-height: 82vh; display: flex; flex-direction: column; overflow: hidden;
}
#modalBody { display: flex; flex-direction: column; min-height: 0; }
/* the info modal's section tabs: sideways-scrollable with the top bar's fades */
.modal-tabs {
  display: flex; gap: 4px; flex: 0 0 auto;
  overflow-x: auto; scrollbar-width: none;
  border-bottom: 1px solid var(--line);
  margin: 0 0 12px; padding: 0 0 8px;
}
.modal-tabs::-webkit-scrollbar { display: none; }
.modal-tabs > * { flex-shrink: 0; }
.mtab {
  border: 0; border-radius: 8px; padding: 6px 12px;
  background: transparent; color: var(--dim);
  cursor: pointer; font-size: 13px; white-space: nowrap;
}
.mtab:hover { color: var(--text); }
.mtab.on { background: var(--panel2); color: var(--text); }
.modal-tab-body { overflow-y: auto; min-height: 0; }
.modal h2 { margin: 0 0 4px; font-size: 18px; }
.modal h3 { margin: 14px 0 4px; font-size: 14px; color: var(--accent); }
.modal p { color: var(--text); }
.modal .dim { color: var(--dim); }
.modal-close {
  position: absolute; top: 8px; right: 10px; width: 30px; height: 30px;
  border: 0; border-radius: 8px; background: transparent; color: var(--dim);
  font-size: 20px; cursor: pointer;
}
.modal-close:hover { background: var(--panel2); color: var(--text); }
.modal table { border-collapse: collapse; font-size: 13px; }
.modal td { padding: 2px 12px 2px 0; vertical-align: top; }
.modal td:first-child { color: var(--dim); white-space: nowrap; }

/* ---- info card (click popups in levels) ---- */
.infocard {
  position: absolute; z-index: 12; max-width: 300px;
  max-height: calc(100% - 16px); overflow-y: auto;
  background: color-mix(in srgb, var(--panel) 94%, transparent);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
  font-size: 13px; pointer-events: auto; box-shadow: 0 6px 24px rgba(0,0,0,.45);
}
.infocard b { display: block; margin-bottom: 3px; }
.infocard .dim { color: var(--dim); font-size: 12px; }
.infocard .mono { font-family: ui-monospace, monospace; font-size: 11px; color: var(--dim); }
.infocard a { color: var(--accent); cursor: pointer; text-decoration: none; }
.infocard .x { position: absolute; top: 4px; right: 8px; cursor: pointer; color: var(--dim); }

/* ---- HUD (bottom-left caption) ---- */
.hud {
  position: absolute; left: 10px; bottom: 8px; z-index: 12;
  font-size: 12px; color: var(--dim); text-shadow: 0 1px 2px #000;
  pointer-events: none; max-width: 70vw;
}
/* AR status: sits above the control hint. The headset has no console, so this
   line is where an AR failure has to be readable. */
.hud.xr-status { bottom: 26px; color: var(--accent); }

/* ---- cutscene transport ---- */
.transport {
  position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%);
  z-index: 13; display: flex; align-items: center; gap: 8px;
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px;
  max-width: min(92vw, 560px);
}
.transport button {
  border: 0; background: transparent; color: var(--text); cursor: pointer;
  width: 28px; height: 28px; padding: 4px; border-radius: 6px;
}
.transport button:hover { background: var(--panel2); }
.transport button svg { width: 100%; height: 100%; }
.transport input[type=range] { flex: 1 1 auto; min-width: 120px; accent-color: var(--accent); }
.transport .t-label { font-size: 12px; color: var(--dim); white-space: nowrap; }

/* ---- media views ---- */
.media-wrap {
  position: absolute; inset: 0; overflow-y: auto;
  padding: 20px clamp(12px, 4vw, 40px);
}
.media-inner { max-width: 700px; margin: 0 auto; }
.tracklist { display: flex; flex-direction: column; gap: 4px; margin-top: 12px; }
.track {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  cursor: pointer;
}
.track:hover { border-color: var(--accent); }
.track.playing { border-color: var(--accent); background: var(--panel2); }
.track .t-name { flex: 1; }
.track .t-dur { color: var(--dim); font-size: 12px; }
/* The bar sticks to the bottom of the scrolling media view, so the play
   controls stay reachable however long the track list is — and scrolling
   works anywhere on the page, not just over the list. */
.player-bar { display: flex; align-items: center; gap: 10px; margin-top: 14px;
  background: var(--panel2); border-radius: 10px; padding: 8px 12px;
  position: sticky; bottom: 0; box-shadow: 0 -6px 18px rgba(4, 6, 10, .45); }
.player-bar button { border: 0; background: transparent; color: var(--text);
  width: 30px; height: 30px; cursor: pointer; padding: 4px; border-radius: 6px; }
.player-bar button.on { color: var(--accent); }
.player-bar button svg { width: 100%; height: 100%; }
.player-bar input[type=range] { flex: 1; accent-color: var(--accent); }
.player-bar .t-time { font-size: 12px; color: var(--dim); font-variant-numeric: tabular-nums; }
.vu { display: flex; gap: 2px; align-items: flex-end; height: 22px; width: 60px; }
.vu i { flex: 1; background: var(--accent); opacity: .85; border-radius: 1px; min-height: 2px; }
.board { display: grid; gap: 10px; margin-top: 14px;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
.board button {
  padding: 14px 10px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--panel); color: var(--text); font: inherit; cursor: pointer;
}
.board button:hover, .board button.hit { border-color: var(--accent); }

/* ---- object views ---- */
.side-list {
  position: absolute; top: 8px; left: 8px; z-index: 12; max-width: 46vw;
  max-height: calc(100% - 60px); overflow-y: auto;
  display: flex; flex-direction: column; gap: 4px;
}
.side-list button {
  text-align: left; padding: 6px 10px; border: 1px solid var(--line);
  border-radius: 8px; background: color-mix(in srgb, var(--panel) 92%, transparent);
  color: var(--text); font: inherit; font-size: 12px; cursor: pointer;
}
.side-list button.on { border-color: var(--accent); color: var(--accent); }

/* picture view */
.picture-stage { position: absolute; inset: 0; overflow: hidden; touch-action: none; }
.video-stage { position: absolute; inset: 0; overflow: hidden; background: #000; }
.picture-stage img { position: absolute; image-rendering: pixelated; transform-origin: 0 0; user-select: none; -webkit-user-drag: none; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  z-index: 60; background: var(--panel2); border: 1px solid var(--line);
  padding: 8px 14px; border-radius: 10px; font-size: 13px;
}

.spinner {
  position: absolute; left: 50%; top: 50%; width: 34px; height: 34px;
  margin: -17px 0 0 -17px; border-radius: 50%; z-index: 20;
  border: 3px solid var(--line); border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 640px) {
  .tb-title { display: none; }
  .tb-select { max-width: 34vw; }
}
