/* Layout: a full-window 3D stage; chrome floats on top (menu bar, title box, legend, timeline). Always dark. */
:root {
  --bg: #161718;
  --bar: #121314;
  --panel: rgba(30, 32, 34, 0.94);
  --line: #2e3135;
  --line-2: #3a3d41;
  --fg: #ececec;
  --fg-hi: #f4f4f4;
  --muted: #9a9ea4;
  --dim: #7e8389;
  --accent: #e5484d;
  --ai: #b197fc;
  --l-artist: #ff8fb1;
  --l-tool: #3dd9c5;
  --l-style: #e5484d;
  --serif: 'Instrument Serif', 'Times New Roman', serif;
  --mono: 'IBM Plex Mono', ui-monospace, Menlo, monospace;
  --sans: 'Geist', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --bar-h: 50px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow: hidden; background: var(--bg); color: var(--fg); font-family: var(--sans); }
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* stage */
#stage { position: fixed; inset: 0; overflow: hidden; background: radial-gradient(ellipse 75% 70% at 50% 50%, var(--bg) 45%, #1f2124 80%, #272a2e 100%); touch-action: none; cursor: grab; outline: none; }
#stage.dragging { cursor: grabbing; }
#world, #labels { position: absolute; inset: 0; pointer-events: none; }
#links { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
#links path { fill: none; stroke-width: 0.7; }

