:root {
  --bg: #f4efe4;
  --bg-2: #ebe3d2;
  --ink: #1d1a15;
  --ink-2: #3d372d;
  --ink-3: #564e41;
  --rule: rgba(29, 26, 21, 0.16);
  --accent: #8a3d12;
  --accent-ink: #7a3510;
  --link: #7a3510;
  --glass: rgba(16, 21, 19, 0.87);
  --glass-ink: #f3eee3;
  --glass-ink-2: #d6cfbf;
  --glass-rule: rgba(243, 238, 227, 0.18);
  --glass-accent: #f5c7a2;
  --bar-bg: rgba(244, 239, 228, 0.94);
  --serif: "Literata", Georgia, "Times New Roman", serif;
  --mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  --bar-h: 48px;
  --sky: #cfd8d4;
  --lake: #3f6b62;
  --c-measured: #ffffff;
  --c-excavated: #d9853b;
  --c-inferred: #f2c46b;
  --c-illustrative: #8fb3d9;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14120f; --bg-2: #1d1a16; --ink: #f1ebdf; --ink-2: #ddd5c6; --ink-3: #c7bdab;
    --rule: rgba(241, 235, 223, 0.16); --accent: #f0b98f; --accent-ink: #f3c39e; --link: #f3c39e;
    --bar-bg: rgba(20, 18, 15, 0.94); --sky: #1a2220; --lake: #24453f; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #14120f; --bg-2: #1d1a16; --ink: #f1ebdf; --ink-2: #ddd5c6; --ink-3: #c7bdab;
  --rule: rgba(241, 235, 223, 0.16); --accent: #f0b98f; --accent-ink: #f3c39e; --link: #f3c39e;
  --bar-bg: rgba(20, 18, 15, 0.94); --sky: #1a2220; --lake: #24453f; color-scheme: dark;
}

* { box-sizing: border-box; }
html { scroll-behavior: auto; }
body { margin: 0; background: var(--sky); color: var(--ink); font-family: var(--serif); font-size: 18px; line-height: 1.6; -webkit-font-smoothing: antialiased; }
a { color: var(--link); text-underline-offset: 0.18em; }
img { max-width: 100%; height: auto; display: block; }
:focus-visible { outline: 3px solid var(--glass-accent); outline-offset: 3px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
a.sr-only:focus { width: auto; height: auto; clip: auto; left: 16px; top: calc(var(--bar-h) + 8px); z-index: 50; padding: 8px 12px; background: var(--bg); color: var(--ink); border-radius: 8px; }

/* ---------- top bar ---------- */
.topbar { position: fixed; inset: 0 0 auto 0; height: var(--bar-h); z-index: 30; display: flex; align-items: center; gap: 14px; padding: 0 16px; background: var(--bar-bg); border-bottom: 1px solid var(--rule); font-family: var(--mono); font-size: 13px; color: var(--ink); }
.topbar a { color: var(--ink); text-decoration: none; }
.topbar .home { font-weight: 600; white-space: nowrap; }
.topnav { display: flex; gap: 16px; overflow-x: auto; scrollbar-width: none; min-width: 0; }
.topnav::-webkit-scrollbar { display: none; }
.topnav a { white-space: nowrap; padding: 12px 0; border-bottom: 2px solid transparent; }
.topnav a[aria-current="true"] { border-bottom-color: var(--accent); }
.spacer { flex: 1; }
.chip { border: 1px solid var(--rule); border-radius: 999px; padding: 4px 10px; white-space: nowrap; }
.icon-btn { width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--rule); background: transparent; color: var(--ink); display: grid; place-items: center; cursor: pointer; flex: none; }
.icon-btn svg { display: block; }
.icon-btn svg[hidden] { display: none; }
section[id] { scroll-margin-top: calc(var(--bar-h) + 12px); }

/* ---------- the scene ---------- */
#scene { position: fixed; inset: 0; width: 100vw; height: 100vh; height: 100lvh; z-index: 0; display: block; pointer-events: none; background: var(--sky); }
.exploring #scene { pointer-events: auto; cursor: grab; touch-action: none; }
.no-webgl #scene, .no-webgl #labels, .no-webgl #explore { display: none; }
#scene-fallback { display: none; position: fixed; inset: 0; z-index: 0; background: var(--sky) url(/sultana-malu-rosu/assets/img/azi-de-sus.webp) center / cover no-repeat; }
.no-webgl #scene-fallback { display: block; }

