:root {
  color-scheme: light;
  --paper: #ffffff;
  --ink: #111111;
  --muted: #737373;
  --line: #dedede;
  --safe-bottom: max(18px, env(safe-area-inset-bottom));
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  font-family: Pretendard, "Noto Sans KR", system-ui, sans-serif;
  background: var(--paper);
}

button { font: inherit; }
button:disabled { cursor: default; opacity: 0.35; }

.reader-frame {
  width: min(calc(100% - 40px), 720px);
  min-height: 100vh;
  margin: 0 auto;
}

.app-shell { min-height: 100vh; }

.topbar {
  position: relative;
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr) 52px;
  gap: 16px;
  align-items: center;
  min-height: 72px;
  border-bottom: 1px solid var(--ink);
  background: var(--paper);
}

.library-link,
.icon-button {
  padding: 0;
  border: 0;
  color: var(--ink);
  font-size: 12px;
  font-weight: 700;
  text-decoration: none;
  background: transparent;
}

.library-link { justify-self: start; }
.icon-button { justify-self: end; cursor: pointer; }
.library-link:hover,
.library-link:focus-visible,
.icon-button:hover,
.icon-button:focus-visible { text-decoration: underline; text-underline-offset: 3px; }

.book-heading { min-width: 0; text-align: center; }
.eyebrow { margin: 0 0 2px; color: var(--muted); font-size: 10px; }
.book-heading h1 {
  overflow: hidden;
  margin: 0;
  font-size: 13px;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cast-panel {
  display: none;
  padding: 18px 0;
  border-bottom: 1px solid var(--line);
}
.cast-panel.is-open { display: block; }
.cast-list { display: flex; gap: 18px; overflow-x: auto; scrollbar-width: none; }
.cast-list::-webkit-scrollbar { display: none; }
.cast-card { flex: 0 0 72px; text-align: center; }
.cast-avatar {
  display: grid;
  width: 42px;
  height: 42px;
  margin: 0 auto;
  place-items: center;
  border-radius: 50%;
  object-fit: cover;
  filter: saturate(0.82);
}
.avatar-fallback {
  border: 1px solid #bbbbbb;
  color: #555555;
  font-family: "KoPub Batang", "Noto Serif KR", Batang, serif;
  font-size: 15px;
  background: #ffffff;
}
.cast-card .cast-name,
.cast-card .cast-detail {
  display: block;
  overflow: hidden;
  margin-top: 6px;
  color: #555555;
  font-size: 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cast-card .cast-detail {
  margin-top: 2px;
  color: #777777;
  font-size: 9px;
  font-weight: 400;
}

.chapter-opener {
  width: min(100%, 36rem);
  margin: 0 auto;
  padding: clamp(72px, 12vh, 112px) 0 72px;
  text-align: left;
}
.chapter-number {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.08em;
}
.chapter-title {
  max-width: 15em;
  margin: 0;
  font-family: "KoPub Batang", "Noto Serif KR", Batang, serif;
  font-size: clamp(28px, 6vw, 42px);
  font-weight: 600;
  line-height: 1.35;
  letter-spacing: -0.035em;
  word-break: keep-all;
}

.story {
  width: min(100%, 36rem);
  min-height: 60vh;
  margin: 0 auto;
  padding: 0 0 72px;
}

.kingdom-map {
  width: calc(100% + 32px);
  margin: 0 0 38px -16px;
  text-align: center;
}

.kingdom-map-link {
  display: block;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.kingdom-map-link img {
  display: block;
  width: 100%;
  height: auto;
}

.kingdom-map figcaption {
  margin-top: 10px;
  color: #6a6259;
  font-family: "KoPub Batang", "Noto Serif KR", "Nanum Myeongjo", Batang, serif;
  font-size: 12px;
  line-height: 1.55;
  text-align: center;
}

.kingdom-map-zoom {
  display: inline-block;
  margin-top: 8px;
  color: #76634a;
  font-size: 11px;
  text-underline-offset: 3px;
}
.story-item { margin: 0; }
.story-block.is-continuation { margin-top: -8px; }

.narration,
.speech-text {
  margin: 0;
  color: var(--ink);
  font-family: "KoPub Batang", "Noto Serif KR", Batang, serif;
  font-size: 18px;
  line-height: 1.9;
  letter-spacing: -0.01em;
  word-break: normal;
  overflow-wrap: break-word;
}
.narration { margin-bottom: 1.25em; }

.speech {
  margin: 2px 0 30px;
  padding: 1px 0 1px 15px;
  border-left: 3px solid #d8d5cf;
  border-left-color: color-mix(in srgb, var(--speaker-color, #8a8a8a) 60%, #ffffff);
}
.speech-speaker {
  display: flex;
  gap: 8px;
  align-items: center;
  margin: 0 0 9px;
}
.avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  object-fit: cover;
  filter: saturate(0.82);
}
.avatar.avatar-fallback {
  display: grid;
  place-items: center;
  font-size: 12px;
}
.speaker-name {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0 6px;
  margin: 0;
  color: #444444;
  color: color-mix(in srgb, var(--speaker-color, #444444) 55%, #111111);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.01em;
  word-break: keep-all;
}
.speaker-detail {
  color: #777777;
  font-size: 10px;
  font-weight: 400;
  letter-spacing: 0;
}
.story-block.is-continuation .speech { margin-top: 0; }
.story-block.is-continuation .speech-speaker { display: none; }

.scene-illustration {
  margin: 52px 0;
  padding: 0;
}
.scene-illustration img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 3 / 2;
  object-fit: cover;
}

.reader-loading,
.reader-error { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.7; }
.reader-error { color: #8a241f; }

.reader-controls {
  width: min(100%, 36rem);
  margin: 0 auto;
  padding: 24px 0 calc(48px + var(--safe-bottom));
  border-top: 1px solid var(--ink);
  background: var(--paper);
}
.reading-progress {
  display: grid;
  grid-template-columns: minmax(60px, 1fr) auto auto;
  gap: 10px;
  align-items: center;
  margin-bottom: 18px;
  color: var(--muted);
  font-size: 10px;
}
.progress-track { overflow: hidden; height: 1px; background: var(--line); }
.progress-fill { width: 0; height: 100%; background: var(--ink); }
.bookmark-status { min-width: 72px; text-align: right; }
.bookmark-status.is-error { color: #973b32; }
.control-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.secondary-button,
.primary-button {
  min-height: 40px;
  padding: 0;
  border: 0;
  border-bottom: 1px solid var(--ink);
  color: var(--ink);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  background: transparent;
}
.secondary-button { text-align: left; }
.primary-button { text-align: right; }
.secondary-button:hover,
.primary-button:hover { border-bottom-color: transparent; }

@media (max-width: 520px) {
  .reader-frame { width: min(calc(100% - 28px), 720px); }
  .topbar { grid-template-columns: 44px minmax(0, 1fr) 44px; gap: 8px; }
  .chapter-opener { padding-top: 56px; padding-bottom: 56px; }
  .narration, .speech-text { font-size: 17px; line-height: 1.85; }
  .scene-illustration { margin-inline: -14px; }
}

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