:root {
  --paper: #e9e6df;
  --paper-deep: #ded9d0;
  --ink: #262522;
  --muted: #77726a;
  --line: rgba(38, 37, 34, 0.18);
  --line-soft: rgba(38, 37, 34, 0.1);
  --red: #b53a2b;
  --red-dark: #86281e;
  --white: #faf8f3;
  --sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --serif: Iowan Old Style, "Noto Serif SC", "Songti SC", Georgia, serif;
}

* { box-sizing: border-box; }

html { min-width: 320px; min-height: 100%; background: var(--paper); }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100svh;
  overflow: hidden;
  color: var(--ink);
  background: var(--paper);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body.viewer-open { overflow: hidden; }

button, a, summary { font: inherit; }

button { color: inherit; }

a { color: inherit; text-decoration: none; }

button:focus-visible, a:focus-visible, summary:focus-visible,
.viewer-image-scroll:focus-visible {
  outline: 2px solid var(--red);
  outline-offset: 3px;
}

[hidden] { display: none !important; }

.floating-shell {
  position: relative;
  display: grid;
  grid-template-columns: minmax(266px, 0.34fr) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) auto;
  column-gap: clamp(28px, 5vw, 82px);
  width: 100%;
  height: 100svh;
  min-height: 680px;
  padding: 34px clamp(28px, 4.8vw, 76px) 21px;
  overflow: hidden;
  background:
    radial-gradient(circle at 78% 18%, rgba(255, 255, 255, 0.46), transparent 36%),
    linear-gradient(132deg, #ebe8e2 0%, #e7e3dc 49%, #ddd8d0 100%);
}

.floating-shell::before {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  content: "";
  opacity: 0.28;
  background-image: radial-gradient(rgba(38, 37, 34, 0.16) 0.6px, transparent 0.6px);
  background-size: 7px 7px;
  mix-blend-mode: multiply;
}

.back-link {
  position: absolute;
  z-index: 10;
  top: 34px;
  right: clamp(28px, 4.8vw, 76px);
  display: inline-flex;
  gap: 9px;
  align-items: center;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.back-link span { color: var(--red); font-size: 15px; line-height: 0; }

.library-sidebar,
.stage-column,
.floating-footer { position: relative; z-index: 1; }

.library-sidebar {
  grid-column: 1;
  grid-row: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.library-header {
  max-width: 330px;
  padding-top: 38px;
}

.kicker,
.stage-heading,
.stage-caption,
.fallback-label,
.viewer-kicker,
.viewer-index,
.viewer-image-label {
  margin: 0;
  font-size: 9px;
  font-weight: 760;
  letter-spacing: 0.17em;
  line-height: 1.4;
  text-transform: uppercase;
}

.kicker { display: flex; gap: 8px; align-items: center; color: var(--muted); }

.kicker-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--red);
}

.library-header h1 {
  margin: 32px 0 20px;
  font-family: var(--serif);
  font-size: clamp(32px, 3.8vw, 60px);
  font-weight: 400;
  letter-spacing: -0.07em;
  line-height: 1.06;
}

.library-header h1 em { color: var(--red); font-style: normal; }

.library-name {
  margin: 0;
  color: var(--red-dark);
  font-family: var(--serif);
  font-size: 16px;
  letter-spacing: 0.04em;
}

.library-en {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 10px;
  font-weight: 750;
  letter-spacing: 0.22em;
  line-height: 1.2;
}

.library-note {
  max-width: 250px;
  margin: 23px 0 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.8;
}

.chapter-rail {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
  margin-top: clamp(30px, 5vh, 68px);
}

.rail-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 11px;
  border-bottom: 1px solid var(--line);
  color: var(--ink);
  font-size: 10px;
  font-weight: 760;
  letter-spacing: 0.16em;
}

.rail-heading span:last-child { color: var(--red); font-size: 9px; }

.chapters {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
  margin: 0;
  padding: 8px 5px 6px 0;
  overflow-y: auto;
  list-style: none;
  scrollbar-color: rgba(38, 37, 34, 0.32) transparent;
  scrollbar-width: thin;
}

.chapter-item { border-bottom: 1px solid var(--line-soft); }

.chapter {
  display: grid;
  grid-template-columns: 26px minmax(0, 1fr) 18px;
  gap: 10px;
  align-items: center;
  width: 100%;
  min-height: 48px;
  padding: 8px 7px 8px 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  text-align: left;
}

