/* ================================================================
   Agent Protocol Tech Tree — Stylesheet
   Aesthetic: brutalist, flat, square, old-Mac-inspired
   ================================================================ */

/* ── Reset & Foundations ───────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #fafafa;
  --fg: #111;
  --fg-muted: #555;
  --fg-dim: #666;
  --border: #111;
  --border-light: #ccc;
  --highlight: #e8e8e8;
  --code-bg: #f0f0f0;
  --font: "SF Mono", "Monaco", "Inconsolata", "Fira Mono",
          "Droid Sans Mono", "Source Code Pro", "Courier New", monospace;
  --header-h: 56px;
  --cell-w: 260px;
  --cell-h: 100px;
  --box-w: 204px;
  --box-h: 80px;
}

html {
  font-size: 15px;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--fg);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

.skip-link {
  position: absolute;
  top: 0;
  left: 12px;
  z-index: 3000;
  transform: translateY(-160%);
  background: var(--bg);
  color: var(--fg);
  border: 2px solid var(--border);
  padding: 6px 10px;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  text-decoration: none;
}

.skip-link:focus-visible {
  transform: translateY(8px);
}

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

/* ── Loading ───────────────────────────────────────────────────── */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  font-size: 1.1rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

/* ================================================================
   TREE VIEW
   ================================================================ */

.tree-page {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Tree Header ───────────────────────────────────────────────── */
.tree-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px 24px;
  padding: 16px 24px;
  border-bottom: 3px solid var(--border);
}

.tree-header-text {
  flex: 1;
  min-width: 280px;
}

.tree-header h1 {
  font-size: 1.6rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-weight: 900;
  margin-bottom: 6px;
}

.tree-header p {
  font-size: 0.8rem;
  color: var(--fg-muted);
  letter-spacing: 0.04em;
}

.tree-header .toolbar {
  position: static;
  flex-shrink: 0;
}

.tree-header-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  flex-shrink: 0;
}

/* ── Attribution ──────────────────────────────────────────────── */
.attribution {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.65rem;
  letter-spacing: 0.04em;
  color: var(--fg-muted);
}

.attribution-text {
  text-align: right;
  line-height: 1.35;
}

.attribution-line {
  white-space: nowrap;
}

.attribution a {
  color: var(--fg-muted);
  text-decoration: none;
  transition: color 0.1s;
}

.attribution a:hover {
  color: var(--fg);
}

.attribution a:focus-visible {
  color: var(--fg);
}

.attribution-logo {
  display: block;
  color: var(--fg);
  transition: opacity 0.1s;
}

.attribution-logo:hover {
  opacity: 0.7;
}

.attribution-logo:focus-visible {
  opacity: 0.7;
}

.attribution-logo svg {
  display: block;
  width: 28px;
  height: auto;
}

.read-more-btn {
  font-family: var(--font);
  font-size: 0.75rem;
  font-weight: 700;
  background: none;
  border: none;
  color: var(--fg-muted);
  cursor: pointer;
  padding: 4px 0;
  margin-top: 8px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  transition: color 0.1s;
}

.read-more-btn:hover {
  color: var(--fg);
}

.read-more-btn:focus-visible {
  color: var(--fg);
}

/* ── Tree Container ────────────────────────────────────────────── */
.tree-container {
  flex: 1;
  overflow-x: auto;
  overflow-y: auto;
  overscroll-behavior-x: contain; /* Prevent horizontal swipe-to-navigate */
  padding: 24px 40px;
  display: flex;
  flex-direction: column;
}

.tree-container:focus-visible {
  outline-offset: -2px;
}

/* ── Era Labels ────────────────────────────────────────────────── */
.tree-eras {
  display: grid;
  gap: 0;
  margin-bottom: 8px;
  margin-left: auto;
  margin-right: auto;
}

.tree-era {
  text-align: center;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--fg-dim);
  padding: 4px 0;
  border-bottom: 1px solid var(--border-light);
}

/* ── Tree Grid ─────────────────────────────────────────────────── */
.tree-wrapper {
  position: relative;
  margin-left: auto;
  margin-right: auto;
}

.tree-grid {
  display: grid;
  gap: 0;
  position: relative;
  z-index: 2;
}

