:root {
  --ink: #172126;
  --muted: #647176;
  --paper: #fbfaf7;
  --line: #d8d4cc;
  --panel: #ffffff;
  --accent: #285f68;
  --accent-2: #9b3e2d;
  --soft: #eef3f1;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font-family: "Noto Sans CJK KR", "Apple SD Gothic Neo", sans-serif;
  letter-spacing: 0;
}
a { color: inherit; }
.topbar {
  height: 76px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 34px;
  background: rgba(251, 250, 247, .94);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { display: flex; gap: 12px; align-items: center; text-decoration: none; }
.brand-mark {
  width: 40px; height: 40px; display: grid; place-items: center;
  background: var(--ink); color: #fff; border-radius: 6px; font-weight: 800;
}
.brand strong { display: block; font-size: 16px; }
.brand small { display: block; color: var(--muted); font-size: 12px; margin-top: 3px; }
nav { display: flex; gap: 18px; align-items: center; font-size: 14px; }
nav a { text-decoration: none; color: var(--muted); }
nav a:hover { color: var(--ink); }
.page { max-width: 1180px; margin: 0 auto; padding: 34px 24px 60px; }
.hero-grid {
  display: grid; grid-template-columns: minmax(0, 1fr) 260px; gap: 24px; align-items: stretch;
  margin-bottom: 28px;
}
.eyebrow { color: var(--accent-2); font-weight: 800; margin: 0 0 10px; }
h1 { font-size: 34px; line-height: 1.23; margin: 0 0 14px; max-width: 760px; }
.lead { color: var(--muted); line-height: 1.7; margin: 0; }
.version-panel, .flow-card, .publish-form, .library, .detail, .doc, .settings, .login-card, .reader-toc, .reader-book, .flip-stage {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 12px 30px rgba(23, 33, 38, .05);
}
.version-panel { padding: 22px; display: flex; flex-direction: column; justify-content: center; }
.version-panel span, .version-panel small { color: var(--muted); }
.version-panel strong { font-size: 38px; margin: 4px 0; }
.workbench { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 22px; align-items: start; }
.publish-form { padding: 24px; }
.panel-title, .section-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 18px; }
.panel-title h2, .section-head h2, .flow-card h2 { margin: 0; font-size: 20px; }
.panel-title span, .section-head span {
  color: var(--accent); background: var(--soft); padding: 6px 10px; border-radius: 999px; font-size: 12px; font-weight: 800;
}
.upload-box { border: 1px dashed #a8b4b2; background: #f8fbfa; padding: 18px; border-radius: 8px; margin-bottom: 18px; }
.upload-box input { width: 100%; }
.upload-box p { color: var(--muted); font-size: 13px; margin: 9px 0 0; }
label { display: grid; gap: 7px; color: #334147; font-weight: 700; font-size: 14px; margin-bottom: 14px; }
input, textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 6px; padding: 11px 12px;
  font: inherit; background: #fff; color: var(--ink);
}
textarea { resize: vertical; }
.field-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
button.primary, .primary {
  display: inline-flex; justify-content: center; align-items: center; min-height: 44px; border: 0; border-radius: 6px;
  padding: 0 18px; background: var(--accent); color: #fff; font-weight: 800; text-decoration: none; cursor: pointer;
}
.flow-card { padding: 22px; }
.flow-card ol { list-style: none; padding: 0; margin: 18px 0 0; display: grid; gap: 14px; }
.flow-card li { display: grid; gap: 4px; border-left: 3px solid var(--accent); padding-left: 12px; }
.flow-card span { color: var(--muted); line-height: 1.5; }
.library { margin-top: 22px; padding: 22px; }
.book-list { display: grid; gap: 8px; }
.book-row { display: flex; justify-content: space-between; gap: 14px; padding: 14px; border: 1px solid var(--line); border-radius: 6px; text-decoration: none; }
.book-row:hover { background: #faf7f1; }
.book-row span { color: var(--muted); font-size: 13px; }
.empty { color: var(--muted); padding: 20px; background: #f8f7f3; border-radius: 6px; }
.detail { padding: 28px; display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 20px; align-items: start; }
.download-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.download { border-radius: 6px; padding: 18px 12px; text-align: center; color: #fff; text-decoration: none; font-weight: 800; }
.download.read { background: #172126; grid-column: 1 / -1; }
.download.epub { background: #285f68; }
.download.pdf { background: #9b3e2d; }
.download.md { background: #4d5b32; }
.download.src { background: #49525a; }
.reader-shell, .flip-reader { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 22px; align-items: start; }
.reader-toc { padding: 22px; position: sticky; top: 100px; }
.reader-toc h2 { margin: 0 0 8px; font-size: 20px; line-height: 1.35; }
.reader-toc p { color: var(--muted); margin: 0 0 18px; }
.chapter-nav { display: grid; gap: 8px; margin: 18px 0; max-height: 52vh; overflow: auto; }
.chapter-nav a { color: var(--muted); text-decoration: none; border-left: 3px solid var(--line); padding: 8px 0 8px 10px; line-height: 1.45; }
.chapter-nav a:hover { color: var(--ink); border-color: var(--accent); background: #f7f4ee; }
.chapter-nav button {
  border: 0;
  border-left: 3px solid var(--line);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  line-height: 1.45;
  padding: 8px 0 8px 10px;
  text-align: left;
}
.chapter-nav button:hover { color: var(--ink); border-color: var(--accent); background: #f7f4ee; }
.reader-back { display: inline-flex; min-height: 38px; align-items: center; border: 1px solid var(--line); border-radius: 6px; padding: 0 12px; text-decoration: none; color: var(--accent); font-weight: 800; }
.reader-book { padding: 0; overflow: hidden; }
.reader-cover {
  min-height: 360px; display: grid; place-items: center; align-content: center; text-align: center;
  padding: 48px 30px; background: #172126; color: #fff;
}
.reader-cover span { color: #d8d4cc; font-size: 13px; font-weight: 800; }
.reader-cover h1 { margin: 16px auto; font-size: 42px; max-width: 720px; }
.reader-cover p { margin: 0; color: #d8d4cc; }
.reader-chapter { max-width: 760px; margin: 0 auto; padding: 56px 34px; border-bottom: 1px solid var(--line); }
.reader-chapter h2 { font-size: 28px; line-height: 1.35; margin: 0 0 26px; color: #243b42; }
.reader-chapter p {
  font-family: "Noto Serif CJK KR", "Noto Sans CJK KR", serif;
  font-size: 18px;
  line-height: 2;
  margin: 0 0 18px;
  word-break: keep-all;
}
.flip-stage {
  padding: 18px;
  min-height: auto;
  background:
    linear-gradient(135deg, rgba(255,255,255,.72), rgba(255,255,255,.2)),
    #ebe5dc;
}
.reader-toolbar {
  display: grid;
  grid-template-columns: 44px minmax(120px, 1fr) 44px 54px 54px 62px 86px;
  gap: 8px;
  align-items: center;
  margin-bottom: 14px;
}
.icon-button, .tool-button {
  min-height: 42px;
  border: 1px solid #c9c1b6;
  border-radius: 6px;
  background: #fffdf8;
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  font-weight: 800;
}
.tool-button.wide { min-width: 86px; }
.icon-button { font-size: 30px; line-height: 1; }
.icon-button:disabled { opacity: .35; cursor: not-allowed; }
.reader-status {
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border: 1px solid #d9d1c5;
  border-radius: 6px;
  background: rgba(255,253,248,.72);
}
.reader-status span { color: var(--muted); font-size: 13px; }
.book-viewport {
  min-height: 0;
  height: clamp(500px, calc(100vh - 230px), 640px);
  display: grid;
  place-items: center;
  perspective: 1800px;
  padding: 20px;
  border-radius: 8px;
  touch-action: pan-y;
  user-select: none;
  background:
    radial-gradient(circle at 50% 30%, rgba(255,255,255,.7), transparent 46%),
    linear-gradient(90deg, #d5cab9, #eee7db 22%, #eee7db 78%, #cbbfae);
}
body.reader-focus-mode {
  overflow: hidden;
  background: #1b2022;
}
body.reader-focus-mode .topbar,
body.reader-focus-mode .footer,
body.reader-focus-mode .flip-toc {
  display: none;
}
body.reader-focus-mode .page {
  max-width: none;
  padding: 0;
}
body.reader-focus-mode .flip-reader {
  display: block;
}
body.reader-focus-mode .flip-stage {
  min-height: 100vh;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  padding: 12px;
}
body.reader-focus-mode .book-viewport {
  height: calc(100vh - 68px);
}
.book-viewport.dark {
  background:
    radial-gradient(circle at 50% 30%, rgba(78, 86, 88, .5), transparent 46%),
    linear-gradient(90deg, #1d2427, #273033 22%, #273033 78%, #171d20);
}
.book-spread {
  --reader-scale: 1;
  --drag-x: 0;
  --drag-progress: 0;
  --drag-abs: 0;
  width: min(100%, 860px);
  height: 100%;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  filter: drop-shadow(0 22px 34px rgba(23, 33, 38, .18));
  transform-style: preserve-3d;
  transition: transform .52s cubic-bezier(.18,.84,.24,1), filter .52s cubic-bezier(.18,.84,.24,1);
}
.book-spread.dragging {
  transform: translateX(calc(var(--drag-x) * .12px)) rotateY(calc(var(--drag-progress) * -9deg));
  filter: drop-shadow(0 28px 42px rgba(23, 33, 38, .22));
  transition: none;
}
.book-spread.turn-forward { animation: turnForward .62s cubic-bezier(.16,.78,.21,1); }
.book-spread.turn-back { animation: turnBack .62s cubic-bezier(.16,.78,.21,1); }
.book-page {
  position: relative;
  height: 100%;
  min-height: 0;
  padding: 42px 38px 48px;
  overflow: hidden;
  background:
    linear-gradient(90deg, rgba(255,255,255,.92), rgba(255,255,255,.68)),
    repeating-linear-gradient(0deg, rgba(80,61,36,.025), rgba(80,61,36,.025) 1px, transparent 1px, transparent 7px),
    #fffaf0;
  color: #172126;
  border: 1px solid #d4cabd;
  transform-style: preserve-3d;
  backface-visibility: hidden;
  transition: transform .52s cubic-bezier(.18,.84,.24,1), box-shadow .52s cubic-bezier(.18,.84,.24,1);
}
.book-page::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity .45s ease;
}
.book-page.left {
  border-radius: 8px 0 0 8px;
  box-shadow: inset -18px 0 24px rgba(62, 47, 30, .08);
}
.book-page.left::after {
  background: linear-gradient(90deg, transparent 70%, rgba(45, 31, 16, .14));
}
.book-page.right {
  border-radius: 0 8px 8px 0;
  box-shadow: inset 18px 0 24px rgba(62, 47, 30, .08);
}
.book-page.right::after {
  background: linear-gradient(90deg, rgba(45, 31, 16, .16), transparent 32%);
}
.book-spread.drag-left .book-page.right {
  transform: rotateY(calc(var(--drag-progress) * 34deg)) translateX(calc(var(--drag-x) * .08px));
  transform-origin: left center;
  box-shadow: inset 22px 0 28px rgba(62, 47, 30, .16), -14px 0 26px rgba(23, 33, 38, .12);
}
.book-spread.drag-right .book-page.left {
  transform: rotateY(calc(var(--drag-progress) * 34deg)) translateX(calc(var(--drag-x) * .08px));
  transform-origin: right center;
  box-shadow: inset -22px 0 28px rgba(62, 47, 30, .16), 14px 0 26px rgba(23, 33, 38, .12);
}
.book-spread.dragging .book-page::after { opacity: calc(var(--drag-abs) * .9); }
.book-spread.turn-forward .book-page.right {
  transform-origin: left center;
  animation: pageCurlForward .62s cubic-bezier(.16,.78,.21,1);
}
.book-spread.turn-back .book-page.left {
  transform-origin: right center;
  animation: pageCurlBack .62s cubic-bezier(.16,.78,.21,1);
}
.book-spread.turn-forward .book-page.right::after,
.book-spread.turn-back .book-page.left::after {
  animation: pageShadow .62s ease;
}
.book-page.cover {
  background: #172126;
  color: #fff;
}
.book-cover-page {
  min-height: 100%;
  display: grid;
  place-items: center;
  align-content: center;
  text-align: center;
  border: 1px solid rgba(255,255,255,.22);
}
.book-cover-page span, .book-cover-page small { color: #d8d4cc; }
.book-cover-page h1 { font-size: 38px; margin: 18px auto; max-width: 340px; }
.book-cover-page p { color: #f6eadc; font-weight: 800; }
.page-running {
  min-height: 22px;
  color: #8a8072;
  font-size: 12px;
  font-weight: 800;
  margin-bottom: 16px;
}
.book-page h2 {
  font-size: 25px;
  line-height: 1.35;
  margin: 0 0 22px;
  color: #243b42;
}
.book-page p {
  font-family: "Noto Serif CJK KR", "Noto Sans CJK KR", serif;
  font-size: calc(17px * var(--reader-scale));
  line-height: 1.92;
  margin: 0 0 14px;
  word-break: keep-all;
}
.page-number {
  position: absolute;
  bottom: 20px;
  left: 0;
  right: 0;
  text-align: center;
  color: #9a9185;
  font-size: 12px;
}
.book-viewport.dark .book-page {
  background: linear-gradient(90deg, rgba(42,49,51,.96), rgba(36,43,45,.94)), #252d30;
  border-color: #3f494c;
  color: #e9e3d8;
}
.book-viewport.dark .book-page h2 { color: #f2eadc; }
.book-viewport.dark .page-running, .book-viewport.dark .page-number { color: #a99f90; }

@keyframes turnForward {
  0% { transform: rotateY(0deg) translateX(0); opacity: 1; }
  42% { transform: rotateY(-5deg) translateX(-10px); opacity: .9; }
  100% { transform: rotateY(0deg) translateX(0); opacity: 1; }
}

@keyframes turnBack {
  0% { transform: rotateY(0deg) translateX(0); opacity: 1; }
  42% { transform: rotateY(5deg) translateX(10px); opacity: .9; }
  100% { transform: rotateY(0deg) translateX(0); opacity: 1; }
}

@keyframes pageCurlForward {
  0% { transform: rotateY(0deg) translateX(0) skewY(0deg); }
  46% { transform: rotateY(-28deg) translateX(-14px) skewY(.8deg); }
  100% { transform: rotateY(0deg) translateX(0) skewY(0deg); }
}

@keyframes pageCurlBack {
  0% { transform: rotateY(0deg) translateX(0) skewY(0deg); }
  46% { transform: rotateY(28deg) translateX(14px) skewY(-.8deg); }
  100% { transform: rotateY(0deg) translateX(0) skewY(0deg); }
}

@keyframes pageShadow {
  0% { opacity: 0; }
  45% { opacity: .85; }
  100% { opacity: 0; }
}
.doc, .settings { padding: 28px; line-height: 1.75; }
.doc h2 { margin-top: 26px; }
.settings dl { display: grid; grid-template-columns: 160px minmax(0, 1fr); gap: 12px 18px; }
.settings dt { color: var(--muted); font-weight: 800; }
.settings dd { margin: 0; word-break: break-all; }
.messages { display: grid; gap: 8px; margin-bottom: 18px; }
.message { padding: 12px 14px; border-radius: 6px; border: 1px solid var(--line); background: #fff; }
.message.error { border-color: #e1a6a0; background: #fff2f0; color: #8a2c21; }
.message.success { border-color: #9ac9b2; background: #effaf4; color: #23613c; }
.login-shell { min-height: calc(100vh - 190px); display: grid; place-items: center; }
.login-card { width: min(440px, 100%); padding: 28px; }
.login-card h1 { font-size: 26px; }
.login-card p { color: var(--muted); }
.footer { display: flex; justify-content: center; gap: 16px; color: var(--muted); font-size: 12px; padding: 24px; border-top: 1px solid var(--line); }

@media (max-width: 820px) {
  .topbar { height: auto; padding: 16px; display: grid; gap: 12px; }
  nav { flex-wrap: wrap; }
  .hero-grid, .workbench, .detail, .reader-shell, .flip-reader { grid-template-columns: 1fr; }
  .reader-toc { position: static; }
  .field-grid, .download-grid, .reader-toolbar { grid-template-columns: 1fr 1fr 1fr; }
  .tool-button.wide { min-width: 0; }
  .reader-status { grid-column: 1 / -1; order: -1; }
  h1 { font-size: 27px; }
  .reader-cover h1 { font-size: 30px; }
  .reader-chapter { padding: 36px 20px; }
  .reader-chapter p { font-size: 16px; line-height: 1.85; }
  .flip-stage { padding: 12px; min-height: auto; }
  .book-viewport { height: clamp(460px, calc(100vh - 250px), 560px); min-height: 0; padding: 10px; }
  .book-spread { grid-template-columns: 1fr; height: 100%; min-height: 0; }
  .book-page { height: 100%; min-height: 0; padding: 34px 26px 44px; border-radius: 8px; }
  .book-page.left, .book-page.right { border-radius: 8px; }
  .book-page p { font-size: calc(16px * var(--reader-scale)); line-height: 1.82; }
  .book-row { display: grid; }
}
