/* Onest and Literata are SIL Open Font License. */
@font-face {
  font-family: "Onest";
  src: url("../fonts/Onest.ttf") format("truetype");
  font-weight: 100 900;
  font-display: swap;
}
@font-face {
  font-family: "Literata";
  src: url("../fonts/Literata.ttf") format("truetype");
  font-weight: 400 800;
  font-display: swap;
}

:root {
  --bg: #020915;
  --bg-2: #071426;
  --ink: #f3f7fb;
  --body: #c9d5e2;
  --muted: #8fa1b4;
  --line: rgba(175, 192, 210, 0.16);
  --blue: #168bff;
  --cyan: #55c7ff;
  --mist: #dce5ee;
  --pad: clamp(16px, 2.2vw, 32px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
html { overflow: hidden; }
body {
  margin: 0;
  overflow: hidden;
  background:
    radial-gradient(980px 520px at 8% -12%, rgba(22, 139, 255, 0.18), transparent 58%),
    radial-gradient(720px 420px at 110% 110%, rgba(85, 199, 255, 0.08), transparent 50%),
    var(--bg);
  color: var(--ink);
  font-family: "Onest", "Segoe UI", sans-serif;
  font-optical-sizing: auto;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
img { max-width: 100%; display: block; }
::selection { background: rgba(22, 139, 255, 0.35); }

.app {
  height: 100vh;
  height: 100dvh;
  width: 100%;
  max-width: 100vw;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto 2px minmax(0, 1fr);
}

.top {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 24px;
  padding: 14px var(--pad) 12px;
  min-width: 0;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 180px; }
.mark {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background:
    linear-gradient(160deg, var(--cyan), var(--blue) 55%, #077fff);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.16), 0 8px 24px rgba(22, 139, 255, 0.35);
}
.brand strong {
  display: block;
  font-size: 13px;
  letter-spacing: 0.16em;
  font-weight: 650;
}
.brand span, .talk {
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.04em;
}
.talk {
  margin: 0;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.top-actions { display: flex; align-items: center; gap: 14px; }
.counter {
  margin: 0;
  font-variant-numeric: tabular-nums;
  font-weight: 560;
  letter-spacing: 0.04em;
  min-width: 72px;
  text-align: right;
}
.counter .of { color: var(--muted); font-weight: 450; }
.ghost {
  border: 1px solid var(--line);
  background: rgba(7, 20, 38, 0.55);
  border-radius: 999px;
  padding: 7px 14px;
  color: var(--mist);
  font-size: 13px;
}
.ghost:hover { border-color: rgba(22, 139, 255, 0.55); color: white; }

.progress { background: rgba(255, 255, 255, 0.05); }
.progress i {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, #077fff, var(--cyan));
  transition: width 280ms ease;
}

main {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(320px, 0.72fr);
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 12px clamp(18px, 2vw, 32px);
  padding: 16px var(--pad) 12px;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
}
.stage { grid-column: 1; grid-row: 1; }
.strip-wrap { grid-column: 1; grid-row: 2; }
.reader { grid-column: 2; grid-row: 1 / span 2; }

.stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}
.frame {
  position: absolute;
  inset: 8px 2px 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.frame img {
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 14px;
  background: #06101c;
  user-select: none;
  box-shadow:
    0 0 0 1px rgba(85, 199, 255, 0.28),
    0 28px 70px rgba(0, 0, 0, 0.42);
}
.hit {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 22%;
  border: 0;
  background: transparent;
  padding: 0;
}
.hit.prev { left: 0; }
.hit.next { right: 0; }
.arrows {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  pointer-events: none;
}
.round {
  pointer-events: auto;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid rgba(220, 229, 238, 0.2);
  background: rgba(2, 9, 21, 0.55);
  backdrop-filter: blur(10px);
  display: grid;
  place-items: center;
  color: var(--mist);
  opacity: 0;
  transition: opacity 160ms ease, border-color 160ms ease;
}
.frame:hover .round, .round:focus-visible { opacity: 1; }
.round svg { width: 22px; height: 22px; }
.round:hover { border-color: var(--blue); color: white; }
.round:disabled { opacity: 0.25; }

.reader {
  min-width: 0;
  min-height: 0;
  overflow: auto;
  padding: 8px 4px 18px 28px;
  border-left: 1px solid var(--line);
  scrollbar-width: thin;
  scrollbar-color: rgba(143, 161, 180, 0.4) transparent;
}
.kicker {
  margin: 0 0 10px;
  color: var(--cyan);
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}
h1 {
  margin: 0 0 16px;
  font-size: clamp(26px, 2.1vw, 36px);
  line-height: 1.12;
  font-weight: 580;
  letter-spacing: -0.03em;
}
.prose p, .pull, .points p {
  font-family: "Literata", "Iowan Old Style", Georgia, serif;
}
.lead, .prose p {
  margin: 0 0 14px;
  color: var(--body);
  font-size: 17.5px;
  line-height: 1.55;
}
.lead { color: #e7eef6; font-size: 18.5px; }
.pull {
  margin: 6px 0 16px;
  padding: 2px 0 2px 16px;
  border-left: 2px solid var(--blue);
  color: var(--ink);
  font-size: 20px;
  line-height: 1.35;
}
.points {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
  display: grid;
  gap: 0;
}
.points li {
  padding: 11px 0;
  border-top: 1px solid var(--line);
}
.points .num, .points strong {
  font-family: "Onest", sans-serif;
}
.points strong {
  display: block;
  font-size: 14px;
  font-weight: 620;
  letter-spacing: -0.01em;
}
.points p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 14.5px;
  line-height: 1.4;
}

.strip-wrap {
  min-width: 0;
  overflow: hidden;
  padding: 6px var(--pad) 14px;
}
.strip {
  display: flex;
  gap: 8px;
  min-width: 0;
  width: 100%;
  overflow-x: auto;
  scroll-snap-type: x proximity;
  scrollbar-width: none;
  padding-bottom: 2px;
}
.strip::-webkit-scrollbar { display: none; }
.strip button {
  flex: 0 0 auto;
  width: 112px;
  padding: 0;
  border: 0;
  background: transparent;
  scroll-snap-align: center;
  opacity: 0.48;
  border-radius: 7px;
}
.strip button img {
  width: 112px;
  height: 63px;
  object-fit: cover;
  border-radius: 7px;
  box-shadow: 0 0 0 1px rgba(175, 192, 210, 0.16);
}
.strip button[aria-selected="true"] {
  opacity: 1;
}
.strip button[aria-selected="true"] img {
  box-shadow: 0 0 0 2px var(--blue);
}
.strip button:hover { opacity: 0.9; }

dialog {
  width: min(920px, calc(100vw - 32px));
  max-height: min(780px, calc(100dvh - 32px));
  margin: auto;
  padding: 22px 22px 12px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background:
    radial-gradient(600px 240px at 0 0, rgba(22, 139, 255, 0.16), transparent 60%),
    #071426;
  color: var(--ink);
  box-shadow: 0 40px 90px rgba(0, 0, 0, 0.5);
}
dialog::backdrop { background: rgba(2, 9, 21, 0.72); backdrop-filter: blur(6px); }
.toc-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 12px;
}
dialog h2 {
  margin: 0;
  font-size: 22px;
  font-weight: 580;
  letter-spacing: -0.03em;
}
#toc-list {
  list-style: none;
  margin: 0;
  padding: 0 0 10px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  overflow: auto;
  max-height: min(620px, calc(100dvh - 160px));
}
#toc-list button {
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 10px;
  padding: 10px 12px;
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr);
  gap: 8px;
  align-items: baseline;
}
#toc-list button:hover { background: rgba(255, 255, 255, 0.04); }
#toc-list button[aria-current="true"] {
  border-color: rgba(22, 139, 255, 0.45);
  background: rgba(22, 139, 255, 0.08);
}
#toc-list .n {
  color: var(--cyan);
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  letter-spacing: 0.06em;
}
#toc-list .t {
  font-size: 14px;
  line-height: 1.3;
}

