/* —————————————————————————————————— The Founders’ Library · stage UI */

@font-face {
  font-family: "EB Garamond";
  src: url("../fonts/ebgaramond-roman-var.woff2") format("woff2");
  font-weight: 400 800;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "EB Garamond";
  src: url("../fonts/ebgaramond-italic-var.woff2") format("woff2");
  font-weight: 400 800;
  font-style: italic;
  font-display: swap;
}

:root {
  --bg0: #0b0908;
  --bg1: #17110d;
  --bg2: #241a13;
  --brass: #c9a35f;
  --brass-dim: #8d7448;
  --cream: #ede3cf;
  --cream-dim: #b3a68d;
  --serif: "EB Garamond", Georgia, "Times New Roman", serif;
  --ease-out: cubic-bezier(.22,.9,.24,1);
  --ease-in-out: cubic-bezier(.65,0,.3,1);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body { height: 100%; }

body {
  font-family: var(--serif);
  background: var(--bg0);
  color: var(--cream);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

#bg {
  position: fixed; inset: 0; z-index: 0;
  background:
    radial-gradient(120% 90% at 50% 8%, #33241a 0%, #1c1410 44%, #0b0908 100%);
}
#bg::after {
  content: ""; position: absolute; inset: 0;
  background: radial-gradient(60% 42% at 50% 32%, rgba(201,163,95,.10), transparent 70%);
}

#stage { position: fixed; inset: 0; z-index: 1; display: block; touch-action: none; }

#vignette {
  position: fixed; inset: 0; z-index: 2; pointer-events: none;
  background:
    radial-gradient(140% 110% at 50% 46%, transparent 55%, rgba(5,3,2,.55) 100%);
  mix-blend-mode: multiply;
}

/* ————— masthead ————— */

#masthead {
  position: fixed; top: clamp(14px, 3.4vh, 34px); left: 50%; transform: translateX(-50%);
  z-index: 5; text-align: center; pointer-events: none;
  opacity: 0; transition: opacity 1.2s var(--ease-out) .25s;
}
body[data-stage="ready"] #masthead { opacity: 1; }
#masthead .rule {
  width: clamp(120px, 22vw, 260px); height: 1px; margin: 0 auto;
  background: linear-gradient(90deg, transparent, var(--brass-dim), transparent);
}
#masthead h1 {
  font-size: clamp(17px, 2.5vw, 26px); font-weight: 500;
  letter-spacing: .42em; text-indent: .42em;
  color: var(--cream); margin: 10px 0 6px;
  text-shadow: 0 1px 18px rgba(0,0,0,.6);
}
#masthead .sub {
  font-style: italic; font-size: clamp(11px, 1.35vw, 14px);
  color: var(--cream-dim); letter-spacing: .04em;
}

/* ————— hint bar ————— */

#hint {
  position: fixed; bottom: max(16px, env(safe-area-inset-bottom)); left: 50%;
  transform: translateX(-50%); z-index: 5;
  display: flex; align-items: center; gap: 10px;
  font-size: 12.5px; color: var(--cream-dim);
  opacity: 0; transition: opacity 1.2s var(--ease-out) .6s;
  white-space: nowrap;
}
body[data-stage="ready"] #hint { opacity: 1; }
body[data-mode="reader"] #hint { opacity: 0; pointer-events: none; }
#hint i { opacity: .45; font-style: normal; }
#hint b { color: var(--cream); font-weight: 500; }
#about-btn {
  font: inherit; color: var(--brass); background: none; border: 0;
  cursor: pointer; letter-spacing: .02em; text-decoration: underline dotted;
  text-underline-offset: 3px; margin-left: 4px;
}
#about-btn:hover { color: var(--cream); }

/* ————— tooltip ————— */

