/* The website's own skin (tools/reskin.py). Phone first. Night by default. */
@font-face { font-family: "Literata"; font-style: normal; font-display: swap; font-weight: 200 900; src: url("fonts/literata-latin-wght-normal.woff2") format("woff2"); }
@font-face { font-family: "Literata"; font-style: italic; font-display: swap; font-weight: 200 900; src: url("fonts/literata-latin-wght-italic.woff2") format("woff2"); }
@font-face { font-family: "Inter"; font-style: normal; font-display: swap; font-weight: 100 900; src: url("fonts/inter-latin-wght-normal.woff2") format("woff2"); }

:root, [data-theme="night"] {
  --bg: #17181b; --panel: #1f2125; --line: #2e3137; --text: #dedad3; --muted: #a19d96;
  --head: #f3efe8; --accent: #e0b25c; --accent-ink: #1a1408; --link: #e0b25c;
  --quote: rgba(224, 178, 92, 0.08); --shadow: 0 10px 30px rgba(0,0,0,.45);
  color-scheme: dark;
}
[data-theme="paper"] {
  --bg: #f4ecd8; --panel: #ece2c9; --line: #d9cba8; --text: #3b3226; --muted: #7a6b55;
  --head: #2a2218; --accent: #9a6418; --accent-ink: #fffaf0; --link: #8a5a14;
  --quote: rgba(154, 100, 24, 0.08); --shadow: 0 10px 30px rgba(60,40,10,.2);
  color-scheme: light;
}
[data-theme="light"] {
  --bg: #fdfcf8; --panel: #f3f1ea; --line: #e2ded3; --text: #24262b; --muted: #6b6b6b;
  --head: #111; --accent: #9a6418; --accent-ink: #fff; --link: #1d5fa8;
  --quote: rgba(29, 95, 168, 0.06); --shadow: 0 10px 30px rgba(0,0,0,.18);
  color-scheme: light;
}
:root { --size: 19px; --ui: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif; --read: "Literata", Georgia, serif; }
[data-size="s"] { --size: 17px; }
[data-size="l"] { --size: 21px; }
[data-size="xl"] { --size: 24px; }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 64px; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 400 var(--size)/1.7 var(--read);
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; font-kerning: normal;
}
a { color: var(--link); text-underline-offset: 0.15em; }
button { font: inherit; color: inherit; }
img { max-width: 100%; height: auto; }
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip-link { position: absolute; left: -9999px; top: 8px; z-index: 1000; padding: 8px 14px; background: var(--accent); color: var(--accent-ink); font: 700 15px var(--ui); border-radius: 6px; }
.skip-link:focus { left: 8px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- top bar ---- */
.topbar {
  position: sticky; top: 0; z-index: 50; display: flex; align-items: center; gap: 4px;
  height: 52px; padding: 0 8px; padding-top: env(safe-area-inset-top);
  background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line); font-family: var(--ui);
  transition: transform .2s ease;
}
.topbar.hide { transform: translateY(-100%); }
.tb-btn {
  display: inline-flex; align-items: center; gap: 6px; height: 40px; min-width: 40px; padding: 0 10px;
  border: 0; border-radius: 8px; background: transparent; color: var(--text); cursor: pointer;
  font: 600 14px var(--ui);
}
.tb-btn:hover { background: var(--panel); }
.tb-btn .aa { font: 700 16px var(--read); }
.tb-title {
  flex: 1; min-width: 0; text-align: center; color: var(--head); text-decoration: none;
  font: 700 14px var(--ui); letter-spacing: 0.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.read-progress { position: fixed; top: 0; left: 0; height: 3px; width: 0; z-index: 60; background: var(--accent); pointer-events: none; }

/* ---- contents drawer ---- */
.scrim { position: fixed; inset: 0; z-index: 70; background: rgba(0,0,0,.45); }
.drawer {
  position: fixed; top: 0; bottom: 0; left: 0; z-index: 80; width: min(360px, 88vw);
  overflow-y: auto; overscroll-behavior: contain; padding: 0 0 32px;
  background: var(--panel); border-right: 1px solid var(--line); font: 15px/1.45 var(--ui);
  box-shadow: var(--shadow);
}
.drawer[hidden], .scrim[hidden], .popover[hidden] { display: none; }
.drawer-head { position: sticky; top: 0; display: flex; align-items: center; gap: 8px; padding: 10px 8px 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
.drawer-title { flex: 1; display: flex; align-items: center; gap: 10px; color: var(--head); font-weight: 700; text-decoration: none; }
.search { display: block; padding: 14px 16px 6px; }
.search input {
  width: 100%; height: 42px; padding: 0 12px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); color: var(--text); font: 16px var(--ui);
}
.search-results { list-style: none; margin: 4px 0 8px; padding: 0 8px; }
.search-results a { display: block; padding: 8px; border-radius: 8px; color: var(--text); text-decoration: none; }
.search-results a:hover, .search-results a:focus { background: var(--bg); }
.search-results b { display: block; color: var(--head); }
.search-results small { color: var(--muted); }
.search-results mark { background: none; color: var(--accent); font-weight: 700; }
.search-results .none { padding: 8px; color: var(--muted); }
.drawer-continue { margin: 10px 16px 4px; }
.drawer-continue a { display: block; padding: 10px 12px; border-radius: 8px; background: var(--accent); color: var(--accent-ink); font-weight: 700; text-decoration: none; }
.drawer-links { list-style: none; margin: 10px 0; padding: 0 8px; }
.drawer-links a { display: block; padding: 7px 8px; border-radius: 8px; color: var(--text); text-decoration: none; }
.drawer-links a:hover { background: var(--bg); }
.visit-count { margin: 0 16px 6px; color: var(--muted); font-size: 13px; }
.toc-part { margin: 18px 16px 4px; color: var(--muted); font: 700 12px var(--ui); letter-spacing: 0.08em; text-transform: uppercase; }
.toc-list { list-style: none; margin: 0; padding: 0 8px; }
.toc-list a { display: flex; gap: 10px; padding: 7px 8px; border-radius: 8px; color: var(--text); text-decoration: none; }
.toc-list a:hover { background: var(--bg); }
.toc-list a[aria-current="page"] { background: var(--bg); color: var(--accent); font-weight: 700; }
.toc-list a.read .toc-num::after { content: " ✓"; color: var(--accent); }
.toc-num { flex: 0 0 2.2em; color: var(--muted); font-variant-numeric: tabular-nums; text-align: right; }
.drawer-foot { margin: 24px 16px 0; color: var(--muted); font-size: 13px; }
.drawer-foot a { color: var(--muted); }

/* ---- popovers (settings, share) ---- */
.popover {
  position: fixed; top: 58px; right: 8px; z-index: 90; width: min(320px, calc(100vw - 16px));
  padding: 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel);
  box-shadow: var(--shadow); font: 14px/1.4 var(--ui);
}
.pop-label { margin: 0 0 6px; color: var(--muted); font-weight: 600; font-size: 12px; letter-spacing: 0.06em; text-transform: uppercase; }
.pop-label + .seg { margin-bottom: 14px; }
.seg { display: flex; gap: 6px; }
.seg button { flex: 1; height: 40px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); cursor: pointer; font: 600 14px var(--ui); }
.seg button[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }
/* each color button shows its own colors */
.seg button[data-theme] { background: var(--bg); color: var(--text); }
.seg button[data-theme][aria-pressed="true"] { border: 2px solid var(--accent); color: var(--text); }
.share-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
.share-grid a, .share-grid button {
  display: flex; align-items: center; gap: 8px; height: 42px; padding: 0 10px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--text);
  text-decoration: none; cursor: pointer; font: 600 14px var(--ui);
}
.share-grid svg { flex: 0 0 18px; }
.share-note { margin: 10px 0 0; color: var(--muted); font-size: 12px; }

