:root {
  --bg: #f4f7f8;
  --surface: #ffffff;
  --surface-2: #eef3f5;
  --text: #15232b;
  --muted: #5a6b74;
  --line: #d9e3e7;
  --primary: #007d93;
  --primary-ink: #ffffff;
  --primary-soft: #e0f2f5;
  --accent: #f2b705;
  --ok: #1d8a4e;
  --ok-soft: #e3f4ea;
  --bad: #c63b3b;
  --bad-soft: #fbe7e7;
  --shadow: 0 1px 2px rgba(16, 40, 50, .06), 0 4px 16px rgba(16, 40, 50, .06);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f171b;
    --surface: #17232a;
    --surface-2: #1e2d35;
    --text: #e6eef1;
    --muted: #9db0b9;
    --line: #2b3d46;
    --primary: #2bb3c9;
    --primary-ink: #06181d;
    --primary-soft: #143a43;
    --ok: #4cc283;
    --ok-soft: #153526;
    --bad: #ef7676;
    --bad-soft: #3d1c1e;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f171b; --surface: #17232a; --surface-2: #1e2d35; --text: #e6eef1; --muted: #9db0b9;
  --line: #2b3d46; --primary: #2bb3c9; --primary-ink: #06181d; --primary-soft: #143a43;
  --ok: #4cc283; --ok-soft: #153526; --bad: #ef7676; --bad-soft: #3d1c1e; --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
}
button, select, input { font: inherit; color: inherit; }
a { color: var(--primary); }
.wrap { max-width: 860px; margin: 0 auto; padding: 20px 16px 64px; outline: none; }
.loading { color: var(--muted); text-align: center; padding: 48px 0; }

/* header */
.top { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.top-inner { max-width: 860px; margin: 0 auto; padding: 10px 16px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); font-weight: 700; margin-right: auto; }
.brand-mark { background: var(--primary); color: var(--primary-ink); border-radius: 9px; padding: 3px 7px; font-size: 14px; letter-spacing: .5px; }
.tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 12px; overflow-x: auto; max-width: 100%; }
.tab { border: 0; background: transparent; padding: 7px 12px; border-radius: 9px; cursor: pointer; white-space: nowrap; font-size: 15px; color: var(--muted); text-decoration: none; }
.tab[aria-current="page"] { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: var(--shadow); }
@media (max-width: 520px) {
  .top-inner { padding: 8px 12px; }
  .brand { width: 100%; }
  .tabs { width: 100%; }
  .tab { flex: 1; padding: 7px 6px; font-size: 14px; text-align: center; }
}

/* cards */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.card + .card, .card + .task, .task + .task { margin-top: 16px; }
h1 { font-size: 26px; line-height: 1.25; margin: 4px 0 6px; }
h2 { font-size: 19px; margin: 0 0 4px; }
.muted { color: var(--muted); }
.lead { margin: 0 0 16px; color: var(--muted); }

/* home */
.hero { display: flex; gap: 16px; align-items: center; justify-content: space-between; flex-wrap: wrap; margin-bottom: 16px; }
.progress { flex: 1 1 220px; }
.bar { height: 10px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin-top: 6px; }
.bar > span { display: block; height: 100%; background: var(--primary); border-radius: 99px; transition: width .4s; }

