:root {
  color-scheme: dark;
  --bg: #0f172a;
  --elev: #1b2336;
  --ink: #f8fafc;
  --muted: #94a3b8;
  --line: #3e4c63;
  --stroke: #64748b;
  --accent: #22c55e;
  --accent-hover: #4ade80;
  --on-accent: #0f172a;
  --link: #4ade80;
  --good: #22c55e;
  --on-good: #0f172a;
  --danger: #f87171;
  --hover: #272f42;
  --active: color-mix(in srgb, #22c55e 18%, #1b2336);
  --code-bg: #020617;
  --code-fg: #f8fafc;
  --code-inline: #272f42;
  --ring: #ffffff;
  --header: 4.75rem;
  --sans: "IBM Plex Sans", "Segoe UI", "Noto Sans", "Liberation Sans", system-ui, sans-serif;
  --mono: "JetBrains Mono", "SFMono-Regular", "Cascadia Mono", "Noto Sans Mono", "Liberation Mono", ui-monospace, monospace;
  --move: 180ms;
  --ease: cubic-bezier(0.2, 0, 0, 1);
  --shadow: none;
}

@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --bg: #f1f5f9;
    --elev: #ffffff;
    --ink: #0f172a;
    --muted: #334155;
    --line: #e2e8f0;
    --stroke: #64748b;
    --accent: #15803d;
    --accent-hover: #166534;
    --on-accent: #ffffff;
    --link: #166534;
    --good: #15803d;
    --on-good: #ffffff;
    --danger: #b91c1c;
    --hover: #e2e8f0;
    --active: #dcfce7;
    --code-bg: #0f172a;
    --code-fg: #f8fafc;
    --code-inline: #e2e8f0;
    --ring: #0f172a;
    --shadow: 0 1px 2px rgb(15 23 42 / 0.06);
  }
}

* { box-sizing: border-box; }

html { scroll-padding-top: var(--header); }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.65;
  text-rendering: optimizeLegibility;
}

::selection { background: var(--accent); color: var(--on-accent); }

:where(a, button, input, summary, h1, h2, h3, h4) { scroll-margin-top: calc(var(--header) + 0.5rem); }

a:focus-visible,
button:focus-visible,
input:focus-visible,
summary:focus-visible,
.nav-toggle:focus-visible + .nav-label {
  outline: 2px solid var(--ring);
  outline-offset: 2px;
}

.skip {
  position: absolute;
  left: max(0.75rem, env(safe-area-inset-left));
  top: max(0.75rem, env(safe-area-inset-top));
  transform: translateY(-150%);
  background: var(--accent);
  color: var(--on-accent);
  padding: 0.55rem 0.85rem;
  border-radius: 8px;
  z-index: 30;
  font-weight: 600;
}
.skip:focus { transform: none; }

.top {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--bg);
  padding: max(0.35rem, env(safe-area-inset-top)) 0 0;
}

.toprow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1rem;
  max-width: 1180px;
  margin: 0 auto;
  padding: 0.35rem max(1.25rem, env(safe-area-inset-right)) 0.35rem max(1.25rem, env(safe-area-inset-left));
  min-height: 3rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-width: 0;
  min-height: 44px;
  color: inherit;
  text-decoration: none;
  font-size: 1.05rem;
}
.brand b {
  font-family: var(--mono);
  font-weight: 600;
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  background: var(--accent);
  color: var(--on-accent);
  padding: 0.28rem 0.42rem;
  border-radius: 4px;
}
.brand span {
  font-weight: 600;
  letter-spacing: -0.02em;
  text-wrap: balance;
}