/* ---- the page ---- */
.page-inner { display: block; max-width: 700px; margin: 0 auto; padding: 8px 22px 40px; outline: none; }
.normal p { margin: 0 0 1.1em; }
.normal li { margin-bottom: 0.35em; }
.normal ul, .normal ol { padding-left: 1.3em; }
.normal h1, .normal h2, .normal h3 { font-family: var(--ui); color: var(--head); line-height: 1.22; }
.normal h1 { font-size: 1.85em; font-weight: 800; letter-spacing: -0.02em; margin: 1.1em 0 0.5em; }
.normal h2 { font-size: 1.3em; font-weight: 700; letter-spacing: -0.01em; margin: 2em 0 0.6em; }
.normal h3 { font-size: 1.1em; font-weight: 700; margin: 1.8em 0 0.5em; }
.normal .header-section-number { display: none; }
.normal strong { color: var(--head); }
.normal hr { border: 0; border-top: 1px solid var(--line); margin: 2.5em 0; }
.normal blockquote {
  margin: 1.6em 0; padding: 0.9em 1.2em; border-left: 4px solid var(--accent); border-radius: 0 10px 10px 0;
  background: var(--quote); font-style: italic;
}
.normal blockquote p { margin: 0 0 0.6em; }
.normal blockquote p:last-child { margin-bottom: 0; }
.normal blockquote p:last-child:not(:first-child) { font-style: normal; font-size: 0.82em; color: var(--muted); }
.normal img.illustration { display: block; max-width: 100%; height: auto; margin: 1.5em auto; border-radius: 14px; }
.normal p.chapter-meta { margin: -0.2em 0 2em; color: var(--muted); font: 500 0.75em var(--ui); letter-spacing: 0.02em; }
.normal #header .title { margin-top: 0; }

