@font-face {
  font-family: "Pretendard";
  src: url("fonts/Pretendard-Regular.subset.woff2") format("woff2");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}

@font-face {
  font-family: "Pretendard";
  src: url("fonts/Pretendard-Medium.subset.woff2") format("woff2");
  font-style: normal;
  font-weight: 500;
  font-display: swap;
}

@font-face {
  font-family: "Pretendard";
  src: url("fonts/Pretendard-SemiBold.subset.woff2") format("woff2");
  font-style: normal;
  font-weight: 600;
  font-display: swap;
}

@font-face {
  font-family: "Noto Serif KR";
  src: url("fonts/NotoSerifKR-Korean-400.woff2") format("woff2");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}

@font-face {
  font-family: "Noto Serif KR";
  src: url("fonts/NotoSerifKR-Korean-500.woff2") format("woff2");
  font-style: normal;
  font-weight: 500;
  font-display: swap;
}

@font-face {
  font-family: "Noto Serif KR";
  src: url("fonts/NotoSerifKR-Korean-600.woff2") format("woff2");
  font-style: normal;
  font-weight: 600;
  font-display: swap;
}

:root {
  --ink: #111314;
  --ink-raised: #181a1b;
  --ink-soft: #222526;
  --paper: #e8e4db;
  --paper-soft: #a8a49a;
  --muted: #6f7473;
  --line: rgba(232, 228, 219, 0.1);
  --line-strong: rgba(232, 228, 219, 0.18);
  --accent: #c4a574;
  --accent-soft: rgba(196, 165, 116, 0.12);
  --font-size: 19px;
  --reader-width: 640px;
  --panel-width: 260px;
  --sans: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  --serif: "Noto Serif KR", "Apple Myungjo", "Batang", Georgia, serif;
  color-scheme: dark;
}

html[data-theme="light"] {
  --ink: #f3efe6;
  --ink-raised: #ebe6db;
  --ink-soft: #e0dacd;
  --paper: #1c1f20;
  --paper-soft: #4d5251;
  --muted: #747a79;
  --line: rgba(28, 31, 32, 0.1);
  --line-strong: rgba(28, 31, 32, 0.18);
  --accent: #8a6b3d;
  --accent-soft: rgba(138, 107, 61, 0.1);
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-width: 320px;
  overflow-x: hidden;
  background: var(--ink);
  color: var(--paper);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  transition: background-color 200ms ease, color 200ms ease;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
}

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

[hidden] {
  display: none !important;
}

.skip-link {
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 1000;
  padding: 10px 14px;
  background: var(--paper);
  color: var(--ink);
  text-decoration: none;
  transform: translateY(-150%);
  transition: transform 160ms ease;
}

.skip-link:focus {
  transform: translateY(0);
}

.reading-progress {
  position: fixed;
  z-index: 900;
  top: 0;
  right: 0;
  left: 0;
  height: 1px;
  background: transparent;
}

.reading-progress span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--accent);
  transition: width 80ms linear;
}

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

.library-panel {
  position: fixed;
  z-index: 700;
  top: 0;
  bottom: 0;
  left: 0;
  display: flex;
  width: var(--panel-width);
  flex-direction: column;
  padding: 32px 24px 24px;
  overflow-y: auto;
  background: var(--ink-raised);
  border-right: 1px solid var(--line);
}

.nav-label {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
}

.panel-close {
  display: none;
}

.story-nav {
  padding: 0 0 22px;
  border-bottom: 1px solid var(--line);
}

.story-nav ul {
  display: grid;
  gap: 4px;
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
}

.story-link {
  display: grid;
  gap: 2px;
  width: 100%;
  padding: 9px 6px;
  border: 0;
  border-radius: 2px;
  background: transparent;
  color: var(--paper-soft);
  text-align: left;
  cursor: pointer;
}

.story-link:hover {
  background: var(--accent-soft);
  color: var(--paper);
}

.story-link[aria-current="true"] {
  color: var(--paper);
}

.story-link[aria-current="true"] strong {
  color: var(--paper);
}

.story-link strong {
  font-family: var(--serif);
  font-size: 14px;
  font-weight: 500;
  line-height: 1.45;
  word-break: keep-all;
}

.story-link span {
  color: var(--muted);
  font-size: 11px;
}

.chapter-nav {
  flex: 1;
  padding: 22px 0;
}

.chapter-nav ol {
  display: grid;
  gap: 1px;
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
}

.chapter-empty {
  margin: 0;
  padding: 4px 6px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
  list-style: none;
}

.chapter-link {
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 6px;
  width: 100%;
  padding: 8px 6px;
  border: 0;
  border-radius: 2px;
  background: transparent;
  color: var(--paper-soft);
  text-align: left;
  cursor: pointer;
  transition: color 140ms ease, background-color 140ms ease;
}

.chapter-link:hover {
  color: var(--paper);
  background: var(--accent-soft);
}

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

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

.chapter-link .nav-number {
  color: var(--muted);
  font-family: var(--serif);
  font-size: 12px;
  line-height: 1.7;
  font-variant-numeric: tabular-nums;
}