.chapter:hover .chapter-title,
.chapter[aria-current="true"] .chapter-title { color: var(--red-dark); }

.chapter-number {
  color: var(--muted);
  font-family: var(--serif);
  font-size: 11px;
}

.chapter[aria-current="true"] .chapter-number { color: var(--red); }

.chapter-text { min-width: 0; }

.chapter-title,
.chapter-meta { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.chapter-title {
  color: var(--ink);
  font-size: 11px;
  line-height: 1.4;
  transition: color 160ms ease;
}

.chapter-meta {
  margin-top: 2px;
  color: var(--muted);
  font-size: 9px;
  letter-spacing: 0.05em;
}

.chapter-arrow { color: var(--muted); font-size: 13px; opacity: 0.55; transition: color 160ms ease, transform 160ms ease; }

.chapter:hover .chapter-arrow,
.chapter[aria-current="true"] .chapter-arrow { color: var(--red); transform: translate(2px, -2px); }

.chapter-empty { padding: 18px 0; color: var(--muted); font-size: 11px; line-height: 1.7; }

.rail-note {
  margin: 13px 0 0;
  color: var(--muted);
  font-size: 9px;
  line-height: 1.65;
}

.stage-column {
  grid-column: 2;
  grid-row: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  padding-top: 38px;
}

.stage-heading {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
  min-height: 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
}

.stage-heading span:last-child { letter-spacing: 0.06em; text-align: right; text-transform: none; }

.exhibition-stage {
  position: relative;
  flex: 1;
  min-width: 0;
  min-height: 0;
  margin-top: 15px;
  overflow: hidden;
  border: 1px solid var(--line);
  background:
    radial-gradient(circle at 51% 44%, rgba(255, 255, 255, 0.68), transparent 34%),
    linear-gradient(150deg, rgba(250, 248, 243, 0.28), rgba(201, 195, 186, 0.33));
}

.exhibition-stage::before,
.exhibition-stage::after {
  position: absolute;
  z-index: 0;
  pointer-events: none;
  content: "";
  background: var(--line-soft);
}

.exhibition-stage::before { top: 0; bottom: 0; left: 27%; width: 1px; }
.exhibition-stage::after { top: 0; right: 26%; bottom: 0; width: 1px; opacity: 0.6; }

.scene {
  position: absolute;
  z-index: 1;
  inset: 0;
  overflow: hidden;
  cursor: grab;
  touch-action: none;
}

.scene:active { cursor: grabbing; }

.scene-canvas { display: block; width: 100%; height: 100%; }

.scene-wash {
  position: absolute;
  z-index: 2;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 48%, rgba(58, 54, 48, 0.09) 100%);
}

.scene-fallback {
  position: absolute;
  z-index: 4;
  inset: 0;
  display: grid;
  grid-template-columns: minmax(150px, 0.9fr) minmax(190px, 1.1fr);
  gap: clamp(16px, 3vw, 42px);
  align-items: center;
  padding: clamp(20px, 6vw, 72px);
  background: rgba(232, 228, 220, 0.93);
}

.fallback-art {
  aspect-ratio: 0.76;
  overflow: hidden;
  background: #d9d2c8;
}

.fallback-art img { display: block; width: 100%; height: 100%; object-fit: cover; }

.fallback-copy { max-width: 260px; }

.fallback-copy p:not(.fallback-label) { margin: 11px 0 18px; color: var(--muted); font-size: 12px; line-height: 1.7; }

.fallback-copy a { color: var(--red-dark); font-size: 11px; font-weight: 700; }

.scene-hud {
  position: absolute;
  z-index: 5;
  right: 20px;
  bottom: 18px;
  left: 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  pointer-events: none;
}

.zoom-readout { color: var(--muted); font-size: 9px; font-weight: 700; letter-spacing: 0.12em; }

.panorama-button {
  display: inline-flex;
  gap: 9px;
  align-items: center;
  padding: 8px 10px;
  border: 1px solid var(--line);
  background: rgba(250, 248, 243, 0.72);
  color: var(--ink);
  cursor: pointer;
  font-size: 9px;
  font-weight: 760;
  letter-spacing: 0.08em;
  pointer-events: auto;
}

.panorama-button span { color: var(--red); font-size: 8px; }

.stage-caption {
  position: absolute;
  z-index: 5;
  right: 20px;
  bottom: 58px;
  left: 20px;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  color: var(--muted);
  pointer-events: none;
}

