/* Web eBook Studio reader — framework-free, works hosted, embedded and offline (ZIP). */
:root {
  /* default palette from the KSPO&CO logo: navy #003775 + sky blue #008ed9 */
  --accent: #003775;                 /* per-book override via theme.accent */
  --accent-2: #008ed9;               /* secondary blue: gradients on the top line / progress bar */
  --accent-fg: var(--accent);        /* accent used for text & icons */
  --bg: #e6ebf1;
  --bar: rgba(255, 255, 255, .92);
  --bar-fg: #1c2733;
  --muted: #66717e;
  --panel: #ffffff;
  --line: #dde3ea;
  --page-shadow: 0 10px 30px rgba(10, 35, 70, .20), 0 2px 6px rgba(10, 35, 70, .10);
  --top-h: 52px;
  --bottom-h: 56px;
  color-scheme: light;
}
html[data-theme="dark"] {
  --bg: #1b1d21;
  --bar: rgba(30, 32, 37, .94);
  --bar-fg: #eceef1;
  --muted: #9aa0a8;
  --panel: #24272c;
  --line: #34383e;
  --page-shadow: 0 10px 30px rgba(0, 0, 0, .55);
  --accent-fg: color-mix(in srgb, var(--accent) 40%, #cfe6ff);   /* dark navy is unreadable on dark UI */
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", system-ui, sans-serif;
  background: var(--bg);
  color: var(--bar-fg);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip-link { position: absolute; left: -999px; top: 8px; z-index: 100; background: var(--panel); padding: 8px 12px; border-radius: 6px; }
.skip-link:focus { left: 8px; }
:focus-visible { outline: 3px solid var(--accent-2); outline-offset: 2px; }

.wr-app { position: fixed; inset: 0; display: grid; grid-template-rows: var(--top-h) minmax(0, 1fr) var(--bottom-h); grid-template-columns: minmax(0, 1fr); }

/* top bar */
.wr-top {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 0 max(10px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
  background: var(--bar); border-bottom: 3px solid var(--accent);
  border-image: linear-gradient(90deg, var(--accent) 0%, var(--accent) 55%, var(--accent-2) 100%) 1;
  backdrop-filter: blur(8px); z-index: 20;
}
.wr-brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.wr-logo { height: 30px; width: auto; max-width: 120px; object-fit: contain; }
.wr-title { font-size: 15px; font-weight: 700; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; letter-spacing: -.01em; }
.wr-tools { display: flex; align-items: center; gap: 2px; flex-shrink: 0; }
.wr-btn {
  appearance: none; border: 0; background: transparent; color: inherit; cursor: pointer;
  min-width: 40px; height: 40px; border-radius: 10px; display: inline-grid; place-items: center;
  font-size: 20px; line-height: 1; padding: 0 6px;
}
.wr-btn:hover { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.wr-btn[aria-pressed="true"] { color: var(--accent-fg); }
.wr-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
#wr-bookmark[aria-pressed="true"] svg { fill: var(--accent-fg); stroke: var(--accent-fg); }

/* stage */
/* touch gestures (swipe / pinch / pan) are handled by the reader, so the browser must not zoom the whole UI */
.wr-stage { position: relative; overflow: hidden; display: grid; place-items: center; touch-action: none; }
.wr-stage.zoomed { overflow: auto; place-items: start; }
.wr-book { position: relative; display: flex; perspective: 2400px; transition: opacity .2s; }
.wr-stage.zoomed .wr-book { margin: 24px auto; }
.wr-page {
  position: relative; background: #fff; box-shadow: var(--page-shadow); overflow: hidden;
  user-select: text; -webkit-user-select: text;
}
.wr-page img.wr-img { position: absolute; inset: 0; width: 100%; height: 100%; display: block; pointer-events: none; user-select: none; -webkit-user-drag: none; }
.wr-page.left { border-radius: 3px 0 0 3px; }
.wr-page.right { border-radius: 0 3px 3px 0; }
/* subtle gutter shading where the two pages meet */
.wr-page.left::after, .wr-page.right::before { content: ""; position: absolute; top: 0; bottom: 0; width: 14px; pointer-events: none; z-index: 3; }
.wr-page.left::after { right: 0; background: linear-gradient(to left, rgba(0,0,0,.055), transparent); }
.wr-page.right::before { left: 0; background: linear-gradient(to right, rgba(0,0,0,.045), transparent); }
.wr-page.blank { background: transparent; box-shadow: none; }
.wr-page .wr-loading { position: absolute; inset: 0; display: grid; place-items: center; color: #999; font-size: 13px; }

/* invisible but selectable/searchable text layer */
.wr-text { position: absolute; inset: 0; z-index: 2; line-height: 1; }
.wr-text span {
  position: absolute; white-space: pre; color: transparent; transform-origin: 0 0; cursor: text;
}
.wr-text span::selection { background: rgba(0, 110, 255, .3); color: transparent; }
.wr-text mark { background: rgba(255, 196, 0, .45); color: transparent; border-radius: 2px; }
.wr-links { position: absolute; inset: 0; z-index: 4; pointer-events: none; }
.wr-links a { position: absolute; pointer-events: auto; border-radius: 2px; }
.wr-links a:hover, .wr-links a:focus-visible { background: color-mix(in srgb, var(--accent) 18%, transparent); outline: 1px solid var(--accent); }

/* flip leaf */
.wr-leaf { position: absolute; top: 0; z-index: 10; transform-style: preserve-3d; transition: transform var(--flip-ms, 650ms) cubic-bezier(.45, .05, .25, 1); }
.wr-leaf .face { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; background: #fff; overflow: hidden; }
.wr-leaf .face img { width: 100%; height: 100%; display: block; }
.wr-leaf .back { transform: rotateY(180deg); }
.wr-leaf .face::after { content: ""; position: absolute; inset: 0; background: linear-gradient(to right, rgba(0,0,0,.07), transparent 25%, transparent 80%, rgba(0,0,0,.04)); opacity: 0; transition: opacity var(--flip-ms, 650ms); }
.wr-leaf.turning .face::after { opacity: 1; }

/* transitions */
.wr-book.anim-slide-next { animation: slideNext .38s ease; }
.wr-book.anim-slide-prev { animation: slidePrev .38s ease; }
.wr-book.anim-fade { animation: fadeIn .3s ease; }
@keyframes slideNext { from { transform: translateX(8%); opacity: .2; } to { transform: none; opacity: 1; } }
@keyframes slidePrev { from { transform: translateX(-8%); opacity: .2; } to { transform: none; opacity: 1; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* nav arrows */
.wr-nav {
  position: absolute; top: 50%; transform: translateY(-50%); z-index: 15;
  width: 48px; height: 72px; border: 0; border-radius: 12px; cursor: pointer;
  background: color-mix(in srgb, var(--panel) 70%, transparent); color: var(--bar-fg);
  display: grid; place-items: center; opacity: .75; transition: opacity .2s, background .2s;
}
.wr-nav:hover { opacity: 1; background: var(--panel); }
.wr-nav:disabled { opacity: .15; cursor: default; }
.wr-nav svg { width: 28px; height: 28px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.wr-prev { left: 10px; } .wr-next { right: 10px; }

.wr-zoom {
  position: absolute; right: 12px; bottom: 12px; z-index: 15; display: flex; flex-direction: column; align-items: center;
  background: var(--bar); border: 1px solid var(--line); border-radius: 12px; padding: 4px; gap: 2px;
}
.wr-zoom-val { font-size: 11px; font-weight: 700; color: var(--muted); padding: 2px 0; min-width: 38px; text-align: center; align-self: center; }

/* bottom */
.wr-bottom { background: var(--bar); border-top: 1px solid var(--line); position: relative; z-index: 20; padding-bottom: env(safe-area-inset-bottom); }
.wr-progress { position: absolute; left: 0; right: 0; top: -1px; height: 3px; background: transparent; }
#wr-progress-bar { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .3s; }
.wr-pager { height: 100%; display: flex; align-items: center; justify-content: center; gap: 6px; position: relative; }
.wr-pager .wr-btn:disabled { opacity: .3; cursor: default; background: transparent; }
.wr-sound { position: absolute; right: max(12px, env(safe-area-inset-right)); }
.wr-sound .off, .wr-sound[aria-pressed="false"] .on { display: none; }
.wr-sound[aria-pressed="false"] .off { display: block; }
.wr-sound[aria-pressed="false"] { color: var(--muted); }
.wr-goto { display: flex; align-items: center; gap: 6px; font-size: 14px; color: var(--muted); }
.wr-goto input {
  width: 56px; height: 34px; text-align: center; font: inherit; font-weight: 700; color: var(--bar-fg);
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
}

/* side panel */
.wr-panel {
  position: fixed; top: var(--top-h); right: 0; bottom: var(--bottom-h); width: min(360px, 92vw); z-index: 30;
  background: var(--panel); border-left: 1px solid var(--line); box-shadow: -12px 0 30px rgba(0,0,0,.12);
  display: flex; flex-direction: column; animation: panelIn .2s ease;
}
@keyframes panelIn { from { transform: translateX(30px); opacity: 0; } }
.wr-panel-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 8px 8px 16px; border-bottom: 1px solid var(--line); }
.wr-panel-head h2 { font-size: 15px; margin: 0; }
.wr-panel-body { overflow: auto; padding: 12px 16px 24px; flex: 1; font-size: 14px; }
.wr-list { list-style: none; margin: 0; padding: 0; }
.wr-list li button, .wr-list li a.item {
  width: 100%; text-align: left; border: 0; background: transparent; color: inherit; font: inherit; cursor: pointer;
  padding: 10px 8px; border-radius: 8px; display: flex; justify-content: space-between; gap: 12px; min-height: 44px; align-items: center;
}
.wr-list li button:hover { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.wr-list li button[aria-current="true"] { color: var(--accent-fg); font-weight: 700; }
.wr-list .pg { color: var(--muted); font-variant-numeric: tabular-nums; flex-shrink: 0; }
.wr-list .lv2 { padding-left: 20px; } .wr-list .lv3 { padding-left: 32px; font-size: 13px; } .wr-list .lv4 { padding-left: 44px; font-size: 13px; }
.wr-thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 12px; }
.wr-thumbs button { border: 2px solid transparent; background: none; padding: 0; cursor: pointer; border-radius: 6px; color: inherit; font-size: 12px; }
.wr-thumbs button[aria-current="true"] { border-color: var(--accent-fg); }
.wr-thumbs img { width: 100%; display: block; border-radius: 4px; box-shadow: 0 2px 6px rgba(0,0,0,.15); background: #fff; aspect-ratio: var(--ar, 0.707); object-fit: contain; }
.wr-field { display: grid; gap: 6px; margin: 0 0 16px; }
.wr-field label, .wr-field .lbl { font-size: 12px; font-weight: 700; color: var(--muted); }
.wr-input, .wr-select, .wr-textarea {
  width: 100%; font: inherit; color: inherit; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px;
}
.wr-textarea { min-height: 84px; font-family: ui-monospace, Consolas, monospace; font-size: 12px; resize: vertical; }
.wr-seg { display: flex; flex-wrap: wrap; gap: 6px; }
.wr-seg button { flex: 1; min-height: 38px; border: 1px solid var(--line); background: transparent; color: inherit; border-radius: 8px; cursor: pointer; font: inherit; font-size: 13px; }
.wr-seg button[aria-pressed="true"] { border-color: var(--accent-fg); color: var(--accent-fg); font-weight: 700; background: color-mix(in srgb, var(--accent) 8%, transparent); }
.wr-primary { border: 0; background: var(--accent); color: #fff; border-radius: 8px; padding: 10px 14px; font: inherit; font-weight: 700; cursor: pointer; min-height: 40px; }
.wr-secondary { border: 1px solid var(--line); background: transparent; color: inherit; border-radius: 8px; padding: 9px 12px; font: inherit; cursor: pointer; min-height: 40px; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; }
.wr-row { display: flex; gap: 8px; flex-wrap: wrap; }
.wr-hit { display: block; font-size: 13px; color: var(--muted); margin-top: 4px; line-height: 1.5; }
.wr-hit b { color: var(--bar-fg); background: rgba(255, 196, 0, .4); font-weight: 700; }
.wr-empty { color: var(--muted); padding: 12px 0; }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.swatches button { width: 30px; height: 30px; border-radius: 50%; border: 2px solid var(--line); cursor: pointer; }
.swatches input[type=color] { width: 38px; height: 32px; border: 0; background: none; padding: 0; }

.wr-toast {
  position: fixed; left: 50%; bottom: calc(var(--bottom-h) + 16px); transform: translateX(-50%); z-index: 50;
  background: #222; color: #fff; padding: 10px 16px; border-radius: 999px; font-size: 13px; box-shadow: 0 6px 20px rgba(0,0,0,.25);
}
.wr-banner { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); z-index: 16; background: #fff4e6; color: #7a3a00; border: 1px solid #ffc078; padding: 8px 12px; border-radius: 10px; font-size: 13px; display: flex; gap: 10px; align-items: center; max-width: calc(100% - 24px); }
.wr-banner button { border: 0; background: var(--accent); color: #fff; border-radius: 6px; padding: 5px 9px; cursor: pointer; font: inherit; white-space: nowrap; }

/* password gate */
.wr-gate { max-width: 360px; margin: 0 auto; background: var(--panel); padding: 28px; border-radius: 16px; box-shadow: var(--page-shadow); display: grid; gap: 12px; }
.wr-gate h2 { margin: 0; font-size: 18px; }
.wr-error { color: #c92a2a; font-size: 13px; min-height: 1em; }

/* print: only the generated print container */
.wr-print { display: none; }
@media print {
  @page { margin: 0; }
  body { overflow: visible; background: #fff; }
  .wr-app > *:not(.wr-print) { display: none !important; }
  .wr-app { position: static; display: block; }
  body.print-allowed .wr-print { display: block; }
  .wr-print img { width: 100%; page-break-after: always; break-after: page; display: block; }
  body:not(.print-allowed) .wr-app::before { content: "이 도서는 인쇄가 허용되지 않습니다."; display: block; padding: 40px; font-size: 18px; }
}

/* embed mode: compact chrome */
body.embed .wr-title { font-size: 13px; }
body.embed #wr-fullscreen { display: inline-grid; }

/* tablet */
@media (max-width: 1199px) {
  .wr-nav { width: 40px; height: 60px; }
}
/* mobile */
@media (max-width: 767px) {
  :root { --top-h: 50px; --bottom-h: 54px; }
  .hide-sm { display: none !important; }
  .wr-btn { min-width: 44px; height: 44px; }
  .wr-nav { background: transparent; opacity: .5; width: 36px; }
  .wr-prev { left: 0; } .wr-next { right: 0; }
  /* compact horizontal zoom / text-size control in the bottom-right corner */
  .wr-zoom { flex-direction: row; right: 6px; bottom: 6px; padding: 2px; border-radius: 22px; box-shadow: 0 2px 10px rgba(0,0,0,.15); }
  .wr-zoom .wr-btn { min-width: 40px; height: 40px; border-radius: 20px; }
  .wr-panel { width: 100vw; top: auto; bottom: 0; height: min(75vh, 560px); border-left: 0; border-radius: 16px 16px 0 0; box-shadow: 0 -12px 30px rgba(0,0,0,.2); }
}
@media (prefers-reduced-motion: reduce) {
  .wr-leaf, .wr-book, .wr-panel { transition: none !important; animation: none !important; }
}
