:root {
  --bg: #f6f5f1;
  --card: #ffffff;
  --ink: #1d232b;
  --muted: #5a636e;
  --line: #e2dfd7;
  --navy: #1d2a3a;
  --navy2: #2b3b50;
  --accent: #ffd23f;
  --link: #1f5fbf;
  --note: #fff7dc;
  --noteline: #e8c54a;
  --mark: #ffe27a;
  --head: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #13171c;
    --card: #1b2128;
    --ink: #e5e8ec;
    --muted: #9ba5b0;
    --line: #2b333c;
    --link: #82b2ff;
    --note: #29250f;
    --noteline: #8a7426;
    --mark: #6b5a12;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: calc(var(--head) + 12px); }
body {
  margin: 0;
  font: 17px/1.6 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
}
body.locked { overflow: hidden; }
a { color: var(--link); }
button { font: inherit; color: inherit; cursor: pointer; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- header ---------- */
.top {
  position: sticky; top: 0; z-index: 20;
  background: var(--navy); color: #fff;
  padding-top: env(safe-area-inset-top);
  box-shadow: 0 1px 0 rgba(0,0,0,.2);
}
.top-row {
  max-width: 1280px; margin: 0 auto;
  display: flex; align-items: center; gap: 14px;
  padding: 10px 20px;
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; font-weight: 700; white-space: nowrap; }
.brand-mark { background: var(--accent); color: var(--navy); border-radius: 7px; padding: 3px 7px; font-size: 13px; letter-spacing: .05em; }
.tabs { display: flex; gap: 4px; }
.tabs a { color: #c9d3df; text-decoration: none; padding: 7px 12px; border-radius: 8px; font-weight: 600; font-size: 15px; white-space: nowrap; }
.tabs a:hover { color: #fff; }
.tabs a.on { background: rgba(255,255,255,.15); color: #fff; }
.search { flex: 1; position: relative; min-width: 0; }
.search svg, .toc-btn svg { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.search svg { position: absolute; left: 11px; top: 50%; width: 18px; height: 18px; transform: translateY(-50%); color: #8fa0b3; pointer-events: none; }
.search input {
  width: 100%; height: 40px; border: 0; border-radius: 10px;
  padding: 0 12px 0 37px; font: inherit; font-size: 16px;
  background: var(--navy2); color: #fff;
}
.search input::placeholder { color: #93a3b6; }
.search input:focus { outline: 2px solid var(--accent); outline-offset: 0; }
.lang { display: flex; background: var(--navy2); border-radius: 10px; padding: 3px; flex: none; }
.lang button { border: 0; background: none; color: #c9d3df; font-weight: 700; font-size: 14px; line-height: 1; padding: 9px 11px; border-radius: 7px; }
.lang button.on { background: var(--accent); color: var(--navy); }
.toc-btn { display: none; border: 0; background: var(--navy2); color: #fff; width: 40px; height: 40px; border-radius: 10px; padding: 9px; flex: none; }
.toc-btn svg { width: 22px; height: 22px; }

/* ---------- layout ---------- */
.layout {
  max-width: 1280px; margin: 0 auto;
  display: grid; grid-template-columns: 290px minmax(0, 1fr); gap: 36px;
  padding: 0 20px;
}
main { padding: 8px 0 80px; min-width: 0; max-width: 860px; outline: none; }
.toc {
  position: sticky; top: var(--head); align-self: start;
  max-height: calc(100vh - var(--head)); overflow: auto;
  padding: 24px 6px 40px 0;
  font-size: 14px; line-height: 1.4;
}
.toc h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0 0 8px 10px; }
.toc a { display: block; padding: 6px 10px; border-radius: 8px; color: var(--ink); text-decoration: none; border-left: 3px solid transparent; }
.toc a:hover { background: rgba(127,127,127,.1); }
.toc a.active { border-left-color: var(--accent); background: rgba(127,127,127,.12); font-weight: 600; }
.toc-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 30; }

/* ---------- content ---------- */
.chapter { scroll-margin-top: calc(var(--head) + 8px); }
.chapter > h2 {
  font-size: 25px; line-height: 1.25; letter-spacing: -.01em;
  margin: 36px 0 16px; padding-bottom: 10px;
  border-bottom: 2px solid var(--line);
}
.point {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 16px 22px 18px; margin: 0 0 14px;
  scroll-margin-top: calc(var(--head) + 12px);
}
.point-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.num {
  display: inline-block; font-weight: 800; font-size: 14px; line-height: 1.5;
  background: var(--navy); color: #fff; border-radius: 7px; padding: 1px 9px;
  text-decoration: none; white-space: nowrap;
}
@media (prefers-color-scheme: dark) { .num { background: #34485f; } }
.has-visual { font-size: 12px; color: var(--muted); font-weight: 600; }
.mini-lang {
  margin-left: auto; border: 1px solid var(--line); background: none; border-radius: 7px;
  font-size: 12px; font-weight: 700; padding: 3px 8px; color: var(--muted);
}
.mini-lang:hover { color: var(--ink); border-color: var(--muted); }
.mini-lang.on { background: var(--accent); color: var(--navy); border-color: var(--accent); }
.point-body p { margin: 0 0 .55em; }
.point-body p:last-child { margin-bottom: 0; }
.point-body p.li { position: relative; padding-left: 1.2em; }
.point-body p.li::before { content: ""; position: absolute; left: .3em; top: .72em; width: 5px; height: 5px; border-radius: 50%; background: var(--muted); }

.visual { margin: 16px 0 4px; }
.zoom { display: block; position: relative; width: 100%; padding: 0; border: 0; background: none; text-align: left; }
.visual img { display: block; width: 100%; height: auto; border-radius: 10px; border: 1px solid var(--line); background: #f7f6f2; }
.expand {
  position: absolute; right: 10px; bottom: 10px; width: 38px; height: 38px;
  display: grid; place-items: center; border-radius: 50%;
  background: rgba(29,42,58,.85); color: #fff; font-size: 19px; line-height: 1;
  box-shadow: 0 2px 6px rgba(0,0,0,.25);
}
.visual figcaption { font-size: 14px; color: var(--muted); margin-top: 6px; }
.tag { display: inline-block; font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; border: 1px solid var(--line); border-radius: 5px; padding: 0 5px; margin-left: 4px; color: var(--muted); vertical-align: 1px; }

.refs { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.ref {
  display: inline-flex; align-items: center; gap: 6px; text-decoration: none; color: var(--ink);
  border: 1px solid var(--line); border-radius: 9px; padding: 3px 9px 3px 4px; font-size: 13px; font-weight: 600;
  background: var(--bg);
}
.ref img { width: 28px; height: 28px; object-fit: contain; }
.ref:hover { border-color: var(--muted); }

.notes {
  margin-top: 14px; padding: 9px 12px; border-radius: 8px;
  background: var(--note); border-left: 3px solid var(--noteline);
  font-size: 14px; line-height: 1.5; color: var(--muted);
}
.notes p { margin: 0 0 4px; }
.notes p:last-child { margin: 0; }
.notes b { color: var(--ink); }

.intro { color: var(--muted); margin-bottom: 16px; }
.intro p { margin: 0 0 .5em; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.card {
  display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 10px 12px;
  scroll-margin-top: calc(var(--head) + 16px);
}
.card:hover { border-color: var(--muted); }
.card-img { display: flex; justify-content: center; gap: 4px; height: 84px; align-items: center; }
.card-img img { max-height: 84px; max-width: 100%; object-fit: contain; }
.card-img.many img { max-height: 56px; max-width: 30%; }
.card-num { font-weight: 800; font-size: 14px; }
.card-name { font-size: 13.5px; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.general { margin-top: 14px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 16px; }
.general summary { font-weight: 700; cursor: pointer; }
.general .point-body { margin-top: 8px; font-size: 15.5px; }
.flash { animation: flash 1.8s ease-out; }
@keyframes flash { 0%, 30% { box-shadow: 0 0 0 4px var(--accent); } 100% { box-shadow: 0 0 0 4px transparent; } }

/* ---------- search ---------- */
.search-head { margin: 24px 0 8px; }
.search-head h1 { font-size: 22px; margin: 0; }
.search-head p { margin: 2px 0 0; color: var(--muted); font-size: 14px; }
.hits > h2 { font-size: 18px; margin: 24px 0 10px; }
.count { color: var(--muted); font-weight: 600; font-size: 14px; }
.hit {
  display: flex; gap: 14px; align-items: flex-start; text-decoration: none; color: var(--ink);
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin-bottom: 8px;
}
.hit:hover { border-color: var(--muted); }
.hit-main { flex: 1; min-width: 0; }
.hit-top { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.hit-ch { font-size: 13px; color: var(--muted); }
.snip { margin: 6px 0 0; font-size: 15px; line-height: 1.5; }
.hit-thumb { width: 120px; height: auto; border-radius: 6px; border: 1px solid var(--line); flex: none; }
.hit-sign { width: 52px; height: 52px; object-fit: contain; flex: none; }
mark { background: var(--mark); color: inherit; border-radius: 3px; padding: 0 1px; }
.empty { color: var(--muted); margin-top: 24px; }

.foot { margin-top: 40px; padding-top: 16px; border-top: 1px solid var(--line); font-size: 13.5px; color: var(--muted); }

/* ---------- sheet (sign details) ---------- */
.sheet { position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.5); display: flex; align-items: center; justify-content: center; padding: 20px; }
.sheet-panel {
  position: relative; width: 100%; max-width: 640px; max-height: 86vh; overflow: auto;
  background: var(--card); border-radius: 16px; padding: 22px 24px 24px;
  overscroll-behavior: contain;
}
.icon-btn { border: 0; background: rgba(127,127,127,.15); width: 38px; height: 38px; border-radius: 50%; font-size: 17px; line-height: 1; flex: none; }
.sheet-close { position: sticky; float: right; top: 0; margin: -6px -8px 0 8px; z-index: 1; }
.sheet-imgs { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 12px; }
.sheet-img { width: auto; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 12px; color: var(--muted); }
.sheet-img img { width: 110px; height: 110px; object-fit: contain; }
.sheet-title { font-size: 21px; line-height: 1.3; margin: 0 0 12px; }
.sheet-title .num { vertical-align: 3px; margin-right: 4px; }
.sheet h3 { font-size: 14px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 20px 0 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips .num { font-size: 14px; }

/* ---------- lightbox ---------- */
.lightbox { position: fixed; inset: 0; z-index: 60; background: #0b0f14; display: flex; flex-direction: column; }
.lb-bar { display: flex; align-items: center; gap: 8px; padding: calc(8px + env(safe-area-inset-top)) 12px 8px; color: #fff; }
.lb-bar .icon-btn { background: rgba(255,255,255,.14); color: #fff; }
.lb-title { flex: 1; min-width: 0; font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-scroll { flex: 1; overflow: auto; display: flex; padding: 8px; -webkit-overflow-scrolling: touch; }
.lb-scroll img { margin: auto; max-width: 100%; max-height: 100%; object-fit: contain; background: #f7f6f2; border-radius: 6px; cursor: zoom-in; }
.lightbox.zoomed .lb-scroll img { max-width: none; max-height: none; width: 260%; cursor: zoom-out; }
@media (min-width: 900px) { .lightbox.zoomed .lb-scroll img { width: 180%; } }

/* ---------- mobile ---------- */
@media (max-width: 900px) {
  .top-row { flex-wrap: wrap; gap: 8px; padding: 8px 12px 6px; }
  .brand { display: none; }
  .toc-btn { display: block; }
  .tabs { order: 4; width: 100%; }
  .tabs a { flex: 1; text-align: center; padding: 6px 4px; }
  .layout { display: block; padding: 0 12px; }
  .toc {
    position: fixed; top: 0; bottom: 0; left: 0; z-index: 35;
    width: min(86vw, 340px); max-height: none;
    background: var(--card); padding: calc(18px + env(safe-area-inset-top)) 10px 30px;
    transform: translateX(-105%); transition: transform .22s ease;
    box-shadow: 2px 0 18px rgba(0,0,0,.25);
  }
  .toc.open { transform: none; }
  .toc a { padding: 9px 10px; font-size: 15px; }
  body { font-size: 16.5px; }
  .chapter > h2 { font-size: 21px; margin-top: 28px; }
  .point { padding: 14px 15px 16px; border-radius: 12px; }
  .visual { margin-left: -6px; margin-right: -6px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
  .sheet { padding: 0; align-items: flex-end; }
  .sheet-panel { max-width: none; max-height: 88vh; border-radius: 16px 16px 0 0; padding: 18px 16px calc(24px + env(safe-area-inset-bottom)); }
  .hit { flex-direction: column-reverse; gap: 8px; }
  .hit-thumb { width: 100%; }
  .hit-sign { width: 44px; height: 44px; }
  .hit.sign-hit { flex-direction: row; }
}