.chapter-link .nav-title {
  font-size: 13px;
  line-height: 1.65;
  word-break: keep-all;
}

.library-status {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.status-copy {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.status-copy span {
  color: var(--muted);
  font-size: 11px;
}

.status-copy strong {
  color: var(--paper-soft);
  font-size: 12px;
  font-weight: 500;
  word-break: keep-all;
}

.text-button {
  flex-shrink: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  cursor: pointer;
}

.text-button:hover {
  color: var(--paper);
}

.main-stage {
  min-height: 100vh;
  margin-left: var(--panel-width);
}

.reader-toolbar {
  position: sticky;
  z-index: 500;
  top: 0;
  display: flex;
  min-height: 56px;
  align-items: center;
  justify-content: flex-end;
  gap: 16px;
  padding: 10px clamp(20px, 4vw, 48px);
  background: color-mix(in srgb, var(--ink) 92%, transparent);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}

.toolbar-location {
  display: grid;
  gap: 2px;
  min-width: 0;
  margin-right: auto;
}

.toolbar-location[hidden] {
  display: none !important;
}

.toolbar-location span {
  color: var(--muted);
  font-size: 11px;
}

.toolbar-location strong {
  overflow: hidden;
  color: var(--paper-soft);
  font-family: var(--serif);
  font-size: 14px;
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reader-controls {
  display: flex;
  gap: 6px;
}

.control-button,
.icon-button {
  min-width: 36px;
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: transparent;
  color: var(--paper-soft);
  font-size: 11px;
  cursor: pointer;
  transition: border-color 140ms ease, color 140ms ease, background-color 140ms ease;
}

.control-button:hover,
.control-button[aria-pressed="true"] {
  border-color: var(--line-strong);
  background: var(--accent-soft);
  color: var(--paper);
}

.theme-light {
  display: none;
}

html[data-theme="light"] .theme-dark {
  display: none;
}

html[data-theme="light"] .theme-light {
  display: inline;
}

.mobile-menu {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 0;
}

.mobile-menu span {
  width: 14px;
  height: 1px;
  background: currentColor;
}

/* ——— Library (work list) ——— */

.library-view {
  display: flex;
  min-height: calc(100vh - 56px);
  align-items: center;
  padding: clamp(48px, 7vw, 88px) clamp(28px, 6vw, 80px);
}

.library-copy {
  width: 100%;
  max-width: 36rem;
}

.book-list {
  display: grid;
  gap: 0;
  border-top: 1px solid var(--line);
}

.book-row {
  display: grid;
  gap: 10px;
  width: 100%;
  padding: 22px 0;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.book-row:hover .book-row-title {
  color: var(--accent);
}

.book-row-meta {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.book-row-title {
  margin: 0;
  color: var(--paper);
  font-family: var(--serif);
  font-size: clamp(1.2rem, 2.4vw, 1.45rem);
  font-weight: 500;
  letter-spacing: -0.02em;
  line-height: 1.4;
  word-break: keep-all;
  transition: color 140ms ease;
}

.book-row-deck {
  margin: 0;
  color: var(--paper-soft);
  font-family: var(--serif);
  font-size: 0.95rem;
  line-height: 1.75;
  word-break: keep-all;
}

.book-row-action {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 12px;
}

/* ——— Cover ——— */

.intro-view {
  display: flex;
  min-height: calc(100vh - 56px);
  align-items: center;
  justify-content: center;
  padding: clamp(48px, 8vw, 96px) clamp(28px, 6vw, 80px);
}

.intro-copy {
  width: 100%;
  max-width: 34rem;
}

.text-link {
  display: inline-block;
  margin: 0 0 28px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
}

.text-link:hover {
  color: var(--paper);
}

.intro-meta {
  margin: 0 0 28px;
  color: var(--muted);
  font-size: 13px;
}

.intro-copy h1 {
  margin: 0 0 28px;
  color: var(--paper);
  font-family: var(--serif);
  font-size: clamp(2rem, 4.5vw, 2.75rem);
  font-weight: 500;
  letter-spacing: -0.03em;
  line-height: 1.25;
  word-break: keep-all;
}

.intro-deck {
  margin: 0;
  color: var(--paper-soft);
  font-family: var(--serif);
  font-size: 1.05rem;
  line-height: 1.85;
  word-break: keep-all;
}

.intro-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 36px;
}

.primary-button,
.secondary-button {
  min-height: 42px;
  padding: 0 18px;
  border: 1px solid var(--paper);
  border-radius: 2px;
  cursor: pointer;
  font-size: 13px;
  transition: background-color 140ms ease, color 140ms ease, border-color 140ms ease;
}

.primary-button {
  background: var(--paper);
  color: var(--ink);
  font-weight: 600;
  border-color: var(--paper);
}

.secondary-button {
  background: transparent;
  color: var(--paper);
  border-color: var(--line-strong);
}

.primary-button:hover {
  background: var(--paper-soft);
  border-color: var(--paper-soft);
  color: var(--ink);
}

.secondary-button:hover {
  border-color: var(--paper-soft);
  color: var(--paper);
}

.intro-quote {
  margin: 48px 0 0;
  padding: 20px 0 0;
  border-top: 1px solid var(--line);
}

.intro-quote p {
  margin: 0;
  color: var(--paper-soft);
  font-family: var(--serif);
  font-size: 0.98rem;
  line-height: 1.75;
  word-break: keep-all;
}

/* ——— Reader ——— */

.reader-view {
  min-height: calc(100vh - 56px);
  padding: clamp(56px, 7vw, 96px) clamp(24px, 6vw, 80px) 96px;
}

.chapter-header,
.chapter-copy,
.chapter-footer {
  max-width: var(--reader-width);
  margin-right: auto;
  margin-left: auto;
}

.chapter-number {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
}

.chapter-header h1 {
  margin: 10px 0 0;
  color: var(--paper);
  font-family: var(--serif);
  font-size: clamp(1.6rem, 3.5vw, 2.1rem);
  font-weight: 500;
  letter-spacing: -0.03em;
  line-height: 1.3;
  word-break: keep-all;
}

.chapter-copy {
  padding-top: 48px;
  font-family: var(--serif);
  font-size: var(--font-size);
  line-height: 2;
  letter-spacing: -0.01em;
  word-break: keep-all;
}

.chapter-copy p {
  margin: 0 0 1.35em;
}

.chapter-copy p.dialogue {
  color: var(--paper);
}

.chapter-copy .system-line {
  margin: 2em 0;
  padding: 14px 16px;
  background: var(--ink-soft);
  border-left: 1px solid var(--line-strong);
  color: var(--paper-soft);
  font-family: var(--sans);
  font-size: 0.82em;
  letter-spacing: 0.01em;
  line-height: 1.7;
}

.chapter-footer {
  margin-top: 64px;
  padding-top: 28px;
  border-top: 1px solid var(--line);
}

.end-mark {
  margin: 0 0 24px;
  color: var(--muted);
  font-size: 14px;
  text-align: center;
  letter-spacing: 0.2em;
}

.chapter-navigation {
  display: flex;
  justify-content: center;
  gap: 10px;
}

.site-footer {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  padding: 22px clamp(28px, 6vw, 80px);
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
}

.site-footer p {
  margin: 0;
}

.loading-state {
  position: fixed;
  z-index: 1100;
  inset: 0;
  display: grid;
  place-content: center;
  background: var(--ink);
  transition: opacity 220ms ease, visibility 220ms ease;
}

.loading-state.is-ready {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
}

.loading-state p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

body.focus-mode .library-panel,
body.focus-mode .reader-toolbar,
body.focus-mode .site-footer {
  opacity: 0;
  pointer-events: none;
}

body.focus-mode .main-stage {
  margin-left: 0;
}

body.focus-mode .reader-view {
  padding-top: 64px;
}

body.focus-mode .reading-progress {
  z-index: 1200;
}

@media (max-width: 900px) {
  .library-panel {
    width: 280px;
    transform: translateX(-102%);
    transition: transform 200ms ease;
  }

  body.panel-open .library-panel {
    transform: translateX(0);
  }

  .panel-close {
    position: absolute;
    top: 18px;
    right: 18px;
    display: block;
    z-index: 1;
    padding: 4px;
    border: 0;
    background: transparent;
    color: var(--muted);
    font-size: 12px;
    cursor: pointer;
  }

  .reader-toolbar {
    justify-content: space-between;
  }

  .panel-scrim {
    position: fixed;
    z-index: 650;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
  }

  .main-stage {
    margin-left: 0;
  }

  .mobile-menu {
    display: flex;
  }
}

@media (max-width: 680px) {
  :root {
    --font-size: 18px;
  }

  .reader-toolbar {
    display: grid;
    grid-template-columns: 36px minmax(0, 1fr) auto;
    gap: 8px;
    min-height: 52px;
    padding: 8px 14px;
  }

  .reader-toolbar:not(:has(#toolbar-location:not([hidden]))) {
    grid-template-columns: 36px auto;
    justify-content: space-between;
  }

  .toolbar-location span {
    display: none;
  }

  .reader-controls {
    gap: 4px;
  }

  .control-button {
    min-width: 32px;
    min-height: 32px;
    padding: 0 6px;
    font-size: 10px;
  }

  #focus-toggle {
    display: none;
  }

  .library-view,
  .intro-view {
    min-height: calc(100svh - 52px);
    align-items: flex-start;
    padding: 48px 22px 64px;
  }

  .intro-actions {
    display: grid;
    width: 100%;
  }

  .primary-button,
  .secondary-button {
    width: 100%;
  }

  .reader-view {
    padding: 48px 20px 72px;
  }

  .chapter-header h1 {
    font-size: 1.55rem;
  }

  .chapter-copy {
    padding-top: 36px;
    line-height: 1.95;
  }

  .chapter-navigation {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .site-footer {
    display: grid;
    gap: 6px;
    padding: 20px 22px;
  }
}

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