.tree-cell {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Tree Node (Protocol Box) ──────────────────────────────────── */
.tree-node {
  position: absolute;
  width: var(--box-w);
  height: var(--box-h);
  border: 2px solid var(--border);
  background: var(--bg);
  padding: 10px 12px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  justify-content: center;
  text-align: left;
  font-family: var(--font);
  color: inherit;
  appearance: none;
  -webkit-appearance: none;
  transition: background 0.1s, color 0.1s;
}

.tech-badge {
  width: 22px;
  height: 22px;
  border: 2px solid var(--border);
  background: var(--bg);
  color: var(--fg);
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  line-height: 1;
  position: relative;
  vertical-align: middle;
}

.tech-badge::after {
  content: attr(data-badge-label);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  padding: 2px 6px;
  border: 2px solid var(--border);
  background: var(--bg);
  color: var(--fg);
  font-size: 0.6rem;
  letter-spacing: 0.04em;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
}

.tech-badge:hover::after,
.tech-badge:focus-visible::after {
  opacity: 1;
}

.tech-badge--tree {
  position: absolute;
  top: 0;
  right: 0;
  transform: translate(50%, -50%);
  z-index: 3;
}

.tree-node:hover,
.tree-node:focus-visible {
  background: var(--fg);
  color: var(--bg);
}

.tree-node:hover .node-tagline,
.tree-node:focus-visible .node-tagline {
  color: var(--border-light);
}

.tree-node:hover .node-icon,
.tree-node:focus-visible .node-icon {
  border-color: var(--bg);
  color: var(--bg);
}

.node-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.node-icon {
  width: 28px;
  height: 28px;
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.5rem;
  text-transform: uppercase;
  flex-shrink: 0;
  letter-spacing: 0;
  overflow: hidden;
  line-height: 1;
}

.node-icon-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.node-title {
  font-size: 0.85rem;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.node-tagline {
  font-size: 0.65rem;
  color: var(--fg-muted);
  letter-spacing: 0.01em;
  line-height: 1.3;
}

/* ── Locked Nodes ──────────────────────────────────────────────── */
.tree-node.node-locked {
  opacity: 0.4;
  cursor: pointer;
}

.tree-node.node-locked:hover,
.tree-node.node-locked:focus-visible {
  background: var(--bg);
  color: var(--fg);
}

.tree-node.node-locked:hover .node-tagline,
.tree-node.node-locked:focus-visible .node-tagline {
  color: var(--fg-muted);
}

.tree-node.node-locked:hover .node-icon,
.tree-node.node-locked:focus-visible .node-icon {
  border-color: var(--border);
  color: var(--fg);
}

/* ── Cluster-node (display: node) — round-rect box ────────────── */
.tree-node--cluster-node {
  border-radius: 20px;
  align-items: center;
  text-align: center;
}

.tree-node--cluster-node .node-icon {
  display: none;
}

/* ── Group outlines (dashed rectangles) ────────────────────────── */
.tree-group {
  position: absolute;
  border: 1px dashed var(--fg-dim);
  z-index: 1;
  pointer-events: none;
}

.tree-group-label {
  position: absolute;
  top: -10px;
  left: 12px;
  background: var(--bg);
  padding: 0 6px;
  font-size: 0.55rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--fg-dim);
  border: none;
  font-family: var(--font);
  font-weight: inherit;
}

.tree-group-label--clickable {
  pointer-events: auto;
  cursor: pointer;
  transition: color 0.1s;
}

.tree-group-label--clickable:hover {
  color: var(--fg);
}

.tree-group-label--clickable:focus-visible {
  color: var(--fg);
}

.tree-group-info {
  font-size: 0.5rem;
  opacity: 0.4;
  transition: opacity 0.15s;
}

.tree-group-label--clickable:hover .tree-group-info {
  opacity: 1;
}

.tree-group-label--clickable:focus-visible .tree-group-info {
  opacity: 1;
}

/* ── SVG Connections ───────────────────────────────────────────── */
.tree-svg {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 1;
  pointer-events: none;
}

.tree-svg path {
  fill: none;
  stroke: var(--border);
  stroke-width: 2;
}

.tree-svg .arrow-head {
  fill: var(--border);
}

/* ── Tree Footer ───────────────────────────────────────────────── */
.tree-footer {
  text-align: center;
  padding: 16px 24px 32px;
  font-size: 0.7rem;
  color: var(--fg-dim);
  letter-spacing: 0.04em;
  border-top: 1px solid var(--border-light);
}

/* ================================================================
   DETAIL VIEW
   ================================================================ */

.detail-page {
  min-height: 100vh;
}

/* ── Detail Header (fixed) ─────────────────────────────────────── */
.detail-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg);
  border-bottom: 3px solid var(--border);
  height: var(--header-h);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
}

