:root {
  --bg: #F7F6F2; --card: #FDFCFA; --text: #1E2533; --muted: #4A5568;
  --accent: #2459C7; --hi: #E3893B; --head: #14213D;
  --ok: #1F7A45; --bad: #B42318; --line: #D9D6CC; --on-accent: #fff;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0E1626; --card: #16213A; --text: #E6EAF2; --muted: #A9B3C6;
    --accent: #7FA2FF; --hi: #F0A35E; --head: #F7F6F2;
    --ok: #5BC77A; --bad: #FF7A70; --line: #2B3857; --on-accent: #0E1626;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 1.1rem/1.6 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
h1, h2, h3 { color: var(--head); line-height: 1.25; }
h1 { font-size: 2rem; margin: 1.2rem 0 .4rem; }
h2 { font-size: 1.45rem; margin: 2rem 0 .6rem; }
h3, .h3 { font-size: 1.15rem; margin: 1.2rem 0 .4rem; }
a { color: var(--accent); }
p, li { max-width: 68ch; }
.muted { color: var(--muted); }
.lead { font-size: 1.2rem; color: var(--text); margin: 0 0 1.2rem; max-width: 60ch; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 0; background: var(--accent); color: var(--on-accent); padding: .6rem 1rem; z-index: 50; }
.skip:focus { left: 0; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
h1:focus { outline: none; }

.topbar { display: flex; align-items: center; gap: 1.5rem; flex-wrap: wrap; padding: .6rem 1rem; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.brand { font-weight: 700; font-size: 1.2rem; color: var(--head); text-decoration: none; }
#nav { display: flex; gap: .25rem; flex-wrap: wrap; }
#nav a { display: inline-flex; align-items: center; gap: .35rem; min-height: 44px; padding: 0 .8rem; border-radius: 8px; text-decoration: none; color: var(--text); }
#nav a:hover { background: var(--bg); }
#nav a[aria-current="page"] { color: var(--accent); font-weight: 700; box-shadow: inset 0 -3px 0 var(--hi); }
.notice, .notice-inline { background: var(--card); border: 1px solid var(--hi); border-left-width: 6px; padding: .6rem 1rem; margin: 0; }
.notice-inline { margin: 0 0 1rem; border-radius: 6px; max-width: 68ch; }

main { max-width: 56rem; margin: 0 auto; padding: 0 1rem 3rem; }
main:focus { outline: none; }
.foot { max-width: 56rem; margin: 0 auto; padding: 0 1rem 2rem; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 1rem 1.2rem; margin: .8rem 0; }
.card > :first-child { margin-top: 0; } .card > :last-child { margin-bottom: 0; }
ul.plain, ol.steps { list-style: none; padding: 0; margin: 0; }
.row { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; margin: 1rem 0; }
.crumb { margin: 1rem 0 0; }

.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: .4rem 1.1rem; font: inherit; font-size: 1rem; border: 2px solid var(--accent); background: transparent; color: var(--accent); border-radius: 8px; cursor: pointer; text-decoration: none; }
.btn:hover { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.btn.primary { background: var(--accent); color: var(--on-accent); }
.btn.primary:hover { background: var(--accent); filter: brightness(1.1); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.small { min-height: 44px; padding: .2rem .8rem; }

.meter { height: 14px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.meter-fill { height: 100%; background: var(--hi); transition: width .3s; }
.meter-label { margin: 0 0 .4rem; }
.step-head { display: flex; flex-wrap: wrap; gap: .3rem 1rem; align-items: baseline; }
.step-head h3 { margin: 0; flex: 1 1 14rem; }
.time { color: var(--muted); } .status { font-weight: 600; }
.step.done { border-left: 6px solid var(--ok); } .step.doing { border-left: 6px solid var(--hi); }
.step ul { margin-top: .5rem; }
.list-cards > li { margin: 0; max-width: none; }

.tag-answer { display: inline-block; font-size: .8rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--hi); }
.keyidea { border: 2px solid var(--accent); border-radius: 10px; padding: .8rem 1.2rem; background: var(--card); margin: .6rem 0 1.4rem; }
.keyidea p { margin: .2rem 0 0; font-size: 1.25rem; font-weight: 600; color: var(--head); }
.prose { max-width: 68ch; }
.prose h3 { margin-top: 1.6rem; }
.table-wrap { overflow-x: auto; margin: 1rem 0; }
table { border-collapse: collapse; font-size: .98rem; min-width: 100%; }
th, td { border: 1px solid var(--line); padding: .45rem .6rem; text-align: left; vertical-align: top; }
th { background: var(--card); color: var(--head); }

.before, .after { border-left: 6px solid var(--muted); padding: .2rem 0 .2rem 1rem; margin: .8rem 0; background: transparent; }
.after { border-left-color: var(--accent); }
.lbl { display: inline-block; font-size: .8rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.after .lbl { color: var(--accent); }
.plain-text { white-space: pre-wrap; }
.ba { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.ba > div { min-width: 0; margin: 0; }
.ex-body p, .ex-body li { max-width: none; }
.example { margin: 2rem 0; }
.why { margin: .6rem 0; } .why summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; color: var(--accent); font-weight: 600; }
@media (max-width: 760px) { .ba { grid-template-columns: 1fr; } }

/* quiz and drills */
fieldset { border: 1px solid var(--line); border-radius: 10px; margin: 1rem 0; padding: .8rem 1.2rem; background: var(--card); min-width: 0; }
legend { font-weight: 600; padding: 0 .4rem; color: var(--head); }
.opt { display: flex; gap: .7rem; align-items: flex-start; min-height: 44px; padding: .45rem .3rem; cursor: pointer; }
.opt input { width: 1.3rem; height: 1.3rem; margin-top: .25rem; flex: none; accent-color: var(--accent); }
.feedback { margin: .5rem 0 0; }
.feedback.ok { color: var(--ok); } .feedback.bad { color: var(--bad); }
.feedback strong { white-space: nowrap; }
.items { list-style: decimal; padding-left: 1.6rem; }
.item { display: flex; flex-direction: column; gap: .5rem; }
.item label { font-weight: 500; }
select, textarea, input[type=text] { font: inherit; font-size: 1rem; color: var(--text); background: var(--bg); border: 2px solid var(--line); border-radius: 8px; padding: .5rem .6rem; max-width: 100%; }
select { min-height: 44px; }
textarea.big { width: 100%; max-width: 68ch; display: block; line-height: 1.5; }
.fieldlabel { display: block; margin: 1.2rem 0 .3rem; font-weight: 600; }
.order { list-style: decimal; padding-left: 1.6rem; }
.order-item { flex-direction: row; flex-wrap: wrap; align-items: center; justify-content: space-between; }
.ordtext { flex: 1 1 16rem; } .btns { display: flex; gap: .4rem; }
.result { border-left: 6px solid var(--hi); }
.timer { font-size: 3rem; font-weight: 700; margin: 1rem 0 .2rem; font-variant-numeric: tabular-nums; color: var(--head); }
.prompt { border-left: 6px solid var(--accent); }
pre.tpl { white-space: pre-wrap; word-wrap: break-word; font: .95rem/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: .8rem; margin: .6rem 0 0; overflow-x: auto; }
.tpl-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: .5rem; align-items: center; }
.tpl-head h3 { margin: 0; }

/* build drill */
.tray { display: flex; flex-wrap: wrap; gap: .5rem; margin: .5rem 0 1rem; }
.tray li { max-width: none; }
.cardbtn { font: inherit; font-size: .95rem; text-align: left; min-height: 44px; padding: .5rem .8rem; border: 2px solid var(--line); background: var(--card); color: var(--text); border-radius: 8px; cursor: pointer; max-width: 22rem; }
.cardbtn.sel { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 30%, transparent); }
.cardbtn.sel::before { content: '● Selected: '; font-weight: 700; color: var(--accent); }
.buildpyr { margin: .5rem 0; }
.bp-top { margin-bottom: .8rem; }
.bp-cols { display: grid; grid-template-columns: repeat(3, 1fr); gap: .8rem; }
.bp-col { display: flex; flex-direction: column; gap: .5rem; min-width: 0; }
.slot { font: inherit; font-size: .95rem; text-align: left; width: 100%; min-height: 4.5rem; padding: .5rem .7rem; border: 2px dashed var(--muted); background: var(--card); color: var(--text); border-radius: 8px; cursor: pointer; display: flex; flex-direction: column; gap: .2rem; }
.slot.filled { border-style: solid; border-color: var(--accent); }
.slot.target { border-color: var(--hi); border-style: solid; }
.slot:disabled { cursor: default; color: var(--text); opacity: 1; }
.slotlabel { font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
@media (max-width: 700px) { .bp-cols { grid-template-columns: 1fr; } .bp-col { padding-bottom: .6rem; border-bottom: 1px solid var(--line); } }

/* flashcards */
.boxes { display: flex; gap: .5rem; flex-wrap: wrap; margin: 0 0 .5rem; }
.pill { border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: .15rem .8rem; font-size: .95rem; }
.flash { min-height: 14rem; }
.flash h2 { margin-top: .2rem; }

/* lesson 1 diagram */
.pyr { margin: 1.2rem 0; padding: 1rem; background: var(--card); border: 1px solid var(--line); border-radius: 10px; }
.pyr-grid { display: grid; grid-template-columns: 8.5rem repeat(3, 1fr); column-gap: .7rem; align-items: center; }
.pyr-col { display: contents; }
.pyr-label { font-size: .8rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.pyr-l-top { grid-column: 1; grid-row: 1; } .pyr-top { grid-column: 2 / 5; grid-row: 1; }
.pyr-q-top { grid-column: 2 / 5; grid-row: 2; }
.pyr-l-key { grid-column: 1; grid-row: 3; }
.pyr-l-sup { grid-column: 1; grid-row: 5; }
.c1 > * { grid-column: 2; } .c2 > * { grid-column: 3; } .c3 > * { grid-column: 4; }
.pyr-key { grid-row: 3; } .pyr-col .pyr-q { grid-row: 4; } .pyr-sup { grid-row: 5; }
.pyr-box { border: 2px solid var(--line); border-radius: 8px; padding: .6rem .7rem; font-size: .95rem; background: var(--bg); text-align: center; height: 100%; }
.pyr-box.box-accent { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, var(--card)); font-weight: 700; font-size: 1.05rem; }
.pyr-key { border-color: var(--hi); font-weight: 600; }
.pyr-q { text-align: center; color: var(--accent); font-weight: 700; font-size: .95rem; padding: .3rem 0; }
.pyr-side { margin-top: 1rem; font-weight: 700; color: var(--accent); }
.pyr figcaption { color: var(--muted); font-size: .95rem; margin-top: .2rem; }
@media (max-width: 700px) {
  .pyr-grid { display: block; }
  .pyr-col { display: block; margin: .6rem 0; padding: .5rem; border: 1px dashed var(--line); border-radius: 8px; }
  .pyr-l-top, .pyr-l-key { display: block; margin: .6rem 0 .2rem; }
  .pyr-l-sup { display: none; }
  .pyr-key::before { content: 'Key: '; font-weight: 400; color: var(--muted); }
  .pyr-sup::before { content: 'Support: '; font-weight: 400; color: var(--muted); }
  .pyr-col .pyr-q { padding: .15rem 0; }
}

/* phone: bottom tab bar */
@media (max-width: 700px) {
  body { padding-bottom: 68px; }
  .topbar { position: static; }
  #nav { position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; background: var(--card); border-top: 1px solid var(--line); display: grid; grid-template-columns: repeat(6, 1fr); gap: 0; padding: 0 0 env(safe-area-inset-bottom); }
  #nav a { flex-direction: column; gap: 0; justify-content: center; padding: .2rem 0; font-size: .72rem; border-radius: 0; min-height: 56px; }
  #nav a[aria-current="page"] { box-shadow: inset 0 3px 0 var(--hi); }
  .ico { font-size: 1.15rem; line-height: 1; }
  h1 { font-size: 1.6rem; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

@media print {
  .topbar, #nav, .foot, .notice, .no-print, .skip { display: none !important; }
  body { background: #fff; color: #000; font-size: 11pt; padding: 0; }
  main { max-width: none; padding: 0; }
  .card { border: 1px solid #999; break-inside: avoid; background: #fff; }
  h1, h2, h3 { color: #000; }
  .opt input { accent-color: #000; }
}
