/* main.css — the quiet room: chrome, reading view, states. */

:root {
  --ink: #efe6d2;
  --ink-dim: #b9ab90;
  --paper: #efe5c8;
  --paper-dark: #e2d5b0;
  --accent: #c9a23c;
  --accent-deep: #8e6f1d;
  --wood: #241811;
  --bg: #14100c;
  --rv-max: min(1060px, 94vw);
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.55);
  --serif: "EB Garamond", Georgia, serif;
  --display: "Cinzel", "Playfair Display", serif;
  --caps: "Libre Caslon Text", Georgia, serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--serif);
  overflow: hidden;
}
#app { position: fixed; inset: 0; }
#stage { position: absolute; inset: 0; }
#stage canvas { display: block; }

.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px;
  clip: rect(0 0 0 0); overflow: hidden; white-space: nowrap;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
}

/* ---------- loading veil ---------- */
#veil {
  position: absolute; inset: 0; z-index: 60;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(120% 90% at 50% 20%, #241a12 0%, #0d0a07 70%);
  transition: opacity .7s ease;
}
#veil.gone { opacity: 0; pointer-events: none; }
.veil-inner { text-align: center; max-width: 420px; padding: 24px; }
.veil-mark { display: flex; gap: 7px; justify-content: center; margin-bottom: 26px; }
.veil-mark span {
  width: 14px; border-radius: 2px 2px 0 0;
  background: linear-gradient(180deg, #caa14b, #6d4f1c);
  animation: rise 1.6s ease-in-out infinite;
}
.veil-mark span:nth-child(1) { height: 44px; background: linear-gradient(180deg, #b0563f, #5d2a1c); animation-delay: 0s; }
.veil-mark span:nth-child(2) { height: 58px; animation-delay: .12s; }
.veil-mark span:nth-child(3) { height: 40px; background: linear-gradient(180deg, #7d9961, #37472a); animation-delay: .24s; }
.veil-mark span:nth-child(4) { height: 62px; animation-delay: .36s; }
.veil-mark span:nth-child(5) { height: 50px; background: linear-gradient(180deg, #d9c25e, #7a651f); animation-delay: .48s; }
@keyframes rise { 0%, 100% { transform: translateY(4px); } 50% { transform: translateY(-6px); } }
#veil h2 { font-family: var(--display); font-weight: 400; letter-spacing: .12em; font-size: 22px; margin: 0 0 10px; }
.veil-line { color: var(--ink-dim); font-style: italic; min-height: 1.6em; margin: 0 0 18px; }
.veil-bar { height: 3px; background: #3a2c1d; border-radius: 2px; overflow: hidden; }
.veil-bar i { display: block; height: 100%; width: 0%; background: linear-gradient(90deg, #8e6f1d, #e3c063); transition: width .25s ease; }

/* ---------- top bar ---------- */
.topbar {
  position: absolute; top: 0; left: 0; right: 0; z-index: 30;
  display: flex; align-items: flex-start; justify-content: space-between; gap: 16px;
  padding: 16px 22px;
  background: linear-gradient(180deg, rgba(13, 10, 7, 0.82), rgba(13, 10, 7, 0));
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }
.brand h1 {
  font-family: var(--display); font-weight: 400; font-size: 19px; letter-spacing: .14em;
  margin: 0; color: var(--ink); text-shadow: 0 2px 12px rgba(0,0,0,.6);
}
.brand .tag { margin: 3px 0 0; color: var(--ink-dim); font-style: italic; font-size: 13.5px; }
.controls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.controls input[type="search"], .controls select, .controls button, .rv-controls select {
  font-family: var(--caps); font-size: 14px;
  color: var(--ink);
  background: rgba(30, 22, 14, 0.85);
  border: 1px solid rgba(201, 162, 60, 0.35);
  border-radius: 3px;
  padding: 7px 11px;
}
.controls input[type="search"] { width: 210px; }
.controls button { cursor: pointer; }
.controls button:hover, .controls button[aria-expanded="true"] { border-color: var(--accent); }
.help {
  position: absolute; right: 22px; top: 64px; max-width: 420px;
  background: rgba(24, 17, 11, 0.95); border: 1px solid rgba(201,162,60,.3);
  padding: 14px 18px; border-radius: 4px; font-size: 14.5px; line-height: 1.55;
  color: var(--ink-dim); box-shadow: var(--shadow);
}
.help kbd {
  font-family: var(--caps); border: 1px solid #5a4930; border-bottom-width: 2px;
  border-radius: 3px; padding: 0 5px; font-size: 12.5px; color: var(--ink);
}
.hint {
  position: absolute; left: 22px; bottom: 20px; z-index: 25;
  color: var(--ink-dim); font-style: italic; font-size: 14px;
  display: flex; align-items: center; gap: 9px;
  text-shadow: 0 2px 8px rgba(0,0,0,.8);
  transition: opacity 1.2s ease; pointer-events: none;
}
.hint .dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--accent); box-shadow: 0 0 10px var(--accent);
  animation: pulse 2.4s ease-in-out infinite;
}
@keyframes pulse { 0%,100% { opacity: .5; } 50% { opacity: 1; } }
.hint.fade { opacity: 0; }

/* ---------- tooltip ---------- */
#tip {
  position: absolute; z-index: 40; pointer-events: none;
  display: flex; flex-direction: column; max-width: 280px;
  background: rgba(20, 14, 9, 0.92); border: 1px solid rgba(201,162,60,.4);
  padding: 8px 12px; border-radius: 3px; box-shadow: var(--shadow);
  transform-origin: left top;
}
#tip .tip-title { font-family: var(--caps); font-size: 14.5px; color: var(--ink); }
#tip .tip-sub { font-size: 12.5px; color: var(--ink-dim); font-style: italic; }

/* ---------- banner ---------- */
.banner {
  position: absolute; left: 50%; transform: translateX(-50%);
  top: 74px; z-index: 45; max-width: min(560px, 90vw);
  background: rgba(24, 17, 11, 0.95); border: 1px solid rgba(201,162,60,.45);
  color: var(--ink); padding: 9px 16px; border-radius: 3px;
  font-size: 14px; box-shadow: var(--shadow); text-align: center;
}
.banner.warn { border-color: #b0563f; }

/* ---------- book list ---------- */
.booklist {
  position: absolute; z-index: 50; top: 0; bottom: 0; left: 0;
  width: min(430px, 94vw);
  background: rgba(16, 11, 7, 0.96); border-right: 1px solid rgba(201,162,60,.25);
  overflow-y: auto; padding: 18px 14px 60px;
}
.booklist ul { list-style: none; margin: 0; padding: 0; }
.booklist li + li { margin-top: 6px; }
.booklist button {
  width: 100%; text-align: left; cursor: pointer;
  display: grid; grid-template-columns: 44px 1fr; gap: 4px 12px;
  background: rgba(38, 28, 18, 0.5); color: var(--ink);
  border: 1px solid transparent; border-radius: 3px; padding: 9px 12px;
  font-family: var(--serif);
}
.booklist button:hover { border-color: rgba(201,162,60,.5); background: rgba(48, 36, 22, 0.6); }
.bl-year { grid-row: span 2; color: var(--accent); font-size: 15px; align-self: center; text-align: right; }
.bl-title { font-family: var(--caps); font-size: 15.5px; line-height: 1.3; }
.bl-author { color: var(--ink-dim); font-style: italic; font-size: 13.5px; }
.bl-note { grid-column: 2; color: #8d7c60; font-size: 12.5px; }

/* ---------- detail (inspect) panel ---------- */
.detail {
  position: absolute; z-index: 42; top: 88px; right: 22px;
  width: min(370px, 92vw);
  max-height: calc(100% - 130px); overflow-y: auto;
  display: block;
}
.detail[hidden] { display: none; }
.detail-card {
  background: linear-gradient(180deg, rgba(31, 23, 14, 0.97), rgba(22, 15, 9, 0.97));
  border: 1px solid rgba(201,162,60,.4); border-radius: 4px;
  padding: 20px 22px; box-shadow: var(--shadow);
}
.detail h2 { font-family: var(--caps); font-size: 19px; line-height: 1.3; margin: 0 0 4px; }
.detail .byline { margin: 0 0 14px; color: var(--ink-dim); font-style: italic; }
.detail dl { margin: 0 0 12px; font-size: 13.5px; }
.detail dt { color: var(--accent); font-family: var(--caps); font-size: 12px; letter-spacing: .08em; text-transform: uppercase; margin-top: 8px; }
.detail dd { margin: 2px 0 0; color: var(--ink); }
.detail .notes { font-size: 14.5px; line-height: 1.6; color: var(--ink-dim); }
.detail .binding-note { font-size: 13px; line-height: 1.55; color: #9b8a6c; font-style: italic; }
.detail .resume { color: var(--accent); font-size: 14px; }
.detail-actions { display: flex; gap: 10px; margin-top: 16px; }
.btn {
  font-family: var(--caps); font-size: 15px; cursor: pointer;
  border-radius: 3px; padding: 9px 16px;
  background: rgba(58, 43, 22, 0.6); color: var(--ink);
  border: 1px solid rgba(201,162,60,.45);
}
.btn.primary { background: linear-gradient(180deg, #8e6f1d, #6d520f); border-color: #c9a23c; }
.btn:hover { filter: brightness(1.13); }

/* ---------- now playing chip ---------- */
.chip {
  position: absolute; z-index: 41; right: 22px; bottom: 20px;
  display: flex; align-items: center; gap: 10px;
  background: rgba(22, 15, 9, 0.93); border: 1px solid rgba(201,162,60,.5);
  border-radius: 4px; padding: 8px 14px 8px 8px; box-shadow: var(--shadow);
  --prog: 0;
}
.chip[hidden] { display: none; }
.chip-btn {
  width: 34px; height: 34px; border-radius: 50%; cursor: pointer;
  border: 1px solid var(--accent); background: radial-gradient(circle at 35% 30%, #8e6f1d, #57400c);
  display: grid; place-items: center;
}
.chip-icon { width: 15px; height: 15px; fill: #f2e4bd; }
.chip-text { display: flex; flex-direction: column; line-height: 1.3; }
.chip-text b { font-family: var(--caps); font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--accent); }
.chip-text span { font-size: 13.5px; color: var(--ink); }
.chip::after {
  content: ""; position: absolute; left: 8px; right: 8px; bottom: 3px; height: 2px;
  background: linear-gradient(90deg, var(--accent) calc(var(--prog) * 100%), rgba(255,255,255,0.08) calc(var(--prog) * 100%));
  border-radius: 1px;
}

/* ---------- reading view ---------- */
.reading {
  position: absolute; inset: auto 0 0 0; z-index: 35;
  display: flex; justify-content: center; align-items: flex-end;
  padding: 0 0 max(12px, env(safe-area-inset-bottom));
  pointer-events: none;
  background: linear-gradient(180deg, rgba(10, 7, 4, 0) 0%, rgba(10, 7, 4, 0.25) 26%, rgba(10, 7, 4, 0.62) 100%);
}
.reading[hidden] { display: none; }
.rv-card {
  pointer-events: auto;
  width: var(--rv-max); height: min(58vh, 620px);
  display: flex; flex-direction: column;
  background:
    radial-gradient(120% 140% at 50% 0%, #f3e9cb 0%, #e7d9b4 58%, #d9c79c 100%);
  color: #2b2113;
  border-radius: 6px 6px 3px 3px;
  box-shadow: var(--shadow), 0 2px 0 rgba(255, 250, 230, 0.35) inset;
  position: relative;
  overflow: hidden;
}
.rv-card::before {  /* gutter shadow down the middle */
  content: ""; position: absolute; top: 0; bottom: 0; left: 50%; width: 46px;
  transform: translateX(-50%);
  background: linear-gradient(90deg, rgba(84,62,26,0) 0%, rgba(84,62,26,0.22) 50%, rgba(84,62,26,0) 100%);
  pointer-events: none; z-index: 2;
}
.rv-head {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 10px 16px 8px;
  border-bottom: 1px solid rgba(84,62,26,0.25);
}
.rv-titles { display: flex; flex-wrap: wrap; gap: 4px 14px; align-items: baseline; min-width: 0; }
.rv-booktitle { font-family: var(--caps); font-weight: 700; font-size: 15px; }
.rv-author { color: #6d5b3c; font-style: italic; font-size: 13px; }
.rv-chapter { font-family: var(--caps); color: #8a6d2c; font-size: 13px; }
.rv-actions { display: flex; gap: 6px; flex-shrink: 0; }
.rv-actions select, .rv-actions button {
  font-family: var(--caps); font-size: 13px; color: #2b2113;
  background: rgba(255, 251, 236, 0.7); border: 1px solid rgba(84,62,26,0.4);
  border-radius: 3px; padding: 5px 9px;
}
.rv-actions button { cursor: pointer; }
.rv-scroll { flex: 1; overflow-y: auto; position: relative; padding: 14px 0 18px; scroll-behavior: smooth; }
.rv-page-turn {
  position: absolute; inset: 0; z-index: 3; pointer-events: none; opacity: 0;
  background: linear-gradient(100deg, rgba(255,252,240,0) 40%, rgba(255,252,240,0.85) 50%, rgba(255,252,240,0) 60%);
  transform: translateX(-60%);
}
.rv-page-turn.turning { animation: pageturn 0.9s cubic-bezier(.3,.7,.3,1); }
@keyframes pageturn {
  0% { opacity: .9; transform: translateX(-70%) skewX(-4deg); }
  100% { opacity: 0; transform: translateX(45%) skewX(4deg); }
}
.rv-text {
  max-width: 92%; margin: 0 auto; column-count: 2; column-gap: 56px; column-rule: 1px solid rgba(84,62,26,0.18);
  font-size: 17.5px; line-height: 1.62; font-family: var(--serif);
  color: #2e2416; text-align: justify; hyphens: auto;
}
.rv-para { margin: 0 0 0.9em; text-indent: 1.6em; }
.rv-para:first-child::first-letter {
  float: left; font-family: var(--display); font-size: 3.1em; line-height: 0.86;
  padding: 0.06em 0.1em 0 0; color: #7c5c1d;
}
.rv-sent { cursor: pointer; border-radius: 2px; transition: background 0.25s ease; }
.rv-sent:hover { background: rgba(201, 162, 60, 0.16); }
.rv-sent.queued { background: rgba(201, 162, 60, 0.14); }
.rv-sent.speaking { background: rgba(201, 162, 60, 0.32); box-shadow: 0 0 0 1px rgba(142, 111, 29, 0.35); }
.rv-word.word-now { border-bottom: 2px solid #a1751f; }
.rv-controls {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 9px 16px; border-top: 1px solid rgba(84,62,26,0.25);
  background: linear-gradient(180deg, rgba(120, 94, 44, 0.08), rgba(120, 94, 44, 0.16));
}
.rv-transport { display: flex; gap: 6px; align-items: center; }
.rv-transport button {
  width: 36px; height: 34px; cursor: pointer; font-size: 13px; line-height: 1;
  color: #2b2113; background: rgba(255, 251, 236, 0.75);
  border: 1px solid rgba(84,62,26,0.4); border-radius: 3px;
  display: grid; place-items: center; padding: 0;
}
.rv-transport svg { fill: #2b2113; }
.rv-transport button:hover { border-color: #8a6d2c; background: #fffaf0; }
.rv-progress { flex: 1; min-width: 160px; display: flex; align-items: center; gap: 10px; }
.rv-progress input[type="range"] { flex: 1; accent-color: #8a6d2c; }
.rv-eta { font-size: 12.5px; color: #6d5b3c; font-style: italic; white-space: nowrap; }
.rv-settings { display: flex; gap: 12px; align-items: center; font-size: 12.5px; color: #6d5b3c; }
.rv-settings select, .rv-settings input { accent-color: #8a6d2c; }
.rv-settings select { font-size: 13px; color: #2b2113; background: rgba(255,251,236,.7); border: 1px solid rgba(84,62,26,.4); border-radius: 3px; padding: 3px 5px; }

/* ---------- noscript ---------- */
.noscript { position: fixed; inset: 0; display: grid; place-items: center; text-align: center; padding: 30px; }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .rv-text { column-count: 1; }
  .rv-card::before { display: none; }
  .reading { align-items: stretch; }
  .rv-card { height: min(66vh, 560px); }
}
@media (max-width: 720px) {
  .topbar { flex-direction: column; align-items: stretch; }
  .controls { justify-content: flex-start; }
  .controls input[type="search"] { flex: 1; width: auto; min-width: 120px; }
  .help { left: 12px; right: 12px; top: 150px; }
  .detail { top: auto; bottom: 12px; right: 12px; left: 12px; width: auto; }
  .chip { right: 12px; bottom: auto; top: 118px; }
  .hint { display: none; }
  .banner { top: 128px; }
  .rv-controls { gap: 8px; }
  .rv-settings label:first-child { display: none; }
}
@media (max-width: 480px) {
  .rv-card { height: 74vh; }
  .rv-text { font-size: 16.5px; }
  .rv-booktitle { font-size: 13.5px; }
  .brand .tag { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .veil-mark span { animation: none; }
  .rv-scroll { scroll-behavior: auto; }
  .rv-sent { transition: none; }
  .rv-page-turn { display: none; }
}
