/* assets/style.css
 * Shared stylesheet for every lesson and reference sheet in this workspace.
 * Tufte-flavoured: one narrow measure of text, wide right margin for notes,
 * quiet palette, real hierarchy from type rather than from boxes.
 */

:root {
  --ink: #14110d;
  --ink-soft: #5c554a;
  --ink-faint: #8b8377;
  --rule: #ddd6c8;
  --paper: #fffdf8;
  --accent: #8a3324;
  --good: #2f6b45;
  --bad: #9c2f27;
  --measure: 36rem;

  /* Chart palette. Categorical, ordered by how often a series is the subject.
     Kept here rather than in chart.js so light and dark stay in one place. */
  --c1: #2f6b45;
  --c2: #8a3324;
  --c3: #3d6f8f;
  --c4: #8a6d1f;
  --c5: #6b4c7a;
  --c6: #556070;
  --grid: rgba(20, 17, 13, .10);
  --chart-ink: #5c554a;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ink: #ece6da;
    --ink-soft: #b0a897;
    --ink-faint: #8a8274;
    --rule: #3a352d;
    --paper: #16140f;
    --accent: #e0866f;
    --good: #7fc79c;
    --bad: #e08b81;

    --c1: #6fbf8f;
    --c2: #e0866f;
    --c3: #7fb2d6;
    --c4: #d6b45c;
    --c5: #b294c4;
    --c6: #97a3b3;
    --grid: rgba(236, 230, 218, .12);
    --chart-ink: #b0a897;
  }
}

/* --------------------------------------------------------------- charts */

