[hidden] { display: none !important; }
:root {
  --bg: #faf8f3;
  --fg: #2b2b2b;
  --muted: #8a8478;
  --line: #e6e1d6;
  --accent: #7a5c3e;
  --story: #f2eee5;
  --size: 17px;
  --bar: 44px;
}
[data-theme="light"] { --bg: #ffffff; --fg: #222; --muted: #888; --line: #e8e8e8; --story: #f5f5f5; }
[data-theme="sepia"] { --bg: #f4ecd8; --fg: #3b3127; --muted: #8b7d66; --line: #e2d6bb; --story: #ebe0c6; --accent: #7a5c3e; }
[data-theme="dark"]  { --bg: #1b1b1d; --fg: #d9d6cf; --muted: #8d8a83; --line: #333; --story: #26262a; --accent: #c9a77c; }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: "Hiragino Mincho ProN", "Yu Mincho", "YuMincho", "Noto Serif JP", "Noto Serif CJK JP", serif;
  font-size: var(--size);
  line-height: 1.95;
  letter-spacing: 0.02em;
  transition: background .2s, color .2s;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }

/* progress line */
#progress { position: fixed; top: 0; left: 0; right: 0; height: 2px; z-index: 30; }
#progress-bar { height: 100%; width: 0; background: var(--accent); opacity: .6; transition: width .2s; }

/* top bar (always horizontal) */
#bar, .sheet, #progress, .home { writing-mode: horizontal-tb; }
#bar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 20;
  height: calc(var(--bar) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 12px 0;
  display: flex; align-items: center; gap: 12px;
  background: var(--bg); border-bottom: 1px solid var(--line);
  font-family: -apple-system, "Hiragino Sans", "Noto Sans JP", sans-serif;
  font-size: 14px; color: var(--muted);
  transition: transform .25s;
}
#bar.away { transform: translateY(-110%); }
#bar-title { flex: 1; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#bar button { padding: 8px 4px; min-width: 40px; }

main {
  max-width: 34em;
  margin: 0 auto;
  padding: calc(var(--bar) + env(safe-area-inset-top) + 24px) max(22px, env(safe-area-inset-right)) 40px max(22px, env(safe-area-inset-left));
}

/* text (logical properties so the same rules work vertically) */
p { margin: 0; margin-block-end: 1.1em; text-align: justify; }
h1, h2, h3 { font-weight: 600; line-height: 1.6; letter-spacing: 0.04em; margin-inline: 0; }
h1 { font-size: 1.35em; margin-block: 1.2em 1.6em; }
h1.part { font-size: .95em; color: var(--muted); font-weight: 400; margin-block: .5em .6em; }
h2 { font-size: 1.12em; margin-block: 2.4em 1em; padding-block-start: 1.2em; border-block-start: 1px solid var(--line); }
h3 { font-size: 1em; margin-block: 1.8em .6em; color: var(--accent); }
strong { font-weight: 700; }
em { font-style: normal; text-emphasis: filled sesame; -webkit-text-emphasis: filled sesame; }
p.story {
  background: var(--story);
  padding: .9em 1.1em;
  border-radius: 6px;
}
p.story + p.story { margin-block-start: -1.1em; padding-block-start: .2em; border-start-start-radius: 0; border-start-end-radius: 0; }
p.story em { text-emphasis: none; -webkit-text-emphasis: none; font-weight: 600; }
p.note { font-size: .82em; color: var(--muted); line-height: 1.8; }
ul { margin: 0; margin-block-end: 1.2em; padding: 0; padding-inline-start: 1.3em; }
li { margin-block-end: .35em; }
figure { margin: 0; margin-block: 1.6em; text-align: center; }
figure img { max-width: 100%; height: auto; border-radius: 4px; }
[data-theme="dark"] figure img { filter: brightness(.85); }
[data-p] { scroll-margin-block-start: calc(var(--bar) + 16px); }

/* chapter navigation */
.chap-nav { display: flex; justify-content: space-between; gap: 12px; margin-block: 3.5em 2em; padding-block-start: 1.5em; border-block-start: 1px solid var(--line); font-size: .85em; }
.chap-nav a { color: var(--accent); text-decoration: none; max-inline-size: 48%; }
.chap-nav a.next { text-align: end; margin-inline-start: auto; }
.chap-nav small { display: block; color: var(--muted); font-size: .8em; }

/* ---- vertical (縦書き) reading ---- */
/* the page itself never scrolls; <main> is a full-screen box that scrolls sideways */
html[data-vertical], html[data-vertical] body { height: 100%; overflow: hidden; overscroll-behavior: none; }
html[data-vertical] main {
  writing-mode: vertical-rl;
  line-height: 1.85;
  position: fixed;
  inset: 0;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  max-width: none;
  margin: 0;
  padding: calc(var(--bar) + env(safe-area-inset-top) + 18px) max(28px, env(safe-area-inset-right)) calc(28px + env(safe-area-inset-bottom)) 28px;
}
html[data-vertical] main::-webkit-scrollbar { display: none; }
html[data-vertical] p { margin-block-end: 0; text-indent: 1em; }
html[data-vertical] p.story, html[data-vertical] p.note,
html[data-vertical] h1 + p, html[data-vertical] h2 + p, html[data-vertical] h3 + p { text-indent: 0; }
html[data-vertical] p.story { margin-block: .6em; }
html[data-vertical] p.story + p.story { margin-block-start: -.6em; }
html[data-vertical] h2 { margin-block: 1.8em 1em; }
html[data-vertical] figure img { max-width: 80vw; max-height: calc(100dvh - 160px); width: auto; }
html[data-vertical] [data-p] { scroll-margin-block-start: 24px; }
html[data-vertical] .tcy { text-combine-upright: all; -webkit-text-combine: horizontal; }
html[data-vertical] .chap-nav { margin-block: 3em 1em; }

/* home */
.home { text-align: center; padding-top: 2em; max-width: 34em; margin: 0 auto; }
.home img.cover { width: 46%; max-width: 200px; border-radius: 4px; box-shadow: 0 6px 24px rgba(0,0,0,.12); margin-bottom: 2em; }
.home h1 { margin: 0 0 .3em; font-size: 1.5em; }
.home .sub { color: var(--muted); margin: 0 0 1.4em; text-align: center; }
.home .author { font-size: .9em; text-align: center; margin: 0 0 .2em; }
.home .ded { color: var(--muted); font-size: .85em; margin: 2em 0; text-align: center; }
.home em { text-emphasis: none; -webkit-text-emphasis: none; }
.btn {
  display: block; width: 100%; max-width: 320px; margin: .7em auto; padding: .85em 1em;
  border: 1px solid var(--accent); border-radius: 8px; color: var(--accent);
  text-decoration: none; text-align: center; font-size: .95em; line-height: 1.5;
}
.btn.primary { background: var(--accent); color: var(--bg); }
.btn small { display: block; font-size: .78em; opacity: .85; }
.home .pct { color: var(--muted); font-size: .8em; text-align: center; margin-top: 1.5em; }

/* sheets (TOC, settings) */
#scrim { position: fixed; inset: 0; background: rgba(0,0,0,.3); z-index: 40; }
.sheet {
  position: fixed; z-index: 50; left: 0; right: 0; bottom: 0;
  max-width: 560px; margin: 0 auto;
  max-height: 85vh; overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: var(--bg); border-radius: 14px 14px 0 0;
  padding: 0 20px calc(20px + env(safe-area-inset-bottom));
  font-family: -apple-system, "Hiragino Sans", "Noto Sans JP", sans-serif;
  font-size: 15px; line-height: 1.6;
  box-shadow: 0 -4px 30px rgba(0,0,0,.15);
}
.sheet-head { position: sticky; top: 0; background: var(--bg); display: flex; justify-content: space-between; align-items: center; padding: 16px 0 10px; font-weight: 600; }
.sheet-head .close { font-size: 22px; color: var(--muted); padding: 0 6px; }
#toc-list .part { color: var(--muted); font-size: 12px; margin: 18px 0 4px; }
#toc-list a { display: flex; gap: 8px; color: var(--fg); text-decoration: none; padding: 9px 0; border-bottom: 1px solid var(--line); }
#toc-list a.sec { padding: 6px 0 6px 1.2em; font-size: 13px; color: var(--muted); border-bottom: 0; }
#toc-list a.current { color: var(--accent); font-weight: 600; }
#toc-list .check { margin-left: auto; color: var(--accent); font-size: 12px; }
.row { display: flex; justify-content: space-between; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--line); }
.seg { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { padding: 6px 12px; font-size: 14px; }
.seg button.on { background: var(--accent); color: var(--bg); }
