/* Clabbe-guiden — a Swedish driver's-theory book for AI.
   The road-sign palette is the one loud thing; everything else stays quiet. */

:root {
  --paper: #EEF1F3;
  --paper-raised: #FFFFFF;
  --ink: #1B2433;
  --ink-soft: #4A5568;
  --rule: #C9D0D8;
  --sign-blue: #0B5CAD;
  --sign-blue-deep: #08447F;
  --sign-yellow: #FFCB05;
  --sign-red: #D7262F;
  --ok: #1E7A46;
  --post: #8A949F;
  --focus: #FFCB05;

  --display: "Barlow Condensed", "Arial Narrow", sans-serif;
  --ui: "Barlow", system-ui, sans-serif;
  --serif: "Source Serif 4", Georgia, serif;

  --measure: 66ch;
  --radius-sign: 10px;
  --radius-ui: 6px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #141A23;
    --paper-raised: #1D2531;
    --ink: #E6EAEF;
    --ink-soft: #A6B0BD;
    --rule: #33404F;
    --post: #4E5966;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #141A23;
  --paper-raised: #1D2531;
  --ink: #E6EAEF;
  --ink-soft: #A6B0BD;
  --rule: #33404F;
  --post: #4E5966;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { scroll-behavior: smooth; scroll-padding-top: 5rem; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 1.1875rem;          /* 19px */
  line-height: 1.62;
  font-optical-sizing: auto;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

a { color: var(--sign-blue); text-underline-offset: .18em; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) a { color: #7FB3EA; } }
:root[data-theme="dark"] a { color: #7FB3EA; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; border-radius: 3px; }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.skip { position: absolute; left: -999px; top: 0; }
.skip:focus { left: 1rem; top: 1rem; z-index: 10; background: var(--sign-yellow); color: #1B2433; padding: .5rem 1rem; font-family: var(--ui); }

/* ---------- Top bar ---------- */

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: .7rem clamp(1rem, 4vw, 2.5rem);
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--rule);
}
.brand { display: flex; align-items: center; gap: .6rem; text-decoration: none; color: var(--ink); font-family: var(--display); font-weight: 700; font-size: 1.45rem; letter-spacing: .01em; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .brand { color: var(--ink); } }
:root[data-theme="dark"] .brand { color: var(--ink); }
.brand-sign { width: 2rem; height: 2rem; }
.topnav { display: flex; gap: 1.25rem; align-items: center; font-family: var(--ui); font-weight: 600; font-size: 1rem; }
.topnav a { color: var(--ink); text-decoration: none; }
.topnav a:hover { text-decoration: underline; }
.topnav-exam { background: var(--sign-blue); color: #fff !important; padding: .45rem .9rem; border-radius: var(--radius-ui); }
.topnav-exam:hover { background: var(--sign-blue-deep); text-decoration: none !important; }
@media (max-width: 520px) { .topnav a:not(.topnav-exam) { display: none; } }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  font-family: var(--ui); font-weight: 600; font-size: 1.05rem;
  padding: .75rem 1.3rem; min-height: 2.9rem;
  border-radius: var(--radius-ui); border: 2px solid transparent;
  cursor: pointer; text-decoration: none; line-height: 1.1;
  transition: background-color .15s, border-color .15s, transform .1s;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--sign-blue); color: #fff !important; }
.btn-primary:hover { background: var(--sign-blue-deep); }
.btn-ghost { background: transparent; color: var(--ink) !important; border-color: var(--ink); }
.btn-ghost:hover { background: var(--ink); color: var(--paper) !important; }
.btn-small { font-size: .95rem; padding: .45rem .9rem; min-height: 2.3rem; background: var(--paper-raised); color: var(--ink); border-color: var(--rule); }
.btn-small:hover { border-color: var(--ink); }
.btn[disabled] { opacity: .55; cursor: progress; }

/* ---------- Hero ---------- */

.hero {
  display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr);
  gap: clamp(2rem, 5vw, 5rem); align-items: center;
  max-width: 1240px; margin: 0 auto;
  padding: clamp(3rem, 9vw, 7.5rem) clamp(1rem, 4vw, 2.5rem) clamp(3rem, 7vw, 6rem);
}
.hero h1 {
  font-family: var(--display); font-weight: 700;
  font-size: clamp(3.6rem, 9.5vw, 8.4rem);
  line-height: .86; letter-spacing: -.015em; margin: 0 0 1.6rem;
}
.lede { font-size: clamp(1.15rem, 1.6vw, 1.35rem); line-height: 1.55; max-width: 34em; margin: 0 0 2rem; }
.hero-actions { display: flex; flex-wrap: wrap; gap: .8rem; }
.hero-note { font-family: var(--ui); font-weight: 500; font-size: .95rem; color: var(--ink-soft); margin: 1.4rem 0 0; }
.hero-sign { margin: 0; }
.hero-sign svg { width: 100%; height: auto; display: block; filter: drop-shadow(0 18px 24px rgba(11, 40, 80, .18)); }

/* The one orchestrated motion: the sign swings into place on load. */
.sign-board { transform-origin: 260px 310px; animation: sign-in 1.1s cubic-bezier(.2, 1.4, .35, 1) .15s both; }
@keyframes sign-in {
  from { transform: rotate(-5deg) translateY(-26px); opacity: 0; }
  to   { transform: none; opacity: 1; }
}
@media (prefers-reduced-motion: reduce) { .sign-board { animation: none; } }

@media (max-width: 860px) {
  .hero { grid-template-columns: 1fr; }
  .hero-sign { max-width: 460px; }
}

/* ---------- Course layout: the road rail + chapters ---------- */

.course {
  display: grid; grid-template-columns: 15rem minmax(0, 1fr);
  gap: clamp(1.5rem, 4vw, 4rem);
  max-width: 1240px; margin: 0 auto;
  padding: 0 clamp(1rem, 4vw, 2.5rem) 4rem;
}

.rail { position: sticky; top: 5.5rem; align-self: start; padding-top: 1rem; }
.rail ol { list-style: none; margin: 0; padding: 0 0 0 1.6rem; position: relative; }
/* the road: a grey strip with a dashed centre line */
.rail ol::before {
  content: ""; position: absolute; left: .35rem; top: .4rem; bottom: .4rem; width: .5rem;
  border-radius: 4px; background: var(--post);
  background-image: linear-gradient(#fff 50%, transparent 50%);
  background-size: 2px 14px; background-repeat: repeat-y; background-position: center;
  opacity: .5;
}
.rail li { margin: 0 0 .55rem; }
.rail a {
  display: flex; align-items: center; gap: .65rem;
  font-family: var(--ui); font-weight: 500; font-size: .98rem;
  color: var(--ink-soft); text-decoration: none; padding: .3rem .4rem; border-radius: var(--radius-ui);
}
.rail a:hover { color: var(--ink); }
.rail svg { width: 1.7rem; height: 1.7rem; flex: none; opacity: .55; transition: opacity .2s, transform .2s; }
.rail a[aria-current="true"] { color: var(--ink); font-weight: 600; }
.rail a[aria-current="true"] svg { opacity: 1; transform: scale(1.12); }
.rail a.done svg { opacity: .9; }

@media (max-width: 960px) {
  .course { grid-template-columns: 1fr; }
  .rail { display: none; }
}

.chapters { min-width: 0; }

.chapter { padding: 4.5rem 0 2rem; border-top: 1px solid var(--rule); }
.chapter:first-child { border-top: 0; padding-top: 1rem; }

.chapter-head {
  display: grid; grid-template-columns: auto 1fr; column-gap: 1.1rem; align-items: end;
  margin-bottom: 1.6rem; max-width: var(--measure);
}
.chapter-sign { grid-row: span 2; width: 4.2rem; height: 4.2rem; }
.chapter-no { margin: 0; font-family: var(--ui); font-weight: 600; font-size: 1rem; color: var(--ink-soft); }
.chapter h2 {
  margin: 0; font-family: var(--display); font-weight: 700;
  font-size: clamp(2.3rem, 4.6vw, 3.4rem); line-height: 1; letter-spacing: -.005em;
}

.prose { max-width: var(--measure); }
.prose p { margin: 0 0 1.1rem; }
.prose h3, .widget h3, .shop-result h3 {
  font-family: var(--display); font-weight: 600; font-size: 1.75rem; line-height: 1.1;
  margin: 2.4rem 0 .8rem;
}
.prose strong { font-weight: 600; }

/* ---------- Widgets (shared shell) ---------- */

.widget {
  background: var(--paper-raised);
  border: 1px solid var(--rule);
  border-radius: var(--radius-sign);
  padding: clamp(1.25rem, 3vw, 2rem);
  margin: 1.8rem 0 2.2rem;
  max-width: 54rem;
  font-family: var(--ui);
}
.widget-note { font-family: var(--serif); font-size: .95rem; color: var(--ink-soft); margin: 1.1rem 0 0; max-width: var(--measure); }
.field-label { display: block; font-family: var(--ui); font-weight: 600; font-size: 1rem; margin: 0 0 .45rem; }
.optional { font-weight: 500; color: var(--ink-soft); margin-left: .35rem; }

textarea, input[type="text"] {
  width: 100%; font: inherit; font-family: var(--serif); font-size: 1.1rem;
  color: var(--ink); background: var(--paper);
  border: 2px solid var(--rule); border-radius: var(--radius-ui);
  padding: .7rem .85rem; resize: vertical;
}
textarea:focus, input[type="text"]:focus { outline: none; border-color: var(--sign-blue); }

/* ---------- 1a: guess the next word ---------- */

.guess-sentence {
  font-family: var(--serif); font-size: clamp(1.5rem, 3.4vw, 2.2rem); line-height: 1.3;
  margin: 0 0 1.5rem; min-height: 2.6em;
}
.guess-blank {
  display: inline-block; min-width: 3.5em; border-bottom: 3px solid var(--sign-blue);
  color: var(--sign-blue); text-align: center;
}
.guess-blank.filled { border-bottom-color: transparent; font-weight: 600; }
.guess-options { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .6rem; }
@media (max-width: 720px) { .guess-options { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.guess-option {
  position: relative; overflow: hidden; text-align: left;
  font-family: var(--ui); font-weight: 600; font-size: 1.1rem; color: var(--ink);
  background: var(--paper); border: 2px solid var(--rule); border-radius: var(--radius-ui);
  padding: .8rem 1rem; cursor: pointer; min-height: 3.6rem;
}
.guess-option:hover:not([disabled]) { border-color: var(--sign-blue); }
.guess-option[disabled] { cursor: default; }
.guess-option .bar {
  position: absolute; inset: auto 0 0 0; height: 0; background: var(--sign-blue); opacity: .16;
  transition: height .7s cubic-bezier(.2, .8, .2, 1);
}
.guess-option .pct { display: block; font-weight: 500; font-size: .95rem; color: var(--ink-soft); margin-top: .15rem; min-height: 1.2em; }
.guess-option.top { border-color: var(--sign-blue); }
.guess-option.picked { box-shadow: inset 0 0 0 2px var(--ink); }
@media (prefers-reduced-motion: reduce) { .guess-option .bar { transition: none; } }

.guess-result { font-family: var(--serif); margin: 1.2rem 0 0; min-height: 1.6em; max-width: var(--measure); }
.guess-footer { display: flex; justify-content: space-between; align-items: center; margin-top: 1rem; gap: 1rem; }
.guess-progress { color: var(--ink-soft); font-size: .95rem; }

/* ---------- 1b: temperature ---------- */

.temp-controls { margin-bottom: 1.2rem; max-width: 34rem; }
.temp-controls label { display: flex; justify-content: space-between; font-weight: 600; margin-bottom: .5rem; }
.temp-controls output { font-variant-numeric: tabular-nums; color: var(--sign-blue); }
input[type="range"] { width: 100%; accent-color: var(--sign-blue); height: 2rem; }
.temp-scale { display: flex; justify-content: space-between; font-size: .9rem; color: var(--ink-soft); }
.temp-out { list-style: none; padding: 0; margin: 1.4rem 0 0; display: grid; gap: .9rem; }
.temp-out li { display: flex; flex-wrap: wrap; gap: .35rem .45rem; align-items: flex-start; font-family: var(--serif); font-size: 1.15rem; }
.temp-word { display: inline-flex; flex-direction: column; align-items: center; line-height: 1.2; }
.temp-word b { font-weight: 400; }
.temp-word.chosen b { background: color-mix(in srgb, var(--sign-blue) 14%, transparent); padding: 0 .25em; border-radius: 3px; }
.temp-word small { font-family: var(--ui); font-size: .72rem; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.temp-word.unlikely small { color: var(--sign-red); font-weight: 600; }

/* ---------- 2: tokens ---------- */

.tok-out { display: flex; flex-wrap: wrap; gap: 3px; margin: 1.1rem 0 .6rem; font-family: var(--serif); font-size: 1.2rem; min-height: 2.2rem; }
.tok { padding: .1rem .2rem; border-radius: 3px; white-space: pre; }
.tok:nth-child(5n+1) { background: #D6E6F7; color: #102A4A; }
.tok:nth-child(5n+2) { background: #FFEFAE; color: #3D3000; }
.tok:nth-child(5n+3) { background: #F8D3D5; color: #4A0D11; }
.tok:nth-child(5n+4) { background: #D4ECDD; color: #0F3A22; }
.tok:nth-child(5n+5) { background: #E3DDF3; color: #251A47; }
.tok-count { font-weight: 600; margin: 0; }

/* ---------- 3: rules ---------- */

.rules { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 22rem), 1fr)); gap: 1.4rem 2rem; margin: 2rem 0; max-width: 60rem; }
.rule { border-left: 4px solid var(--sign-blue); padding: .2rem 0 .2rem 1.1rem; }
.rule h3 { font-family: var(--display); font-weight: 600; font-size: 1.6rem; line-height: 1.1; margin: 0 0 .3rem; }
.rule > p { margin: 0 0 .8rem; font-size: 1.02rem; color: var(--ink-soft); }
.rule-toggle { display: inline-flex; border: 2px solid var(--ink); border-radius: var(--radius-ui); overflow: hidden; margin-bottom: .7rem; }
.rule-toggle button {
  font-family: var(--ui); font-weight: 600; font-size: .92rem; padding: .3rem .85rem; min-height: 2.2rem;
  background: transparent; color: var(--ink); border: 0; cursor: pointer;
}
.rule-toggle button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.rule blockquote {
  margin: 0; padding: .9rem 1rem; border-radius: var(--radius-ui);
  background: var(--paper-raised); border: 1px solid var(--rule);
  font-size: 1.02rem; line-height: 1.5;
}
.rule .rule-efter { border-color: var(--sign-blue); }
.rule[data-state="fore"] .rule-efter, .rule[data-state="efter"] .rule-fore { display: none; }

.clabbe-says {
  max-width: var(--measure); margin: 1rem 0 0;
  background: var(--sign-blue); color: #fff; border-radius: var(--radius-sign);
  padding: 1.2rem 1.4rem; font-size: 1.1rem;
}
.clabbe-says p { margin: 0; }
.clabbe-says strong { font-family: var(--display); font-weight: 600; font-size: 1.25rem; margin-right: .2rem; }

/* ---------- 4: workshop ---------- */

.shop label + textarea, .shop label + input { margin-bottom: 1.1rem; }
.shop-privacy { font-family: var(--serif); font-size: .95rem; color: var(--ink-soft); margin: 0 0 1.1rem; }
.shop-actions { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.shop-status { color: var(--ink-soft); font-weight: 500; }
.shop-status.error { color: var(--sign-red); font-weight: 600; }
.shop-result { border-top: 1px solid var(--rule); margin-top: 1.6rem; padding-top: .4rem; }
.shop-result h3 { margin-top: 1.4rem; }
.shop-better {
  margin: 0 0 .8rem; padding: 1rem 1.2rem; background: var(--paper);
  border-left: 4px solid var(--sign-blue); border-radius: 0 var(--radius-ui) var(--radius-ui) 0;
  font-family: var(--serif); font-size: 1.1rem; white-space: pre-wrap;
}
.shop-changes { font-family: var(--serif); margin: 0; padding-left: 1.2rem; }
.shop-changes li { margin-bottom: .35rem; }
.shop-quip { font-family: var(--serif); font-style: italic; color: var(--ink-soft); margin: 1.2rem 0 0; }

/* ---------- 5: warnings ---------- */

.warnings { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 22rem), 1fr)); gap: 2rem 2.5rem; margin: 2rem 0; max-width: 60rem; }
.warning { display: grid; grid-template-columns: 3.6rem 1fr; column-gap: 1rem; }
.warning svg { width: 3.6rem; height: 3.6rem; grid-row: span 2; }
.warning h3 { font-family: var(--display); font-weight: 600; font-size: 1.6rem; line-height: 1.1; margin: .2rem 0 .4rem; }
.warning p { margin: 0; font-size: 1.05rem; }

/* ---------- 6: recipes ---------- */

.recipes { list-style: none; padding: 0; margin: 1.8rem 0; max-width: 54rem; border-top: 1px solid var(--rule); }
.recipe { border-bottom: 1px solid var(--rule); }
.recipe details > summary {
  list-style: none; cursor: pointer; display: flex; justify-content: space-between; align-items: center; gap: 1rem;
  padding: 1rem .2rem; font-family: var(--display); font-weight: 600; font-size: 1.45rem; line-height: 1.15;
}
.recipe details > summary::-webkit-details-marker { display: none; }
.recipe summary::after {
  content: ""; flex: none; width: .7rem; height: .7rem; margin-right: .4rem;
  border-right: 3px solid var(--sign-blue); border-bottom: 3px solid var(--sign-blue);
  transform: rotate(45deg); transition: transform .2s;
}
.recipe details[open] summary::after { transform: rotate(-135deg); }
.recipe-body { padding: 0 .2rem 1.3rem; }
.recipe-body pre {
  margin: 0 0 .8rem; padding: 1rem 1.1rem; white-space: pre-wrap;
  background: var(--paper-raised); border: 1px solid var(--rule); border-radius: var(--radius-ui);
  font-family: var(--serif); font-size: 1.04rem; line-height: 1.55;
}
.recipe-body mark { background: color-mix(in srgb, var(--sign-yellow) 55%, transparent); color: inherit; padding: 0 .15em; border-radius: 2px; }

/* ---------- 7: exam ---------- */

.exam-road { position: relative; height: 10px; border-radius: 5px; background: var(--post); opacity: .9; overflow: hidden; }
.exam-road::after {
  content: ""; position: absolute; left: 0; right: 0; top: 4px; height: 2px;
  background-image: linear-gradient(90deg, #fff 50%, transparent 50%); background-size: 22px 2px;
}
.exam-road-fill { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--sign-blue); transition: width .4s; z-index: 1; }
.exam-progress { color: var(--ink-soft); font-size: .95rem; margin: .8rem 0 1rem; }
.exam-statement { font-family: var(--serif); font-size: clamp(1.35rem, 3vw, 1.85rem); line-height: 1.35; margin: 0 0 1.5rem; min-height: 2.7em; max-width: 36em; }
.exam-answers { display: flex; gap: .8rem; flex-wrap: wrap; }
.btn-answer { min-width: 9rem; background: var(--paper); color: var(--ink); border-color: var(--ink); font-size: 1.15rem; }
.btn-answer:hover:not([disabled]) { background: var(--ink); color: var(--paper); }
.btn-answer.right { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn-answer.wrong { background: var(--sign-red); border-color: var(--sign-red); color: #fff; }
.btn-answer[disabled] { cursor: default; }
.exam-feedback { font-family: var(--serif); margin: 1.2rem 0; max-width: var(--measure); }
.exam-feedback strong { font-family: var(--ui); }
.exam-result h3 { font-family: var(--display); font-weight: 700; font-size: 2.4rem; margin: 0 0 .5rem; }

.license-wrap { margin: 2rem 0; max-width: 34rem; }
.license-form { margin-bottom: 1.4rem; }
.license {
  background: #fff; color: #1B2433;
  border-radius: 14px; overflow: hidden;
  border: 1px solid #C9D0D8;
  box-shadow: 0 1px 0 rgba(0,0,0,.04), 0 20px 40px -18px rgba(11, 40, 80, .45);
  aspect-ratio: 85.6 / 54; display: flex; flex-direction: column;
}
.license-band { background: var(--sign-blue); color: #fff; display: flex; justify-content: space-between; align-items: center; padding: .7rem 1.1rem; }
.license-title { font-family: var(--display); font-weight: 700; font-size: 1.8rem; line-height: 1; }
.license-band svg { width: 2.3rem; height: 2.3rem; }
.license-body { flex: 1; display: grid; grid-template-columns: 1fr 1fr; gap: .5rem 1rem; margin: 0; padding: .9rem 1.1rem 0; font-family: var(--ui); }
.license-body div:first-child { grid-column: 1 / -1; }
.license-body dt { font-size: .75rem; font-weight: 500; color: #5A6575; }
.license-body dd { margin: 0; font-weight: 600; font-size: 1.1rem; line-height: 1.2; }
.license-body dd span { font-weight: 500; color: #5A6575; font-size: .9rem; }
.license-holder { font-family: var(--display); font-size: 1.7rem !important; font-weight: 700 !important; }
.license-fine { margin: 0; padding: .4rem 1.1rem .7rem; font-family: var(--ui); font-size: .72rem; color: #5A6575; border-top: 4px solid var(--sign-yellow); }
.license-actions { display: flex; gap: .8rem; margin-top: 1.4rem; flex-wrap: wrap; }

/* ---------- Glossary ---------- */

.glossary { padding: 4.5rem 0 1rem; border-top: 1px solid var(--rule); }
.glossary h2 { font-family: var(--display); font-weight: 700; font-size: clamp(2.3rem, 4.6vw, 3.4rem); line-height: 1; margin: 0 0 1.5rem; }
.glossary-list { max-width: var(--measure); }
.glossary details { border-bottom: 1px solid var(--rule); }
.glossary summary { cursor: pointer; padding: .75rem 0; font-family: var(--ui); font-weight: 600; font-size: 1.1rem; }
.glossary details p { margin: 0 0 1rem; }

/* ---------- Footer ---------- */

.footer { border-top: 1px solid var(--rule); padding: 2.5rem clamp(1rem, 4vw, 2.5rem) 3.5rem; max-width: 1240px; margin: 0 auto; font-size: 1rem; color: var(--ink-soft); }
.footer p { max-width: var(--measure); margin: 0 0 .7rem; }

/* ---------- Print: only the licence ---------- */

@media print {
  body { background: #fff; }
  body * { visibility: hidden; }
  .license, .license * { visibility: visible; }
  .license { position: absolute; left: 1cm; top: 1cm; width: 12cm; box-shadow: none; }
  .license-band, .license-fine { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
