/* ============ 테마 ============ */
:root {
  --fs: 17px;
  --lh: 1.8;
  --measure: 36em;
  --sans: "Pretendard", -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", system-ui, sans-serif;
  --serif: "Noto Serif KR", "Nanum Myeongjo", "AppleMyungjo", "Batang", serif;
  --font: var(--sans);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --bar-h: 52px;
  --radius: 14px;
}
html[data-theme="light"] {
  --bg: #fbfaf7; --bg2: #f3f1ec; --card: #ffffff; --text: #1e1e20; --sub: #6b6a70;
  --line: #e5e1d8; --accent: #2f5d50; --accent-soft: #e4eee9; --strong: #111;
  --th: #f1eee7; --sticky: #fbfaf7; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 6px 20px rgba(0,0,0,.06);
}
html[data-theme="sepia"] {
  --bg: #f4ecd8; --bg2: #ece2c8; --card: #f9f3e2; --text: #3a2e21; --sub: #7b6a54;
  --line: #dccfb2; --accent: #8a4b2a; --accent-soft: #ead9c0; --strong: #2a1f14;
  --th: #ebdfc3; --sticky: #f4ecd8; --shadow: 0 1px 2px rgba(60,40,10,.06), 0 6px 20px rgba(60,40,10,.08);
}
html[data-theme="dark"] {
  --bg: #141416; --bg2: #1b1b1e; --card: #1e1e21; --text: #e5e3de; --sub: #9a999f;
  --line: #2e2e33; --accent: #8fc9b2; --accent-soft: #23332d; --strong: #fff;
  --th: #24242a; --sticky: #141416; --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);
  color-scheme: dark;
}
html[data-font="serif"] { --font: var(--serif); }
html[data-lh="tight"] { --lh: 1.6; }
html[data-lh="loose"] { --lh: 2.0; }

/* ============ 기본 ============ */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; background: var(--bg); }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: var(--sans); font-size: 16px; line-height: 1.5;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
  word-break: keep-all; overflow-wrap: break-word;
  transition: background-color .25s, color .25s;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
