@font-face {
  font-family: Literata;
  src: url("fonts/literata.woff2") format("woff2");
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}

:root {
  color-scheme: light;
  --paper: #f3f4f6;
  --sheet: #ffffff;
  --ink: #1c1f24;
  --quiet: #3c4450;
  --line: #d5dae2;
  --link: #0f3f73;
  --key: #f7f8fa;
  --bar: #0f3f73;
  --shadow: 0 12px 28px rgba(28, 31, 36, 0.16);
  --nav: 16.5rem;
  --measure: 68ch;
  --page: calc(var(--nav) + var(--measure) + 5rem);
  --fast: 180ms;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  font-family: Literata, "Iowan Old Style", Palatino, "Palatino Linotype", Georgia, serif;
  font-size: 19px;
  line-height: 1.65;
  color: var(--ink);
  background: var(--paper);
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --paper: #14161a;
    --sheet: #1c1f26;
    --ink: #f3f4f6;
    --quiet: #c8cdd6;
    --line: #3a4150;
    --link: #b7d0f0;
    --key: #12141a;
    --bar: #b7d0f0;
    --shadow: 0 12px 28px rgba(0, 0, 0, 0.45);
  }
}

* { box-sizing: border-box; }

html { scroll-padding-top: 1.25rem; overflow-anchor: none; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  touch-action: manipulation;
}

::selection { background: #d5e4f5; color: #1c1f24; }

@media (prefers-color-scheme: dark) {
  ::selection { background: #24466e; color: #f3f4f6; }
}

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 99px; border: 3px solid var(--paper); }

.lessons.desk { scrollbar-width: thin; scrollbar-color: var(--line) transparent; }

.skip {
  position: absolute;
  left: 1rem;
  top: -4rem;
  background: var(--ink);
  color: var(--paper);
  padding: 0.6rem 0.9rem;
  z-index: 20;
}

.skip:focus { top: 0.6rem; }

.readbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  z-index: 30;
  background: transparent;
}

.readbar span {
  display: block;
  height: 100%;
  width: 100%;
  background: var(--bar);
  transform: scaleX(0);
  transform-origin: 0 50%;
}

.mast, .layout { padding-inline: 1.25rem; }

.mast {
  display: grid;
  grid-template-columns: var(--nav) minmax(0, var(--measure));
  column-gap: 2.5rem;
  align-items: end;
  max-width: var(--page);
  margin: 0 auto;
  padding-top: 1.75rem;
  padding-bottom: 0.35rem;
}

h1, h2, h3, h4 {
  font-weight: 650;
  letter-spacing: -0.02em;
  line-height: 1.2;
  text-wrap: balance;
  scroll-margin-top: 1.25rem;
}

h1 {
  grid-column: 2;
  grid-row: 1;
  font-size: clamp(2rem, 2.7vw, 2.55rem);
  max-width: none;
  margin: 0;
  padding-bottom: 3.5rem;
}

.start { grid-column: 2; grid-row: 1; align-self: end; justify-self: start; }

h2 { font-size: clamp(1.7rem, 3vw, 2.15rem); margin: 0 0 0.8rem; }

h3 { font-size: 1.35rem; margin: 2rem 0 0.45rem; }

h4 { font-size: 1.12rem; margin: 1.4rem 0 0.35rem; }

p, li { text-wrap: pretty; overflow-wrap: anywhere; }

a { color: var(--link); text-underline-offset: 0.18em; }

a:hover { text-decoration-thickness: 2px; }

:focus-visible {
  outline: 2px solid var(--link);
  outline-offset: 3px;
}

.start, button, summary {
  font: inherit;
  cursor: pointer;
}

.start, .play, .copy, dialog button, summary {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.4rem 0.95rem;
  border-radius: 999px;
  border: 1px solid var(--ink);
  background: var(--ink);
  color: var(--paper);
  text-decoration: none;
}

.start:hover, .play:hover, .copy:hover, dialog button:hover, summary:hover {
  background: var(--link);
  border-color: var(--link);
  color: #fff;
}

.find {
  display: block;
  grid-column: 1;
  grid-row: 1;
  align-self: end;
  margin: 0;
  max-width: none;
}

.find label, .finder label {
  display: grid;
  gap: 0.35rem;
  font-size: 0.95rem;
  color: var(--quiet);
}

input[type="search"] {
  font: inherit;
  font-size: 1rem;
  color: var(--ink);
  background: var(--sheet);
  border: 1px solid var(--line);
  border-radius: 10px;
  min-height: 44px;
  padding: 0.4rem 0.75rem;
  width: 100%;
}

#find-status, #dueler-status { min-height: 1.4em; color: var(--quiet); margin: 0.2rem 0 0.6rem; }

#find-status, #find-results { grid-column: 1; }

#find-status:empty, #find-results:empty { display: none; }

#find-results { margin: 0.35rem 0 0; padding-left: 1.1rem; }

.layout {
  display: grid;
  grid-template-columns: var(--nav) minmax(0, var(--measure));
  gap: 2.5rem;
  max-width: var(--page);
  margin: 0 auto;
  padding-bottom: 5rem;
  align-items: start;
}

.lessons.desk {
  position: sticky;
  top: 1rem;
  max-height: calc(100dvh - 2rem);
  overflow: auto;
  padding-right: 0.4rem;
}

.lessons ol { margin: 0; padding-left: 1.15rem; }

.lessons li { margin: 0.15rem 0; }

.lessons a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  color: var(--ink);
  text-decoration: none;
}

.lessons a[aria-current="true"] { font-weight: 650; text-decoration: underline; text-underline-offset: 0.2em; }

