:root {
  color-scheme: light dark;
  --bg: #fff;
  --elev: #fff;
  --text: #111;
  --muted: #6b6b70;
  --line: rgba(60, 60, 67, .18);
  --fill: #f2f2f7;
  --fill-strong: rgba(60, 60, 67, .2);
  --sel: rgba(255, 149, 0, .4);
  --lit: rgba(255, 204, 0, .45);
  --sheet: #fff;
  --accent: #0a6cff;
  --shadow: 0 8px 28px rgba(0, 0, 0, .18);
  --gutter: 16px;
  --measure: 720px;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --serif: ui-serif, "New York", "Iowan Old Style", Georgia, serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000;
    --elev: #1c1c1e;
    --text: #f2f2f7;
    --muted: #98989f;
    --line: rgba(235, 235, 245, .2);
    --fill: #1c1c1e;
    --fill-strong: rgba(235, 235, 245, .22);
    --sel: rgba(255, 159, 10, .5);
    --lit: rgba(255, 214, 10, .34);
    --sheet: #1c1c1e;
    --accent: #4da3ff;
    --shadow: 0 8px 28px rgba(0, 0, 0, .6);
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.4 var(--sans);
  padding-bottom: calc(64px + env(safe-area-inset-bottom));
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:focus-visible, input:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.muted { color: var(--muted); }
.center { text-align: center; }
.small-text { font-size: 13px; }
.digits { font-variant-numeric: tabular-nums; }
.icon { display: inline-flex; }
.icon-btn { width: 44px; height: 44px; display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; }
.icon-btn.small { width: 32px; height: 32px; }
.icon-btn.round { background: var(--fill); color: var(--muted); }
.icon-btn:hover { background: var(--fill); }

#bar {
  position: sticky; top: 0; z-index: 10; height: calc(52px + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) max(10px, calc((100% - var(--measure)) / 2 + 6px)) 0;
  display: grid; grid-template-columns: 64px 1fr 64px; align-items: center;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
#bar .side { position: relative; display: flex; align-items: center; }
#bar .side.end { justify-content: flex-end; }
#bar .center { display: flex; justify-content: center; gap: 12px; min-width: 0; }
.picker-btn { display: inline-flex; align-items: center; gap: 5px; min-height: 44px; font-size: 17px; font-weight: 600; white-space: nowrap; min-width: 0; }
.picker-btn > span:first-child { overflow: hidden; text-overflow: ellipsis; }
.picker-btn .icon svg { width: 12px; height: 12px; stroke-width: 3; }
.capsule { display: inline-flex; align-items: center; gap: 3px; height: 28px; padding: 0 9px; border-radius: 14px; background: var(--fill); font-size: 13px; font-weight: 600; }
.capsule svg { width: 13px; height: 13px; }

.menu {
  position: absolute; right: 0; top: calc(100% + 4px); z-index: 20; min-width: 250px; max-width: calc(100vw - 20px);
  background: var(--elev); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 4px;
}
.menu-group + .menu-group { border-top: 1px solid var(--line); margin-top: 4px; padding-top: 4px; }
.menu-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px; border-radius: 8px; text-align: left; font-size: 15px; cursor: pointer; }
.menu-item:hover { background: var(--fill); }
.menu-item .abbr { font-weight: 600; }
.menu-item.check { display: grid; grid-template-columns: auto auto 1fr; }
.menu-item.check .muted { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-item.check input { width: 18px; height: 18px; margin: 0; }
.menu-anchor { position: relative; }
.card-menu { min-width: 210px; }

#reader { max-width: var(--measure); margin: 0 auto; }
.card { position: relative; padding: 20px var(--gutter) 22px; }
.card + .card::before { content: ""; position: absolute; top: 0; left: var(--gutter); right: var(--gutter); border-top: 1px solid var(--line); }
.card-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.card-head h2 { margin: 0; font-size: 19px; line-height: 1.3; font-weight: 700; white-space: nowrap; flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.card-title { flex: 1 1 0; min-width: 0; text-align: right; font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-head .menu-anchor { margin-right: -8px; }
.card-head .icon-btn { color: var(--muted); }

.text { margin: 0; font-size: 22px; line-height: 1.55; overflow-wrap: break-word; }
.text.en { font-family: var(--serif); line-height: 1.5; }
.text.ja { font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic", "Noto Sans JP", Meiryo, sans-serif; line-height: 1.65; }
.text.zh { font-family: "PingFang SC", "Noto Sans SC", "Microsoft YaHei", sans-serif; line-height: 1.7; }
.text.zh:lang(zh-Hant) { font-family: "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif; }
.text.reading { line-height: 2.1; }
.text.reading.en { line-height: 2.2; }
.text.reading.zh { line-height: 2.3; }
.group { white-space: nowrap; }
.text.zh .tok, .text.ja .tok { line-break: strict; }
.tok { border-radius: 4px; }
.tok.linked { cursor: pointer; }
.tok.lit { background: var(--lit); }
.tok.sel { background: var(--sel); }
ruby { ruby-position: over; ruby-align: center; }
rt { font-family: var(--sans); font-size: 10px; line-height: 1; font-weight: 400; color: var(--muted); }
.text.en rt { font-size: 11px; }
.text.zh rt { margin: 0 -1px; }
.vn { font: 12px/1 var(--sans); color: var(--muted); margin-right: 4px; vertical-align: baseline; position: relative; top: -.5em; }
.note { margin: 10px 0 0; font-size: 12px; color: var(--muted); }
.link { color: var(--accent); text-decoration: underline; }
.empty { padding: 64px var(--gutter); text-align: center; color: var(--muted); }
.empty-title { font-size: 20px; font-weight: 600; color: var(--text); margin: 0 0 6px; }

#nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 9; display: flex; justify-content: space-between; align-items: center;
  padding: 6px max(10px, calc((100% - var(--measure)) / 2 + 6px)) calc(6px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
#nav .icon-btn { width: 64px; border-radius: 22px; background: var(--fill); }
#trail { position: fixed; left: 0; right: 0; bottom: calc(64px + env(safe-area-inset-bottom)); z-index: 12; display: flex; justify-content: center; padding: 0 var(--gutter) 8px; pointer-events: none; }
.pill { display: inline-flex; align-items: center; max-width: 100%; background: var(--elev); border: 1px solid var(--line); border-radius: 22px; box-shadow: var(--shadow); font-size: 15px; pointer-events: auto; }
.pill-btn { display: inline-flex; align-items: center; gap: 4px; height: 44px; padding: 0 14px; min-width: 0; white-space: nowrap; }
.pill-btn svg { width: 14px; height: 14px; stroke-width: 3; flex: none; }
.pill-btn strong { overflow: hidden; text-overflow: ellipsis; }
.pill .sep { width: 1px; height: 24px; background: var(--line); }
@media (max-width: 480px) { .pill .next-ref { display: none; } }

dialog {
  --bg: var(--sheet);
  border: 0; padding: 0; color: var(--text); background: var(--bg); width: min(560px, 100%); max-width: 100%;
  max-height: 90dvh; margin: auto auto 0; border-radius: 16px 16px 0 0; box-shadow: var(--shadow); overflow: hidden;
}
dialog[open] { display: flex; flex-direction: column; }
dialog::backdrop { background: rgba(0, 0, 0, .4); }
@media (min-width: 640px) { dialog { margin: auto; border-radius: 16px; max-height: 82vh; } }
.grabber { flex: none; width: 36px; height: 5px; border-radius: 3px; background: var(--fill-strong); margin: 8px auto 0; }
.picker { overflow-y: auto; padding: 12px var(--gutter) calc(16px + env(safe-area-inset-bottom)); min-height: min(60dvh, 520px); }
.sheet-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.sheet-head.top { align-items: flex-start; margin-top: 10px; }
.grow { flex: 1; min-width: 0; }
.title3 { font-size: 20px; line-height: 1.25; display: block; }
.search { margin-bottom: 12px; }
.search-input { width: 100%; height: 40px; border: 0; border-radius: 20px; padding: 0 14px; background: var(--fill); color: var(--text); font: inherit; font-size: 16px; }
.section { margin: 14px 0 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
.grid { display: grid; gap: 6px; }
.books-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.chapters-grid { grid-template-columns: repeat(auto-fill, minmax(52px, 1fr)); }
.tile { min-height: 44px; border-radius: 8px; background: var(--fill); display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 2px 4px; min-width: 0; text-align: center; }
.tile.current { background: var(--fill-strong); font-weight: 700; }
.tile .n1 { font-size: 12.5px; font-weight: 600; max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile.long .n1 { font-size: 10.5px; }
.tile .n2 { font-size: 11px; color: var(--muted); max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 400; }
.tile .digits { font-size: 16px; }
.chips { display: flex; gap: 6px; margin-bottom: 8px; flex-wrap: wrap; }
.chip { padding: 6px 12px; border-radius: 16px; background: var(--fill); font-size: 13px; color: var(--muted); }
.chip.on { background: var(--text); color: var(--bg); font-weight: 600; }
.rel-row { padding: 2px 2px; border-top: 1px solid var(--line); }
.rel-row:first-child { border-top: 0; }
.rel-row.open { background: var(--fill); border-radius: 12px; border-color: transparent; padding: 2px 12px 12px; margin: 4px 0; }
.rel-row.open + .rel-row { border-top-color: transparent; }
.rel-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%; min-height: 44px; text-align: left; }
.rel-ref { font-size: 15px; font-weight: 600; }
.bars { display: inline-flex; gap: 2px; flex: none; }
.bars i { width: 4px; height: 10px; border-radius: 1px; background: var(--text); opacity: .14; }
.bars i.on { opacity: .55; }
.pv { margin-bottom: 8px; }
.pv-text { font-size: 16px; line-height: 1.5; }
.pv-text:lang(en) { font-family: var(--serif); }
mark { background: var(--lit); color: inherit; border-radius: 3px; }
.go { width: 100%; margin-top: 4px; padding: 9px; border-radius: 10px; background: var(--bg); color: var(--accent); font-size: 15px; font-weight: 600; }
.about p { margin: 8px 0; }
.about-row { padding: 8px 0; border-top: 1px solid var(--line); }
.about-row:first-child { border-top: 0; }
.about a { color: var(--accent); }

#toast { position: fixed; left: 50%; bottom: calc(80px + env(safe-area-inset-bottom)); transform: translate(-50%, 10px); background: var(--text); color: var(--bg); padding: 8px 16px; border-radius: 18px; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 30; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (prefers-reduced-motion: reduce) { #toast { transition: none; } }
@media (min-width: 640px) { .text { font-size: 23px; } .card { padding-left: 24px; padding-right: 24px; } .card + .card::before { left: 24px; right: 24px; } }
.picker.tall { height: min(85dvh, 760px); }
@media (prefers-color-scheme: dark) { dialog { --fill: #2c2c2e; --fill-strong: rgba(235, 235, 245, .26); } }