a { color: inherit; text-decoration: none; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

.loading { min-height: 100dvh; display: grid; place-items: center; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.ib { width: 44px; height: 44px; display: inline-grid; place-items: center; border-radius: 12px; color: var(--text); flex: none; }
.ib:active { background: var(--bg2); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4em;
  min-height: 48px; padding: 0 20px; border-radius: 12px; font-weight: 600;
  background: var(--bg2); color: var(--text);
}
.btn.primary { background: var(--accent); color: var(--bg); }
html[data-theme="dark"] .btn.primary { color: #0f1a16; }
.btn.block { width: 100%; }
.btn:active { transform: scale(.98); }

/* ============ 서재 ============ */
.lib { max-width: 720px; margin: 0 auto; padding: calc(var(--safe-t) + 24px) calc(var(--safe-r) + 20px) calc(var(--safe-b) + 40px) calc(var(--safe-l) + 20px); }
.lib-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.lib-tools { display: flex; gap: 2px; margin-right: -10px; }
.lib-head h1 { font-size: 28px; letter-spacing: -.02em; margin: 0; }
.lib-sub { color: var(--sub); margin: 0 0 24px; font-size: 14px; }
.shelf { display: grid; gap: 16px; }
.install {
  display: flex; align-items: center; gap: 12px; margin: -8px 0 20px; padding: 14px 10px 14px 16px;
  border-radius: var(--radius); background: var(--accent-soft); position: relative;
}
.install > div { flex: 1; min-width: 0; font-size: 13px; line-height: 1.5; color: var(--sub); }
.install b { display: block; color: var(--text); font-size: 14.5px; margin-bottom: 2px; }
.install .btn { min-height: 40px; padding: 0 16px; flex: none; }
.install-x { width: 32px; height: 32px; border-radius: 8px; font-size: 20px; color: var(--sub); flex: none; align-self: flex-start; margin-top: -4px; }
.ios-share { display: inline-block; width: .9em; height: 1.1em; vertical-align: -.15em; border: 1.5px solid currentColor; border-top: 0; border-radius: 0 0 2px 2px; position: relative; margin: 0 1px; }
.ios-share::before { content: ""; position: absolute; left: 50%; top: -.35em; width: 1.5px; height: .8em; background: currentColor; transform: translateX(-50%); }
.book-card {
  display: grid; grid-template-columns: 96px 1fr; gap: 16px; align-items: center;
  padding: 14px; border-radius: var(--radius); background: var(--card); box-shadow: var(--shadow);
  transition: transform .15s;
}
.book-card:active { transform: scale(.985); }
.book-card .cover { --w: 96px; }
.bc-info { min-width: 0; }
.bc-info h2 { font-size: 17px; line-height: 1.4; margin: 0 0 4px; letter-spacing: -.01em; }
.bc-info p { margin: 0 0 10px; color: var(--sub); font-size: 13.5px; line-height: 1.45; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.meter { height: 4px; border-radius: 4px; background: var(--bg2); overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.bc-meta { display: flex; justify-content: space-between; gap: 8px; margin-top: 6px; font-size: 12.5px; color: var(--sub); }
.bc-pillar { font-size: .78em; font-weight: 600; color: var(--accent); white-space: nowrap; }
.bc-info p.bc-series { font-size: 12.5px; margin-top: -6px; -webkit-line-clamp: 1; }
.book-card.missing { opacity: .7; }
.book-card.missing p { color: #b5523b; }
@media (min-width: 640px) {
  .shelf { grid-template-columns: repeat(3, 1fr); }
  .book-card { grid-template-columns: 1fr; padding: 18px; align-items: start; }
  .book-card .cover { --w: 180px; margin: 0 auto; }
}

/* ============ 표지 ============ */
.cover {
  --c1: #23413a; --c2: #b8643c;
  position: relative; aspect-ratio: 2 / 3; border-radius: 4px 8px 8px 4px; overflow: hidden;
  background:
    radial-gradient(120% 80% at 80% 0%, rgba(255,255,255,.18), transparent 55%),
    linear-gradient(160deg, var(--c1) 0%, var(--c1) 45%, var(--c2) 140%);
  background-size: cover; background-position: center;
  color: #fff; box-shadow: 0 2px 4px rgba(0,0,0,.18), 0 10px 30px rgba(0,0,0,.18);
  --w: 240px; width: var(--w); font-size: calc(var(--w) / 26); /* 표지 내부 크기는 폭에 비례 (em) */
  display: flex; flex-direction: column; padding: 2.2em 1.8em 1.8em 2.4em;
  font-family: var(--serif);
}
.cover::before { /* 책등 */
  content: ""; position: absolute; inset: 0 auto 0 0; width: 6%;
  background: linear-gradient(90deg, rgba(0,0,0,.28), rgba(255,255,255,.08) 60%, transparent);
}
.cover::after { /* 결 */
  content: ""; position: absolute; inset: 0; pointer-events: none; opacity: .5;
  background: repeating-linear-gradient(115deg, rgba(255,255,255,.03) 0 2px, transparent 2px 6px);
}
.cover.has-image::after { background: linear-gradient(180deg, rgba(0,0,0,.35), transparent 40%, transparent 60%, rgba(0,0,0,.45)); opacity: 1; }
.cv-emblem {
  position: absolute; right: -.05em; bottom: .05em; font-size: 13em; line-height: 1;
  color: rgba(255,255,255,.13); font-weight: 700; pointer-events: none;
}
.cv-kicker { font-family: var(--sans); font-size: 1.05em; letter-spacing: .25em; opacity: .75; text-transform: uppercase; }
.cv-title { font-size: 2.6em; line-height: 1.32; font-weight: 700; margin-top: .9em; letter-spacing: -.01em; position: relative; z-index: 1; word-break: keep-all; }
.cv-sub { font-size: 1.3em; line-height: 1.5; margin-top: .9em; opacity: .85; position: relative; z-index: 1; }
.cv-rule { width: 2.6em; height: 2px; background: rgba(255,255,255,.6); margin-top: 1.4em; position: relative; z-index: 1; }
.cv-author { margin-top: auto; font-family: var(--sans); font-size: 1.1em; opacity: .8; position: relative; z-index: 1; }

.cover-page {
  min-height: 100dvh; display: flex; flex-direction: column; align-items: center;
  padding: calc(var(--safe-t) + 8px) calc(var(--safe-r) + 24px) calc(var(--safe-b) + 28px) calc(var(--safe-l) + 24px);
}
.cover-page .topline { align-self: stretch; display: flex; justify-content: space-between; margin: 0 -10px 8px; }
.cover-page .cover { --w: min(68vw, 300px, 36dvh); }
.cp-info { text-align: center; margin-top: 26px; max-width: 30em; }
.cp-info h1 { font-size: 21px; line-height: 1.4; margin: 0 0 6px; letter-spacing: -.015em; }
.cp-info .cp-meta { color: var(--sub); font-size: 14px; margin: 0; }
.cp-info .cp-series { color: var(--sub); font-size: 13px; margin: 4px 0 0; }
.cp-info .cp-prelude { color: var(--sub); font-size: 13px; margin: 6px 0 0; }
.cp-actions { width: 100%; max-width: 360px; display: grid; gap: 10px; margin-top: 26px; }
.cp-actions .row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ============ 상단/하단 바 ============ */
.topbar {
  position: fixed; inset: 0 0 auto 0; z-index: 20;
  padding: var(--safe-t) calc(var(--safe-r) + 4px) 0 calc(var(--safe-l) + 4px);
  display: flex; align-items: center; gap: 2px; height: calc(var(--bar-h) + var(--safe-t));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(14px); backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid var(--line);
  transition: transform .25s ease;
}
.tb-title { flex: 1; min-width: 0; text-align: center; line-height: 1.25; }
.tb-title small { display: block; font-size: 11px; color: var(--sub); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tb-title span { display: block; font-size: 14.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.progress { position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; }
.progress i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .1s linear; }

.bottombar {
  position: fixed; inset: auto 0 0 0; z-index: 20;
  padding: 0 calc(var(--safe-r) + 8px) var(--safe-b) calc(var(--safe-l) + 8px);
  height: calc(56px + var(--safe-b));
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(14px); backdrop-filter: saturate(1.4) blur(14px);
  border-top: 1px solid var(--line);
  transition: transform .25s ease;
}
.bottombar .nav { display: flex; align-items: center; gap: 4px; height: 44px; padding: 0 10px; border-radius: 12px; font-size: 14.5px; font-weight: 600; }
.bottombar .nav:active { background: var(--bg2); }
.bottombar .nav[disabled] { opacity: .3; pointer-events: none; }
.bottombar .nav.next { justify-self: end; }
.bottombar .pos { font-size: 12.5px; color: var(--sub); text-align: center; white-space: nowrap; }
body.chrome-hidden .topbar { transform: translateY(-100%); }
body.chrome-hidden .bottombar { transform: translateY(100%); }

/* ============ 본문 ============ */
.reader {
  padding: calc(var(--bar-h) + var(--safe-t) + 20px) calc(var(--safe-r) + 22px) calc(80px + var(--safe-b)) calc(var(--safe-l) + 22px);
  min-height: 100dvh;
}
.prose {
  max-width: var(--measure); margin: 0 auto;
  font-family: var(--font); font-size: var(--fs); line-height: var(--lh);
  letter-spacing: -.003em; color: var(--text);
}
.reader.turn-next .prose { animation: in-r .28s ease both; }
.reader.turn-prev .prose { animation: in-l .28s ease both; }
@keyframes in-r { from { opacity: 0; transform: translateX(24px); } }
@keyframes in-l { from { opacity: 0; transform: translateX(-24px); } }

.prose > :first-child { margin-top: 0; }
.prose p { margin: 0 0 1.05em; }
.prose h2 {
  font-family: var(--sans); font-size: 1.45em; line-height: 1.38; letter-spacing: -.02em;
  margin: .2em 0 1.2em; padding-bottom: .8em; border-bottom: 1px solid var(--line);
}
.prose h2 .ch-num {
  display: block; font-size: .5em; letter-spacing: .14em; color: var(--accent); font-weight: 700; margin-bottom: .55em;
}
.prose h3 {
  font-family: var(--sans); font-size: 1.12em; line-height: 1.45; letter-spacing: -.01em;
  margin: 2.2em 0 .8em; scroll-margin-top: calc(var(--bar-h) + var(--safe-t) + 16px);
}
.prose h3::before { content: ""; display: block; width: 1.4em; height: 3px; border-radius: 2px; background: var(--accent); margin-bottom: .7em; opacity: .8; }
.prose h4 { font-family: var(--sans); font-size: 1em; margin: 1.8em 0 .6em; }
.prose strong { color: var(--strong); font-weight: 700; }
.prose em { font-style: normal; background: linear-gradient(transparent 62%, var(--accent-soft) 62%); }
.prose a { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px; word-break: break-all; }
.prose ul, .prose ol { margin: 0 0 1.1em; padding-left: 1.35em; }
.prose li { margin: .4em 0; padding-left: .15em; }
.prose li::marker { color: var(--sub); }
.prose ol > li::marker { font-family: var(--sans); font-weight: 700; color: var(--accent); }
.prose li > p { margin: 0 0 .5em; }
.prose blockquote {
  margin: 1.4em 0; padding: .9em 1.1em; border-left: 3px solid var(--accent);
  background: var(--bg2); border-radius: 0 10px 10px 0; color: var(--text);
}
.prose blockquote p:last-child { margin-bottom: 0; }
.prose hr { border: 0; height: 1px; background: var(--line); margin: 2.4em 0; }
.prose code { font-size: .88em; background: var(--bg2); padding: .1em .35em; border-radius: 5px; }
.prose pre { overflow-x: auto; background: var(--bg2); padding: 1em; border-radius: 10px; font-size: .85em; line-height: 1.6; }
.prose pre code { background: none; padding: 0; }
.prose img { max-width: 100%; height: auto; border-radius: 8px; }

/* 장 끝 */
.ch-end { max-width: var(--measure); margin: 3em auto 0; display: grid; gap: 10px; }
.next-card {
  display: block; padding: 18px 20px; border-radius: var(--radius); background: var(--card); box-shadow: var(--shadow);
}
.next-card small { display: block; color: var(--sub); font-size: 12.5px; margin-bottom: 4px; }
.next-card b { font-size: 16px; line-height: 1.45; }
.ch-end .done { text-align: center; color: var(--sub); font-size: 14px; padding: 18px 0 6px; }

/* ============ 표 ============ */
.tbl { margin: 1.5em -4px 1.8em; font-family: var(--sans); }
.tbl-scroll {
  position: relative; overflow-x: auto; overflow-y: hidden; -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain; border: 1px solid var(--line); border-radius: 12px; background: var(--card);
  scrollbar-width: thin;
}
.tbl table { border-collapse: separate; border-spacing: 0; width: 100%; font-size: .84em; line-height: 1.55; }
.tbl th, .tbl td { padding: .7em .85em; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); }
.tbl tr:last-child td { border-bottom: 0; }
.tbl th { background: var(--th); font-weight: 700; }
.tbl td + td, .tbl th + th { border-left: 1px solid var(--line); }
.tbl tbody tr:nth-child(even) td { background: color-mix(in srgb, var(--bg2) 45%, transparent); }

/* 가로 스크롤 모드: 넘치는 표 */
.tbl.is-scroll.overflow table { width: auto; min-width: 100%; }
.tbl.is-scroll.overflow td, .tbl.is-scroll.overflow th { min-width: 7em; }
.tbl.is-scroll.overflow td:first-child, .tbl.is-scroll.overflow th:first-child {
  position: sticky; left: 0; z-index: 2; background: var(--card); min-width: 5.5em; width: 6.5em;
  font-weight: 600;
  box-shadow: 1px 0 0 var(--line);
}
.tbl.is-scroll.overflow th:first-child { background: var(--th); z-index: 3; }
.tbl.is-scroll.overflow tbody tr:nth-child(even) td:first-child { background: color-mix(in srgb, var(--bg2) 45%, var(--card)); }
.tbl-edge { position: relative; }
.tbl-edge::before, .tbl-edge::after {
  content: ""; position: absolute; top: 1px; bottom: 1px; width: 26px; z-index: 4; pointer-events: none;
  opacity: 0; transition: opacity .2s; border-radius: 12px;
}
.tbl-edge::after { right: 1px; background: linear-gradient(270deg, color-mix(in srgb, var(--text) 16%, transparent), transparent); border-top-left-radius: 0; border-bottom-left-radius: 0; }
.tbl.can-right .tbl-edge::after { opacity: 1; }

/* 카드 모드 */
.tbl.is-card .tbl-scroll { border: 0; background: none; overflow: visible; border-radius: 0; }
.tbl.is-card table, .tbl.is-card tbody, .tbl.is-card tr, .tbl.is-card td { display: block; width: auto; }
.tbl.is-card thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.tbl.is-card tr {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; margin: 0 0 10px; overflow: hidden;
}
.tbl.is-card tbody tr:nth-child(even) td { background: none; }
.tbl.is-card td { border: 0 !important; padding: .55em 1em; display: grid; grid-template-columns: minmax(5.5em, 32%) 1fr; gap: .8em; }
.tbl.is-card td::before { content: attr(data-label); color: var(--sub); font-weight: 600; font-size: .92em; }
.tbl.is-card td[data-label=""]::before { content: none; }
.tbl.is-card td[data-label=""] { grid-template-columns: 1fr; }
.tbl.is-card td:first-child {
  display: block; background: var(--th) !important; font-weight: 700; padding: .7em 1em; font-size: 1.02em;
}
.tbl.is-card td:first-child::before { display: block; font-size: .78em; font-weight: 600; margin-bottom: .15em; }
.tbl.is-card td + td { border-top: 1px dashed var(--line) !important; }
.tbl.is-card td:nth-child(2) { border-top: 0 !important; padding-top: .8em; }
.tbl.is-card td:last-child { padding-bottom: .85em; }

.tbl-bar { display: flex; align-items: center; justify-content: flex-end; gap: 6px; margin-top: 6px; font-size: 12.5px; color: var(--sub); }
.tbl-hint { margin-right: auto; display: none; align-items: center; gap: 4px; }
.tbl.is-scroll.overflow .tbl-hint { display: inline-flex; }
.tbl-btn { display: inline-flex; align-items: center; gap: 4px; height: 32px; padding: 0 10px; border-radius: 8px; background: var(--bg2); font-weight: 600; font-size: 12.5px; color: var(--text); }
.tbl-btn:active { transform: scale(.96); }

/* ============ 목차 ============ */
.toc-page { max-width: 720px; margin: 0 auto; padding: calc(var(--bar-h) + var(--safe-t) + 16px) calc(var(--safe-r) + 16px) calc(var(--safe-b) + 40px) calc(var(--safe-l) + 16px); }
.toc-head { display: grid; grid-template-columns: 72px 1fr; gap: 16px; align-items: center; padding: 8px 6px 22px; border-bottom: 1px solid var(--line); margin-bottom: 8px; }
.toc-head .cover { --w: 72px; }
.toc-head h1 { font-size: 18px; line-height: 1.4; margin: 0 0 4px; }
.toc-head p { margin: 0; color: var(--sub); font-size: 13px; }
.toc-head p.toc-birth { color: var(--text); font-weight: 600; margin-bottom: 2px; }
.toc { list-style: none; margin: 0; padding: 0; }
.toc > li { border-bottom: 1px solid var(--line); }
.toc-row { display: flex; align-items: stretch; }
.toc-link { flex: 1; min-width: 0; display: grid; grid-template-columns: 2.4em 1fr; gap: 6px; align-items: baseline; padding: 15px 6px; }
.toc-link .n { font-weight: 700; color: var(--accent); font-size: 14px; font-variant-numeric: tabular-nums; }
.toc-link .t { font-size: 15.5px; line-height: 1.45; font-weight: 600; }
.toc-link .m { grid-column: 2; font-size: 12px; color: var(--sub); margin-top: 2px; }
.toc > li.current .toc-link .t { color: var(--accent); }
.toc > li.current .toc-link .m::after { content: " · 읽는 중"; color: var(--accent); font-weight: 600; }
.toc > li.read .toc-link .m::before { content: "✓ "; color: var(--accent); }
.toc-exp { width: 44px; display: grid; place-items: center; color: var(--sub); flex: none; }
.toc-exp svg { transition: transform .2s; }
.toc > li.open .toc-exp svg { transform: rotate(180deg); }
.toc-subs { list-style: none; margin: 0; padding: 0 0 10px calc(2.4em + 12px); display: none; }
.toc > li.open .toc-subs { display: block; }
.toc-subs a { display: block; padding: 9px 6px; font-size: 14px; color: var(--sub); line-height: 1.45; border-radius: 8px; }
.toc-subs a:active { background: var(--bg2); }

/* ============ 바텀시트 / 오버레이 ============ */
.overlay { position: fixed; inset: 0; z-index: 50; }
.scrim { position: absolute; inset: 0; background: rgba(0,0,0,.35); animation: fade .2s ease both; }
@keyframes fade { from { opacity: 0; } }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 88dvh; overflow-y: auto;
  background: var(--card); border-radius: 20px 20px 0 0;
  padding: 8px calc(var(--safe-r) + 20px) calc(var(--safe-b) + 18px) calc(var(--safe-l) + 20px);
  animation: up .25s cubic-bezier(.2,.8,.2,1) both; max-width: 560px; margin: 0 auto;
}
@keyframes up { from { transform: translateY(100%); } }
.sheet-grip { width: 38px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 12px; }
.sheet h2 { font-size: 17px; margin: 0 0 12px; }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.set-row.col { flex-direction: column; align-items: stretch; }
.set-label { font-size: 14.5px; font-weight: 600; flex: none; }
.set-help { margin: 2px 0 0; font-size: 12.5px; color: var(--sub); line-height: 1.5; }
.stepper { display: flex; align-items: center; gap: 6px; }
.stepper button { width: 48px; height: 40px; border-radius: 10px; background: var(--bg2); font-size: 15px; }
.stepper button b { font-size: 19px; }
.stepper sup { font-size: 10px; margin-left: 1px; }
.stepper output { min-width: 2.6em; text-align: center; font-variant-numeric: tabular-nums; color: var(--sub); font-size: 14px; }
.seg { display: flex; background: var(--bg2); border-radius: 11px; padding: 3px; gap: 2px; flex-wrap: nowrap; }
.set-row.col .seg { width: 100%; }
.set-row.col .seg button { flex: 1; }
.seg button { min-height: 36px; padding: 0 12px; border-radius: 9px; font-size: 13.5px; font-weight: 600; color: var(--sub); white-space: nowrap; }
.seg button.on { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.seg .serif { font-family: var(--serif); }
.themes button { padding: 0 9px; }
.sw::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 5px; vertical-align: -1px; border: 1px solid rgba(0,0,0,.15); }
.sw-light::before { background: #fbfaf7; } .sw-sepia::before { background: #f4ecd8; } .sw-dark::before { background: #141416; }
.sheet .btn.block { margin-top: 16px; }

/* 표 크게 보기 */
#table-view { background: var(--bg); animation: fade .2s ease both; }
.tv { height: 100%; display: flex; flex-direction: column; }
.tv-head {
  display: flex; align-items: center; gap: 8px; padding: calc(var(--safe-t) + 4px) calc(var(--safe-r) + 6px) 4px calc(var(--safe-l) + 16px);
  border-bottom: 1px solid var(--line);
}
.tv-title { flex: 1; font-weight: 700; font-size: 15px; }
.tv-zoom { display: flex; gap: 4px; }
.tv-zoom button { width: 40px; height: 36px; border-radius: 9px; background: var(--bg2); font-size: 18px; font-weight: 700; }
.tv-body { flex: 1; overflow: auto; -webkit-overflow-scrolling: touch; padding: 14px calc(var(--safe-r) + 14px) 14px calc(var(--safe-l) + 14px); font-size: var(--tv-fs, 15px); }
.tv-body .tbl { margin: 0; }
.tv-body .tbl-bar { display: none; }
.tv-body .tbl-scroll { overflow: visible; display: inline-block; min-width: 100%; }
.tv-body table { width: max-content !important; min-width: 100%; font-size: 1em !important; }
.tv-body td { min-width: 6em; max-width: 22em; }
.tv-body td:first-child, .tv-body th:first-child { position: sticky; left: -14px; background: var(--card); z-index: 2; box-shadow: 1px 0 0 var(--line); }
.tv-body th { position: sticky; top: -14px; z-index: 3; }
.tv-body th:first-child { z-index: 4; background: var(--th); }
.tv-tip { margin: 0; padding: 8px 16px calc(var(--safe-b) + 10px); font-size: 12.5px; color: var(--sub); text-align: center; border-top: 1px solid var(--line); }
@media (orientation: landscape) and (max-height: 500px) { .tv-tip { display: none; } }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-b) + 76px); transform: translate(-50%, 20px); z-index: 60;
  background: var(--text); color: var(--bg); font-size: 13.5px; padding: 10px 16px; border-radius: 999px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; white-space: nowrap;
}
.toast.show { opacity: .94; transform: translate(-50%, 0); }

.empty { text-align: center; color: var(--sub); padding: 60px 20px; line-height: 1.7; }

@media (min-width: 900px) {
  .reader { padding-left: 40px; padding-right: 40px; }
  .tbl { margin-left: -1em; margin-right: -1em; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* 앱으로 저장 안내 */
.guide h3 { font-size: 14px; margin: 18px 0 6px; color: var(--sub); font-weight: 700; }
.guide-lead { margin: -4px 0 14px; font-size: 13.5px; color: var(--sub); line-height: 1.55; }
.guide-tabs { margin-bottom: 4px; }
.guide-tabs button { flex: 1; }
.guide-now { margin: 16px 0 4px; }
.guide-now .set-help { text-align: center; margin-top: 8px; }
.steps { list-style: none; counter-reset: st; margin: 0; padding: 0; }
.steps li {
  counter-increment: st; position: relative; padding: 10px 0 10px 40px; font-size: 14.5px; line-height: 1.6;
  border-bottom: 1px dashed var(--line);
}
.steps li:last-child { border-bottom: 0; }
.steps li::before {
  content: counter(st); position: absolute; left: 0; top: 10px; width: 26px; height: 26px; border-radius: 50%;
  display: grid; place-items: center; font-size: 13px; font-weight: 700; background: var(--accent); color: var(--bg);
}
html[data-theme="dark"] .steps li::before { color: #0f1a16; }
.key {
  display: inline-flex; align-items: center; gap: 4px; padding: 0 7px; min-height: 1.6em; border-radius: 6px;
  background: var(--bg2); border: 1px solid var(--line); font-weight: 700; font-size: .92em; vertical-align: 1px;
}
.guide-inapp {
  margin: 0 0 14px; padding: 14px 16px; border-radius: 12px; background: color-mix(in srgb, #e0a13a 18%, var(--card));
  border: 1px solid color-mix(in srgb, #e0a13a 45%, transparent); font-size: 13.5px; line-height: 1.55;
}
.guide-inapp b { display: block; font-size: 14.5px; margin-bottom: 2px; }
.guide-inapp .row { display: flex; gap: 8px; margin-top: 10px; }
.guide-inapp .btn { min-height: 40px; padding: 0 14px; flex: 1; }
.guide-done p { margin: 14px 0 0; font-size: 14.5px; line-height: 1.6; }
.sheet .guide-open { margin-top: 18px; }
.sheet .guide-open + .btn.block { margin-top: 8px; }
