:root {
  --paper: #efe7d7;
  --paper-light: #faf6ec;
  --ink: #0d1117;
  --code: #0a0f16;
  --cinnabar: #aa3f32;
  --cobalt: #2d4fd7;
  --acid: #dcefb2;
  --line: rgba(13, 17, 23, 0.22);
  --ink-fixed: #0d1117;
  --paper-fixed: #faf6ec;
  --surface: #faf6ec;
  --surface-glass: rgba(250, 246, 236, 0.78);
  --copy: #56544e;
  --subtle: #69665e;
  --edge: rgba(13, 17, 23, 0.68);
  --header-glass: rgba(239, 231, 215, 0.9);
  --grid-line: rgba(13, 17, 23, 0.035);
  --shadow: rgba(13, 17, 23, 0.2);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
img, picture, svg { height: auto; max-width: 100%; }
body {
  background:
    radial-gradient(circle at 8% 5%, rgba(170, 63, 50, 0.11), transparent 26rem),
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px),
    var(--paper);
  background-size: auto, 34px 34px, 34px 34px, auto;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  margin: 0;
}
a { color: inherit; }
a:focus-visible { outline: 3px solid var(--cobalt); outline-offset: 4px; }

.site-header {
  align-items: center;
  backdrop-filter: blur(18px);
  background: var(--header-glass);
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  min-height: 76px;
  padding: 0 clamp(20px, 5vw, 72px);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { align-items: center; display: flex; gap: 12px; text-decoration: none; }
.brand > span {
  align-items: center;
  background: var(--ink-fixed);
  color: var(--paper-fixed);
  display: inline-flex;
  font-family: Georgia, serif;
  height: 42px;
  justify-content: center;
  letter-spacing: 0.08em;
  width: 42px;
}
.brand strong { font-family: Georgia, serif; font-size: 1.02rem; letter-spacing: 0.02em; }
.library-link { font-size: 0.76rem; font-weight: 850; letter-spacing: 0.08em; text-decoration: none; text-transform: uppercase; }
.header-tools { align-items: center; display: flex; gap: 14px; }
.header-tools button { background: transparent; border: 1px solid var(--line); color: var(--ink); cursor: pointer; font-size: 0.68rem; font-weight: 850; min-height: 38px; padding: 0 12px; text-transform: uppercase; }
.header-tools button:hover { background: var(--cobalt); border-color: var(--cobalt); color: white; }

main { margin: 0 auto; max-width: 1240px; padding: 46px clamp(20px, 5vw, 72px) 100px; }
.breadcrumbs { align-items: center; color: var(--subtle); display: flex; flex-wrap: wrap; font-size: 0.76rem; gap: 9px; margin-bottom: 44px; }
.breadcrumbs a { font-weight: 800; text-decoration: none; }
.breadcrumbs span:last-child { color: var(--ink); }

.problem-hero { align-items: end; display: grid; gap: 38px; grid-template-columns: 1fr auto; padding-bottom: 42px; }
.eyebrow { color: var(--cinnabar); font-size: 0.72rem; font-weight: 900; letter-spacing: 0.14em; margin: 0 0 18px; text-transform: uppercase; }
h1, h2 { font-family: Georgia, "Times New Roman", serif; font-weight: 500; }
h1 { font-size: clamp(3.4rem, 8vw, 7.6rem); letter-spacing: -0.055em; line-height: 0.9; margin: 0; max-width: 1000px; }
.summary { color: var(--copy); font-family: Georgia, serif; font-size: clamp(1.05rem, 2vw, 1.35rem); line-height: 1.55; margin: 28px 0 0; max-width: 700px; }
.tags { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 26px; }
.tags span { border: 1px solid var(--edge); border-radius: 999px; font-family: ui-monospace, monospace; font-size: 0.7rem; padding: 7px 11px; }
.problem-number { align-items: center; background: var(--ink-fixed); color: white; display: flex; flex-direction: column; height: 176px; justify-content: center; width: 176px; }
.problem-number span, .problem-number small { font-size: 0.64rem; font-weight: 850; letter-spacing: 0.12em; text-transform: uppercase; }
.problem-number strong { color: var(--acid); font-family: Georgia, serif; font-size: 4.4rem; font-weight: 400; line-height: 1; margin: 5px 0; }

.actions { border-bottom: 1px solid var(--edge); border-top: 1px solid var(--edge); display: flex; flex-wrap: wrap; margin-bottom: 38px; }
.actions a, .actions button { align-items: center; background: transparent; border: 0; border-right: 1px solid var(--edge); color: var(--ink); cursor: pointer; display: inline-flex; font-size: 0.74rem; font-weight: 850; gap: 22px; justify-content: space-between; letter-spacing: 0.06em; min-height: 56px; padding: 0 20px; text-decoration: none; text-transform: uppercase; }
.actions a:hover, .actions button:hover, .actions button[aria-pressed="true"] { background: var(--acid); color: #0d1117; }
.actions a.primary { background: var(--cinnabar); color: white; }
.actions a.primary:hover { background: #c24e3e; }

[hidden] { display: none !important; }
.practice-card { align-items: center; background: var(--code); color: white; display: flex; flex-direction: column; min-height: 540px; padding: 72px 28px; text-align: center; }
.practice-sigil { align-items: center; border: 1px solid #607089; border-radius: 50%; color: var(--acid); display: flex; font-family: Georgia, serif; font-size: 2.3rem; height: 86px; justify-content: center; margin-bottom: 24px; width: 86px; }
.practice-card h2 { font-size: clamp(2.7rem, 5vw, 5rem); margin: 0; }
.practice-card > p:not(.eyebrow) { color: #a7b2c2; line-height: 1.7; max-width: 620px; }
.practice-card > div { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 20px; }
.practice-card a, .practice-card button { align-items: center; border: 1px solid var(--acid); cursor: pointer; display: inline-flex; font-size: 0.72rem; font-weight: 850; min-height: 48px; padding: 0 18px; text-decoration: none; text-transform: uppercase; }
.practice-card a { color: var(--acid); }
.practice-card button { background: var(--acid); color: #0d1117; }

.learning-panel { align-items: stretch; background: var(--surface-glass); border: 1px solid var(--edge); display: grid; gap: 34px; grid-template-columns: 1fr auto; margin-bottom: 36px; padding: 30px; }
.learning-panel h2 { font-size: clamp(2.3rem, 4vw, 4.2rem); margin: 0; }
.learning-panel > div > p:not(.eyebrow) { color: var(--copy); line-height: 1.7; max-width: 780px; }
.learning-tags { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 18px; }
.learning-tags span { border: 1px solid var(--edge); border-radius: 999px; font-size: 0.68rem; padding: 6px 10px; }
.learning-panel dl { display: grid; gap: 10px; margin: 0; min-width: 180px; }
.learning-panel dl > div { background: var(--ink-fixed); color: white; padding: 18px; }
.learning-panel dt { color: #9da8b7; font-size: 0.63rem; font-weight: 850; letter-spacing: 0.1em; text-transform: uppercase; }
.learning-panel dd { color: var(--acid); font-family: ui-monospace, monospace; font-size: 0.9rem; margin: 7px 0 0; }

.solution-credit { align-items: center; background: var(--surface-glass); border: 1px solid var(--edge); display: grid; gap: 28px; grid-template-columns: minmax(0, 1fr) auto; margin: -18px 0 36px; padding: 24px 30px; }
.solution-credit h2 { font-size: clamp(1.6rem, 3vw, 2.5rem); margin: 4px 0 8px; }
.solution-credit p:not(.eyebrow) { color: var(--copy); line-height: 1.65; margin: 0; max-width: 760px; }
.solution-credit p a { color: var(--cobalt); font-weight: 800; }
.solution-credit > div:last-child { display: flex; flex-wrap: wrap; gap: 9px; justify-content: flex-end; }
.solution-credit > div:last-child a { border: 1px solid var(--edge); color: var(--ink); font: 800 0.66rem/1 ui-monospace, SFMono-Regular, Menlo, monospace; padding: 13px 15px; text-decoration: none; text-transform: uppercase; }
.solution-credit > div:last-child a.primary { background: var(--cobalt); border-color: var(--cobalt); color: white; }
.solution-credit > div:last-child a:hover { background: var(--ink); color: var(--surface); }

.problem-runner {
  background: #0b111a;
  border: 1px solid #334156;
  color: #eef3f9;
  margin: 0 0 38px;
}
.problem-runner-heading {
  align-items: end;
  border-bottom: 1px solid #334156;
  display: grid;
  gap: 30px;
  grid-template-columns: 1fr 0.9fr;
  padding: 30px;
}
.problem-runner-heading h2 { font-size: clamp(2.7rem, 5vw, 5rem); letter-spacing: -0.05em; line-height: 0.9; margin: 0; }
.problem-runner-heading > p { color: #9ca8b9; line-height: 1.7; margin: 0; }
.problem-runner-toolbar {
  align-items: end;
  background: #121b28;
  border-bottom: 1px solid #334156;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 14px 18px;
}
.problem-runner-toolbar label { display: flex; flex-direction: column; gap: 5px; }
.problem-runner-toolbar label > span,
.problem-runner-grid label > span,
.problem-runner-result span {
  color: #8996a9;
  font: 800 0.58rem/1.3 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.problem-runner-toolbar select,
.problem-runner-toolbar button,
.problem-runner-toolbar a {
  align-items: center;
  background: #0a1019;
  border: 1px solid #46556a;
  color: #dbe3ee;
  cursor: pointer;
  display: inline-flex;
  font: 800 0.63rem/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  min-height: 40px;
  padding: 0 12px;
  text-decoration: none;
  text-transform: uppercase;
}
.problem-runner-toolbar button:hover,
.problem-runner-toolbar a:hover { border-color: var(--acid); color: var(--acid); }
.problem-runner-toolbar a { margin-left: auto; }
.problem-runner-grid { background: #334156; display: grid; gap: 1px; grid-template-columns: minmax(0, 1.25fr) minmax(300px, 0.75fr); }
.problem-runner-grid label { display: flex; flex-direction: column; gap: 8px; }
.runner-source,
.runner-inputs { background: #0d151f; padding: 18px; }
.problem-runner textarea {
  background: #070c13;
  border: 1px solid #2d3a4d;
  border-radius: 0;
  color: #dce6f3;
  font: 12px/1.65 "SFMono-Regular", Consolas, Menlo, monospace;
  outline: 0;
  padding: 14px;
  resize: vertical;
  tab-size: 4;
  width: 100%;
}
.problem-runner textarea:focus { border-color: #8dd8ff; box-shadow: 0 0 0 2px rgba(141, 216, 255, 0.12); }
.runner-source textarea {
  background:
    radial-gradient(circle at 88% 12%, rgba(66, 92, 136, 0.25), transparent 28rem),
    linear-gradient(145deg, #07101c 0%, #0b1625 52%, #09111d 100%);
  min-height: 430px;
}
.runner-inputs { display: flex; flex-direction: column; gap: 14px; }
.runner-inputs textarea { min-height: 112px; }
.runner-inputs p { background: #172235; color: #aeb9c8; font-size: 0.7rem; line-height: 1.6; margin: 0; padding: 12px; }
.runner-inputs p code { color: #8dd8ff; font-size: 0.68rem; }
.runner-inputs > button {
  background: var(--acid);
  border: 0;
  color: #0d1117;
  cursor: pointer;
  font-size: 0.69rem;
  font-weight: 900;
  margin-top: auto;
  min-height: 50px;
  text-transform: uppercase;
}
.runner-inputs > button:disabled,
.problem-runner-toolbar button:disabled { cursor: wait; opacity: 0.55; }
.problem-runner-result { border-top: 1px solid #334156; }
.problem-runner-result > div:first-child { align-items: center; display: flex; gap: 12px; min-height: 62px; padding: 12px 18px; }
.problem-runner-result strong { color: var(--acid); font: 800 0.82rem/1 ui-monospace, SFMono-Regular, Menlo, monospace; }
.problem-runner-result strong[data-verdict="pass"] { color: #b8f0b1; }
.problem-runner-result strong[data-verdict="fail"] { color: #ff9b8f; }
.problem-runner-result small { color: #758398; font: 0.62rem/1 ui-monospace, SFMono-Regular, Menlo, monospace; margin-left: auto; }
.problem-runner-output { background: #334156; display: grid; gap: 1px; grid-template-columns: 1fr 1fr; }
.problem-runner-output section { background: #070c13; min-width: 0; padding: 16px; }
.problem-runner-output pre { color: #dbe5f2; margin: 10px 0 0; max-height: 260px; overflow: auto; white-space: pre-wrap; }
.problem-trace-list { border-top: 1px solid #334156; list-style: none; margin: 0; max-height: 440px; overflow: auto; padding: 16px 18px; }
.problem-trace-list li { border-left: 2px solid #3d4f68; display: flex; flex-direction: column; gap: 7px; padding: 0 0 16px 14px; }
.problem-trace-list li strong { color: #8dd8ff; font: 700 0.67rem/1.3 ui-monospace, SFMono-Regular, Menlo, monospace; }
.problem-trace-list li span { color: #c2ccda; letter-spacing: 0; text-transform: none; }
.problem-runner-note { border-top: 1px solid #334156; color: #748196; font: 0.62rem/1.55 ui-monospace, SFMono-Regular, Menlo, monospace; margin: 0; padding: 13px 18px; }

.solution-panel { background: var(--code); box-shadow: 10px 10px 0 var(--shadow); color: white; }
.panel-heading { align-items: center; border-bottom: 1px solid #344154; display: flex; justify-content: space-between; padding: 22px 26px; }
.panel-heading span { color: #9eacbd; font-size: 0.68rem; font-weight: 850; letter-spacing: 0.11em; text-transform: uppercase; }
.panel-heading h2 { font-family: ui-monospace, monospace; font-size: 0.9rem; font-weight: 600; margin: 5px 0 0; }
.panel-heading .language { background: var(--acid); border-radius: 999px; color: #0d1117; padding: 7px 11px; }
.panel-tools { align-items: center; display: flex; flex-wrap: wrap; gap: 7px; justify-content: flex-end; }
.panel-tools button { background: transparent; border: 1px solid #536278; color: #d7dfeb; cursor: pointer; font-size: 0.64rem; font-weight: 850; min-height: 34px; padding: 0 10px; text-transform: uppercase; }
.panel-tools button:hover, .panel-tools button[aria-pressed="true"] { border-color: var(--acid); color: var(--acid); }
.solution-panel pre {
  background:
    radial-gradient(circle at 88% 12%, rgba(66, 92, 136, 0.25), transparent 28rem),
    linear-gradient(145deg, #07101c 0%, #0b1625 52%, #09111d 100%);
  margin: 0;
  max-height: 760px;
  overflow: auto;
  padding: 22px 0 30px;
}
code { color: #dce6f3; font-family: "SFMono-Regular", Consolas, monospace; font-size: 0.82rem; line-height: 1.65; }
.code-line { display: grid; grid-template-columns: 58px 1fr; min-height: 1.65em; padding-right: 24px; white-space: pre; }
.code-line:hover { background: rgba(220, 239, 178, 0.055); }
.line-number { border-right: 1px solid #263244; color: #64748b; margin-right: 18px; padding-right: 13px; text-align: right; user-select: none; }
.token-keyword, .token-preprocessor { color: #c586c0; }
.token-string { color: #ce9178; }
.token-number { color: #b5cea8; }
.token-comment { color: #6a9955; font-style: italic; }
.token-type { color: #4ec9b0; }
.token-function { color: #dcdcaa; }
.token-constant { color: #4fc1ff; }
.token-operator { color: #d4d4d4; }
.wrap-code .code-line > span:last-child { overflow-wrap: anywhere; white-space: pre-wrap; }
.solution-panel.fullscreen { bottom: 18px; display: flex; flex-direction: column; left: 18px; position: fixed; right: 18px; top: 18px; z-index: 100; }
.solution-panel.fullscreen pre { flex: 1; max-height: none; }
.no-scroll { overflow: hidden; }

.problem-support { align-items: center; background: linear-gradient(115deg, #172238 0%, #243d79 100%); color: white; display: flex; gap: 28px; justify-content: space-between; margin: 28px 0 38px; padding: 24px 28px; }
.problem-support > div:first-child { align-items: center; display: flex; gap: 16px; }
.problem-support > div:first-child > span { align-items: center; background: var(--acid); color: #0d1117; display: flex; flex: 0 0 48px; height: 48px; justify-content: center; }
.problem-support p { color: #d0dae9; font-size: 0.78rem; line-height: 1.6; margin: 0; max-width: 720px; }
.problem-support p strong { color: white; }
.problem-support > div:last-child { display: flex; flex: 0 0 auto; gap: 8px; }
.problem-support a { align-items: center; border: 1px solid #8190aa; color: white; display: inline-flex; font-size: 0.66rem; font-weight: 850; justify-content: center; min-height: 44px; padding: 0 14px; text-decoration: none; text-transform: uppercase; }
.problem-support a.primary { background: var(--acid); border-color: var(--acid); color: #0d1117; }
.problem-support a:hover { border-color: white; }

.related { padding: 82px 0 58px; }
.related h2 { font-size: clamp(2.5rem, 5vw, 4.5rem); margin: 0 0 30px; }
.related > div { display: grid; gap: 12px; grid-template-columns: repeat(3, 1fr); }
.related a { background: var(--surface-glass); border: 1px solid var(--edge); display: flex; flex-direction: column; min-height: 140px; padding: 22px; text-decoration: none; transition: transform 160ms ease, box-shadow 160ms ease; }
.related a:hover { box-shadow: 6px 6px 0 var(--shadow); transform: translate(-2px, -2px); }
.related a span { color: var(--cinnabar); font-size: 0.66rem; font-weight: 850; letter-spacing: 0.08em; text-transform: uppercase; }
.related a strong { font-family: Georgia, serif; font-size: 1.35rem; font-weight: 500; margin-top: auto; }

.page-nav { border-top: 1px solid var(--edge); display: grid; grid-template-columns: 1fr 1fr; padding-top: 26px; }
.page-nav a { display: flex; flex-direction: column; gap: 9px; max-width: 430px; text-decoration: none; }
.page-nav a.next { justify-self: end; text-align: right; }
.page-nav span { font-size: 0.68rem; font-weight: 850; letter-spacing: 0.1em; text-transform: uppercase; }
.page-nav strong { font-family: Georgia, serif; font-size: 1.2rem; font-weight: 500; }

footer { background: #080c13; color: white; display: flex; justify-content: space-between; padding: 32px clamp(20px, 5vw, 72px); }
footer a { font-family: Georgia, serif; font-size: 1.05rem; text-decoration: none; }
footer span { color: #aab3c0; font-size: 0.72rem; }

html[data-theme="moon"] {
  color-scheme: dark;
  --paper: #090d14;
  --paper-light: #151d2a;
  --ink: #f4efe6;
  --cinnabar: #e06a56;
  --cobalt: #8297ff;
  --acid: #cfe49b;
  --line: rgba(214, 224, 238, 0.2);
  --surface: #111925;
  --surface-glass: rgba(17, 25, 37, 0.9);
  --copy: #c5ceda;
  --subtle: #9ba8ba;
  --edge: rgba(209, 220, 236, 0.42);
  --header-glass: rgba(9, 13, 20, 0.88);
  --grid-line: rgba(221, 229, 241, 0.032);
  --shadow: rgba(0, 0, 0, 0.52);
}
html[data-theme="moon"] body { background: radial-gradient(circle at 12% 2%, rgba(130, 151, 255, 0.16), transparent 32rem), radial-gradient(circle at 88% 22%, rgba(224, 106, 86, 0.09), transparent 30rem), linear-gradient(var(--grid-line) 1px, transparent 1px), linear-gradient(90deg, var(--grid-line) 1px, transparent 1px), var(--paper); background-size: auto, auto, 34px 34px, 34px 34px, auto; }
html[data-theme="moon"] .site-header { border-bottom-color: rgba(211, 179, 110, 0.25); }
html[data-theme="moon"] .brand > span { background: #f4efe6; color: #090d14; }
html[data-theme="moon"] .learning-panel dl > div { background: #06090f; }
html[data-theme="moon"] .problem-number { background: #06090f; }
html[data-theme="moon"] .actions a.primary { background: #aa3f32; }

@media (max-width: 760px) {
  .brand strong { display: none; }
  main { padding-top: 30px; }
  .breadcrumbs { margin-bottom: 32px; }
  .problem-hero { align-items: start; grid-template-columns: 1fr; }
  .problem-number { height: 104px; width: 104px; }
  .problem-number strong { font-size: 2.6rem; }
  .actions { display: grid; }
  .actions a, .actions button { border-bottom: 1px solid var(--edge); border-right: 0; }
  .learning-panel { grid-template-columns: 1fr; padding: 22px; }
  .learning-panel dl { grid-template-columns: 1fr 1fr; min-width: 0; }
  .solution-credit { align-items: start; grid-template-columns: 1fr; margin-top: -18px; padding: 22px; }
  .solution-credit > div:last-child { justify-content: flex-start; }
  .problem-runner-heading { align-items: start; grid-template-columns: 1fr; padding: 24px 20px; }
  .problem-runner-toolbar { align-items: stretch; flex-direction: column; }
  .problem-runner-toolbar label { width: 100%; }
  .problem-runner-toolbar select,
  .problem-runner-toolbar button,
  .problem-runner-toolbar a { margin-left: 0; width: 100%; }
  .problem-runner-grid,
  .problem-runner-output { grid-template-columns: 1fr; }
  .runner-source textarea {
    background: linear-gradient(160deg, #07101c 0%, #0b1625 56%, #09111d 100%);
    min-height: 360px;
  }
  .problem-runner-result > div:first-child { align-items: flex-start; flex-direction: column; }
  .problem-runner-result small { margin-left: 0; }
  .panel-heading { align-items: flex-start; flex-direction: column; gap: 16px; }
  .panel-tools { justify-content: flex-start; }
  .solution-panel pre {
    background: linear-gradient(160deg, #07101c 0%, #0b1625 56%, #09111d 100%);
  }
  .code-line { grid-template-columns: 48px 1fr; padding-right: 16px; }
  .solution-panel.fullscreen { bottom: 0; left: 0; right: 0; top: 0; }
  .problem-support { align-items: stretch; flex-direction: column; padding: 22px; }
  .problem-support > div:last-child { flex-wrap: wrap; }
  .related > div { grid-template-columns: 1fr; }
  .page-nav { gap: 28px; grid-template-columns: 1fr; }
  .page-nav a.next { justify-self: start; text-align: left; }
  footer { flex-direction: column; gap: 10px; }
}

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