:root {
  color-scheme: light;
  font-family: "Pretendard", "Noto Sans KR", "Kantumruy Pro", system-ui, "Malgun Gothic", sans-serif;
  color: #17233a;
  background: #f7f9fd;
  --accent: #244ed8;
  --ink-muted: #4f6080;
  --line: #e3e9f3;
  --surface: #fff;
  --arrow-inset: clamp(12px, 2.4vw, 34px);
  --arrow-size: 48px;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 72px;
  padding: 8px var(--arrow-inset);
}

.book-heading { min-width: 0; }

.book-heading p {
  margin: 0 0 3px;
  color: var(--ink-muted);
  font-size: .75rem;
  font-weight: 600;
  line-height: 1.25;
}

h1 {
  margin: 0;
  font-size: clamp(1.08rem, 1.55vw, 1.4rem);
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: -.035em;
  word-break: keep-all;
  overflow-wrap: anywhere;
}

.layout {
  flex: none;
  display: flex;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--line);
  background: #f5f7fc;
  border-radius: 12px;
}

button {
  display: inline-grid;
  place-items: center;
  padding: 0 11px;
  background: transparent;
  border: 0;
  border-radius: 9px;
  color: inherit;
  cursor: pointer;
  font: inherit;
  font-size: .875rem;
  font-weight: 650;
  min-height: 44px;
  -webkit-tap-highlight-color: #244ed81c;
}

button:enabled:hover { background: #edf2ff; color: var(--accent); }
button:disabled { color: #697792; opacity: .54; cursor: default; }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.layout button { min-width: 61px; min-height: 34px; color: var(--ink-muted); }
.layout button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--accent);
  box-shadow: 0 1px 3px #1e3a751c;
}

.reading-area { position: relative; min-width: 0; min-height: 0; }

.reader {
  width: 100%;
  height: 100%;
  overflow: auto;
  background: #f7f9fd;
  overscroll-behavior: contain;
}

.reader:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

@media (any-pointer: fine) {
  .reader.is-zoomed .stage { cursor: grab; user-select: none; }
  .reader.is-panning .stage { cursor: grabbing; }
}

.stage {
  display: grid;
  place-items: center;
  width: max-content;
  min-width: 100%;
  min-height: 100%;
  padding: clamp(10px, 1.8vh, 22px) calc(var(--arrow-inset) + var(--arrow-size) + 15px);
}

.pages {
  display: flex;
  gap: 1px;
  align-items: center;
  background: #e3e8f2;
  outline: 1px solid #dfe5ef;
  box-shadow: 0 12px 35px #233b6210, 0 2px 8px #233b6210;
}

.pages canvas { display: block; background: white; }
.message { padding: 14px 20px; text-align: center; line-height: 1.5; }

.side-navigation { position: absolute; inset: 0; pointer-events: none; }

.side-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: var(--arrow-size);
  height: var(--arrow-size);
  padding: 0;
  border: 1px solid #e0e7f4;
  border-radius: 50%;
  background: var(--surface);
  color: var(--accent);
  box-shadow: 0 4px 12px #223b7314;
  pointer-events: auto;
}

.side-arrow.previous { left: var(--arrow-inset); }
.side-arrow.following { right: var(--arrow-inset); }
.side-arrow:disabled { box-shadow: none; }
.chevron {
  width: 9px;
  height: 9px;
  border: solid currentColor;
  border-width: 0 2px 2px 0;
}
.previous .chevron { transform: translateX(2px) rotate(135deg); }
.following .chevron { transform: translateX(-2px) rotate(-45deg); }

.toolbar {
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--surface);
}

.toolbar-inner {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: clamp(6px, 2.2vw, 22px);
  min-height: 57px;
  padding: 3px 10px;
}

.control-group { display: flex; align-items: center; gap: 2px; }
.zoom { border-left: 1px solid var(--line); padding-left: clamp(6px, 2.2vw, 22px); }
.icon { min-width: 44px; font-size: 1.35rem; line-height: 1; font-weight: 500; }
.mobile-arrow { display: none; }
.mobile-close { display: none; }
.page-count, .zoom-level {
  min-width: 72px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.page-count { font-size: .875rem; font-weight: 650; }
.zoom-level:disabled { opacity: 1; color: var(--ink-muted); }

@media (max-width: 767px) {
  .topbar-inner { min-height: 58px; padding-inline: 16px; }
  .book-heading p { font-size: .6875rem; margin-bottom: 2px; }
  .stage { padding-inline: 12px; }
  .side-navigation { display: none; }
  .mobile-arrow { display: inline-grid; color: var(--accent); }
  .toolbar-inner { min-height: 53px; }
  .zoom-level { min-width: 45px; padding-inline: 2px; }
  .page-count { min-width: 60px; }

  .mobile-close {
    display: block;
    background: #101827;
    color: white;
  }

  #close-preview {
    width: 100%;
    padding: 0 16px;
    border-radius: 0;
    color: inherit;
  }

  #close-preview:hover { background: #22304a; }
  #close-preview:focus-visible { outline: 2px solid #aec2ff; outline-offset: -3px; }

  #close-help {
    margin: 0;
    padding: 8px 16px 0;
    text-align: center;
    font-size: .8125rem;
    line-height: 1.5;
  }
}