.notice { display: grid; grid-template-columns: 1fr auto; gap: 16px; align-items: center; background: var(--primary-soft); border: 1px solid transparent; }
.notice p { margin: 0 0 12px; font-weight: 600; }
.notice .qr { width: 132px; text-align: center; font-size: 13px; color: var(--muted); }
.notice .qr img { width: 132px; height: 132px; background: #fff; border-radius: 10px; padding: 6px; display: block; }
@media (max-width: 520px) {
  .notice { grid-template-columns: 1fr; }
  .notice .qr { display: none; }
}

.units { list-style: none; padding: 0; margin: 16px 0 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.unit-link { display: flex; gap: 12px; align-items: center; padding: 14px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); text-decoration: none; color: var(--text); min-height: 72px; box-shadow: var(--shadow); transition: border-color .15s, transform .15s; }
a.unit-link:hover { border-color: var(--primary); transform: translateY(-1px); }
.unit-num { flex: none; width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; background: var(--surface-2); color: var(--muted); }
.unit-link.open .unit-num { background: var(--primary); color: var(--primary-ink); }
.unit-link.done .unit-num { background: var(--ok); color: #fff; }
.unit-link.locked { opacity: .55; cursor: not-allowed; box-shadow: none; }
.unit-title { font-weight: 600; line-height: 1.3; }
.unit-sub { font-size: 13px; color: var(--muted); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--line); background: var(--surface); padding: 10px 16px; border-radius: 11px; cursor: pointer; text-decoration: none; color: var(--text); font-weight: 600; min-height: 44px; }
.btn:hover { border-color: var(--primary); }
.btn.primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); padding-left: 0; }
.btn.small { min-height: 34px; padding: 5px 10px; font-size: 14px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.footer-actions { margin-top: 28px; text-align: center; }

/* unit */
.crumbs { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.reading p { margin: 0 0 10px; }
.reading p:last-child { margin-bottom: 0; }
.reading { font-size: 17px; }
.task h2 { margin-bottom: 2px; }
.task .instr { color: var(--muted); margin: 0 0 12px; font-size: 15px; }
.task.card { padding: 18px 18px 10px; }
.item { padding: 10px 0; border-top: 1px dashed var(--line); position: relative; }
.item:first-of-type { border-top: 0; }
.item.ok, .item.bad { border-radius: 10px; padding-left: 10px; padding-right: 10px; border-top-color: transparent; }
.item.ok + .item.ok, .item.bad + .item.bad, .item.ok + .item.bad, .item.bad + .item.ok { margin-top: 6px; }
.nb { white-space: nowrap; }
.item.ok { background: var(--ok-soft); }
.item.bad { background: var(--bad-soft); box-shadow: inset 3px 0 0 var(--bad); }
.q { margin: 0 0 8px; }
.qn { color: var(--muted); font-variant-numeric: tabular-nums; margin-right: 4px; }

.opts { display: flex; flex-wrap: wrap; gap: 8px; }
.opt { border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 8px 12px; cursor: pointer; text-align: left; min-height: 40px; }
.opt:hover { border-color: var(--primary); }
.opt.sel { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.opts.col { flex-direction: column; align-items: stretch; }
.tf-row { display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.tf-row .q { margin: 0; flex: 1 1 260px; }
.tf-row .opts { flex: none; }

.bank { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px; background: var(--surface-2); border-radius: 10px; margin-bottom: 6px; }
.chip { background: var(--surface); border: 1px solid var(--line); border-radius: 99px; padding: 3px 11px; font-size: 15px; }
.chip.used { opacity: .4; text-decoration: line-through; }
select.gap { border: 1px solid var(--line); border-bottom: 2px solid var(--primary); background: var(--surface); border-radius: 8px; padding: 4px 6px; max-width: 100%; margin: 2px 2px; cursor: pointer; }
.cat-row { display: grid; grid-template-columns: 1fr minmax(150px, 220px); gap: 10px; align-items: center; }
.cat-row select.gap { width: 100%; }
.cat-head { display: grid; grid-template-columns: 1fr minmax(150px, 220px); gap: 10px; font-size: 13px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .3px; }

.zone { min-height: 48px; border: 2px dashed var(--line); border-radius: 10px; padding: 6px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.zone.filled { border-style: solid; border-color: var(--primary); }
.zone .ph { color: var(--muted); font-size: 14px; padding: 0 6px; }
.pool { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; align-items: center; }
.tile { border: 1px solid var(--line); background: var(--surface); border-radius: 9px; padding: 6px 11px; cursor: pointer; min-height: 38px; box-shadow: 0 1px 0 var(--line); }
.tile:hover { border-color: var(--primary); }
.zone .tile { background: var(--primary-soft); border-color: transparent; }

.multi { display: flex; flex-wrap: wrap; gap: 8px; padding: 6px 0 10px; }
.multi .item { border: 0; padding: 0; }
.multi .item.ok, .multi .item.bad { padding: 0; background: none; box-shadow: none; }
.multi .item.bad .opt { border-color: var(--bad); box-shadow: 0 0 0 2px var(--bad-soft); }
.multi .item.ok .opt { border-color: var(--ok); }

.checkbar { position: sticky; bottom: 0; margin-top: 18px; padding: 12px 0 calc(12px + env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--bg) 30%); }
.result { margin-top: 16px; padding: 14px 16px; border-radius: var(--radius); font-weight: 600; }
.result.ok { background: var(--ok-soft); color: var(--ok); }
.result.bad { background: var(--bad-soft); color: var(--bad); }
.result .row { margin-top: 12px; }

.hint { margin: 8px 0 0; font-size: 14px; color: var(--text); background: var(--surface); border: 1px dashed var(--accent); border-radius: 8px; padding: 6px 10px; }

.locked-box { text-align: center; padding: 40px 18px; }

/* done */
.done-hero { text-align: center; padding: 32px 18px; background: linear-gradient(135deg, var(--primary-soft), var(--surface)); }
.done-hero .medal { font-size: 56px; line-height: 1; }
.done-hero h1 { margin-top: 12px; }
.cert-form { display: flex; gap: 10px; flex-wrap: wrap; margin: 12px 0; }
.cert-form input { flex: 1 1 240px; border: 1px solid var(--line); border-radius: 11px; padding: 10px 12px; background: var(--surface); min-height: 44px; }
.cert-preview { width: 100%; height: auto; border-radius: 10px; border: 1px solid var(--line); margin-top: 8px; display: block; }
.err { color: var(--bad); font-size: 14px; min-height: 1em; margin: 4px 0 0; }

.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 600; z-index: 50; max-width: calc(100% - 32px); }