/* ---------- story ---------- */
.story { position: relative; z-index: 10; padding: 0 0 30vh; }
.step { position: relative; width: min(430px, calc(100vw - 32px)); margin: 0 0 88vh 5vw; padding: 20px 22px 22px; background: var(--glass); color: var(--glass-ink); border: 1px solid var(--glass-rule); border-radius: 14px; font-size: 17px; line-height: 1.55; }
.step:first-child { margin-top: 62vh; }
.step p { margin: 0 0 0.8em; }
.step p:last-child { margin-bottom: 0; }
.step h2 { font-size: 1.35rem; line-height: 1.25; margin: 0 0 0.55em; font-weight: 600; }
.step .kicker { font-family: var(--mono); font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--glass-accent); margin: 0 0 8px; }
.step a { color: var(--glass-accent); }
.step blockquote { margin: 0.9em 0; padding: 0 0 0 14px; border-left: 2px solid var(--glass-accent); font-style: italic; }
.step blockquote footer { font-style: normal; font-family: var(--mono); font-size: 12px; color: var(--glass-ink-2); margin-top: 6px; }
.step figure { margin: 14px -8px 2px; }
.step figure img { border-radius: 6px; width: 100%; }
.step figcaption { font-family: var(--mono); font-size: 11.5px; line-height: 1.45; color: var(--glass-ink-2); margin-top: 6px; }
.step.right { margin-left: auto; margin-right: 5vw; }
.step.wide { width: min(560px, calc(100vw - 32px)); }

.hero { padding: 26px 26px 24px; width: min(620px, calc(100vw - 32px)); }
.hero h1 { font-size: clamp(2.2rem, 5.4vw, 3.9rem); line-height: 1.04; margin: 0 0 16px; font-weight: 600; letter-spacing: -0.01em; }
.hero .deck { font-size: 1.12rem; color: var(--glass-ink); }
.hero .cue { font-family: var(--mono); font-size: 13px; color: var(--glass-accent); margin-top: 14px; }
.hero .byline { font-family: var(--mono); font-size: 12px; color: var(--glass-ink-2); }

.levels { list-style: none; padding: 0; margin: 10px 0 0; font-family: var(--mono); font-size: 13px; }
.levels li { display: flex; justify-content: space-between; gap: 12px; border-top: 1px solid var(--glass-rule); padding: 5px 0; }