.topmeta {
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.15rem 0.35rem;
  font-family: var(--mono);
  font-size: 0.8125rem;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

.bar {
  margin: 0.45rem 0 0;
  height: 6px;
  background: var(--line);
}
.bar::before {
  content: "";
  display: block;
  height: 100%;
  width: var(--p, 0%);
  background: var(--accent);
  box-shadow: 0 0 10px color-mix(in srgb, var(--accent) 65%, transparent);
}

.shell {
  display: grid;
  grid-template-columns: 18rem minmax(0, 1fr);
  gap: 2rem;
  max-width: 1180px;
  margin: 0 auto;
  padding: 1.5rem max(1.25rem, env(safe-area-inset-right)) max(4rem, env(safe-area-inset-bottom)) max(1.25rem, env(safe-area-inset-left));
}

.rail { min-width: 0; }

@media (min-width: 801px) {
  .rail {
    position: sticky;
    top: var(--header);
    max-height: calc(100vh - var(--header) - 1rem);
    max-height: calc(100dvh - var(--header) - 1rem);
    overflow: auto;
    padding-right: 0.2rem;
    overscroll-behavior: contain;
  }
}

.desk {
  background: var(--elev);
  border: 1px solid var(--stroke);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 0.9rem 0.9rem 0.75rem;
  margin-bottom: 1rem;
}
.desk h2,
.ladder-wrap summary,
nav.side h2 {
  margin: 0 0 0.5rem;
  font-family: var(--mono);
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}
.desk label {
  display: block;
  margin-bottom: 0.35rem;
  font-size: 0.95rem;
  font-weight: 500;
}
.desk-row { display: flex; gap: 0.5rem; align-items: stretch; }
.desk-row input {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  font-family: var(--mono);
  font-size: 16px;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--stroke);
  border-radius: 8px;
  padding: 0.45rem 0.65rem;
  transition: border-color var(--move) var(--ease), background-color var(--move) var(--ease);
}
.desk-row input[aria-invalid="true"] { border-color: var(--danger); border-width: 2px; }
.desk-row input::placeholder { color: var(--muted); opacity: 0.7; }
#gate {
  margin: 0.65rem 0 0.35rem;
  padding: 0.65rem 0.7rem;
  min-height: 2.7em;
  font-size: 0.9rem;
  line-height: 1.45;
  color: var(--muted);
  border: 1px dashed var(--stroke);
  border-radius: 8px;
}
#gate[data-state="logged"] {
  color: var(--ink);
  border-style: solid;
  border-color: color-mix(in srgb, var(--accent) 55%, var(--stroke));
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}
#gate[data-state="invalid"],
#gate[data-state="blocked"] {
  color: var(--danger);
  border-style: solid;
  border-color: var(--danger);
  background: color-mix(in srgb, var(--danger) 10%, transparent);
}
.ladder-wrap summary {
  cursor: pointer;
  display: flex;
  align-items: center;
  min-height: 44px;
  margin: 0.25rem 0 0;
  list-style: none;
  touch-action: manipulation;
}
.ladder-wrap summary::-webkit-details-marker { display: none; }
.ladder-wrap summary::before {
  content: "";
  width: 0.45rem;
  height: 0.45rem;
  margin-right: 0.5rem;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(-45deg);
  transition: transform var(--move) var(--ease);
}
.ladder-wrap[open] summary::before { transform: rotate(45deg) translateY(-2px); }
.ladder-wrap summary:hover { color: var(--ink); }
#ladder {
  list-style: none;
  margin: 0.15rem 0 0;
  padding: 0;
  display: grid;
  gap: 0.15rem;
}
#ladder li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 1.75rem;
  font-family: var(--mono);
  font-size: 0.8125rem;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  padding-left: 0.55rem;
  border-left: 2px solid var(--line);
}
#ladder li::before {
  content: "";
  width: 0.75rem;
  height: 0.75rem;
  flex: none;
  border: 1.5px solid var(--stroke);
  border-radius: 2px;
  background: transparent;
}
#ladder li.cleared { color: var(--ink); border-left-color: var(--accent); }
#ladder li.cleared::before { background: var(--accent); border-color: var(--accent); }
.noscript { margin: 0.5rem 0 0; font-size: 0.9rem; color: var(--muted); }

button,
.nav-label,
nav.side a,
.turn a,
summary { touch-action: manipulation; }