/* next chapter card */
.next-card { margin: 3em 0 1.2em; }
.next-card a {
  display: block; padding: 1.1em 1.3em 1.2em; border: 1px solid var(--line); border-radius: 12px;
  background: var(--panel); color: inherit; text-decoration: none; transition: border-color .15s, transform .15s;
}
.next-card a:hover { border-color: var(--accent); transform: translateY(-1px); }
.next-label { display: block; color: var(--accent); font: 700 0.72em var(--ui); letter-spacing: 0.12em; text-transform: uppercase; }
.next-title { display: block; margin: 0.25em 0 0.2em; color: var(--head); font-size: 1.4em; font-weight: 600; line-height: 1.25; }
.next-meta { display: block; color: var(--muted); font: 0.78em var(--ui); }
.chapter-share { display: flex; justify-content: center; margin: 0 0 1.5em; }
.chapter-share button {
  display: inline-flex; align-items: center; gap: 8px; padding: 10px 16px; border: 1px solid var(--line); border-radius: 999px;
  background: transparent; color: var(--muted); cursor: pointer; font: 600 14px var(--ui);
}
.chapter-share button:hover { color: var(--text); border-color: var(--accent); }
.pager { display: flex; justify-content: space-between; gap: 12px; margin: 0 0 2em; font: 14px/1.35 var(--ui); }
.pager a { flex: 1; max-width: 48%; color: var(--muted); text-decoration: none; }
.pager a span { display: block; font-size: 12px; letter-spacing: 0.06em; text-transform: uppercase; }
.pager a:hover { color: var(--text); }
.pager-next { text-align: right; }
.site-footer { max-width: 700px; margin: 0 auto; padding: 18px 22px calc(28px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); color: var(--muted); font: 13px/1.6 var(--ui); text-align: center; }
.site-footer a { color: var(--muted); }

/* feedback box (site/feedback.js, hidden until switched on) */
#sjo-feedback { margin: 3em 0 1em; padding: 1em 1.2em; border: 1px solid var(--line); border-radius: 10px; font-family: var(--ui); font-size: 0.85em; }
#sjo-feedback h3 { margin-top: 0; }
#sjo-feedback textarea { width: 100%; padding: 0.6em; font: inherit; border-radius: 6px; border: 1px solid var(--line); background: var(--bg); color: inherit; }
#sjo-feedback button { margin-top: 0.6em; padding: 0.5em 1em; border: 0; border-radius: 6px; background: var(--accent); color: var(--accent-ink); font-weight: 700; cursor: pointer; }
#sjo-feedback .sjo-hp { position: absolute; left: -9999px; }

/* ---- homepage hero ---- */
.home-hero { display: flex; align-items: center; justify-content: center; gap: 3em; min-height: calc(100svh - 120px); margin: 0 0 2em; }
.home-hero img.home-cover { flex: 0 0 auto; width: min(clamp(260px, 30vw, 420px), calc((100svh - 140px) * 0.625)); border-radius: 8px; box-shadow: var(--shadow); }
.hero-text { flex: 0 1 26em; }
.home-hero p { text-indent: 0; }
.home-hero p.hero-line { font-size: 1.4em; line-height: 1.35; margin: 0 0 0.6em; color: var(--head); }
.home-hero p.hero-facts { color: var(--muted); font: 0.8em var(--ui); margin: 0 0 1.3em; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 0.6em; margin: 0 0 1em; }
.hero-start, .hero-continue { display: inline-block; padding: 0.7em 1.5em; border-radius: 10px; font: 700 0.9em var(--ui); text-decoration: none; }
.hero-start { background: var(--accent); color: var(--accent-ink); }
.hero-continue { border: 1px solid var(--accent); color: var(--accent); }
.hero-continue[hidden] { display: none; }
.home-hero p.hero-downloads { color: var(--muted); font-size: 0.85em; margin: 0; }
.home-hero p.hero-privacy { color: var(--muted); font: 0.72em/1.5 var(--ui); margin: 1.1em 0 0; }
.forget-place { padding: 0; border: 0; background: none; color: inherit; text-decoration: underline; cursor: pointer; }
.forget-place[hidden] { display: none; }
@media (min-width: 1000px) {
  body.home .page-inner { max-width: 1000px; }
  body.home .normal > *:not(.home-hero):not(#header) { max-width: 656px; margin-left: auto; margin-right: auto; }
}
@media (max-width: 700px) {
  .home-hero { flex-direction: column; text-align: center; gap: 0.9em; min-height: 0; margin-top: 18px; }
  .home-hero img.home-cover { width: max(130px, min(220px, 56vw, calc((100svh - 420px) * 0.625))); }
  .hero-actions { justify-content: center; }
  .home-hero p.hero-line { font-size: 1.15em; margin-bottom: 0.5em; }
  .home-hero p.hero-facts { margin-bottom: 0.9em; }
}

/* ---- phones ---- */
@media (max-width: 600px) {
  :root { --size: 18px; }
  [data-size="s"] { --size: 16px; }
  [data-size="l"] { --size: 20px; }
  [data-size="xl"] { --size: 23px; }
  .page-inner { padding: 4px 18px 32px; }
  .normal h1 { font-size: 1.65em; }
  .tb-contents span, .tb-share span { display: none; }
  .tb-title { font-size: 13px; }
}
@media (min-width: 601px) {
  .tb-btn { padding: 0 12px; }
}
@media print {
  .topbar, .drawer, .scrim, .popover, .read-progress, .pager, .chapter-share, .next-card, .site-footer, .skip-link { display: none !important; }
  body { background: #fff; color: #000; font-size: 12pt; }
  .page-inner { max-width: none; padding: 0; }
  a { color: inherit; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