.thumb { position: absolute; left: 0; top: 0; transform-origin: 50% 50%; pointer-events: auto; }
.thumb, .thumb * { -webkit-user-select: none; user-select: none; -webkit-user-drag: none; }
.thumb .art { display: block; width: 100%; height: 100%; padding: 0; border: 0; border-radius: 4px; overflow: hidden; background: #26282b; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45); position: relative; }
.thumb .art img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .art .ph { position: absolute; inset: 0; }
.thumb.linked .art { outline: 2px solid var(--ring, transparent); outline-offset: 3px; }
.thumb .art:hover { filter: brightness(1.08); }
.thumb .play { position: absolute; right: 6%; bottom: 6%; width: 18%; aspect-ratio: 1; border-radius: 50%; background: rgba(0, 0, 0, 0.55); display: flex; align-items: center; justify-content: center; }
.thumb .play::after { content: ""; border-left: 7px solid #fff; border-top: 4.5px solid transparent; border-bottom: 4.5px solid transparent; margin-left: 2px; transform: scale(var(--ps, 1)); }

/* constant-size caption under a thumb (counter-scaled in JS) */
.cap { position: absolute; left: 0; top: 100%; padding-top: 6px; pointer-events: auto; -webkit-user-select: text; user-select: text; white-space: nowrap; display: none; font-size: 12px; line-height: 1.35; }
.thumb.near .cap { display: block; }
.cap a { color: var(--fg); text-decoration: none; font-weight: 500; }
.cap a:hover { text-decoration: underline; }
.cap .meta { font-family: var(--mono); font-size: 10px; letter-spacing: 0.08em; color: var(--muted); }
.cap .badge { font-family: var(--mono); font-size: 9px; letter-spacing: 0.1em; padding: 1px 5px; border-radius: 3px; margin-left: 6px; border: 1px solid var(--line-2); color: var(--muted); }
.cap .badge.ai { border-color: var(--ai); color: var(--ai); }

/* floating cluster titles + link labels (constant size) */
.ctitle { position: absolute; left: 0; top: 0; white-space: nowrap; transform-origin: 0 100%; }
.ctitle .n { font-family: var(--serif); font-size: 30px; line-height: 1.02; color: var(--fg-hi); }
.ctitle .c { font-family: var(--mono); font-size: 11px; letter-spacing: 0.14em; color: var(--accent); margin-top: 3px; }
.ctitle.ai .c { color: var(--ai); }
.ctitle.dim { opacity: 0.15; }
#links .hull { fill: rgba(255, 255, 255, 0.015); stroke: rgba(236, 236, 236, 0.16); stroke-width: 1; stroke-dasharray: 2 6; }
#links .hull.ai { fill: rgba(177, 151, 252, 0.03); stroke: rgba(177, 151, 252, 0.5); }
.llabel { position: absolute; left: 0; top: 0; font-family: var(--mono); font-size: 9.5px; letter-spacing: 0.08em; padding: 2px 6px; border-radius: 3px; background: var(--bg); border: 1px solid; white-space: nowrap; }

/* menu bar */
#bar { position: fixed; left: 0; right: 0; top: 0; z-index: 20; display: flex; align-items: flex-start; gap: 20px; padding: 10px max(16px, env(safe-area-inset-right, 0px)) 10px max(16px, env(safe-area-inset-left, 0px)); padding-top: calc(10px + env(safe-area-inset-top, 0px)); background: var(--bar); border-bottom: 1px solid #26282b; }
.brand { font-family: var(--serif); font-size: 24px; line-height: 30px; color: var(--fg-hi); text-decoration: none; }
#topics { display: flex; flex-wrap: wrap; gap: 4px 2px; flex: 1 1 auto; min-width: 0; }
#topics button { display: flex; align-items: center; gap: 6px; font-family: var(--mono); font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; padding: 6px 9px; border-radius: 6px; border: 0; background: transparent; color: var(--muted); }
#topics button:hover { color: var(--fg-hi); }
#topics button[aria-pressed="true"] { background: #2a2c2f; color: var(--fg-hi); }
#topics .new { font-size: 8px; padding: 1px 4px; border-radius: 3px; background: var(--accent); color: #fff; letter-spacing: 0.08em; }
.bar-actions { display: flex; gap: 10px; align-items: center; }
.pill { display: flex; align-items: center; gap: 8px; font-family: var(--mono); font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; padding: 6px 12px; border: 1px solid var(--line-2); border-radius: 6px; background: transparent; color: var(--fg-hi); }
.pill svg path { fill: var(--accent); }
.pill:disabled { opacity: 0.5; cursor: default; }

/* title box */
#titlebox { position: fixed; left: max(16px, env(safe-area-inset-left, 0px)); top: calc(var(--bar-h) + 16px); z-index: 15; width: 264px; padding: 18px 20px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; display: flex; flex-direction: column; pointer-events: none; }
.tb-row { display: flex; gap: 14px; align-items: center; }
.tb-icon { width: 40px; height: 40px; flex: 0 0 40px; border: 1.5px solid var(--accent); border-radius: 10px; display: flex; align-items: center; justify-content: center; }
.tb-icon.round { border-radius: 50%; }
.tb-icon svg * { stroke: var(--accent); stroke-width: 1.4; }
.tb-icon svg .fill { fill: var(--accent); stroke: none; }
.tb-link { width: 1px; height: 12px; background: var(--accent); margin-left: 19.5px; }
.tb-k { font-family: var(--mono); font-size: 11px; letter-spacing: 0.14em; color: #b8bcc2; }
.tb-k b { color: var(--accent); font-weight: 400; }
.tb-v { font-size: 21px; font-weight: 500; color: var(--fg-hi); }
.tb-v.serif { font-family: var(--serif); font-size: 30px; font-weight: 400; line-height: 1.05; }
.tb-v.mono { font-family: var(--mono); font-size: 16px; font-weight: 400; }

#hint, #sampleNote { position: fixed; z-index: 15; font-family: var(--mono); font-size: 10px; letter-spacing: 0.1em; color: var(--dim); pointer-events: none; }
#hint { right: max(16px, env(safe-area-inset-right, 0px)); top: calc(var(--bar-h) + 14px); }
#sampleNote { left: max(16px, env(safe-area-inset-left, 0px)); bottom: calc(96px + env(safe-area-inset-bottom, 0px)); color: var(--accent); }
#hint { transition: opacity 0.6s; }
#hint.gone { opacity: 0; }

#legend { position: fixed; z-index: 15; right: max(16px, env(safe-area-inset-right, 0px)); bottom: calc(96px + env(safe-area-inset-bottom, 0px)); display: flex; flex-direction: column; gap: 8px; font-family: var(--mono); font-size: 10px; letter-spacing: 0.1em; color: #b8bcc2; padding: 12px 14px; background: rgba(22, 23, 24, 0.85); border-radius: 8px; pointer-events: none; }
#legend div { display: flex; align-items: center; gap: 10px; }
#legend i { width: 26px; height: 1.5px; display: block; }
#legend .lg-k { color: var(--dim); letter-spacing: 0.14em; }

/* timeline */
#timeline { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; height: calc(84px + env(safe-area-inset-bottom, 0px)); padding: 0 max(16px, env(safe-area-inset-right, 0px)) env(safe-area-inset-bottom, 0px) max(16px, env(safe-area-inset-left, 0px)); display: flex; align-items: center; background: linear-gradient(to top, var(--bg) 60%, rgba(22, 23, 24, 0)); }
.round-btn { width: 32px; height: 32px; flex: 0 0 32px; border-radius: 50%; border: 1px solid var(--line-2); background: var(--bg); display: flex; align-items: center; justify-content: center; }
.round-btn svg path { stroke: #c9ccd1; stroke-width: 1.4; fill: none; stroke-linecap: round; }
.round-btn:disabled { opacity: 0.35; cursor: default; }
#track { position: relative; flex: 1 1 auto; height: 84px; }
#line { position: absolute; left: 0; right: 0; top: 52px; height: 1px; background: var(--line-2); }
.wk { position: absolute; top: 40px; width: 24px; height: 26px; margin-left: -12px; border: 0; background: transparent; padding: 0; }
.wk::before { content: ""; position: absolute; left: 11.5px; top: 8px; width: 1px; height: 9px; background: #5b5f65; }
.wk:hover::before { background: var(--fg-hi); }
.wk-l { position: absolute; top: 64px; transform: translateX(-50%); font-family: var(--mono); font-size: 10px; letter-spacing: 0.1em; color: var(--dim); white-space: nowrap; pointer-events: none; }
.wk-cur { position: absolute; top: 4px; transform: translateX(-50%); text-align: center; pointer-events: none; white-space: nowrap; }
.wk-cur .w { font-family: var(--serif); font-size: 28px; line-height: 1; color: var(--fg-hi); }
.wk-cur .d { font-family: var(--mono); font-size: 10px; letter-spacing: 0.1em; color: var(--accent); margin-top: 3px; }
#handle { position: absolute; top: 44px; width: 16px; height: 16px; margin-left: -8px; border-radius: 50%; background: var(--accent); border: 3px solid var(--fg-hi); box-shadow: 0 0 0 4px rgba(229, 72, 77, 0.25); cursor: grab; touch-action: none; padding: 0; }
#handle:active { cursor: grabbing; }

#loading { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; font-family: var(--mono); font-size: 11px; letter-spacing: 0.14em; color: var(--dim); pointer-events: none; }

@media (max-width: 720px) {
  #titlebox { width: auto; right: max(16px, env(safe-area-inset-right, 0px)); padding: 12px 14px; flex-direction: row; flex-wrap: wrap; gap: 6px 16px; }
  .tb-link, .tb-icon { display: none; }
  .tb-v.serif { font-size: 22px; }
  .tb-v { font-size: 16px; }
  #hint, #legend { display: none; }
  .brand { font-size: 20px; }
  #bar { gap: 10px; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; } }

/* hearts on pieces */
.cap .hrt { margin-left: 6px; width: 22px; height: 22px; padding: 0; border: 1px solid var(--line-2); border-radius: 50%; background: rgba(22, 23, 24, 0.85); display: inline-flex; align-items: center; justify-content: center; vertical-align: middle; }
.cap .hrt svg path, .bx-fav svg path, .fdot svg path { fill: none; stroke: var(--fg-hi); stroke-width: 1.4; }
.cap .hrt[aria-pressed="true"] svg path, .bx-fav[aria-pressed="true"] svg path, .fdot svg path { fill: var(--accent); stroke: var(--accent); }
.fdot { position: absolute; right: 6%; top: 6%; width: 20px; height: 20px; border-radius: 50%; background: rgba(0, 0, 0, 0.55); display: none; align-items: center; justify-content: center; pointer-events: none; }
.thumb.faved .fdot { display: flex; }
#favBtn[aria-pressed="true"] { border-color: var(--accent); background: rgba(229, 72, 77, 0.14); }

/* hovering box */
#box { position: fixed; inset: 0; z-index: 40; display: flex; align-items: center; justify-content: center; padding: calc(var(--bar-h) + 20px) max(16px, env(safe-area-inset-right, 0px)) 24px max(16px, env(safe-area-inset-left, 0px)); }
#box[hidden] { display: none; }
.bx-scrim { position: absolute; inset: 0; background: rgba(12, 13, 14, 0.62); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.bx-panel { position: relative; width: min(1180px, 100%); max-height: 100%; display: flex; gap: 28px; padding: 24px; background: #1b1c1e; border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 40px 120px rgba(0, 0, 0, 0.7); overflow: auto; }
.bx-media { flex: 1 1 64%; min-width: 0; display: flex; flex-direction: column; gap: 12px; }
.bx-stage { position: relative; aspect-ratio: 16 / 10; width: 100%; border-radius: 8px; overflow: hidden; background: #111213; display: flex; align-items: center; justify-content: center; }
.bx-stage img { width: 100%; height: 100%; object-fit: contain; }
.bx-stage iframe { width: 100%; height: 100%; border: 0; background: #fff; }
.bx-stage iframe.video { background: #000; }
.bx-tabs { display: flex; gap: 4px; }
.bx-tabs button, .seg button { font-family: var(--mono); font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; padding: 8px 12px; min-height: 36px; border: 1px solid var(--line-2); background: transparent; color: var(--muted); border-radius: 6px; }
.bx-tabs button[aria-pressed="true"], .seg button[aria-pressed="true"] { background: #2a2c2f; color: var(--fg-hi); }
.bx-note { font-family: var(--mono); font-size: 10.5px; letter-spacing: 0.06em; color: var(--muted); line-height: 1.5; }
.bx-info { flex: 1 1 36%; min-width: 0; display: flex; flex-direction: column; gap: 14px; }
.bx-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.bx-k { font-family: var(--mono); font-size: 11px; letter-spacing: 0.14em; color: var(--accent); text-transform: uppercase; padding-top: 6px; }
.bx-close { width: 44px; height: 44px; flex: 0 0 44px; border: 0; border-radius: 8px; background: #2a2c2f; display: flex; align-items: center; justify-content: center; }
.bx-close svg path { stroke: var(--fg-hi); stroke-width: 1.6; stroke-linecap: round; }
#bxTitle { margin: 0; font-family: var(--serif); font-weight: 400; font-size: 34px; line-height: 1.08; color: var(--fg-hi); text-wrap: balance; }
#bxArtist { font-size: 16px; font-weight: 500; color: var(--fg); text-decoration: none; }
#bxArtist:hover { text-decoration: underline; }
#bxArtist::after { content: " ↗"; color: var(--muted); }
.bx-meta { display: flex; flex-direction: column; gap: 6px; font-family: var(--mono); font-size: 11px; letter-spacing: 0.08em; color: var(--muted); text-transform: uppercase; }
.bx-meta .ai { color: var(--ai); }
.bx-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.bx-chips span { font-family: var(--mono); font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase; padding: 3px 7px; border-radius: 4px; border: 1px solid var(--line-2); color: #c9ccd1; }
.bx-chips span.tool { border-color: rgba(61, 217, 197, 0.5); color: var(--l-tool); }
.bx-actions { margin-top: auto; display: flex; flex-direction: column; gap: 10px; }
.bx-fav, .bx-btn, .bx-nav button { display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; border-radius: 8px; font-family: var(--mono); font-size: 11.5px; letter-spacing: 0.1em; text-transform: uppercase; text-decoration: none; }
.bx-fav { border: 1px solid var(--line-2); background: transparent; color: var(--fg-hi); }
.bx-fav[aria-pressed="true"] { border-color: var(--accent); background: rgba(229, 72, 77, 0.14); }
.bx-btn { border: 1px solid var(--line-2); color: var(--fg-hi); }
.bx-btn.primary { background: var(--fg-hi); color: #141516; border-color: var(--fg-hi); }
.bx-nav { display: flex; gap: 10px; }
.bx-nav button { flex: 1; border: 0; background: #2a2c2f; color: var(--fg); }

/* favourites: the inside of a sphere */
#favs { position: fixed; inset: 0; z-index: 18; background: radial-gradient(ellipse 75% 70% at 50% 50%, var(--bg) 45%, #1f2124 80%, #272a2e 100%); overflow: hidden; touch-action: none; cursor: grab; }
#favs[hidden] { display: none; }
#favSphere { position: absolute; inset: 0; perspective: 700px; perspective-origin: 50% 50%; }
#favWorld { position: absolute; left: 50%; top: 50%; width: 0; height: 0; transform-style: preserve-3d; }
.ft { position: absolute; left: 0; top: 0; width: 230px; height: 300px; margin: -150px 0 0 -115px; box-sizing: border-box; padding: 0; border: 7px solid var(--wk); border-radius: 14px; background: var(--wk); display: flex; flex-direction: column; backface-visibility: hidden; box-shadow: 0 18px 40px rgba(0, 0, 0, 0.45); }
.ft .im { position: relative; flex: 1 1 auto; border-radius: 7px; overflow: hidden; background: #26282b; }
.ft .im img, .ft .im .ph { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.ft .lb { display: flex; justify-content: space-between; gap: 6px; padding: 6px 2px 0; font-family: var(--mono); font-size: 10px; letter-spacing: 0.08em; white-space: nowrap; color: var(--ink); }
.ft .lb b { font-weight: 500; }
.ft .who { position: absolute; left: 8px; right: 8px; bottom: 8px; font-size: 11px; font-weight: 500; color: #fff; text-shadow: 0 1px 6px rgba(0, 0, 0, 0.8); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fav-bar { position: absolute; left: 0; right: 0; top: var(--bar-h); display: flex; flex-wrap: wrap; align-items: center; gap: 12px 18px; padding: 10px max(16px, env(safe-area-inset-right, 0px)) 10px max(16px, env(safe-area-inset-left, 0px)); background: rgba(18, 19, 20, 0.94); border-bottom: 1px solid #26282b; z-index: 2; }
.fav-bar .pill svg path { stroke: var(--fg-hi); stroke-width: 1.4; fill: none; stroke-linecap: round; }
.seg { display: flex; gap: 0; }
.seg button:first-child { border-radius: 6px 0 0 6px; }
.seg button:last-child { border-radius: 0 6px 6px 0; border-left: 0; }
#favWeeks { display: flex; flex-wrap: wrap; gap: 4px; }
#favWeeks button { display: flex; align-items: center; gap: 6px; font-family: var(--mono); font-size: 11px; letter-spacing: 0.1em; padding: 6px 9px; border: 0; border-radius: 6px; background: transparent; color: #c9ccd1; }
#favWeeks button:hover { background: #2a2c2f; }
#favWeeks i { width: 8px; height: 8px; border-radius: 50%; display: block; }
#favCount { margin-left: auto; font-family: var(--mono); font-size: 11px; letter-spacing: 0.1em; color: var(--muted); text-transform: uppercase; }
#favEmpty { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); text-align: center; max-width: 420px; padding: 0 16px; }
#favEmpty[hidden] { display: none; }
.fe-t { font-family: var(--serif); font-size: 34px; color: var(--fg-hi); }
.fe-d { margin-top: 8px; color: var(--muted); line-height: 1.5; }
.fav-hint { position: absolute; right: max(16px, env(safe-area-inset-right, 0px)); bottom: calc(16px + env(safe-area-inset-bottom, 0px)); font-family: var(--mono); font-size: 10px; letter-spacing: 0.1em; color: var(--dim); pointer-events: none; }

@media (max-width: 820px) {
  .bx-panel { flex-direction: column; padding: 16px; gap: 16px; }
  #bxTitle { font-size: 26px; }
  .fav-hint { display: none; }
}
.bx-stage .ph { position: absolute; inset: 0; }