.back-btn {
  font-family: var(--font);
  font-size: 0.85rem;
  font-weight: 800;
  background: none;
  border: 2px solid var(--border);
  padding: 6px 14px;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  transition: background 0.1s, color 0.1s;
}

.back-btn:hover {
  background: var(--fg);
  color: var(--bg);
}

.back-btn:focus-visible {
  background: var(--fg);
  color: var(--bg);
}

/* ── Detail Content ────────────────────────────────────────────── */
.detail-content {
  max-width: 900px;
  margin: 0 auto;
  padding: 0 24px 80px;
}

/* ── Hero / Tagline ────────────────────────────────────────────── */
.detail-hero {
  padding: 48px 0 40px;
  border-bottom: 2px solid var(--border);
  margin-bottom: 40px;
  display: flex;
  align-items: center;
  gap: 24px;
}

.hero-icon {
  width: 80px;
  height: 80px;
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  text-transform: uppercase;
  overflow: hidden;
  flex-shrink: 0;
}

.hero-icon-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.hero-text {
  flex: 1;
}

.hero-title {
  font-size: 1.6rem;
  font-weight: 900;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-bottom: 4px;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.tech-badge--detail {
  width: 24px;
  height: 24px;
  font-size: 0.78rem;
}

.detail-hero .tagline {
  font-size: 1.2rem;
  font-weight: 600;
  line-height: 1.3;
}

/* ── Detail Links (bottom list) ────────────────────────────────── */
.detail-links-section {
  margin-top: 0;
}

.detail-links-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.detail-link-item {
  font-family: var(--font);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--fg-muted);
  text-decoration: none;
  letter-spacing: 0.02em;
  transition: color 0.1s;
}

.detail-link-item::before {
  content: "\2192\00a0";
  opacity: 0.4;
}

.detail-link-item:hover {
  color: var(--fg);
}

.detail-link-item:focus-visible {
  color: var(--fg);
}

/* ── Tree Relationships (unlocked by / unlocks) ───────────────── */
.tree-rel-bar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-left: auto;
  flex-shrink: 0;
  align-self: center;
}

.tree-rel {
  display: flex;
  align-items: center;
  gap: 8px;
}

.tree-rel-label {
  font-family: var(--font);
  font-size: 0.55rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--fg-dim);
  white-space: nowrap;
  width: 72px;
  text-align: right;
}

.tree-rel-nodes {
  display: flex;
  gap: 6px;
  padding-bottom: 14px;
}

.tree-rel-node {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-decoration: none;
  color: var(--fg-dim);
}

.tree-rel-node:hover {
  color: var(--fg);
}

.tree-rel-node:focus-visible {
  color: var(--fg);
}

.tree-rel-icon {
  width: 28px;
  height: 28px;
  border: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
  opacity: 0.45;
  transition: opacity 0.15s, border-color 0.15s;
}

.tree-rel-node:hover .tree-rel-icon {
  opacity: 1;
  border-color: var(--border);
}

.tree-rel-node:focus-visible .tree-rel-icon {
  opacity: 1;
  border-color: var(--border);
}