.stage-caption span:last-child { color: var(--red-dark); letter-spacing: 0.04em; text-align: right; text-transform: none; }

.stage-arrow {
  position: absolute;
  z-index: 6;
  top: 50%;
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: rgba(250, 248, 243, 0.72);
  color: var(--ink);
  cursor: pointer;
  font-size: 17px;
  line-height: 1;
  transform: translateY(-50%);
  transition: background 150ms ease, color 150ms ease, border-color 150ms ease;
}

.stage-arrow:hover { border-color: var(--red); background: var(--red); color: var(--white); }
.stage-arrow-prev { left: 16px; }
.stage-arrow-next { right: 16px; }

.floating-footer {
  grid-column: 1 / -1;
  grid-row: 2;
  display: flex;
  justify-content: space-between;
  gap: 18px;
  padding-top: 14px;
  color: var(--muted);
  font-size: 9px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.viewer-layer {
  position: fixed;
  z-index: 100;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(32, 30, 27, 0.44);
}

.viewer-backdrop { position: absolute; inset: 0; }

.viewer-card {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  width: min(1160px, 100%);
  max-height: min(88svh, 820px);
  overflow: hidden;
  border: 1px solid rgba(38, 37, 34, 0.28);
  background: var(--white);
  box-shadow: 0 28px 80px rgba(30, 27, 24, 0.22);
}

.viewer-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 54px;
  padding: 0 20px;
  border-bottom: 1px solid var(--line-soft);
}

.viewer-back,
.viewer-close,
.image-step,
.group-actions button,
.copy-button {
  border: 0;
  background: transparent;
  cursor: pointer;
}

.viewer-back { color: var(--red-dark); font-size: 10px; font-weight: 750; letter-spacing: 0.08em; }
.viewer-index { color: var(--muted); }
.viewer-close { width: 28px; height: 28px; color: var(--muted); font-size: 23px; line-height: 1; }

.viewer-body {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(265px, 0.75fr);
  min-height: 0;
  overflow: auto;
}