button {
  font-family: var(--sans);
  font-weight: 600;
  font-size: 0.95rem;
  min-height: 44px;
  min-width: 44px;
  background: var(--accent);
  color: var(--on-accent);
  border: 0;
  border-radius: 999px;
  padding: 0.45rem 1rem;
  cursor: pointer;
  transition: background-color var(--move) var(--ease), transform var(--move) var(--ease);
}
button:hover { background: var(--accent-hover); }
button:active { transform: scale(0.98); }
#mark {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--stroke);
}
#mark:hover { background: var(--hover); color: var(--ink); }
#mark[aria-pressed="true"],
#mark[aria-pressed="true"]:hover {
  background: var(--accent);
  color: var(--on-accent);
  border-color: var(--accent);
}

.nav-toggle {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}
.nav-label { display: none; }

nav.side { display: flex; flex-direction: column; gap: 0.15rem; }
nav.side h2 { margin-top: 1rem; }
nav.side h2:first-child { margin-top: 0; }
nav.side a {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 2.25rem;
  color: inherit;
  text-decoration: none;
  border-radius: 8px;
  padding: 0.35rem 0.6rem;
  font-size: 0.95rem;
  cursor: pointer;
  transition: background-color var(--move) var(--ease), color var(--move) var(--ease);
}
nav.side a:hover { background: var(--hover); }
nav.side a:focus-visible { outline-offset: -2px; }
nav.side a.active {
  background: var(--active);
  font-weight: 600;
  box-shadow: inset 3px 0 0 var(--accent);
}
nav.side a.active:hover { background: var(--active); }
nav.side a.is-read::after {
  content: "";
  width: 0.42rem;
  height: 0.24rem;
  margin-left: auto;
  flex: none;
  border-left: 2px solid var(--accent);
  border-bottom: 2px solid var(--accent);
  transform: rotate(-45deg) translateY(-1px);
}

main, .prose, .rail { min-width: 0; }
.prose a { overflow-wrap: anywhere; }

.prose h1 {
  font-weight: 700;
  font-size: clamp(2rem, 4vw, 2.75rem);
  line-height: 1.12;
  letter-spacing: -0.03em;
  text-wrap: balance;
  margin: 0 0 0.85rem;
}
.prose h1 + p {
  font-size: 1.2rem;
  line-height: 1.5;
  color: var(--ink);
}
.prose h2, .prose h3, .prose h4 {
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: -0.02em;
  text-wrap: balance;
  margin: 2.5rem 0 0.65rem;
}
.prose h2 {
  font-size: 1.4rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--line);
}
.prose h3 { font-size: 1.15rem; }
.prose p, .prose ul, .prose ol, .prose blockquote, .prose pre, .prose h1, .prose h2, .prose h3, .prose h4 {
  max-width: 68ch;
}
.prose p { margin: 0.85rem 0; }
.prose a { color: var(--link); text-underline-offset: 0.18em; }
.prose a:hover { color: var(--accent-hover); }
.prose ul, .prose ol { padding-left: 1.25rem; }
.prose li { margin: 0.35rem 0; }
.prose li.task { list-style: none; margin-left: -1.15rem; }
.prose li.task label {
  display: flex;
  gap: 0.65rem;
  align-items: flex-start;
  min-height: 44px;
  padding: 0.35rem 0;
  cursor: pointer;
}
.prose li.task input {
  margin-top: 0.3rem;
  width: 1.25rem;
  height: 1.25rem;
  accent-color: var(--accent);
}
.prose li.task:has(input:checked) span { color: var(--muted); }
.prose blockquote {
  margin: 1.25rem 0;
  padding: 0.15rem 0 0.15rem 0.9rem;
  border-left: 3px solid var(--accent);
  color: var(--muted);
  font-size: 1.08rem;
}
.prose blockquote p { margin: 0; }
.prose hr { border: 0; border-top: 1px solid var(--line); margin: 1.75rem 0; max-width: 68ch; }
.prose code {
  font-family: var(--mono);
  font-size: 0.86em;
  background: var(--code-inline);
  padding: 0.1em 0.35em;
  border-radius: 4px;
}
.prose pre {
  background: var(--code-bg);
  color: var(--code-fg);
  padding: 1rem 1.05rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  overflow-x: auto;
  line-height: 1.5;
  max-width: min(68ch, 100%);
  min-width: 0;
}
.prose pre code { background: none; color: inherit; padding: 0; font-size: 0.84rem; }