.tree-rel-icon-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.tree-rel-icon-text {
  font-size: 0.45rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.tree-rel-title {
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  margin-top: 3px;
  font-size: 0.5rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
}

.tree-rel-node:hover .tree-rel-title {
  opacity: 1;
}

.tree-rel-node:focus-visible .tree-rel-title {
  opacity: 1;
}

/* On narrow screens, drop rel-bar below the hero text */
@media (max-width: 700px) {
  .detail-hero {
    flex-wrap: wrap;
  }

  .tree-rel-bar {
    flex-direction: row;
    gap: 20px;
    width: 100%;
    margin-left: 0;
    padding-top: 12px;
  }

  .tree-rel-label {
    width: auto;
    text-align: left;
  }
}

/* ── Section Headings ──────────────────────────────────────────── */
.detail-section {
  margin-bottom: 48px;
}

.section-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--fg-dim);
  margin-bottom: 14px;
  font-weight: 800;
  border-bottom: 1px solid var(--border-light);
  padding-bottom: 6px;
  display: inline-block;
}

.section-body {
  font-size: 1rem;
  line-height: 1.65;
  max-width: 640px;
}

/* ── Scene Step Text ───────────────────────────────────────────── */

.step__title {
  font-size: 0.75rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 6px;
}

.step__number {
  font-size: 0.6rem;
  color: var(--fg-dim);
  margin-bottom: 4px;
}

.step__description {
  font-size: 0.8rem;
  line-height: 1.5;
  color: var(--fg-muted);
}

/* ── Animation Stage ───────────────────────────────────────────── */
.anim-stage {
  display: flex;
  flex-direction: column;
  height: 100%;
  position: relative;
}

/* Actor strip */
.anim-actors {
  position: relative;
  height: 110px;
  margin-bottom: 20px;
  flex-shrink: 0;
}

.anim-actor {
  position: absolute;
  transform: translateX(-50%);
  text-align: center;
  transition: opacity 0.35s ease, left 0.35s ease;
}

.anim-actor[style*="opacity: 0"],
.anim-actor[style*="opacity:0"] {
  pointer-events: none;
}

.actor-icon {
  position: relative;
  width: 80px;
  height: 80px;
  border: 2px solid var(--border);
  margin: 0 auto 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  background: var(--bg);
  overflow: hidden;
}

.actor-icon-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.actor-label {
  font-size: 0.75rem;
  font-weight: 700;
  white-space: nowrap;
}

/* Message list */
.anim-messages {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
  transition: opacity 0.2s;
}

.anim-message {
  position: relative;
  padding: 8px 0;
}

.msg-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  text-align: center;
  margin-bottom: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.msg-arrow {
  position: relative;
  height: 3px;
  background: var(--fg);
}

.msg-arrow-head {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 0;
  height: 0;
}

.msg-arrow-head.right {
  right: -1px;
  border-top: 8px solid transparent;
  border-bottom: 8px solid transparent;
  border-left: 12px solid var(--fg);
}

.msg-arrow-head.left {
  left: -1px;
  border-top: 8px solid transparent;
  border-bottom: 8px solid transparent;
  border-right: 12px solid var(--fg);
}

/* JSON previews */
.msg-preview {
  font-size: 0.7rem;
  text-align: center;
  margin-top: 6px;
  cursor: pointer;
  color: var(--fg-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.msg-preview:hover {
  color: var(--fg);
}

.msg-preview.expandable {
  cursor: pointer;
}

.msg-preview-btn {
  font-family: var(--font);
  font-size: 0.7rem;
  background: none;
  border: none;
  padding: 0;
}

.msg-preview.expandable:hover code {
  background: var(--fg);
  color: var(--bg);
  border-color: var(--fg);
}

.msg-preview.expandable:focus-visible code {
  background: var(--fg);
  color: var(--bg);
  border-color: var(--fg);
}

.msg-preview .expand-hint {
  font-size: 0.65rem;
  opacity: 0.5;
  transition: opacity 0.15s;
}

.msg-preview:hover .expand-hint {
  opacity: 1;
}

.msg-preview:focus-visible .expand-hint {
  opacity: 1;
}

.msg-preview code {
  background: var(--code-bg);
  padding: 3px 8px;
  border: 1px solid var(--border-light);
  transition: background 0.1s, color 0.1s;
}

/* Hidden storage for full JSON (accessed by modal) */
.msg-detail {
  display: none;
}

/* ================================================================
   JSON DETAIL MODAL
   ================================================================ */

.json-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.json-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
}

.json-modal__content {
  position: relative;
  background: var(--bg);
  border: 3px solid var(--border);
  max-width: 700px;
  max-height: 80vh;
  width: 100%;
  display: flex;
  flex-direction: column;
  box-shadow: 8px 8px 0 var(--border);
}

.json-modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 2px solid var(--border);
  flex-shrink: 0;
}

