/* Tutorial site styles, "Night stacks": UChicago colors on a dark ground, set in Fraunces Light.
   The ground is the university's darkest secondary color (#350E20); goldenrod marks actions and
   progress; the lighter secondary tints mark right (green) and wrong (orange) answers, because
   the standard ones turn muddy on a dark ground. Maroon never means "wrong".
   The landing page, every tutorial and every widget share this file; the widget palette in
   draw.js mirrors these values. */
@font-face {
  font-family: "Fraunces";
  font-style: normal;
  font-weight: 300 500;
  font-display: swap;
  src: url("fonts/fraunces-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Fraunces";
  font-style: italic;
  font-weight: 300 500;
  font-display: swap;
  src: url("fonts/fraunces-italic-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  color-scheme: dark;
  --ground: #350E20;
  --raised: #43152A;
  --track: #5A2A3F;
  --line: #6B2E48;
  --text: #F7EEE3;
  --text-2: #F1E5D6;
  --muted: #E0CFC3;
  --accent: #FFB547;
  --gold: #FFA319;
  --on-gold: #350E20;
  --good: #ADB17D;
  --good-bg: #2E3219;
  --good-text: #EEF0D6;
  --bad: #D49464;
  --bad-bg: #4A2112;
  --bad-text: #F9E0CB;

  --font: "Fraunces", Georgia, "Times New Roman", serif;
  --step-max: 640px;
  --footer-h: 128px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  font-size: 18px;
  font-weight: 300;
  line-height: 1.6;
  color: var(--text);
  background: var(--ground);
  -webkit-font-smoothing: antialiased;
  font-optical-sizing: auto;
}
h1, h2, h3 { font-weight: 300; line-height: 1.1; margin: 0; }
h1, .prompt { font-style: italic; letter-spacing: -0.005em; }
p { margin: 0 0 0.8em; }
a { color: var(--accent); }
button, input { font: inherit; color: inherit; }
b, strong { font-weight: 500; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 6px; }
.nomath { white-space: nowrap; }

/* top bar */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 14px;
  max-width: var(--step-max); margin: 0 auto;
  padding: 16px 20px 10px;
  background: var(--ground);
}
.icon-btn {
  width: 36px; height: 36px; flex: none;
  display: grid; place-items: center;
  border: none; background: transparent; border-radius: 50%;
  color: var(--muted); cursor: pointer;
}
.icon-btn:hover { background: var(--raised); color: var(--text); }
.progress { flex: 1; height: 3px; border-radius: 2px; background: var(--track); overflow: hidden; }
.progress > span { display: block; height: 100%; width: 0; background: var(--gold); transition: width .45s ease; }
.count { flex: none; min-width: 56px; text-align: right; font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* stage */
.stage { max-width: var(--step-max); margin: 0 auto; padding: 10px 20px calc(var(--footer-h) + 40px); }
.unit-label { font-style: italic; font-size: 15px; color: var(--accent); margin-bottom: 6px; }
.prompt { font-size: 32px; margin-bottom: 16px; }
.prompt:focus { outline: none; }
.body-text { font-size: 18px; color: var(--text-2); }
.body-text p:last-child { margin-bottom: 0; }
.body-text b { color: var(--text); }
.source { font-size: 14px; font-style: italic; color: var(--muted); margin-top: 0.4em; }
.hint { color: var(--muted); font-size: 15px; margin-top: 10px; }
.visual { margin: 4px 0 20px; }
.retry-note {
  display: inline-block; font-size: 13px; font-style: italic;
  color: var(--bad-text); background: var(--bad-bg); border: 1px solid var(--bad);
  padding: 1px 10px; border-radius: 99px; margin-bottom: 8px;
}

/* answer tiles */
.options { display: grid; gap: 10px; margin-top: 8px; }
.tile {
  display: flex; align-items: center; gap: 12px;
  width: 100%; text-align: left;
  padding: 12px 14px;
  background: var(--raised);
  border: 1px solid var(--line);
  border-radius: 14px;
  cursor: pointer;
  font-size: 17px; line-height: 1.4; color: var(--text);
  transition: border-color .12s, background .12s;
}
.tile:hover:not(:disabled) { border-color: var(--muted); }
.tile .key {
  flex: none; width: 26px; height: 26px; display: grid; place-items: center;
  border: 1px solid var(--line); border-radius: 50%;
  font-size: 13px; color: var(--muted);
}
.tile[aria-checked="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.tile[aria-checked="true"] .key { border-color: var(--accent); color: var(--accent); }
.tile.is-good { border-color: var(--good); background: var(--good-bg); box-shadow: inset 0 0 0 1px var(--good); color: var(--good-text); }
.tile.is-good .key { border-color: var(--good); color: var(--good-text); }
.tile.is-bad { border-color: var(--bad); background: var(--bad-bg); box-shadow: inset 0 0 0 1px var(--bad); color: var(--bad-text); }
.tile.is-bad .key { border-color: var(--bad); color: var(--bad-text); }
.tile:disabled { cursor: default; }
.options.two-up { grid-template-columns: 1fr 1fr; }
.frac { display: inline-flex; flex-direction: column; align-items: center; line-height: 1.12; font-size: 1.5em; font-variant-numeric: lining-nums tabular-nums; vertical-align: middle; }
.frac > span:first-child { border-bottom: 1px solid currentColor; padding: 0 0.2em; }
.frac > span:last-child { padding-top: 0.1em; }
.whole { font-size: 1.5em; line-height: 1; }
.readout .frac { font-size: 1em; }

/* numeric answer */
.num-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.num-input {
  font-size: 26px;
  width: 200px; padding: 10px 16px;
  border: 1px solid var(--line); border-radius: 14px;
  background: var(--raised); color: var(--text);
}
.num-input::placeholder { color: var(--muted); opacity: 0.7; }
.num-input:focus { outline: none; border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.num-input.is-good { border-color: var(--good); background: var(--good-bg); }
.num-input.is-bad { border-color: var(--bad); background: var(--bad-bg); }
.num-error { color: var(--bad-text); font-size: 15px; margin-top: 6px; }

/* match pairs */
.match { display: grid; grid-template-columns: 1fr 1.7fr; gap: 10px 12px; align-items: stretch; }
.match .col { display: grid; gap: 10px; }
.match .tile { justify-content: center; text-align: center; min-height: 60px; font-size: 16px; }
.match .col.right .tile { justify-content: flex-start; text-align: left; font-size: 15px; }
.match .tile.is-matched { border-color: var(--good); background: var(--good-bg); color: var(--good-text); box-shadow: none; }
.match .tile.is-flash { animation: shake .35s; border-color: var(--bad); background: var(--bad-bg); }
@keyframes shake { 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }

/* footer and feedback */
.footer {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  border-top: 1px solid var(--line);
  background: var(--ground);
  transition: background .2s, border-color .2s;
}
.footer-inner {
  max-width: var(--step-max); margin: 0 auto;
  min-height: var(--footer-h);
  padding: 16px 20px 20px;
  display: flex; align-items: center; gap: 16px;
}
.feedback { flex: 1; min-width: 0; }
.feedback h3 { font-size: 22px; font-style: italic; margin-bottom: 4px; }
.feedback .fb-text { font-size: 15px; line-height: 1.5; max-height: 38vh; overflow: auto; color: var(--text-2); }
.footer.is-good { background: var(--good-bg); border-color: var(--good); }
.footer.is-good h3 { color: var(--good); }
.footer.is-good .fb-text { color: var(--good-text); }
.footer.is-bad { background: var(--bad-bg); border-color: var(--bad); }
.footer.is-bad h3 { color: var(--bad); }
.footer.is-bad .fb-text { color: var(--bad-text); }
.feedback .why { font-weight: 400; margin-bottom: 0.45em; }
.footer.is-open .feedback { animation: rise .22s ease-out; }
@keyframes rise { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

.btn {
  flex: none; min-width: 160px;
  padding: 12px 26px;
  border: none; border-radius: 12px;
  font-size: 17px; font-weight: 400;
  color: var(--on-gold); background: var(--gold);
  cursor: pointer;
  transition: filter .12s, transform .06s;
}
.btn:hover:not(:disabled) { filter: brightness(1.08); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { color: var(--muted); background: var(--track); cursor: not-allowed; }
.btn.good { background: var(--good); }
.btn.bad { background: var(--bad); }
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); font-weight: 300; }
.btn.small { min-width: 0; padding: 7px 16px; font-size: 15px; }

/* intro and finish */
.intro { max-width: var(--step-max); margin: 0 auto; padding: 44px 20px 60px; }
.intro .kicker { font-style: italic; color: var(--accent); margin-bottom: 8px; }
.intro h1 { font-size: 46px; margin-bottom: 14px; }
.intro .lede { font-size: 19px; color: var(--text-2); max-width: 34em; }
.intro-visual { margin: 24px 0 28px; }
.path { list-style: none; padding: 0; margin: 0 0 32px; display: grid; gap: 8px; }
.path li { display: flex; align-items: center; gap: 12px; font-size: 17px; color: var(--text-2); }
.path .dot {
  width: 28px; height: 28px; flex: none; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--raised); border: 1px solid var(--line);
  font-size: 13px; color: var(--muted);
}
.path li.is-done .dot { color: var(--on-gold); background: var(--good); border-color: var(--good); }
.signin { display: grid; gap: 8px; max-width: 420px; }
.signin label { font-weight: 400; }
.signin input {
  font-size: 19px; padding: 10px 16px;
  border: 1px solid var(--line); border-radius: 14px;
  background: var(--raised); color: var(--text);
}
.signin input::placeholder { color: var(--muted); opacity: 0.7; }
.signin input:focus { outline: none; border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.signin .note { font-size: 14px; color: var(--muted); }
.signin .warn { font-size: 15px; color: var(--bad-text); background: var(--bad-bg); border: 1px solid var(--bad); padding: 8px 12px; border-radius: 10px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; margin-top: 8px; }
.linklike { background: none; border: none; color: var(--muted); text-decoration: underline; cursor: pointer; font-size: 15px; padding: 4px 0; }

.finish { text-align: center; }
.finish-visual { margin: 4px 0 6px; }
.finish h1 { font-size: 42px; margin: 10px 0 6px; }
.finish .lede { margin: 0 auto; }
.finish-stats { font-style: italic; color: var(--muted); font-size: 15px; margin: 8px 0 22px; }
.magic {
  margin: 0 auto 16px; max-width: 460px;
  padding: 18px 20px 20px;
  border-radius: 18px;
  background: var(--raised); border: 1px solid var(--line);
  animation: fadein .6s ease-out both;
}
.magic .label { font-size: 14px; color: var(--muted); }
.magic .word { color: var(--accent); font-style: italic; font-size: clamp(32px, 8vw, 46px); margin: 4px 0 12px; word-break: break-word; }
@keyframes fadein { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.finish .next { max-width: 30em; margin: 16px auto 0; color: var(--text-2); font-size: 16px; }

/* landing page */
.weeks { list-style: none; padding: 0; margin: 28px 0 0; display: grid; gap: 12px; }
.weeks a, .weeks .soon {
  display: flex; align-items: center; gap: 16px;
  padding: 16px 18px; border-radius: 16px;
  text-decoration: none; color: var(--text);
  background: var(--raised); border: 1px solid var(--line);
}
.weeks a:hover { border-color: var(--accent); }
.weeks .n { flex: none; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; font-size: 18px; font-weight: 400; color: var(--on-gold); background: var(--gold); }
.weeks b { display: block; font-weight: 400; font-size: 20px; }
.weeks .d { font-size: 15px; color: var(--muted); font-style: italic; }
.weeks .soon { color: var(--muted); background: transparent; border-style: dashed; }
.weeks .soon .n { background: var(--track); color: var(--muted); }

/* widgets */
.card { background: var(--raised); border: 1px solid var(--line); border-radius: 18px; padding: 14px 16px; }
.card > svg { display: block; max-width: 100%; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 14px; color: var(--muted); margin-top: 8px; }
.legend i { display: inline-block; width: 11px; height: 11px; border-radius: 50%; margin-right: 5px; vertical-align: -1px; }
.controls { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.wbtn {
  padding: 6px 14px; border: 1px solid var(--line); border-radius: 999px;
  background: var(--ground); font-size: 15px; color: var(--text); cursor: pointer;
}
.wbtn:hover:not(:disabled) { border-color: var(--accent); }
.wbtn[aria-pressed="true"] { border-color: var(--accent); background: var(--accent); color: var(--on-gold); font-weight: 400; }
.wbtn:disabled { opacity: 0.45; cursor: default; }
.readout { font-size: 16px; color: var(--text-2); margin-top: 8px; }
.readout b { color: var(--text); }
.caption { font-size: 14px; font-style: italic; color: var(--muted); margin-top: 6px; }
.tbl { border-collapse: collapse; width: 100%; font-size: 15px; font-variant-numeric: tabular-nums; }
.tbl th, .tbl td { padding: 7px 8px; border: 1px solid var(--line); text-align: center; }
.tbl th { font-weight: 300; font-style: italic; color: var(--text-2); background: var(--ground); }
.tbl td.ask { color: var(--accent); font-weight: 500; box-shadow: inset 0 0 0 2px var(--accent); }
.formula { margin: 4px 0 18px; font-size: 21px; text-align: center; color: var(--text); }
.formula .katex-display { margin: 0.3em 0; }
.eq-line { transition: opacity .3s; }
.eq-line.is-hidden { opacity: 0; visibility: hidden; }
.slider-row { display: flex; align-items: center; gap: 12px; font-size: 15px; color: var(--text-2); }
.slider-row output { min-width: 2.6em; text-align: right; font-variant-numeric: tabular-nums; color: var(--text); }
input[type="range"] { width: 100%; accent-color: var(--gold); }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
svg[data-panel="prior"]:focus { outline: none; }
svg[data-panel="prior"]:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.box {
  display: grid; grid-template-columns: 5.2em 1fr 1fr 1.3fr 1.4fr;
  gap: 8px; align-items: center; margin-top: 12px;
  font-size: 15px; font-variant-numeric: tabular-nums;
}
.box .h { font-style: italic; color: var(--muted); font-size: 13px; line-height: 1.2; align-self: end; }
.box .track { height: 16px; background: var(--ground); border-radius: 3px; overflow: hidden; border: 1px solid var(--line); }
.box .bar { height: 100%; border-right: 1px solid var(--ground); transition: width .25s; }
.dice-rows { display: grid; gap: 10px; }
.dice-row { display: grid; grid-template-columns: 4.6em 1fr 5.2em; align-items: center; gap: 10px; font-size: 16px; }
.dice-row .track { height: 16px; background: var(--ground); border: 1px solid var(--line); border-radius: 4px; overflow: hidden; }
.dice-row .bar { height: 100%; border-radius: 4px; transition: width .35s; }
.dice-row .value { text-align: right; min-height: 2.6em; display: flex; align-items: center; justify-content: flex-end; font-variant-numeric: tabular-nums; }
.dice-row .frac { font-size: 1.15em; }
.dice-row.is-out .name { text-decoration: line-through; color: var(--muted); }
.dice-row .ruled { font-size: 14px; font-style: italic; color: var(--muted); }
.dice-log { min-height: 30px; margin-top: 10px; }
.chip { display: inline-block; min-width: 28px; text-align: center; margin: 0 4px 4px 0; padding: 1px 6px; border: 1px solid var(--line); border-radius: 7px; background: var(--ground); font-size: 15px; }
.chip.is-last { border-color: var(--accent); color: var(--accent); }

/* small screens */
@media (max-width: 560px) {
  body { font-size: 17px; }
  .prompt { font-size: 27px; }
  .intro h1 { font-size: 36px; }
  .footer-inner { flex-direction: column; align-items: stretch; gap: 10px; min-height: 0; padding: 12px 20px 16px; }
  .feedback:empty { display: none; }
  .btn { width: 100%; }
  :root { --footer-h: 160px; }
  .match { grid-template-columns: 1fr; }
  .box { font-size: 14px; grid-template-columns: 4.6em 1fr 1fr 1.2fr 1.3fr; gap: 6px; }
}
@media (max-width: 360px) {
  .box { font-size: 11px; gap: 6px 4px; grid-template-columns: 4.4em minmax(0, 0.7fr) minmax(0, 1.05fr) minmax(0, 1.05fr) minmax(0, 1fr); }
  .box .h { font-size: 11px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