/* ---------- explore ---------- */
#explore { position: relative; z-index: 10; min-height: 100vh; pointer-events: none; display: flex; align-items: flex-end; justify-content: center; padding: 0 16px 90px; }
#explore .panel { pointer-events: auto; background: var(--glass); color: var(--glass-ink); border: 1px solid var(--glass-rule); border-radius: 14px; padding: 16px 18px; width: min(640px, 100%); }
#explore h2 { margin: 0 0 6px; font-size: 1.3rem; }
#explore p { margin: 0 0 10px; font-size: 16px; }
.years { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.years button, .ex-toggle { font: 13px/1 var(--mono); color: var(--glass-ink); background: transparent; border: 1px solid var(--glass-rule); border-radius: 999px; padding: 10px 12px; min-height: 44px; cursor: pointer; }
.years button[aria-pressed="true"], .ex-toggle[aria-pressed="true"] { background: var(--glass-ink); color: #15130f; }
.exploring .story .step { visibility: hidden; }
.ex-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.ex-zoom { display: none; gap: 8px; }
.exploring .ex-zoom { display: flex; }
.ex-zoom button { font: 18px/1 var(--mono); color: var(--glass-ink); background: transparent; border: 1px solid var(--glass-rule); border-radius: 999px; width: 44px; min-height: 44px; cursor: pointer; }
.exploring #scene:active { cursor: grabbing; }

/* ---------- paper sections ---------- */
.paper { position: relative; z-index: 12; background: var(--bg); color: var(--ink); padding: 72px 16px 64px; border-top: 1px solid var(--rule); }
.paper > * { max-width: 700px; margin-left: auto; margin-right: auto; }
.paper h2 { font-size: clamp(1.6rem, 3.4vw, 2.2rem); line-height: 1.15; margin: 0 0 18px; }
.paper h3 { font-size: 1.15rem; margin: 1.8em auto 0.4em; }
.paper p, .paper li { color: var(--ink-2); }
.paper figure { max-width: 900px; margin: 28px auto; }
.paper figcaption { font-family: var(--mono); font-size: 12.5px; color: var(--ink-3); margin-top: 8px; line-height: 1.5; }
.timeline { list-style: none; padding: 0; margin: 20px auto; }
.timeline li { display: grid; grid-template-columns: 7.5em 1fr; gap: 14px; padding: 10px 0; border-top: 1px solid var(--rule); }
.timeline time { font-family: var(--mono); font-size: 14px; color: var(--accent-ink); font-weight: 600; }
.sources { font-size: 15.5px; }
.sources li { margin-bottom: 0.5em; }
.credits { font-family: var(--mono); font-size: 13px; }
.note { font-size: 15.5px; border-left: 3px solid var(--accent); padding-left: 14px; }
footer.site { position: relative; z-index: 12; background: var(--bg-2); color: var(--ink-2); padding: 28px 16px 40px; font-family: var(--mono); font-size: 13px; text-align: center; border-top: 1px solid var(--rule); }
footer.site a { color: var(--ink); }

@media (max-width: 760px) {
  body { font-size: 17px; }
  .step, .step.right { margin: 0 auto 92vh; width: calc(100vw - 32px); font-size: 16px; padding: 16px 16px 18px; }
  .step:first-child { margin-top: 56vh; }
  .hero h1 { font-size: 2.15rem; }
        .step:first-child { margin-top: 60vh; }
  .timeline li { grid-template-columns: 1fr; gap: 2px; }
  .topbar { gap: 10px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ---------- evidence legend and labels ---------- */
#legend { position: fixed; right: 16px; top: calc(var(--bar-h) + 12px); z-index: 20; background: var(--glass); color: var(--glass-ink); border: 1px solid var(--glass-rule); border-radius: 10px; padding: 8px 12px; font-family: var(--mono); font-size: 12.5px; line-height: 1.3; opacity: 0; transition: opacity .4s; }
.scene-ready #legend, .no-webgl #legend { opacity: 1; }
body.paper-on #legend { opacity: 0; pointer-events: none; }
#legend ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 5px; }
#legend li { display: flex; align-items: center; gap: 8px; }
.sw { width: 22px; height: 10px; flex: none; border-radius: 2px; }
.sw-measured { border: 2px solid var(--c-measured); background: linear-gradient(90deg, #6f7f5a, #b8a98c); }
.sw-excavated { background: var(--c-excavated); }
.sw-inferred { height: 0; border-top: 3px dashed var(--c-inferred); border-radius: 0; }
.sw-illustrative { border: 1px solid var(--c-illustrative); background: repeating-linear-gradient(135deg, var(--c-illustrative) 0 2px, transparent 2px 5px); }
#labels { position: fixed; inset: 0; z-index: 5; pointer-events: none; overflow: hidden; }
.lbl { position: absolute; left: 0; top: 0; font-family: var(--mono); font-size: 12px; line-height: 1.2; padding: 3px 7px; border-radius: 6px; background: rgba(12, 16, 14, 0.82); color: #f3eee3; white-space: nowrap; opacity: 0; will-change: transform; }
.lbl.small { font-size: 11px; padding: 2px 5px; }
.k-measured { box-shadow: inset 0 -2px 0 var(--c-measured); }
.k-excavated { box-shadow: inset 0 -2px 0 var(--c-excavated); }
.k-inferred { box-shadow: inset 0 -2px 0 var(--c-inferred); }
.k-illustrative { box-shadow: inset 0 -2px 0 var(--c-illustrative); }
.exploring #labels .lbl.small { display: none; }

/* ---------- back to top ---------- */
.to-top { position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 40; min-width: 48px; height: 48px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--rule); background: var(--bg); color: var(--ink); font: 600 13px/1 var(--mono); cursor: pointer; box-shadow: 0 2px 10px rgba(0,0,0,.18); }
.to-top[hidden] { display: none; }
@media (max-width: 760px) {
  #legend { left: 0; right: 0; top: var(--bar-h); border-radius: 0; border-width: 0 0 1px; font-size: 11px; padding: 5px 12px; background: rgba(16, 21, 19, 0.94); }
  #legend ul { grid-template-columns: 1fr 1fr; gap: 3px 12px; }
  .to-top { right: 8px; bottom: calc(8px + env(safe-area-inset-bottom)); }
}
.exploring .to-top { display: none; }