.json-modal__title {
  font-size: 0.85rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.json-modal__close {
  font-family: var(--font);
  font-size: 1.5rem;
  font-weight: 400;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.1s, color 0.1s;
}

.json-modal__close:hover {
  background: var(--fg);
  color: var(--bg);
}

.json-modal__close:focus-visible {
  background: var(--fg);
  color: var(--bg);
}

.json-modal__code {
  flex: 1;
  overflow: auto;
  padding: 20px 24px;
  margin: 0;
  font-family: var(--font);
  font-size: 0.85rem;
  line-height: 1.7;
  background: var(--code-bg);
  white-space: pre;
  -webkit-overflow-scrolling: touch;
}

.json-modal__body {
  flex: 1;
  overflow: auto;
  padding: 20px 24px;
  margin: 0;
  font-family: var(--font);
  font-size: 0.9rem;
  line-height: 1.7;
  background: var(--bg);
  -webkit-overflow-scrolling: touch;
}

.json-modal__body p {
  margin-bottom: 1em;
}

.json-modal__body p:last-child {
  margin-bottom: 0;
}

/* ================================================================
   REDUCED MOTION
   ================================================================ */

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    animation-delay: 0ms !important;
    transition-duration: 0.01ms !important;
    transition-delay: 0ms !important;
  }
}

/* ================================================================
   RESPONSIVE
   ================================================================ */

@media (max-width: 768px) {
  :root {
    --cell-w: 200px;
    --cell-h: 90px;
    --box-w: 164px;
    --box-h: 76px;
  }

  .tree-header h1 {
    font-size: 1.1rem;
  }

  .attribution-text {
    display: none;
  }

  .attribution-logo svg {
    width: 24px;
  }

  .detail-hero .tagline {
    font-size: 1.2rem;
  }

  .detail-content {
    padding: 0 16px 60px;
  }

  .node-title {
    font-size: 0.75rem;
  }

  .node-tagline {
    font-size: 0.6rem;
  }
}

/* ── Landscape phones: header becomes left sidebar ─────────────── */
@media (orientation: landscape) and (max-height: 500px) {
  .tree-page {
    flex-direction: row;
  }

  .tree-header {
    flex-direction: column;
    align-items: flex-start;
    width: 220px;
    flex-shrink: 0;
    padding: 16px;
    border-bottom: none;
    border-right: 3px solid var(--border);
    overflow-y: auto;
  }

  .tree-header-text {
    min-width: 0;
  }

  .tree-header h1 {
    font-size: 1rem;
  }

  .tree-header p {
    font-size: 0.7rem;
  }

  .tree-header-right {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  .attribution-text {
    display: none;
  }

  .attribution-logo svg {
    width: 20px;
  }

  .tree-container {
    flex: 1;
  }

  .tree-footer {
    display: none;
  }
}

/* ================================================================
   READER MODE
   ================================================================ */

.reader-page {
  min-height: 100vh;
}

.reader-layout {
  display: flex;
  align-items: flex-start;
  max-width: 1200px;
  margin: 0 auto;
}

/* ── Reader TOC (sticky sidebar) ─────────────────────────────── */
.reader-toc {
  position: sticky;
  top: calc(var(--header-h) + 3px);
  width: 260px;
  flex-shrink: 0;
  padding: 24px 16px 40px 24px;
  max-height: calc(100vh - var(--header-h) - 3px);
  overflow-y: auto;
  border-right: 1px solid var(--border-light);
}

.reader-toc-header {
  font-size: 0.7rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--border);
}

.reader-toc-tree {
  list-style: none;
  padding: 0;
  margin: 0;
}

.reader-toc-tree ul {
  list-style: none;
  padding-left: 16px;
  margin: 0;
}

.reader-toc-tree li {
  margin-bottom: 2px;
}

.reader-toc-link {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--fg-muted);
  text-decoration: none;
  display: block;
  padding: 3px 8px;
  letter-spacing: 0.02em;
  transition: color 0.1s, background 0.1s;
}