.lessons li[hidden] { display: none; }

.pocket { display: none; }

main { min-width: 0; }

main > :first-child { margin-top: 0; }

.chapter { margin: 0 0 3.5rem; }

.outline {
  margin: 0 0 1.4rem;
  padding: 0;
}

.outline ol { margin: 0; padding-left: 1.2rem; }

.outline a { color: var(--ink); }

.prose > :first-child { margin-top: 0; }

blockquote {
  margin: 1.2rem 0;
  padding-left: 1rem;
  border-left: 1px solid var(--ink);
}

.callout {
  margin: 1.2rem 0;
  padding: 0.9rem 1rem;
  background: var(--sheet);
  border: 1px solid var(--line);
  border-radius: 12px;
}

hr { border: 0; border-top: 1px solid var(--line); margin: 2rem 0; }

.columns { display: grid; gap: 1rem; }

.shot { margin: 1.3rem 0; }

.enlarge {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: zoom-in;
  border-radius: 12px;
}

.enlarge img {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 12px;
  background: var(--line);
}

.enlarge span {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  color: var(--link);
}

.video { margin: 1.3rem 0; }

.video iframe {
  width: 100%;
  aspect-ratio: 16 / 9;
  border: 0;
  border-radius: 12px;
  background: #000;
}

.codeblock {
  position: relative;
  margin: 1.2rem 0;
}

.code-label {
  position: absolute;
  left: 0.8rem;
  top: 0.55rem;
  color: #c8cdd6;
  font-size: 0.8rem;
}

.copy {
  position: absolute;
  top: 0.45rem;
  right: 0.45rem;
  min-height: 2rem;
  padding-block: 0.2rem;
  background: transparent;
  color: #f3f4f6;
  border-color: #c8cdd6;
}

.code-actions {
  position: absolute;
  top: 0.45rem;
  right: 0.45rem;
  display: flex;
  gap: 0.4rem;
}

.code-actions .copy {
  position: static;
  padding-inline: 0.65rem;
}

pre {
  overflow: auto;
  margin: 0;
  padding: 3.3rem 0 0.75rem;
  border-radius: 12px;
  background: #262538;
  color: #1e90ff;
  font-size: 0.92rem;
  line-height: 1.45;
}

.codeblock code { display: block; }

.line {
  display: grid;
  grid-template-columns: 2.75rem minmax(0, 1fr);
  min-height: 1.45em;
}

.ln {
  color: #22b4d6;
  text-align: right;
  padding-right: 0.55rem;
  border-right: 1px solid rgba(255, 255, 255, 0.16);
  user-select: none;
}

.src { padding-left: 0.8rem; white-space: pre; }

.tok-flow { color: #fd861e; }
.tok-cmd { color: #2b90af; }
.tok-expr { color: #f02540; }
.tok-obj { color: #ae81ff; }
.tok-str { color: #b5f109; }
.tok-num { color: #7ecbff; }
.tok-note { color: #9a9aa3; }

code { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; }

.prose p code, .prose li code {
  background: var(--key);
  padding: 0.05rem 0.3rem;
  border-radius: 4px;
}

.prose li .codeblock code,
.prose p .codeblock code {
  display: block;
  background: transparent;
  padding: 0;
  border-radius: 0;
}

table {
  border-collapse: collapse;
  width: 100%;
  margin: 1.2rem 0;
  font-variant-numeric: tabular-nums;
  font-size: 0.95rem;
}

th, td {
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  padding: 0.55rem 0.5rem;
}

th { font-weight: 650; }

.table-wrap { overflow-x: auto; }

.keyline {
  display: grid;
  grid-template-columns: 8.5rem minmax(0, 1fr);
  gap: 0.75rem;
  align-items: baseline;
  padding: 0.35rem 0;
  border-bottom: 1px solid var(--line);
}

kbd {
  font-family: inherit;
  font-weight: 650;
  background: var(--key);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 8px;
  padding: 0.2rem 0.5rem;
  justify-self: start;
}

li:has(.keyline) { list-style: none; margin-left: -1.2rem; }

.turn {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.25rem;
  margin-top: 2rem;
}

.finder { margin-top: 1rem; max-width: 24rem; }

dialog {
  width: min(960px, calc(100vw - 2rem));
  border: 0;
  padding: 0.6rem;
  background: var(--sheet);
  color: var(--ink);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

dialog::backdrop { background: rgba(12, 14, 18, 0.72); }

dialog img { width: auto; max-width: 100%; height: auto; display: block; margin: 0 auto; }

dialog form { display: flex; justify-content: flex-end; margin-bottom: 0.4rem; }

@media (min-width: 800px) {
  .columns { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 800px) {
  :root { font-size: 18px; }
  .layout { grid-template-columns: 1fr; gap: 0; padding-bottom: calc(5rem + env(safe-area-inset-bottom)); }
  .desk { display: none; }
  .pocket {
    display: block;
    position: sticky;
    bottom: 0;
    z-index: 15;
    background: var(--sheet);
    border-top: 1px solid var(--line);
    padding: 0.35rem 0.75rem calc(0.35rem + env(safe-area-inset-bottom));
  }
  .pocket summary { width: 100%; }
  .pocket nav { max-height: 50dvh; overflow: auto; padding: 0.4rem 0 0.6rem; }
  .pocket[open] { overscroll-behavior: contain; }
  .mast { display: flex; flex-direction: column; align-items: flex-start; gap: 0.85rem; }
  h1 { padding-bottom: 0; font-size: 2.15rem; }
  .start { align-self: flex-start; }
  .find { align-self: stretch; width: 100%; }
  .keyline { grid-template-columns: 1fr; }
}

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