:root {
  --navy: #12355b; --teal: #0e8f8f; --teal-d: #0b6f6f; --orange: #f08a24; --red: #d9534f;
  --bg: #f4f8fa; --card: #ffffff; --ink: #1f2937; --muted: #64748b; --line: #dbe5ea; --soft: #e6f6f4; --warn: #fff4e5; --bad: #fdecec;
  --fs: 1; --radius: 14px; --bar: #12355b;
}
:root[data-theme="dark"] {
  --bg: #0e1a26; --card: #162536; --ink: #e5edf5; --muted: #9db0c2; --line: #263a4f; --soft: #12333a; --warn: #3a2a14; --bad: #3d1f21;
  --navy: #9cc4ee; --teal: #3dbdbd; --teal-d: #6fd3d3; --bar: #12293f;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1a26; --card: #162536; --ink: #e5edf5; --muted: #9db0c2; --line: #263a4f; --soft: #12333a; --warn: #3a2a14; --bad: #3d1f21;
    --navy: #9cc4ee; --teal: #3dbdbd; --teal-d: #6fd3d3; --bar: #12293f;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: calc(16px * var(--fs))/1.55 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; }
a { color: var(--teal-d); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--orange); outline-offset: 2px; }

/* layout */
.bar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 8px; padding: calc(8px + env(safe-area-inset-top)) 12px 8px; background: var(--bar); color: #fff; }
.bar h1 { font-size: 1.05em; margin: 0; flex: 1; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar button { background: transparent; border: 0; color: inherit; padding: 8px 10px; border-radius: 10px; cursor: pointer; font-size: 1.1em; }
.bar button:hover { background: rgba(255,255,255,.15); }
.bar button.lang { font-size: .8em; font-weight: 700; border: 1px solid rgba(255,255,255,.55); padding: 5px 9px; }
main { max-width: 780px; margin: 0 auto; padding: 14px 14px calc(88px + env(safe-area-inset-bottom)); }
.nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: flex; background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.nav a { flex: 1; text-align: center; text-decoration: none; color: var(--muted); font-size: .72em; padding: 8px 2px 7px; }
.nav a svg { display: block; margin: 0 auto 2px; width: 24px; height: 24px; }
.nav a.on { color: var(--teal-d); font-weight: 650; }

/* cards and text */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin: 0 0 12px; }
.card h2, .card h3 { margin: 0 0 6px; }
h2 { font-size: 1.25em; color: var(--navy); margin: 16px 0 8px; }
h3 { font-size: 1.05em; color: var(--navy); }
.muted { color: var(--muted); }
.small { font-size: .85em; }
.center { text-align: center; }
.hero { background: linear-gradient(160deg, #12355b, #0e6f7a 70%, #0e8f8f); color: #fff; border-radius: 18px; padding: 20px 18px; margin: 0 0 14px; }
.hero h2 { color: #fff; margin: 0 0 6px; font-size: 1.4em; }
.hero p { margin: 0 0 12px; opacity: .95; }
.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.grid a.tile, .grid button.tile { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 10px; text-align: center; text-decoration: none; color: var(--ink); font-weight: 600; cursor: pointer; }
.tile .ic { font-size: 1.7em; display: block; margin-bottom: 4px; }
.btn { display: inline-block; background: var(--orange); color: #1a1209; border: 0; border-radius: 12px; padding: 11px 18px; font-weight: 700; text-decoration: none; cursor: pointer; text-align: center; }
.btn.alt { background: transparent; color: inherit; border: 2px solid currentColor; }
.btn.teal { background: var(--teal); color: #fff; }
.btn.small { padding: 6px 12px; font-size: .88em; border-radius: 9px; }
.btn.block { display: block; width: 100%; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
input[type=text], input[type=email], input[type=password], input[type=search], select { width: 100%; padding: 11px 12px; border: 1.5px solid var(--line); border-radius: 10px; background: var(--card); margin: 4px 0 10px; }
label { font-weight: 600; font-size: .92em; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.pill { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: .75em; font-weight: 700; background: var(--soft); color: var(--teal-d); }
.pill.lock { background: var(--warn); color: #b45f06; }
.pill.done { background: #d7f3e3; color: #166534; }
:root[data-theme="dark"] .pill.done { background: #14402a; color: #7ee2a8; }
.bar-progress { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; }
.bar-progress > i { display: block; height: 100%; background: var(--teal); border-radius: 99px; }
.msg { border-radius: 10px; padding: 10px 12px; margin: 0 0 12px; }
.msg.err { background: var(--bad); border-left: 4px solid var(--red); }
.msg.ok { background: var(--soft); border-left: 4px solid var(--teal); }
.msg.warn { background: var(--warn); border-left: 4px solid var(--orange); }

/* chapter list */
.list a.item { display: flex; gap: 12px; align-items: center; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin: 0 0 8px; text-decoration: none; color: var(--ink); }
.list .num { flex: 0 0 34px; height: 34px; border-radius: 50%; background: var(--teal); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: .9em; }
.list .locked .num { background: var(--muted); }
.list .t { flex: 1; min-width: 0; }
.list .t b { display: block; }

/* reader (book content) */
.prose h2 { border-bottom: 3px solid var(--orange); padding-bottom: 3px; margin-top: 26px; }
.prose p, .prose li { max-width: 68ch; }
.prose .box { border-left: 4px solid var(--muted); padding: 8px 12px; margin: 12px 0; border-radius: 0 10px 10px 0; background: var(--card); }
.prose .box b.k { display: block; font-size: .78em; text-transform: uppercase; letter-spacing: .07em; }
.prose .tip { border-left-color: var(--teal); background: var(--soft); }
.prose .remember { border-left-color: var(--orange); background: var(--warn); }
.prose .careful { border-left-color: var(--red); background: var(--bad); }
.prose .tblwrap { overflow-x: auto; margin: 10px 0; -webkit-overflow-scrolling: touch; }
.prose table { border-collapse: collapse; font-size: .85em; min-width: 520px; width: 100%; }
.prose th { background: var(--navy); color: #fff; text-align: left; padding: 6px 8px; }
:root[data-theme="dark"] .prose th { color: #0e1a26; }
.prose td { border-bottom: 1px solid var(--line); padding: 6px 8px; vertical-align: top; }
.prose img.fig { display: block; max-width: 100%; height: auto; margin: 10px auto; background: #fff; border-radius: 10px; border: 1px solid var(--line); cursor: zoom-in; }
.prose figure { margin: 12px 0; text-align: center; }
.prose figcaption { font-size: .82em; color: var(--muted); }
.prose .lead-p { font-size: 1.05em; }
.prose .badge { color: var(--teal-d); font-weight: 700; }
.prose .it { font-style: italic; color: var(--muted); }
.prose .grid2 > div { margin-bottom: 4px; }
.prose .pillars { display: grid; gap: 8px; }
.prose .pillars div { background: var(--card); border: 1px solid var(--line); border-top: 4px solid var(--teal); border-radius: 10px; padding: 8px 10px; }
.sec:target h2 { background: var(--soft); }
.zoom { position: fixed; inset: 0; z-index: 100; background: rgba(0,0,0,.85); overflow: auto; -webkit-overflow-scrolling: touch; touch-action: pan-x pan-y pinch-zoom; }
.zoom img { display: block; width: 220%; max-width: none; margin: 56px auto 40px; background: #fff; }
.zoom button { position: fixed; top: 10px; right: 10px; z-index: 101; }

/* quiz */
.opt { display: block; width: 100%; text-align: left; background: var(--card); border: 2px solid var(--line); border-radius: 12px; padding: 12px 14px; margin: 0 0 8px; cursor: pointer; }
.opt.right { border-color: #16a34a; background: #d7f3e3; color: #14341f; }
.opt.wrong { border-color: var(--red); background: var(--bad); }
.card.flash { text-align: center; min-height: 170px; display: grid; place-items: center; cursor: pointer; }
.card.flash .term { font-size: 1.5em; font-weight: 750; color: var(--navy); }

/* team */
table.t { width: 100%; border-collapse: collapse; font-size: .88em; }
table.t th { text-align: left; border-bottom: 2px solid var(--line); padding: 6px 4px; }
table.t td { border-bottom: 1px solid var(--line); padding: 6px 4px; vertical-align: top; }
code.k { background: var(--soft); padding: 2px 6px; border-radius: 6px; font-size: .95em; letter-spacing: .04em; word-break: break-all; }
.pack { display: block; position: relative; background: var(--card); border: 2px solid var(--line); border-radius: var(--radius); padding: 12px 14px 12px 44px; margin: 0 0 8px; cursor: pointer; }
.pack input { position: absolute; left: 14px; top: 16px; width: 20px; height: 20px; }
.pack.sel { border-color: var(--teal); background: var(--soft); }
.pack .price { float: right; font-weight: 800; font-size: 1.1em; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(86px + env(safe-area-inset-bottom)); background: #111; color: #fff; padding: 9px 16px; border-radius: 99px; z-index: 200; font-size: .9em; }
@media (min-width: 720px) { .grid { grid-template-columns: repeat(4, 1fr); } }
@media print { .bar, .nav, .no-print { display: none !important; } body { background: #fff; } }
@media (prefers-reduced-motion: no-preference) { .card, .opt { transition: border-color .15s, background .15s; } }

.prose table.c1, .prose table.c2, .prose table.c3 { min-width: 0; }
.prose table.c4 { min-width: 440px; }
