:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --text: #1b2430;
  --muted: #5d6b7c;
  --line: #dde3ea;
  --brand: #1f4e79;
  --brand-ink: #ffffff;
  --accent: #c6d82f;
  --ok: #1e7d43;
  --ok-bg: #e3f4ea;
  --bad: #b3261e;
  --bad-bg: #fbe6e4;
  --chip: #eef2f7;
  --shadow: 0 1px 3px rgba(20, 30, 50, .08);
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f141b; --card: #18202a; --text: #e6ebf1; --muted: #98a6b6; --line: #2a3542;
    --brand: #6fa8dc; --brand-ink: #0f141b; --chip: #223040;
    --ok: #63c98b; --ok-bg: #173325; --bad: #f08b83; --bad-bg: #3a1d1b; --shadow: none;
  }
}
:root[data-theme="dark"] {
  --bg: #0f141b; --card: #18202a; --text: #e6ebf1; --muted: #98a6b6; --line: #2a3542;
  --brand: #6fa8dc; --brand-ink: #0f141b; --chip: #223040;
  --ok: #63c98b; --ok-bg: #173325; --bad: #f08b83; --bad-bg: #3a1d1b; --shadow: none;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--brand); outline-offset: 3px; }
#web-topic, #web-count { margin: 6px 0 14px; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
a { color: var(--brand); }
img { max-width: 100%; }
h1 { font-size: 1.5rem; margin: .2rem 0 .8rem; line-height: 1.25; }
h2 { font-size: 1.15rem; margin: 1.4rem 0 .6rem; }
h3 { font-size: 1rem; margin: 0 0 .3rem; }
p { margin: .4rem 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

.topbar {
  position: sticky; top: 0; z-index: 5; background: var(--brand); color: var(--brand-ink);
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
}
.brand { color: inherit; text-decoration: none; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.brand img { width: 26px; height: 26px; }

main { max-width: 760px; margin: 0 auto; padding: 16px; outline: none; }

.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 5; display: flex;
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  flex: 1; text-align: center; padding: 6px 0 8px; font-size: .72rem; color: var(--muted);
  text-decoration: none; display: flex; flex-direction: column; align-items: center; gap: 1px;
}
.tabbar a span { font-size: 1.25rem; line-height: 1.3; }
.tabbar a.active { color: var(--brand); font-weight: 700; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow); margin-bottom: 12px;
}
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.stats { display: grid; gap: 10px; grid-template-columns: repeat(3, 1fr); }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px; text-align: center; }
.stat b { display: block; font-size: 1.5rem; }
.stat span { font-size: .8rem; color: var(--muted); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 0; border-radius: 12px; padding: 12px 18px; font: inherit; font-weight: 600;
  background: var(--brand); color: var(--brand-ink); cursor: pointer; text-decoration: none; min-height: 44px;
}
.btn.secondary { background: var(--chip); color: var(--text); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

.action { display: flex; gap: 14px; align-items: center; text-decoration: none; color: inherit; }
.action .ico { font-size: 1.8rem; width: 44px; text-align: center; }
.action h3 { color: var(--text); }

.bar { height: 8px; background: var(--chip); border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--brand); border-radius: 99px; }

.chips { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0 14px; }
.chip {
  border: 1px solid var(--line); background: var(--card); color: var(--text); border-radius: 99px;
  padding: 7px 14px; font: inherit; font-size: .9rem; cursor: pointer; min-height: 36px;
}
.chip.on { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }

/* Quiz */
.qhead { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 8px; }
.qimg { display: flex; justify-content: center; margin: 6px 0 14px; }
.qimg img { max-height: 200px; border-radius: 8px; background: #fff; }
.qtext { font-size: 1.12rem; font-weight: 600; margin: 4px 0 14px; }
.choices { display: grid; gap: 10px; }
.choice {
  text-align: left; border: 2px solid var(--line); background: var(--card); color: var(--text);
  border-radius: 12px; padding: 12px 14px; font: inherit; cursor: pointer; min-height: 48px;
}
.choice:hover:not(:disabled) { border-color: var(--brand); }
.choice.picked { border-color: var(--brand); }
.choice.right { border-color: var(--ok); background: var(--ok-bg); }
.choice.wrong { border-color: var(--bad); background: var(--bad-bg); }
.choice:disabled { cursor: default; }
.choices.pics { grid-template-columns: repeat(2, 1fr); }
.choices.pics .choice { display: flex; justify-content: center; align-items: center; padding: 10px; }
.choices.pics img { max-height: 110px; }
.feedback { margin-top: 14px; padding: 12px 14px; border-radius: 12px; }
.feedback.ok { background: var(--ok-bg); }
.feedback.no { background: var(--bad-bg); }
.feedback b { display: block; margin-bottom: 2px; }
.page-ref { font-size: .82rem; color: var(--muted); }

/* Study */
.signgrid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.signcard {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px;
  text-align: center; cursor: pointer; font: inherit; color: var(--text);
}
.signcard .pic { height: 96px; display: flex; align-items: center; justify-content: center; }
.signcard img { max-height: 96px; }
.signcard .nm { font-weight: 600; font-size: .9rem; margin-top: 6px; }
.signcard .mn { font-size: .8rem; color: var(--muted); }
.signcard.hidden .nm, .signcard.hidden .mn { visibility: hidden; }
.viewer { text-align: center; touch-action: pan-y; }
.viewer-count { text-align: right; }
.viewer-pic { height: 240px; display: flex; align-items: center; justify-content: center; margin: 4px 0 12px; }
.viewer-pic img { max-height: 240px; max-width: 100%; background: #fff; border-radius: 8px; }
.viewer-text { min-height: 120px; }
.viewer-text h2 { margin: .2rem 0 .3rem; }
.viewer-text p { font-size: 1.05rem; }
.viewer-nav { justify-content: space-between; margin: 12px 0 4px; }
.viewer-nav .btn { flex: 1; }
.fact { display: flex; gap: 12px; align-items: flex-start; padding: 10px 0; border-bottom: 1px solid var(--line); }
.fact:last-child { border-bottom: 0; }
.fact img { width: 64px; flex: none; border-radius: 6px; background: #fff; }
.search { width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); color: var(--text); font: inherit; }

.result-big { font-size: 2.6rem; font-weight: 800; margin: 0; }
.pass { color: var(--ok); }
.fail { color: var(--bad); }
.missed { padding: 12px 0; border-top: 1px solid var(--line); }
.missed img { max-height: 70px; float: right; margin-left: 10px; background: #fff; border-radius: 6px; }
.notice { background: var(--chip); border-radius: 12px; padding: 10px 14px; font-size: .9rem; }

@media (max-width: 420px) {
  .stats { grid-template-columns: repeat(3, 1fr); gap: 6px; }
  .stat b { font-size: 1.25rem; }
}