.reader-toc-link:hover {
  color: var(--fg);
}

.reader-toc-link:focus-visible {
  color: var(--fg);
  font-weight: 800;
  background: var(--highlight);
}

.reader-toc-link.active {
  color: var(--fg);
  font-weight: 800;
  background: var(--highlight);
}

/* ── Reader TOC Cluster Links ────────────────────────────────── */
.reader-toc-link--cluster {
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* ── Reader Cluster Articles ─────────────────────────────────── */
.reader-article--cluster {
  padding-bottom: 24px;
  margin-bottom: 24px;
  border-bottom-width: 1px;
  border-bottom-style: dashed;
}

.reader-article--cluster .detail-hero {
  padding: 24px 0 16px;
  border-bottom: none;
  margin-bottom: 8px;
}

.reader-article--cluster .hero-title {
  font-size: 1.1rem;
  color: var(--fg-muted);
}

/* ── Reader Content ──────────────────────────────────────────── */
.reader-content {
  flex: 1;
  min-width: 0;
  padding: 0 32px 80px;
  overflow-x: hidden;
}

.reader-article {
  border-bottom: 3px solid var(--border);
  padding-bottom: 40px;
  margin-bottom: 40px;
}

.reader-article:last-child {
  border-bottom: none;
}

.reader-article .detail-hero {
  padding: 32px 0 28px;
  border-bottom: 2px solid var(--border);
  margin-bottom: 32px;
}

.reader-detail-link {
  color: inherit;
  text-decoration: none;
  transition: opacity 0.1s;
}

.reader-detail-link:hover {
  opacity: 0.6;
}

.reader-detail-link:focus-visible {
  opacity: 0.6;
}

/* ── Static Scene Display ────────────────────────────────────── */
.reader-scenes {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.reader-scene {
  border: 2px solid var(--border);
  display: flex;
  gap: 0;
}

.reader-scene-text {
  flex: 0 0 240px;
  padding: 16px 20px;
  border-right: 2px solid var(--border);
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.reader-scene-stage {
  flex: 1;
  min-width: 0;
  padding: 16px 20px;
  overflow: hidden;
}

.reader-scene-stage .anim-stage {
  height: auto;
  min-height: 180px;
}

.reader-scene-stage .anim-actors {
  height: 100px;
  margin-bottom: 12px;
}

.reader-scene-stage .anim-messages {
  gap: 8px;
}

.reader-scene-stage .anim-message {
  padding: 4px 0;
}

/* ── Reader Responsive ───────────────────────────────────────── */
@media (max-width: 900px) {
  .reader-layout {
    flex-direction: column;
  }

  .reader-toc {
    position: static;
    width: 100%;
    max-height: none;
    border-right: none;
    border-bottom: 1px solid var(--border-light);
    padding: 16px 24px;
  }

  .reader-content {
    padding: 0 16px 60px;
  }

  .reader-scene {
    flex-direction: column;
  }

  .reader-scene-text {
    flex: none;
    border-right: none;
    border-bottom: 2px solid var(--border);
  }
}

/* ================================================================
   UTILITY
   ================================================================ */

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* ================================================================
   TOP-RIGHT TOOLBAR
   ================================================================ */

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 200;
}

/* In detail view, toolbar pushes to the right */
.detail-header .toolbar {
  margin-left: auto;
}

.toolbar-link {
  font-family: var(--font);
  font-size: 0.7rem;
  font-weight: 700;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  text-decoration: none;
  color: var(--fg-muted);
  transition: color 0.1s;
}

.toolbar-link:hover {
  color: var(--fg);
}

.toolbar-link:focus-visible {
  color: var(--fg);
}

.toolbar-sep {
  color: var(--fg-muted);
  font-size: 0.7rem;
}

.toolbar-btn {
  font-family: var(--font);
  font-size: 0.7rem;
  font-weight: 800;
  background: var(--bg);
  border: 2px solid var(--border);
  padding: 8px 12px;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  transition: background 0.1s, color 0.1s;
  display: flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
  color: var(--fg);
}

.toolbar-btn:hover {
  background: var(--fg);
  color: var(--bg);
}

.toolbar-btn .btn-icon {
  font-size: 0.9rem;
  line-height: 1;
}
