/* teachwithlife - styles. MIT License. */

:root {
  --font: "Atkinson Hyperlegible", "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  --math: "STIX Two Text", "Cambria Math", Cambria, "Times New Roman", serif;

  --bg: #ffffff;
  --surface: #f3f6f8;
  --card: #ffffff;
  --ink: #1a2230;
  --muted: #556070;
  --line: #dce2e8;
  --grid: #eaeef2;
  --axis: #98a3af;

  --primary: #0b6b69;
  --primary-ink: #ffffff;
  --primary-soft: #e2f1f0;

  --a: #0e8a86;  --a-soft: rgba(14, 138, 134, .20);
  --b: #df7a22;  --b-soft: rgba(223, 122, 34, .22);
  --c: #6a4fc8;  --c-soft: rgba(106, 79, 200, .18);
  --d: #d1405f;  --d-soft: rgba(209, 64, 95, .20);

  --good: #1d7a48; --good-soft: #e6f4ec;
  --bad: #b42318;  --bad-soft: #fdecea;
  --idea-bg: #fff6d6; --idea-line: #e2b43a;

  --radius: 12px;
  --measure: 68ch;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10151b;
    --surface: #161d25;
    --card: #19212a;
    --ink: #e8edf2;
    --muted: #a3aeba;
    --line: #2b3541;
    --grid: #232c36;
    --axis: #5a6673;
    --primary: #5ccbc6;
    --primary-ink: #0b1a1a;
    --primary-soft: #16302f;
    --a: #4fd1c8;  --a-soft: rgba(79, 209, 200, .26);
    --b: #f4a25a;  --b-soft: rgba(244, 162, 90, .26);
    --c: #a992ff;  --c-soft: rgba(169, 146, 255, .24);
    --d: #ff7f98;  --d-soft: rgba(255, 127, 152, .24);
    --good: #74d69e; --good-soft: #14281d;
    --bad: #ff8a7a;  --bad-soft: #34191a;
    --idea-bg: #29230f; --idea-line: #a07f24;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 19px;
  line-height: 1.65;
}
img, svg { max-width: 100%; }
a { color: var(--primary); text-underline-offset: 3px; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 3px solid var(--b); outline-offset: 3px; border-radius: 4px; }
h1:focus { outline: none; }
[hidden] { display: none !important; }
.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: 8px; background: var(--card); padding: 8px 14px; border-radius: 8px; }
.skip:focus { left: 12px; z-index: 10; }

