:root {
  --ink: #17251f; --muted: #55645d; --paper: #f5f2e8; --card: #fffdf8; --line: #ddd8c8;
  --green: #0b5a40; --green-2: #0e7a55; --amber: #f2b632; --red: #b93a2a; --sc: var(--green);
  --serif: Georgia, 'Iowan Old Style', 'Times New Roman', serif;
  --sans: system-ui, -apple-system, 'Segoe UI', Roboto, 'Noto Sans', Arial, sans-serif;
  --mono: ui-monospace, 'SF Mono', Consolas, 'Roboto Mono', monospace;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 16px/1.55 var(--sans); color: var(--ink); background: var(--paper); min-height: 100vh; display: flex; flex-direction: column; }
h1, h2, h3 { font-family: var(--serif); line-height: 1.2; margin: 0 0 .4em; text-wrap: balance; }
a { color: var(--green); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--amber); outline-offset: 2px; }
[hidden] { display: none !important; }

.topbar { background: var(--green); color: #fff; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 16px; position: sticky; top: 0; z-index: 20; }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; font-family: var(--serif); font-size: 1.1rem; white-space: nowrap; }
.brand b { color: var(--amber); font-weight: 700; }
.topbar nav { display: flex; align-items: center; gap: 12px; font-size: .9rem; }
.topbar nav a { color: #fff; white-space: nowrap; }
.net { font-size: .75rem; background: rgba(255,255,255,.14); padding: 3px 9px; border-radius: 99px; white-space: nowrap; }
.net.off { background: var(--amber); color: #2b2000; }
@media (max-width: 560px) { .net { display: none; } .net.off { display: inline; } }

main { width: 100%; max-width: 1120px; margin: 0 auto; padding: 20px 16px 48px; flex: 1; }
.foot { border-top: 1px solid var(--line); padding: 14px 16px; font-size: .8rem; color: var(--muted); display: flex; flex-wrap: wrap; gap: 6px 24px; justify-content: center; text-align: center; }

.btn { border: 1.5px solid var(--green); background: #fff; color: var(--green); padding: 10px 16px; border-radius: 8px; font-weight: 600; cursor: pointer; min-height: 44px; }
.btn:hover { background: #eef6f1; }
.btn.primary { background: var(--green); color: #fff; }
.btn.primary:hover { background: var(--green-2); }
.btn.ghost { border-color: var(--line); color: var(--muted); }
.btn.danger { border-color: var(--red); color: var(--red); }
.btn.small { min-height: 34px; padding: 4px 12px; border-color: var(--amber); background: var(--amber); color: #2b2000; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.link { background: none; border: 0; padding: 0; color: var(--green); text-decoration: underline; cursor: pointer; }

/* home */
.hero { display: grid; grid-template-columns: 1fr auto; gap: 24px; align-items: end; padding: 18px 0 22px; border-bottom: 2px solid var(--ink); margin-bottom: 18px; }
.eyebrow { text-transform: uppercase; letter-spacing: .08em; font-size: .74rem; font-weight: 700; color: var(--sc); margin: 0 0 8px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.hero h1 { font-size: clamp(1.7rem, 5vw, 2.7rem); max-width: 18ch; }
.lead { color: var(--muted); max-width: 56ch; margin: 0; }
.hero-stat { text-align: right; max-width: 150px; font-size: .8rem; color: var(--muted); line-height: 1.3; }
.hero-stat b { display: block; font: 700 3rem/1 var(--serif); color: var(--green); }
.hero-stat small { font-size: 1.2rem; color: var(--muted); }
@media (max-width: 640px) { .hero { grid-template-columns: 1fr; } .hero-stat { text-align: left; display: flex; align-items: baseline; gap: 10px; max-width: none; } .hero-stat b { font-size: 2rem; } }

.filters { display: grid; gap: 10px; margin-bottom: 8px; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: thin; }
.chips button { flex: none; display: inline-flex; align-items: center; gap: 6px; border: 1.5px solid var(--line); background: var(--card); border-radius: 99px; padding: 7px 14px; cursor: pointer; font-size: .88rem; min-height: 40px; }
.chips button .ico { color: var(--sc); }
.chips button.on { background: var(--ink); border-color: var(--ink); color: #fff; }
.chips button.on .ico { color: var(--amber); }
.filter-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; justify-content: space-between; }
input[type=search], .fields input, textarea, select, input[type=number], input[type=text] { border: 1.5px solid var(--line); border-radius: 8px; padding: 9px 12px; background: #fff; min-height: 44px; max-width: 100%; }
#f-q { flex: 1 1 200px; max-width: 320px; }

.subject { margin-top: 26px; }
.subject h2 { display: flex; align-items: center; gap: 10px; font-size: 1.3rem; color: var(--sc); border-bottom: 1px solid var(--line); padding-bottom: 8px; }
.subject h2 small { font: 500 .8rem var(--sans); color: var(--muted); margin-left: auto; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; margin-top: 14px; }
.card { background: var(--card); border: 1px solid var(--line); border-top: 4px solid var(--sc); border-radius: 10px; padding: 14px 16px; text-decoration: none; color: var(--ink); display: flex; flex-direction: column; gap: 6px; transition: transform .12s, box-shadow .12s; }
.card:hover { transform: translateY(-2px); box-shadow: 0 6px 18px rgba(23,37,31,.1); }
.card-top { display: flex; justify-content: space-between; align-items: center; }
.badge { color: var(--sc); display: inline-flex; }
.lvl { font: 600 .72rem var(--mono); background: #efeada; padding: 2px 8px; border-radius: 4px; }
.card h3 { font-size: 1.08rem; margin: 2px 0 0; }
.card p { margin: 0; font-size: .88rem; color: var(--muted); flex: 1; }
.card-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: .74rem; color: var(--muted); border-top: 1px dashed var(--line); padding-top: 8px; margin-top: 4px; }
.chip { padding: 2px 8px; border-radius: 99px; font-weight: 600; white-space: nowrap; }
.chip.done { background: #d9efe2; color: #0b5a40; }
.chip.started { background: #fbeec6; color: #6b4c00; }
.empty { color: var(--muted); background: #efeada; border-radius: 8px; padding: 14px 16px; }

/* lab page */
.back { display: inline-block; font-size: .88rem; margin-bottom: 10px; }
.lab-head h1 { font-size: clamp(1.5rem, 4.5vw, 2.2rem); }
.tabs { display: flex; gap: 2px; overflow-x: auto; border-bottom: 2px solid var(--ink); margin: 14px 0 18px; position: sticky; top: 50px; background: var(--paper); z-index: 10; padding-top: 6px; }
.tabs button { flex: 1 0 auto; border: 0; background: none; padding: 10px 14px; font-weight: 600; color: var(--muted); cursor: pointer; border-radius: 8px 8px 0 0; min-height: 44px; }
.tabs button[aria-selected=true] { background: var(--ink); color: #fff; }
.count { background: var(--amber); color: #2b2000; border-radius: 99px; padding: 0 7px; font-size: .78rem; }
.count:empty { display: none; }
.panel h2 { font-size: 1.15rem; margin-top: 1.2em; }
.panel h2:first-child { margin-top: 0; }
.guide { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(220px, 1fr); gap: 28px; }
.guide aside { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 16px; align-self: start; }
.guide aside ul { padding-left: 1.1em; margin: 0 0 16px; }
.guide ol { padding-left: 1.3em; } .guide li { margin-bottom: 6px; }
.callout { border-left: 4px solid var(--amber); background: #fbf3d9; padding: 10px 14px; border-radius: 0 8px 8px 0; font-size: .92rem; margin-top: 16px; }
@media (max-width: 760px) { .guide { grid-template-columns: 1fr; } }
.formula { font-family: var(--serif); font-size: 1.05rem; background: #efeada; padding: 6px 12px; border-radius: 6px; display: inline-block; }

/* simulations */
.sim { background: var(--card); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(260px, 1fr); }
.sim.wide { grid-template-columns: 1fr; }
.stage { background-color: #fbfaf4; background-image: linear-gradient(#e7e2d2 1px, transparent 1px), linear-gradient(90deg, #e7e2d2 1px, transparent 1px); background-size: 20px 20px; padding: 12px; display: flex; align-items: center; justify-content: center; min-height: 260px; }
.stage svg { width: 100%; height: auto; max-height: 62vh; display: block; }
.ctls { padding: 16px; display: flex; flex-direction: column; gap: 12px; border-left: 1px solid var(--line); }
.sim.wide .ctls { border-left: 0; border-top: 1px solid var(--line); }
@media (max-width: 760px) { .sim { grid-template-columns: 1fr; } .ctls { border-left: 0; border-top: 1px solid var(--line); } }
.ctl { display: grid; gap: 4px; font-size: .9rem; font-weight: 600; }
.ctl output { font-family: var(--mono); color: var(--sc); }
.ctl input[type=range] { width: 100%; accent-color: var(--sc); min-height: 32px; }
.ctl select, .ctl input { font-weight: 400; width: 100%; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row .btn { flex: 1 1 auto; }
.readouts { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 8px; }
.readout { background: #14211b; color: #c7f7d4; border-radius: 8px; padding: 8px 10px; }
.readout span { display: block; font-size: .7rem; color: #9db5a8; text-transform: uppercase; letter-spacing: .05em; }
.readout b { font: 600 1.25rem var(--mono); }
.note { font-size: .9rem; background: #efeada; border-radius: 8px; padding: 10px 12px; margin: 0; min-height: 44px; }
.note.ok { background: #d9efe2; } .note.bad { background: #f7ddd7; } .note.warn { background: #fbeec6; }
.hint { font-size: .88rem; color: var(--muted); }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button { border: 1.5px solid var(--line); background: #fff; border-radius: 8px; padding: 8px 12px; cursor: pointer; min-height: 42px; font-size: .9rem; }
.seg button.on { background: var(--sc); border-color: var(--sc); color: #fff; }
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font-size: .9rem; }
.list li { display: flex; justify-content: space-between; align-items: center; gap: 8px; background: #f3efe2; border-radius: 6px; padding: 6px 10px; }
.x { border: 0; background: none; color: var(--red); font-size: 1.2rem; cursor: pointer; min-width: 32px; min-height: 32px; }
.bar { height: 14px; border-radius: 99px; background: #e7e2d2; overflow: hidden; display: flex; }
.bar i { display: block; height: 100%; }
.sw { fill: #fff; stroke: #17251f; stroke-width: 2; }
svg text { font-family: var(--sans); }
svg .lbl { font-size: 12px; fill: #44524b; }
svg .clk { cursor: pointer; }

/* results */
.tablewrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
table.results { border-collapse: collapse; width: 100%; font-size: .9rem; }
.results th, .results td { padding: 8px 10px; border-bottom: 1px solid #ece7d8; text-align: left; vertical-align: top; }
.results th { background: #efeada; font-weight: 700; white-space: nowrap; }
.results td { font-variant-numeric: tabular-nums; }
.results tr:last-child td { border-bottom: 0; }
#graph, .graph-img { width: 100%; max-width: 720px; height: auto; border: 1px solid var(--line); border-radius: 8px; display: block; background: #fff; }
.fitline { font-size: .92rem; }
.analysis { background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--sc); border-radius: 0 8px 8px 0; padding: 12px 16px; }
.analysis p { margin: 0 0 6px; } .analysis p:last-child { margin: 0; }
details summary { cursor: pointer; color: var(--green); font-weight: 600; }

/* quiz */
.q { border: 1px solid var(--line); border-radius: 10px; background: var(--card); margin: 0 0 14px; padding: 12px 16px; }
.q legend { font-weight: 700; padding: 0 6px; }
.opt { display: flex; gap: 10px; align-items: flex-start; padding: 8px 6px; border-radius: 6px; cursor: pointer; min-height: 40px; }
.opt:hover { background: #f3efe2; }
.opt input { margin-top: 5px; accent-color: var(--green); }
.q.right { border-color: #7fc09c; } .q.wrong { border-color: #e0a096; }
.opt.correct { background: #d9efe2; font-weight: 600; }
.why { font-size: .9rem; margin: 8px 0 0; color: var(--muted); }
.score { font-size: 1.15rem; }

/* report */
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.fields label { display: grid; gap: 4px; font-size: .85rem; font-weight: 600; }
textarea { width: 100%; resize: vertical; }
.sheet { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 28px; margin-top: 24px; box-shadow: 0 2px 10px rgba(0,0,0,.05); }
.sheet header { display: grid; grid-template-columns: 1fr auto; gap: 16px; border-bottom: 2px solid var(--ink); padding-bottom: 12px; margin-bottom: 12px; }
.sheet-sub { text-transform: uppercase; letter-spacing: .08em; font-size: .72rem; font-weight: 700; margin: 0 0 4px; color: var(--muted); }
.sheet dl { margin: 0; font-size: .85rem; display: grid; gap: 2px; min-width: 200px; }
.sheet dl div { display: flex; gap: 8px; } .sheet dt { font-weight: 700; min-width: 54px; } .sheet dd { margin: 0; border-bottom: 1px dotted #999; flex: 1; min-height: 1.3em; }
.sheet h3 { font-size: 1rem; margin: 16px 0 4px; }
.sheet p, .sheet ol { margin: 0 0 6px; } .pre { white-space: pre-wrap; }
.blank { display: block; height: 4.5em; border-bottom: 1px dotted #999; }
.sign { margin-top: 28px !important; font-size: .9rem; } .sheet-score { font-weight: 700; }
@media (max-width: 600px) { .sheet { padding: 16px; } .sheet header { grid-template-columns: 1fr; } }

.prose { max-width: 820px; } .prose h1 { font-size: 2rem; } .prose h2 { font-size: 1.2rem; margin-top: 1.6em; }

.toast { position: fixed; left: 50%; bottom: 20px; transform: translate(-50%, 80px); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 99px; font-size: .9rem; opacity: 0; transition: transform .2s, opacity .2s; z-index: 50; max-width: 90vw; pointer-events: none; }
.toast.show { transform: translate(-50%, 0); opacity: 1; }
.toast.ok { background: var(--green); } .toast.warn { background: #7a5200; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

@media print {
  body { background: #fff; }
  .topbar, .foot, .tabs, .back, .lab-head, .noprint, .toast, .panel:not([data-panel=report]) { display: none !important; }
  main { padding: 0; max-width: none; }
  .sheet { border: 0; box-shadow: none; padding: 0; margin: 0; }
  .tablewrap { overflow: visible; }
  .graph-img { max-width: 480px; }
  h3 { break-after: avoid; } table, img { break-inside: avoid; }
}