.chart { display: block; width: 100%; height: auto; margin: .5rem 0 0; }
.chart text { font-family: Palatino, Georgia, serif; fill: var(--chart-ink); }
.chart .tick { font-size: 11px; }
.chart .axis-line { stroke: var(--grid); stroke-width: 1; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .target { stroke: var(--good); stroke-width: 1.5; stroke-dasharray: 4 3; }
.chart .target-label { font-size: 11px; fill: var(--good); }
.chart .dot { stroke: var(--paper); stroke-width: 1.5; }
.chart .series-label { font-size: 11.5px; font-weight: 600; }
.chart .bar-label { font-size: 11.5px; }
.chart .value { font-size: 11.5px; font-variant-numeric: tabular-nums; }

figure.chart-figure { margin: 2.4rem 0; max-width: 46rem; }
figure.chart-figure h3 { margin: 0 0 .2rem; font-style: normal; font-size: 1.05rem; }
figure.chart-figure .lede {
  font-size: .85rem; color: var(--ink-soft); margin: 0 0 .4rem; max-width: 34rem;
}
figure.chart-figure figcaption {
  font-size: .8rem; color: var(--ink-faint); margin-top: .5rem; max-width: 34rem;
}
.empty-note {
  font-size: .85rem; color: var(--ink-faint); font-style: italic;
  padding: 1.2rem 0;
}
.headline {
  display: flex; flex-wrap: wrap; gap: 2rem; margin: 1.5rem 0 2.5rem;
}
.headline div { display: flex; flex-direction: column; gap: .15rem; }
.headline b { font-size: 1.9rem; font-weight: 400; line-height: 1;
              font-variant-numeric: tabular-nums; }
.headline span { font-variant: small-caps; letter-spacing: .09em;
                 font-size: .74rem; color: var(--ink-faint); }
.headline em { font-style: normal; font-size: .78rem; color: var(--good); }

html { font-size: 17px; }

body {
  margin: 0 auto;
  padding: 4rem 2rem 8rem;
  max-width: 62rem;
  background: var(--paper);
  color: var(--ink);
  font-family: Palatino, "Palatino Linotype", "Book Antiqua", Georgia, serif;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

p, ul, ol, table, blockquote, figure, .block { max-width: var(--measure); }

/* ------------------------------------------------------------- headings */

h1, h2, h3 { font-weight: 400; line-height: 1.15; letter-spacing: -0.01em; }
h1 { font-size: 2.4rem; margin: 0 0 .3rem; }
h2 { font-size: 1.5rem; margin: 3.2rem 0 .8rem; }
h3 { font-size: 1.12rem; margin: 2.2rem 0 .5rem; font-style: italic; }

.subtitle {
  font-style: italic;
  color: var(--ink-soft);
  font-size: 1.15rem;
  margin: 0 0 2.5rem;
  max-width: var(--measure);
}

.eyebrow {
  font-variant: small-caps;
  letter-spacing: .12em;
  font-size: .82rem;
  color: var(--ink-faint);
  margin: 0 0 .6rem;
}

/* ---------------------------------------------------------------- notes */

/* A margin note. It is a body-level element, so the body's 62rem column minus
   the 36rem measure already *is* the gutter -- floating right lands it there.
   No negative margin: that used to shove notes off the right of the viewport. */
.note {
  float: right;
  clear: right;
  width: 17rem;
  margin: .3rem 0 .8rem 2rem;
  font-size: .82rem;
  line-height: 1.45;
  color: var(--ink-soft);
}
.note code { font-size: .95em; }

/* below the width that fits 62rem + padding, stack notes inline instead */
@media (max-width: 1150px) {
  .note {
    float: none;
    width: auto;
    max-width: var(--measure);
    margin: 1rem 0;
    padding-left: .9rem;
    border-left: 2px solid var(--rule);
  }
}

/* ------------------------------------------------------------ key ideas */

.key {
  max-width: var(--measure);
  margin: 1.8rem 0;
  padding: 1rem 1.2rem;
  border-left: 3px solid var(--accent);
  background: color-mix(in srgb, var(--accent) 5%, transparent);
}
.key p:last-child { margin-bottom: 0; }
.key p:first-child { margin-top: 0; }

/* ---------------------------------------------------------------- links */

a { color: var(--accent); text-decoration: none; border-bottom: 1px solid var(--rule); }
a:hover { border-bottom-color: var(--accent); }

/* ----------------------------------------------------------- code, algs */

code, .alg, kbd {
  font-family: "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
}
code { font-size: .88em; background: color-mix(in srgb, var(--ink) 6%, transparent);
       padding: .1em .3em; border-radius: 3px; }
.alg {
  display: inline-block;
  font-size: .95rem;
  letter-spacing: .04em;
  background: color-mix(in srgb, var(--ink) 7%, transparent);
  padding: .35rem .6rem;
  border-radius: 4px;
}
.memo {
  font-family: "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  font-size: 1.05rem;
  letter-spacing: .28em;
  word-spacing: .4em;
}

/* --------------------------------------------------------------- tables */

table { border-collapse: collapse; font-size: .92rem; margin: 1.5rem 0; }
th, td { text-align: left; padding: .35rem .9rem .35rem 0; }
th { font-weight: 400; font-variant: small-caps; letter-spacing: .06em;
     color: var(--ink-faint); border-bottom: 1px solid var(--rule); }
tbody tr + tr td { border-top: 1px solid color-mix(in srgb, var(--rule) 55%, transparent); }

/* ------------------------------------------------------------ cube nets */

.cube-net { display: block; margin: 1.2rem 0; max-width: 100%; height: auto; }
/* fill comes from the inline attribute cube.js sets per sticker; a CSS fill
   here would override it and wreck contrast on the dark faces */
.cube-letter { font-family: "SF Mono", Menlo, monospace; font-weight: 600; }
.figure { margin: 2rem 0; max-width: var(--measure); }
.figure figcaption { font-size: .82rem; color: var(--ink-soft); margin-top: .5rem; }

/* ---------------------------------------------------------------- drill */

.drill {
  max-width: var(--measure);
  margin: 2rem 0;
  padding: 1.3rem 1.4rem;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: color-mix(in srgb, var(--ink) 2.5%, transparent);
}
.drill h3 { margin-top: 0; }
.drill-progress { font-size: .8rem; color: var(--ink-faint); font-variant: small-caps;
                  letter-spacing: .08em; }
.drill-prompt { font-size: 1.05rem; margin: .9rem 0; }

.opts { display: grid; gap: .5rem; margin: 1rem 0 0; }
.opt {
  font: inherit;
  font-size: .95rem;
  text-align: left;
  padding: .55rem .8rem;
  border: 1px solid var(--rule);
  border-radius: 5px;
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
}
.opt:hover:not(:disabled) { border-color: var(--ink-faint); }
.opt.correct { border-color: var(--good); background: color-mix(in srgb, var(--good) 14%, transparent); }
.opt.wrong { border-color: var(--bad); background: color-mix(in srgb, var(--bad) 12%, transparent); }
.opt:disabled { cursor: default; }

.answer-row { display: flex; gap: .5rem; margin-top: 1rem; flex-wrap: wrap; }
input.answer {
  font: inherit;
  font-family: "SF Mono", Menlo, monospace;
  letter-spacing: .2em;
  text-transform: uppercase;
  padding: .5rem .7rem;
  border: 1px solid var(--rule);
  border-radius: 5px;
  background: var(--paper);
  color: var(--ink);
  flex: 1 1 14rem;
  min-width: 0;
}
/* hint text is prose, not an answer — don't shout it */
input.answer::placeholder {
  text-transform: none;
  letter-spacing: normal;
  opacity: .5;
}
/* move notation is case-sensitive — x' is not X' — so no uppercasing here */
input.answer.notation {
  text-transform: none;
  letter-spacing: .08em;
  flex: 1 1 20rem;
}
button.go, button.ghost, a.go, a.ghost {
  font: inherit; font-size: .92rem; padding: .5rem 1rem; border-radius: 5px; cursor: pointer;
  display: inline-block; text-decoration: none; line-height: 1.3;
}
button.go, a.go { border: 1px solid var(--accent); background: var(--accent); color: var(--paper); }
button.ghost, a.ghost {
  border: 1px solid var(--rule); background: transparent; color: var(--ink-soft);
}
a.ghost:hover, button.ghost:hover { border-color: var(--ink-faint); }

.verdict { margin-top: .9rem; font-size: .95rem; min-height: 1.4rem; }
.verdict.ok { color: var(--good); }
.verdict.no { color: var(--bad); }
.verdict .why { display: block; color: var(--ink-soft); font-size: .88rem; margin-top: .35rem; }

/* ------------------------------------------------------------- trainers */

.hud {
  display: flex; flex-wrap: wrap; gap: 1.6rem; align-items: baseline;
  max-width: var(--measure); margin: 1.5rem 0 .8rem;
  padding-bottom: .8rem; border-bottom: 1px solid var(--rule);
}
.hud-item { display: flex; flex-direction: column; gap: .1rem; }
.hud-item b { font-size: 1.35rem; font-weight: 400; line-height: 1; }
.hud-item span {
  font-variant: small-caps; letter-spacing: .09em;
  font-size: .72rem; color: var(--ink-faint);
}
.bar {
  max-width: var(--measure); height: 5px; border-radius: 3px;
  background: color-mix(in srgb, var(--ink) 10%, transparent); overflow: hidden;
}
.bar-fill { height: 100%; background: var(--good); transition: width .3s ease; }

.scope { display: flex; gap: .4rem; margin: 1.2rem 0; flex-wrap: wrap; }
.scope button {
  font: inherit; font-size: .85rem; padding: .35rem .85rem; cursor: pointer;
  border: 1px solid var(--rule); border-radius: 20px;
  background: transparent; color: var(--ink-soft);
}
.scope button[aria-pressed="true"] {
  border-color: var(--accent); color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}

.card {
  max-width: var(--measure); margin: 1.5rem 0;
  padding: 2rem 1.6rem; border: 1px solid var(--rule); border-radius: 8px;
  background: color-mix(in srgb, var(--ink) 2.5%, transparent);
}
.card-kind {
  font-variant: small-caps; letter-spacing: .1em;
  font-size: .74rem; color: var(--ink-faint);
}
/* fixed height so the input does not jump between the one-line and two-line
   prompt shapes -- a moving target is hard to type into fast */
.card-prompt { font-size: 1.5rem; line-height: 1.3; margin: .6rem 0 1.2rem; min-height: 4.6rem; }
.card-prompt .big {
  font-family: "SF Mono", Menlo, monospace;
  font-size: 2.6rem; font-weight: 600; letter-spacing: .06em;
}
.card input {
  font: inherit; font-family: "SF Mono", Menlo, monospace;
  font-size: 1.5rem; letter-spacing: .25em; text-transform: uppercase;
  width: 100%; box-sizing: border-box;
  padding: .5rem .7rem; border: 1px solid var(--rule); border-radius: 6px;
  background: var(--paper); color: var(--ink);
}
.card input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
/* the input's uppercase + tracking is for answers, not for hint text */
.card input::placeholder {
  text-transform: none; letter-spacing: normal;
  font-family: inherit; font-size: .95rem; opacity: .5;
}
.card.ok   { border-color: var(--good); }
.card.slow { border-color: #b8860b; }
.card.no   { border-color: var(--bad); }

.fb { margin-top: .9rem; min-height: 1.5rem; font-size: .95rem; }
.fb.ok { color: var(--good); }
.fb.slow { color: #b8860b; }
.fb.no { color: var(--bad); }
.fb .hint { display: block; color: var(--ink-soft); font-size: .86rem; margin-top: .3rem; }

.tools { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: 2.5rem; }
.done { max-width: var(--measure); }
.done table { width: 100%; }

/* --------------------------------------------------------------- footer */

.source {
  max-width: var(--measure);
  margin: 3rem 0 0;
  padding: 1rem 1.2rem;
  border: 1px solid var(--rule);
  border-radius: 6px;
}
.source .eyebrow { margin-bottom: .4rem; }

.ask {
  max-width: var(--measure);
  margin: 2rem 0 0;
  font-style: italic;
  color: var(--ink-soft);
}

.lesson-nav {
  max-width: var(--measure);
  margin-top: 4rem;
  padding-top: 1rem;
  border-top: 1px solid var(--rule);
  font-size: .88rem;
  color: var(--ink-faint);
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
}

/* ---------------------------------------------------------------- print */

@media print {
  :root { --paper: #fff; --ink: #000; }
  body { padding: 0; max-width: none; font-size: 11pt; }
  .drill, .ask, .lesson-nav { display: none; }
  .note { float: none; width: auto; border-left: 2px solid #ccc; padding-left: .8rem; }
  h2 { page-break-after: avoid; }
  table, .figure { page-break-inside: avoid; }
}