/* ---------- header ---------- */
.site-header {
  position: sticky; top: 0; z-index: 5;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--line);
}
.header-inner {
  max-width: 1080px; margin: 0 auto; padding: 12px 24px;
  display: flex; align-items: center; gap: 12px 28px; flex-wrap: wrap;
}
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; font-weight: 700; font-size: 20px; }
.brand-logo { width: 40px; height: 40px; border-radius: 50%; background: #fff; border: 1px solid var(--line); display: block; }
.site-nav { display: flex; gap: 22px; font-size: 17px; }
.site-nav a { color: var(--muted); text-decoration: none; }
.site-nav a:hover { color: var(--ink); }
#header-progress { margin-left: auto; display: flex; align-items: center; gap: 12px; font-size: 15px; color: var(--muted); }
.hp-bar { display: inline-block; width: 110px; height: 8px; border-radius: 4px; background: var(--grid); overflow: hidden; }
.hp-bar i { display: block; height: 100%; background: var(--primary); }

main { max-width: 880px; margin: 0 auto; padding: 48px 24px 80px; }
main:focus { outline: none; }

h1, h2, h3 { line-height: 1.2; letter-spacing: -0.01em; margin: 0; }
h1 { font-size: clamp(32px, 4.4vw, 42px); font-weight: 700; margin-bottom: 18px; }
h2 { font-size: 26px; font-weight: 700; margin: 0 0 14px; }
h3 { font-size: 21px; font-weight: 700; }
p { margin: 0 0 16px; }
.lead { font-size: 22px; color: var(--muted); max-width: 40em; line-height: 1.55; }
.lead.small { font-size: 19px; }

/* ---------- buttons ---------- */
.button {
  display: inline-block; font: inherit; font-size: 18px; font-weight: 700;
  padding: 12px 22px; border-radius: 10px; border: 2px solid var(--line);
  background: var(--card); color: var(--ink); text-decoration: none; cursor: pointer; line-height: 1.3;
}
.button:hover { border-color: var(--muted); }
.button.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.button.primary:hover { filter: brightness(1.08); }
.button.big { font-size: 20px; padding: 15px 28px; }
.button.quiet { background: transparent; }
.button.disabled { opacity: .4; cursor: not-allowed; }
.text-link { font-weight: 700; }

/* ---------- home ---------- */
.hero { padding: 24px 0 56px; border-bottom: 1px solid var(--line); }
.hero h1 { font-size: clamp(40px, 6.4vw, 66px); line-height: 1.06; letter-spacing: -0.025em; max-width: 13em; margin-bottom: 26px; }
.hero .lead { margin-bottom: 34px; }

.how { padding: 52px 0; border-bottom: 1px solid var(--line); }
.how-steps { list-style: none; counter-reset: step; padding: 0; margin: 26px 0 28px; display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 26px; }
.how-steps li { counter-increment: step; display: flex; flex-direction: column; gap: 6px; }
.how-steps li::before { content: counter(step); font-family: var(--math); font-size: 44px; line-height: 1; color: var(--b); }
.how-steps strong { font-size: 21px; }
.how-steps span { color: var(--muted); font-size: 17px; }
.rule { background: var(--surface); border-radius: var(--radius); padding: 18px 22px; max-width: none; }

.units { padding: 52px 0 0; }
.unit-list { list-style: none; padding: 0; margin: 24px 0 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 18px; }
.unit-card { border: 1px solid var(--line); border-radius: var(--radius); padding: 22px 22px 18px; display: flex; flex-direction: column; background: var(--card); }
.unit-no { font-size: 15px; color: var(--muted); margin: 0 0 4px; }
.unit-card h3 { margin-bottom: 8px; }
.unit-sum { color: var(--muted); font-size: 17px; flex: 1; }
.unit-foot { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; font-size: 16px; }
.unit-count, .unit-locked { color: var(--muted); }

/* ---------- map ---------- */
.map-unit { margin: 40px 0; }
.map-list { list-style: none; padding: 0; margin: 0; border-top: 1px solid var(--line); }
.map-item { border-bottom: 1px solid var(--line); }
.map-row { display: grid; grid-template-columns: 3ch 1fr auto; gap: 16px; padding: 12px 6px; align-items: baseline; color: var(--ink); text-decoration: none; }
a.map-row:hover { background: var(--surface); }
.map-no { color: var(--muted); font-variant-numeric: tabular-nums; text-align: right; }
.map-state { font-size: 15px; color: var(--muted); }
.map-item.done .map-state, .map-item.helped .map-state { color: var(--good); font-weight: 700; }
.map-item.open .map-state { color: var(--primary); font-weight: 700; }
.map-item.locked { opacity: .55; }

.prose { max-width: var(--measure); }
.prose h2 { margin-top: 34px; }

/* ---------- exercise ---------- */
.crumb { font-size: 16px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 18px; margin-bottom: 10px; }
.crumb a { color: var(--muted); }
.story { max-width: var(--measure); font-size: 20px; }
.story p { margin-bottom: 14px; }

.eq { font-family: var(--math); font-size: 1.08em; }
.eq i, .story i, .prompt i, .idea i { font-family: var(--math); }

.visual {
  margin: 30px 0 40px; padding: 22px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line);
}
.v-svg { display: block; width: 100%; height: auto; }
.v-controls { display: flex; flex-wrap: wrap; gap: 14px 22px; align-items: flex-end; margin-top: 16px; }
.v-slider { display: flex; flex-direction: column; gap: 4px; min-width: 200px; flex: 1 1 220px; font-size: 16px; color: var(--muted); }
.v-slider output { color: var(--ink); font-weight: 700; }
.v-slider input[type=range] { width: 100%; accent-color: var(--primary); height: 28px; }
.v-btn {
  font: inherit; font-size: 16px; font-weight: 700; padding: 9px 16px; border-radius: 9px;
  background: var(--card); color: var(--ink); border: 2px solid var(--line); cursor: pointer;
}
.v-btn:hover { border-color: var(--muted); }
.v-btn[aria-pressed="true"] { border-color: var(--primary); background: var(--primary-soft); }
.v-btn.quiet { background: transparent; font-weight: 400; }
.v-btn:disabled { opacity: .45; cursor: not-allowed; }
.v-readout { margin: 14px 0 0; font-size: 18px; }
.v-note { margin: 8px 0 0; font-size: 16px; color: var(--bad); min-height: 1em; }
.v-big { font-size: clamp(34px, 6vw, 56px); font-weight: 700; margin: 6px 0; letter-spacing: -0.02em; }
.v-input { font: inherit; font-size: 18px; width: 9em; padding: 8px 12px; border-radius: 9px; border: 2px solid var(--line); background: var(--card); color: var(--ink); }
.v-inline { display: inline-flex; align-items: center; gap: 10px; font-size: 17px; color: var(--muted); }
.v-steps { margin: 16px 0 0; padding-left: 1.4em; }
.v-steps li { margin: 4px 0; }
.v-table-wrap { overflow-x: auto; }
.v-table { border-collapse: collapse; min-width: 260px; background: var(--card); border-radius: 8px; overflow: hidden; font-variant-numeric: tabular-nums; }
.v-table th, .v-table td { padding: 8px 20px; border-bottom: 1px solid var(--line); text-align: right; }
.v-table th { font-size: 16px; color: var(--muted); font-weight: 700; text-align: right; }
.v-table.grid6 { margin-top: 16px; }
.v-table.grid6 th, .v-table.grid6 td { padding: 6px 12px; text-align: center; }
.v-legend { display: flex; flex-wrap: wrap; gap: 6px 20px; margin-top: 12px; font-size: 15px; color: var(--muted); }
.v-legend span { display: inline-flex; align-items: center; gap: 7px; }
.sw { display: inline-block; width: 22px; height: 12px; border-radius: 3px; background: var(--muted); }
.sw.ca, .sw.fa { background: var(--a); } .sw.cb, .sw.fb { background: var(--b); } .sw.cc, .sw.fc { background: var(--c); }
.sw.cu, .sw.fd { background: var(--d); } .sw.fd-s { background: var(--d-soft); } .sw.fl { background: var(--line); }
.sw.ct { background: transparent; border-top: 3px dashed var(--muted); height: 0; }
.sw.pt { width: 12px; border-radius: 50%; background: var(--ink); }
.v-chain { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: 22px; }
.v-chip { display: inline-flex; min-width: 44px; height: 48px; padding: 0 10px; align-items: center; justify-content: center; border-radius: 9px; background: var(--a-soft); font-weight: 700; }
.v-chip.strong { background: var(--b-soft); }
.v-op { color: var(--muted); }
.v-meter { height: 26px; border-radius: 13px; background: var(--grid); overflow: hidden; }
.v-meter i { display: block; height: 100%; width: 0; background: var(--a); transition: width .3s; }
.v-canvas-wrap { max-width: 420px; margin: 0 auto; }
.v-canvas { width: 100%; height: auto; display: block; background: var(--card); border-radius: 6px; }
.v-doors { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.v-door {
  font: inherit; font-size: 18px; font-weight: 700; min-height: 120px; border-radius: 12px; cursor: pointer;
  border: 2px solid var(--line); background: var(--c-soft); color: var(--ink);
}
.v-door.picked { border-color: var(--primary); border-width: 3px; }
.v-door.open { background: var(--grid); }
.v-door.car { background: var(--b-soft); }
.v-door:disabled { cursor: default; }
.v-board { display: flex; flex-wrap: wrap; gap: 10px; }
.v-tile { font: inherit; font-size: 22px; font-weight: 700; width: 58px; height: 58px; border-radius: 10px; border: 2px solid var(--line); background: var(--card); color: var(--ink); cursor: pointer; }
.v-tile.sel { border-color: var(--b); background: var(--b-soft); }

/* svg classes */
.t { fill: var(--ink); font-size: 18px; font-family: var(--font); }
.tm { fill: var(--muted); font-size: 15px; font-family: var(--font); }
.tick { fill: var(--muted); font-size: 13px; font-family: var(--font); }
.tw { fill: #fff; font-size: 16px; font-weight: 700; font-family: var(--font); }
.tw.small { font-size: 13px; }
.tlabel { fill: var(--ink); font-size: 14px; font-weight: 700; font-family: var(--font); paint-order: stroke; stroke: var(--surface); stroke-width: 5px; }
.strong { font-weight: 700; }
.fa { fill: var(--a); } .fb { fill: var(--b); } .fc { fill: var(--c); } .fd { fill: var(--d); }
.fa-s { fill: var(--a-soft); } .fb-s { fill: var(--b-soft); } .fc-s { fill: var(--c-soft); } .fd-s { fill: var(--d-soft); }
.fm { fill: var(--muted); } .fl { fill: var(--line); } .fcard { fill: var(--card); }
.faded { opacity: .22; }
.stroke { stroke: var(--card); stroke-width: 1.5; }
.stroke-b { stroke: var(--b); stroke-width: 2; }
.stroke-l { stroke: var(--line); stroke-width: 1.5; }
.grid { stroke: var(--grid); stroke-width: 1; }
.axis { stroke: var(--axis); stroke-width: 1.5; }
.axis.thick { stroke-width: 5; stroke-linecap: round; }
.guide { stroke: var(--muted); stroke-width: 1.5; stroke-dasharray: 5 5; }
.outline { fill: none; stroke: var(--ink); stroke-width: 2; stroke-dasharray: 8 6; }
.hole { fill: none; stroke: var(--d); stroke-width: 2.5; stroke-dasharray: 6 5; }
.curve { fill: none; stroke-width: 3; stroke-linejoin: round; stroke-linecap: round; }
.curve.thin { stroke-width: 2; }
.ca { stroke: var(--a); } .cb { stroke: var(--b); } .cc { stroke: var(--c); }
.ct { stroke: var(--muted); } .dashed { stroke-dasharray: 9 7; }
.cu { stroke: var(--d); stroke-width: 3.5; }
.pt { fill: var(--ink); }
.mk { stroke: var(--card); stroke-width: 2; }
.mk.ca { fill: var(--a); } .mk.cb { fill: var(--b); } .mk.cc { fill: var(--c); }
.sec { stroke: var(--c); stroke-width: 2.5; }
.riem { fill: var(--a-soft); stroke: var(--a); stroke-width: 1; }
.stick { stroke-width: 8; stroke-linecap: round; }
.sa { stroke: var(--a); } .sb { stroke: var(--b); }
.hs { stroke: var(--c); stroke-width: 2; opacity: .7; }
.sq-light { fill: #efe3c8; } .sq-dark { fill: #7a5a3a; }
.domino { fill: none; stroke: var(--c); stroke-width: 5; }

/* task */
.your-turn { border-top: 1px solid var(--line); padding-top: 34px; }
.prompt { font-size: 20px; max-width: var(--measure); }
.field { margin: 22px 0; }
.field label { display: block; font-weight: 700; margin-bottom: 6px; }
.field-input { display: flex; align-items: center; gap: 12px; }
.answer {
  font: inherit; font-size: 22px; width: 100%; max-width: 360px; padding: 11px 14px;
  border: 2px solid var(--line); border-radius: 10px; background: var(--card); color: var(--ink);
}
.answer.formula { max-width: 520px; font-family: var(--math); font-size: 24px; }
.answer:focus { border-color: var(--primary); outline: none; box-shadow: 0 0 0 4px var(--primary-soft); }
.field.ok .answer { border-color: var(--good); }
.field.wrong .answer { border-color: var(--bad); }
.mark { font-size: 24px; font-weight: 700; width: 1.2em; }
.field.ok .mark { color: var(--good); }
.field.wrong .mark { color: var(--bad); }
.field-help { font-size: 15px; color: var(--muted); margin: 6px 0 0; }
.preview { font-size: 16px; color: var(--muted); margin: 6px 0 0; font-variant-numeric: tabular-nums; }
.field-msg { font-size: 17px; color: var(--bad); margin: 6px 0 0; }
.field-msg:empty { display: none; }
.choices { border: 0; padding: 0; margin: 20px 0; display: grid; gap: 12px; }
.choice { position: relative; }
.choice input { position: absolute; opacity: 0; }
.choice label {
  display: block; padding: 14px 18px 14px 52px; border: 2px solid var(--line); border-radius: 12px; cursor: pointer; position: relative; background: var(--card);
}
.choice label::before { content: ""; position: absolute; left: 18px; top: 18px; width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--muted); }
.choice input:checked + label { border-color: var(--primary); background: var(--primary-soft); }
.choice input:checked + label::before { border-color: var(--primary); background: radial-gradient(var(--primary) 45%, transparent 50%); }
.choice input:focus-visible + label { outline: 3px solid var(--b); outline-offset: 2px; }
.task-actions { margin-top: 24px; }
.feedback { margin-top: 16px; font-size: 19px; border-radius: 10px; }
.feedback:empty { display: none; }
.feedback.good { background: var(--good-soft); color: var(--good); padding: 12px 16px; font-weight: 700; }
.feedback.bad { background: var(--bad-soft); color: var(--bad); padding: 12px 16px; }

.help { margin-top: 26px; }
.hints { list-style: none; padding: 0; margin: 0 0 12px; display: grid; gap: 10px; max-width: var(--measure); }
.hints li { background: var(--surface); border-radius: 10px; padding: 12px 16px; }
.hint-no { font-weight: 700; color: var(--b); }
.help-actions { display: flex; flex-wrap: wrap; gap: 12px; }
.solution { margin-top: 18px; border-left: 4px solid var(--c); padding: 4px 0 4px 18px; max-width: var(--measure); }
.solution h3 { margin-bottom: 6px; }

.idea {
  margin: 40px 0 10px; background: var(--idea-bg); border-left: 5px solid var(--idea-line);
  border-radius: 0 var(--radius) var(--radius) 0; padding: 22px 26px;
}
.idea h2 { font-size: 23px; margin-bottom: 8px; }
.idea p { margin: 0; max-width: var(--measure); font-size: 20px; }

.ex-nav { display: flex; justify-content: space-between; gap: 14px; margin-top: 44px; padding-top: 24px; border-top: 1px solid var(--line); }
.nav-note { color: var(--muted); font-size: 16px; text-align: right; margin-top: 10px; min-height: 1.4em; }


/* dedication */
.dedication {
  display: grid; grid-template-columns: 200px 1fr; gap: 36px; align-items: center;
  padding: 52px 0; border-bottom: 1px solid var(--line);
}
.dedication-portrait { display: block; }
.dedication-portrait img {
  display: block; width: 100%; height: auto; aspect-ratio: 1; object-fit: cover;
  border-radius: 50%; background: #fff; border: 1px solid var(--line);
}
.dedication-text h2 { font-size: 24px; margin-bottom: 12px; }
.dedication-text p, .dedication-page p {
  font-family: var(--math); font-size: 22px; line-height: 1.55; margin-bottom: 10px; max-width: 34em;
}
.dedication-sign { font-family: var(--font) !important; font-size: 17px !important; color: var(--muted); margin-top: 16px !important; }
.dedication-page { max-width: 620px; margin: 0 auto; text-align: center; }
.dedication-page p { margin-left: auto; margin-right: auto; }
.dedication-portrait.large { width: min(340px, 80%); margin: 0 auto 32px; }
.dedication-back { margin-top: 36px !important; font-family: var(--font) !important; }
.footer-dedication a { color: var(--muted); }
@media (max-width: 640px) {
  .dedication { grid-template-columns: 1fr; gap: 20px; text-align: center; }
  .dedication-portrait { width: 170px; margin: 0 auto; }
  .dedication-text p { font-size: 20px; margin-left: auto; margin-right: auto; }
}

/* footer */
.site-footer { border-top: 1px solid var(--line); background: var(--surface); }
.footer-inner { max-width: 880px; margin: 0 auto; padding: 28px 24px 40px; font-size: 16px; color: var(--muted); }
.footer-inner p { margin: 4px 0; }

@media (max-width: 640px) {
  body { font-size: 18px; }
  .site-header { position: static; }
  .brand { font-size: 18px; }
  .site-nav { gap: 16px; font-size: 16px; }
  main { padding: 30px 18px 60px; }
  .header-inner { padding: 10px 18px; }
  #header-progress { margin-left: 0; width: 100%; }
  .visual { padding: 14px; margin-left: -8px; margin-right: -8px; }
  .story, .prompt, .idea p { font-size: 18px; }
  .v-door { min-height: 90px; font-size: 16px; }
  .nav-note { text-align: left; }
}

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