button:focus-visible, a:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

@media (max-width: 1100px) {
  html, body { overflow: auto; height: auto; }
  .app { height: auto; min-height: 100dvh; overflow: visible; }
  .talk { display: none; }
  .top { grid-template-columns: minmax(0, 1fr) auto; }
  .brand { min-width: 0; }
  .top-actions { flex: 0 0 auto; }
  main {
    display: flex;
    flex-direction: column;
    overflow: visible;
    padding-top: 12px;
    height: auto;
  }
  .stage, .strip-wrap, .reader { grid-column: auto; grid-row: auto; }
  .stage {
    position: static;
    overflow: visible;
    aspect-ratio: 16 / 9;
  }
  .frame {
    position: relative;
    display: block;
    height: 100%;
  }
  .frame img {
    width: 100%;
    height: 100%;
    max-height: none;
  }
  .round { opacity: 1; }
  .reader {
    overflow: visible;
    border-left: 0;
    padding: 18px 2px 8px;
  }
  h1 { font-size: 28px; }
}

@media (max-width: 720px) {
  #toc-list { grid-template-columns: 1fr; }
  .ghost { padding: 6px 10px; font-size: 12px; }
  .counter { min-width: 0; font-size: 13px; }
  .brand span {
    display: block;
    max-width: 42vw;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .strip button, .strip button img { width: 84px; }
  .strip button img { height: 47px; }
  .lead, .prose p { font-size: 16.5px; }
  .hit { width: 28%; }
}

@media (prefers-reduced-motion: reduce) {
  .progress i { transition: none; }
}