.tablewrap {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow-x: auto;
  border: 1px solid var(--stroke);
  border-radius: 10px;
  margin: 1.15rem 0;
  background: var(--elev);
  box-shadow: var(--shadow);
}
table { border-collapse: collapse; width: 100%; font-size: 0.95rem; }
th, td {
  text-align: left;
  vertical-align: top;
  padding: 0.7rem 0.8rem;
  border-bottom: 1px solid var(--line);
}
td { overflow-wrap: break-word; }
tbody tr:hover td { background: var(--hover); }
th {
  font-family: var(--mono);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
  background: var(--elev);
}
tr:last-child td { border-bottom: 0; }

.markrow { margin: 1.75rem 0 0; }
.turn {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  margin-top: 0.75rem;
}
.turn a {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  border: 1px solid var(--stroke);
  background: var(--elev);
  box-shadow: var(--shadow);
  border-radius: 10px;
  padding: 0.75rem 0.9rem;
  text-decoration: none;
  color: inherit;
  cursor: pointer;
  transition: border-color var(--move) var(--ease), background-color var(--move) var(--ease), transform var(--move) var(--ease);
}
.turn a:hover { border-color: var(--accent); background: var(--hover); }
.turn a:active { transform: scale(0.99); }
.turn a.next { text-align: right; }
.turn small {
  display: block;
  font-family: var(--mono);
  font-size: 0.75rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}
.turn span { display: block; font-weight: 600; font-size: 1.05rem; }
.note { margin: 1.5rem 0 0; color: var(--muted); font-size: 0.9rem; }

@media (max-width: 800px) {
  :root { --header: 7.25rem; }
  .shell { grid-template-columns: 1fr; gap: 1rem; padding: 1rem max(1rem, env(safe-area-inset-right)) max(3rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left)); }
  .toprow { padding-left: max(1rem, env(safe-area-inset-left)); padding-right: max(1rem, env(safe-area-inset-right)); }
  .rail {
    position: static;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    max-height: none;
    overflow: visible;
  }
  .desk { margin-bottom: 0; }
  .navblock { order: -1; }
  .nav-label {
    display: flex;
    align-items: center;
    min-height: 44px;
    padding: 0.65rem 0.85rem;
    border: 1px solid var(--stroke);
    border-radius: 10px;
    background: var(--elev);
    font-weight: 600;
    cursor: pointer;
  }
  .nav-label::after {
    content: "";
    width: 0.45rem;
    height: 0.45rem;
    margin-left: auto;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: rotate(-45deg);
    transition: transform var(--move) var(--ease);
  }
  .nav-toggle:checked + .nav-label::after { transform: rotate(45deg) translateY(-2px); }
  nav.side { display: none; gap: 0.5rem; padding-top: 0.5rem; }
  .nav-toggle:checked + .nav-label + nav.side { display: flex; }
  nav.side a { min-height: 44px; }
}

@media (pointer: coarse) {
  nav.side a { min-height: 44px; }
}

@media (max-width: 480px) {
  .toprow { flex-wrap: wrap; }
  .brand span { font-size: 1rem; }
  .desk-row { flex-wrap: wrap; }
  .desk-row button { flex: 1; }
  .turn { flex-direction: column; }
  .turn a.next { text-align: left; }
}

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

@media (forced-colors: active) {
  .bar::before { background: Highlight; box-shadow: none; }
  nav.side a.active { outline: 2px solid Highlight; }
  button { border: 1px solid ButtonText; }
}