#tooltip {
  position: fixed; z-index: 6; width: min(320px, calc(100vw - 40px));
  padding: 14px 16px 12px;
  background: linear-gradient(160deg, rgba(30,23,17,.96), rgba(19,14,10,.97));
  border: 1px solid rgba(201,163,95,.28);
  border-radius: 8px;
  box-shadow: 0 18px 50px rgba(0,0,0,.55), inset 0 1px 0 rgba(255,255,255,.05);
  backdrop-filter: blur(6px);
  transform: translateY(6px) scale(.98); opacity: 0;
  transition: opacity .28s var(--ease-out), transform .28s var(--ease-out);
  pointer-events: none;
}
#tooltip.on { opacity: 1; transform: none; }
.tt-era {
  font-size: 10px; letter-spacing: .24em; text-transform: uppercase;
  color: var(--brass); margin-bottom: 6px;
}
.tt-title { font-size: 19px; line-height: 1.15; color: var(--cream); }
.tt-meta { font-size: 12.5px; font-style: italic; color: var(--cream-dim); margin: 3px 0 8px; }
.tt-hook { font-size: 13.5px; line-height: 1.4; color: #cfc4ad; }
.tt-open {
  margin-top: 10px; font-size: 10.5px; letter-spacing: .18em; text-transform: uppercase;
  color: var(--brass); border-top: 1px solid rgba(201,163,95,.18); padding-top: 8px;
}

/* ————— loader ————— */

#loader {
  position: fixed; inset: 0; z-index: 40;
  display: grid; place-items: center;
  background: radial-gradient(100% 100% at 50% 30%, #201711, #0b0908);
  transition: opacity .7s var(--ease-out), visibility .7s;
}
body[data-stage="ready"] #loader { opacity: 0; visibility: hidden; }
.ld-mark { text-align: center; width: min(320px, 78vw); }
.ld-spines { display: flex; justify-content: center; align-items: flex-end; gap: 4px; height: 56px; margin-bottom: 22px; }
.ld-spines i {
  width: 11px; border-radius: 2px 2px 0 0;
  background: linear-gradient(180deg, #7c5a3b, #4a3521);
  box-shadow: inset 0 2px 0 rgba(255,255,255,.14);
  animation: breathe 2.6s var(--ease-in-out) infinite;
}
.ld-spines i:nth-child(1) { height: 78%; animation-delay: 0s; background: linear-gradient(180deg,#8a4b2a,#552d18); }
.ld-spines i:nth-child(2) { height: 96%; animation-delay: .35s; }
.ld-spines i:nth-child(3) { height: 66%; animation-delay: .7s; background: linear-gradient(180deg,#31536b,#1f3344); }
.ld-spines i:nth-child(4) { height: 88%; animation-delay: 1.05s; }
.ld-spines i:nth-child(5) { height: 72%; animation-delay: 1.4s; background: linear-gradient(180deg,#26364e,#182334); }
@keyframes breathe { 0%,100% { transform: translateY(0) } 50% { transform: translateY(-7px) } }
.ld-mark h2 {
  font-size: 19px; font-weight: 500; letter-spacing: .4em; text-indent: .4em;
  color: var(--cream); margin-bottom: 18px;
}
.ld-bar { height: 2px; background: rgba(201,163,95,.18); border-radius: 2px; overflow: hidden; }
.ld-fill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--brass-dim), var(--brass)); transition: width .4s var(--ease-out); }
.ld-status { margin-top: 14px; font-style: italic; font-size: 13px; color: var(--cream-dim); }

/* ————— about ————— */

#about {
  position: fixed; inset: 0; z-index: 45; display: grid; place-items: center;
  background: rgba(8,6,4,.72); backdrop-filter: blur(8px);
  opacity: 0; pointer-events: none; transition: opacity .35s var(--ease-out);
}
#about.on { opacity: 1; pointer-events: auto; }
.about-card {
  position: relative; width: min(620px, calc(100vw - 36px)); max-height: 82vh; overflow: auto;
  background: linear-gradient(165deg, #221a13, #16100b);
  border: 1px solid rgba(201,163,95,.3); border-radius: 12px;
  padding: 30px 34px 26px;
  box-shadow: 0 40px 120px rgba(0,0,0,.6);
}
.about-card h2 { font-size: 21px; font-weight: 500; letter-spacing: .12em; color: var(--cream); margin-bottom: 14px; }
.about-card p { font-size: 15.5px; line-height: 1.55; color: #cfc4ad; margin-bottom: 12px; }
.about-card a { color: var(--brass); }
.about-close {
  position: absolute; top: 14px; right: 14px; width: 30px; height: 30px;
  background: none; border: 0; color: var(--cream-dim); font-size: 15px; cursor: pointer;
}
.about-close:hover { color: var(--cream); }
#about-list { list-style: none; margin-top: 6px; }
#about-list li {
  padding: 9px 0; border-top: 1px solid rgba(201,163,95,.14);
  font-size: 13.5px; color: var(--cream-dim); display: flex; gap: 12px; align-items: baseline;
}
#about-list li b { color: var(--cream); font-weight: 500; }
#about-list li .src { margin-left: auto; font-size: 11px; color: var(--brass-dim); white-space: nowrap; }

/* ————— access nav (keyboard/SR shelf) ————— */

#shelf-access { position: fixed; opacity: 0; pointer-events: none; z-index: -1; }
#shelf-access button {
  position: absolute; opacity: 0; pointer-events: auto;
  width: 10px; height: 10px; left: -100px;
}
#shelf-access button:focus-visible { outline: 2px solid var(--brass); outline-offset: 3px; opacity: 1; }

/* ————— DOM fallback shelf ————— */

#domshelf {
  position: fixed; inset: 0; z-index: 1; overflow-y: auto;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 26px; padding: 110px 20px 90px;
}
#domshelf .dom-row { display: flex; align-items: flex-end; gap: 7px; }
#domshelf .dom-book {
  position: relative; height: clamp(150px, 26vh, 240px); border-radius: 2px 2px 3px 3px;
  overflow: hidden; cursor: pointer; border: 0; padding: 0;
  box-shadow: 2px 3px 10px rgba(0,0,0,.45), inset 2px 0 3px rgba(255,255,255,.08), inset -2px 0 4px rgba(0,0,0,.5);
  transition: transform .3s var(--ease-out), box-shadow .3s;
}
#domshelf .dom-book img { height: 100%; display: block; }
#domshelf .dom-book:hover, #domshelf .dom-book:focus-visible {
  transform: translateY(-10px) rotate(-1deg);
  box-shadow: 4px 14px 30px rgba(0,0,0,.6), inset 2px 0 3px rgba(255,255,255,.1);
  outline: none;
}
#domshelf .dom-book:focus-visible { outline: 2px solid var(--brass); outline-offset: 3px; }

@media (prefers-reduced-motion: reduce) {
  #masthead, #hint, #loader { transition-duration: .15s; }
  .ld-spines i { animation: none; }
}

/* the hidden attribute always wins over component display rules */
[hidden] { display: none !important; }