.viewer-visual { min-width: 0; padding: clamp(20px, 3vw, 42px); background: #eeeae3; }

.viewer-frame {
  display: flex;
  flex-direction: column;
  min-width: 0;
  border: 7px solid #2d2b28;
  background: #ded8cf;
}

.viewer-image-scroll {
  display: grid;
  place-items: center;
  box-sizing: border-box;
  height: min(59svh, 580px);
  min-height: 310px;
  overflow: hidden;
  background: #d9d3c9;
  cursor: ns-resize;
  touch-action: pan-y;
}

.viewer-image-scroll img {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  min-width: 0;
  min-height: 0;
  object-fit: contain;
  object-position: center;
  transition: opacity 180ms ease;
}

.viewer-image-scroll img.is-loading { opacity: 0.45; }

.frame-actions {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto 34px;
  gap: 8px;
  align-items: center;
  min-height: 42px;
  padding: 0 6px;
  background: #2d2b28;
  color: var(--white);
}

.image-step { color: var(--white); font-size: 23px; line-height: 1; }
.image-step:hover { color: #efb5a9; }
.viewer-image-label { overflow: hidden; color: rgba(250, 248, 243, 0.72); text-overflow: ellipsis; white-space: nowrap; }

.copy-button {
  padding: 7px 9px;
  border: 1px solid rgba(250, 248, 243, 0.33);
  color: var(--white);
  font-size: 9px;
  font-weight: 750;
  letter-spacing: 0.04em;
}

.copy-button:hover { border-color: #efb5a9; color: #efb5a9; }
.copy-button span { margin-left: 4px; color: #efb5a9; }
.viewer-wheel-note { margin: 10px 0 0; color: var(--muted); font-size: 9px; letter-spacing: 0.04em; }

.viewer-copy {
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: clamp(24px, 4vw, 56px) clamp(24px, 4vw, 54px);
}

.viewer-kicker { color: var(--red); }
.viewer-category { margin: 28px 0 9px; color: var(--muted); font-size: 10px; letter-spacing: 0.08em; }
.viewer-copy h2 { margin: 0; font-family: var(--serif); font-size: clamp(24px, 3vw, 40px); font-weight: 400; letter-spacing: -0.04em; line-height: 1.16; }
.viewer-summary { margin: 18px 0 0; color: var(--muted); font-size: 12px; line-height: 1.8; }

.group-actions { display: flex; gap: 9px; margin-top: auto; padding-top: 32px; }

.group-actions button {
  padding: 9px 11px;
  border: 1px solid var(--line);
  color: var(--ink);
  font-size: 10px;
}

.group-actions button:hover { border-color: var(--red); color: var(--red-dark); }

.prompt-details { margin-top: 24px; border-top: 1px solid var(--line-soft); color: var(--muted); }
.prompt-details summary { padding: 13px 0; cursor: pointer; font-size: 10px; font-weight: 700; list-style-position: inside; }
.prompt-details p { max-height: 180px; margin: 0 0 14px; overflow: auto; white-space: pre-wrap; font-size: 10px; line-height: 1.75; }
.source-link { margin-top: 19px; color: var(--red-dark); font-size: 10px; font-weight: 750; }

.toast {
  position: fixed;
  z-index: 200;
  right: 22px;
  bottom: 22px;
  padding: 10px 13px;
  border: 1px solid var(--line);
  background: var(--ink);
  color: var(--white);
  font-size: 11px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.is-visible { opacity: 1; transform: translateY(0); }

@media (max-width: 1120px) {
  .floating-shell { column-gap: 28px; grid-template-columns: minmax(250px, 0.4fr) minmax(0, 1fr); padding-right: 32px; padding-left: 32px; }
  .back-link { right: 32px; }
  .library-header h1 { font-size: clamp(30px, 4.6vw, 47px); }
  .library-note { font-size: 10px; }
  .chapter { grid-template-columns: 23px minmax(0, 1fr) 14px; gap: 7px; }
  .chapter-title { font-size: 10px; }
}

@media (max-width: 760px) {
  body { overflow: auto; }

  .floating-shell {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(390px, 60svh) auto;
    gap: 20px;
    height: auto;
    min-height: 100svh;
    padding: 20px 17px 18px;
    overflow: visible;
  }

  .back-link { position: static; grid-column: 1; grid-row: 1; justify-self: end; margin-bottom: -10px; }
  .library-sidebar { grid-column: 1; grid-row: 1; }
  .library-header { padding-top: 42px; }
  .library-header h1 { margin-top: 23px; font-size: clamp(35px, 11vw, 54px); }
  .library-note { margin-top: 15px; }
  .chapter-rail { margin-top: 25px; }
  .chapters { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 12px; max-height: 28svh; flex: none; }
  .chapter { min-height: 46px; grid-template-columns: 22px minmax(0, 1fr); gap: 7px; padding-right: 0; }
  .chapter-arrow { display: none; }
  .rail-note { margin-top: 10px; }

  .stage-column { grid-column: 1; grid-row: 2; padding-top: 0; min-height: 390px; }
  .stage-heading { padding-bottom: 9px; }
  .stage-heading span:last-child { max-width: 150px; }
  .exhibition-stage { margin-top: 10px; min-height: 0; }
  .scene-fallback { grid-template-columns: 0.8fr 1.2fr; padding: 20px; }
  .scene-hud { right: 12px; bottom: 12px; left: 12px; }
  .stage-caption { right: 12px; bottom: 54px; left: 12px; }
  .stage-caption span:first-child { display: none; }
  .stage-arrow { width: 30px; height: 30px; }
  .stage-arrow-prev { left: 10px; }
  .stage-arrow-next { right: 10px; }

  .floating-footer { grid-column: 1; grid-row: 3; padding-top: 0; font-size: 8px; }

  .viewer-layer { padding: 12px; }
  .viewer-card { max-height: 94svh; }
  .viewer-bar { min-height: 48px; padding: 0 12px; }
  .viewer-body { display: block; overflow-y: auto; }
  .viewer-visual { padding: 14px; }
  .viewer-frame { border-width: 5px; }
  .viewer-image-scroll { height: 52svh; min-height: 235px; }
  .frame-actions { grid-template-columns: 29px minmax(0, 1fr) auto 29px; min-height: 39px; gap: 4px; }
  .copy-button { padding: 6px 7px; }
  .viewer-copy { padding: 22px 18px 25px; }
  .viewer-category { margin-top: 17px; }
  .viewer-copy h2 { font-size: 28px; }
  .group-actions { margin-top: 22px; padding-top: 0; }
  .prompt-details { margin-top: 20px; }
  .source-link { margin-top: 15px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}
