:root {
  --paper: #f7f2e8;
  --surface: #fffdf8;
  --ink: #191919;
  --muted: #5e5d58;
  --line: #d7d1c4;
  --blue: #2e68d1;
  --red: #e95140;
  --yellow: #f7ce63;
  --green: #25845d;
  --shadow: 5px 5px 0 var(--ink);
  --sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --display: Impact, Haettenschweiler, "Arial Narrow Bold", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; }
body { margin: 0; color: var(--ink); background: var(--paper); font-family: var(--sans); line-height: 1.5; }
button, input, select { font: inherit; }
button, a, select { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
a { color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--blue); outline-offset: 3px; }
.skip-link { position: absolute; top: -100px; left: 1rem; z-index: 100; padding: .7rem; background: var(--ink); color: white; }
.skip-link:focus { top: 1rem; }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; min-height: 72px; padding: .7rem clamp(1.2rem, 4vw, 4rem); border-bottom: 2px solid var(--ink); background: var(--surface); }
.brand { display: inline-flex; align-items: center; gap: .7rem; text-decoration: none; }
.brand-mark { display: grid; place-items: center; width: 39px; height: 39px; border: 2px solid var(--ink); background: var(--yellow); font: 1.5rem var(--display); box-shadow: 3px 3px 0 var(--ink); }
.brand strong, .brand small { display: block; line-height: 1.05; }
.brand small { margin-top: .3rem; font-size: .6rem; font-weight: 850; letter-spacing: .16em; }
.topbar nav { display: flex; flex-wrap: wrap; gap: clamp(.75rem, 2vw, 2rem); }
.topbar nav a { font-size: .8rem; font-weight: 800; text-decoration: none; }
.topbar nav a:hover, .back-link:hover { text-decoration: underline; }

.hero, .platform-section, .page-shell, .manifesto { max-width: 1200px; margin: auto; padding-left: clamp(1.2rem, 4vw, 4rem); padding-right: clamp(1.2rem, 4vw, 4rem); }
.hero { padding-top: clamp(3rem, 7vw, 6rem); padding-bottom: 2.5rem; }
.hero-copy { max-width: 820px; }
.eyebrow, .row-eyebrow { margin: 0 0 .65rem; color: var(--muted); font-size: .72rem; font-weight: 900; letter-spacing: .13em; text-transform: uppercase; }
h1, h2 { margin: 0; line-height: 1.02; }
.hero h1, .archive-hero h1, .contest-heading h1, .problem-header h1 { font-family: var(--display); font-weight: 900; letter-spacing: -.02em; text-transform: uppercase; }
.hero h1 { font-size: clamp(3.5rem, 8vw, 7rem); }
.lede { max-width: 640px; margin: 1rem 0 0; color: var(--muted); font-size: 1.15rem; }
.button { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: .65rem 1rem; border: 2px solid var(--ink); background: var(--surface); font-size: .86rem; font-weight: 850; text-decoration: none; }
.button-primary { background: var(--red); color: white; box-shadow: 3px 3px 0 var(--ink); }
.button-ghost:hover, .button-primary:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.hero-art { display: none; }

.platform-section { padding-bottom: 5rem; }
.section-heading { display: flex; justify-content: space-between; align-items: end; gap: 2rem; margin-bottom: 1.4rem; }
.section-heading h2 { font-family: var(--display); font-size: clamp(2.2rem, 4vw, 3.8rem); text-transform: uppercase; }
.section-heading > p { max-width: 330px; margin: 0; color: var(--muted); font-size: .9rem; }
.platform-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; }
.platform-card { display: flex; flex-direction: column; min-height: 250px; border: 2px solid var(--ink); padding: 1.35rem; background: var(--surface); text-decoration: none; transition: transform .15s ease, box-shadow .15s ease; }
.platform-card:hover { transform: translate(-2px, -2px); box-shadow: var(--shadow); }
.platform-card-head { display: flex; justify-content: space-between; align-items: start; gap: 1rem; }
.platform-monogram { display: grid; place-items: center; width: 45px; height: 45px; border: 2px solid var(--ink); font-weight: 950; }
.platform-leetcode .platform-monogram { background: var(--yellow); }
.platform-codeforces .platform-monogram { background: #c7dcff; }
.platform-codechef .platform-monogram { background: #e5d4ba; }
.platform-count { padding: .25rem .5rem; background: #efede7; font-size: .7rem; font-weight: 800; }
.platform-card h3 { margin: 1.2rem 0 .4rem; font-size: 1.4rem; }
.platform-card p { margin: 0 0 1rem; color: var(--muted); font-size: .88rem; }
.platform-cta { margin-top: auto; font-size: .8rem; font-weight: 900; }
.manifesto { display: none; }

.page-shell { padding-top: 2.5rem; padding-bottom: 5rem; min-height: calc(100vh - 150px); }
.back-link { display: inline-block; margin-bottom: 2.3rem; font-size: .82rem; font-weight: 850; text-decoration: none; }
.archive-hero { display: flex; align-items: center; gap: 1.5rem; padding-bottom: 2rem; border-bottom: 1px solid var(--line); }
.platform-badge { display: grid; place-items: center; flex: 0 0 auto; width: 82px; height: 82px; border: 2px solid var(--ink); background: var(--yellow); font-size: 1.5rem; font-weight: 950; box-shadow: 4px 4px 0 var(--ink); }
.archive-hero h1, .contest-heading h1 { font-size: clamp(3rem, 6vw, 5.5rem); }
.archive-hero p:last-child, .contest-heading > p:not(.eyebrow) { max-width: 650px; margin: .6rem 0 0; color: var(--muted); }
.archive-toolbar { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 1rem; padding: 1.5rem 0; }
.archive-toolbar > div { display: flex; gap: .6rem; }
.archive-toolbar span, .contest-meta { padding: .3rem .55rem; border: 1px solid var(--line); background: var(--surface); color: var(--muted); font-size: .75rem; font-weight: 800; }
.archive-toolbar label { display: flex; align-items: center; gap: .7rem; font-size: .75rem; font-weight: 850; }
.archive-toolbar input { width: min(290px, 48vw); min-height: 41px; border: 1px solid var(--ink); padding: .5rem .7rem; background: white; }
.contest-list, .question-list { display: grid; gap: .7rem; }
.contest-row, .question-row { display: flex; align-items: center; gap: 1.5rem; min-height: 136px; border: 1px solid var(--line); padding: 1.2rem 1.4rem; background: var(--surface); text-decoration: none; transition: border-color .15s ease, transform .15s ease; }
.contest-row:hover, .question-row:hover { border-color: var(--ink); transform: translateX(3px); }
.contest-row-main, .question-row-main { flex: 1; min-width: 0; }
.contest-row h2, .question-row h2 { margin: .25rem 0; font-size: 1.3rem; }
.contest-row p, .question-row p { margin: 0; color: var(--muted); font-size: .88rem; }
.row-count, .difficulty { flex: 0 0 auto; border: 1px solid var(--line); padding: .3rem .6rem; font-size: .75rem; font-weight: 800; }
.row-arrow { color: var(--blue); font-size: 1.5rem; font-weight: 900; }
.empty-state { border: 1px dashed #aaa395; padding: 3rem 2rem; background: var(--surface); text-align: center; }
.empty-state h2 { font-size: 1.5rem; }.empty-state p { color: var(--muted); }.empty-state .button { margin-top: .7rem; }
.empty-search { color: var(--muted); }
.contest-heading { padding-bottom: 2rem; border-bottom: 1px solid var(--line); }
.contest-meta { display: inline-block; margin-top: 1rem; }
.question-list { margin-top: 1.5rem; }
.question-number { flex: 0 0 auto; display: grid; place-items: center; width: 48px; height: 48px; border: 2px solid var(--ink); background: #c7dcff; font-weight: 900; }

.problem-header { display: flex; justify-content: space-between; align-items: end; gap: 2rem; padding-bottom: 2rem; }
.problem-header h1 { max-width: 820px; font-size: clamp(2.5rem, 5vw, 5rem); }
.problem-header p:last-child { max-width: 700px; margin: .9rem 0 0; color: var(--muted); }
.problem-actions { display: flex; align-items: center; gap: .7rem; flex: 0 0 auto; }
.problem-shell { max-width: 980px; padding-bottom: calc(7rem + env(safe-area-inset-bottom)); }
.problem-header { align-items: start; gap: 1rem; padding-bottom: 1.5rem; }
.problem-header h1 { font-family: var(--sans); font-size: clamp(1.65rem, 3.8vw, 2.5rem); line-height: 1.18; text-transform: none; letter-spacing: -.035em; }
.problem-header .eyebrow { font-size: .65rem; letter-spacing: .05em; }
.book-toolbar { display: flex; align-items: center; gap: .6rem; padding: .7rem 0; scroll-margin-top: 1rem; }
.book-toolbar label { font-size: .8rem; font-weight: 750; }
.book-toolbar select { flex: 1; min-width: 0; min-height: 48px; padding: .65rem; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font-size: .9rem; }
.book-toolbar button { min-height: 48px; min-width: 48px; border: 1px solid var(--line); background: var(--surface); font-weight: 750; }
.book-progress { height: 3px; background: var(--line); }
.book-progress span { display: block; height: 100%; background: var(--blue); transition: width .15s; }
.solution-book { min-height: 480px; padding: clamp(1.25rem, 4vw, 3rem); border: 1px solid var(--line); border-top: 0; background: var(--surface); font-family: Georgia, "Times New Roman", serif; font-size: 1.125rem; line-height: 1.8; overflow-wrap: break-word; }
.book-section { margin: 0 0 .7rem; color: var(--muted); font: 750 .65rem/1.5 var(--sans); letter-spacing: .1em; }
.solution-book h2 { margin-bottom: 1.5rem; font: 800 clamp(1.6rem, 3vw, 2.1rem)/1.2 var(--sans); letter-spacing: -.025em; }
.solution-book h3 { margin: 0; font: 750 1.1rem/1.4 var(--sans); }
.solution-book p { margin-top: 0; margin-bottom: 1.25rem; }
.solution-book p.book-section { margin-bottom: .7rem; }
.solution-book .eyebrow { margin-bottom: .35rem; font-family: var(--sans); }
.book-example, .book-insight { padding: 1rem; border-left: 3px solid var(--blue); background: #eef3fc; }
.approach-step + .approach-step { margin-top: 1.5rem; }
.approach-step h3 + p { margin-top: .5rem; }
.book-takeaways { padding-left: 1.3rem; }
.book-takeaways li { margin-bottom: .75rem; }
.code-toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .4rem .75rem; margin-top: 1.5rem; color: var(--muted); font: .72rem/1.4 var(--sans); }
.copy-code { min-height: 44px; padding: .5rem .7rem; border: 1px solid var(--line); background: var(--paper); color: var(--ink); font-weight: 700; }
.copy-status { width: 100%; }
.copy-status:empty { display: none; }
.solution-code { margin: .5rem 0 0; padding: 1rem .6rem; border: 1px solid var(--line); background: #f4f6fa; color: #202c42; font: .83rem/1.8 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; tab-size: 4; text-align: left; }
.solution-code code { display: block; }
.code-line { display: grid; grid-template-columns: 2.2em minmax(0, 1fr); gap: .65em; }
.line-number { color: #6b7484; text-align: right; user-select: none; font-size: .85em; padding-top: .12em; }
.line-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.syntax-keyword { color: #6834a3; font-weight: 700; }.syntax-string { color: #146542; }.syntax-number { color: #ac421a; }.syntax-comment { color: #586578; font-style: italic; }
.solution-book.large-text { font-size: 1.35rem; }.large-text .solution-code { font-size: 1rem; }
.solution-book .simulator-shell { font-family: var(--sans); font-size: 1rem; line-height: 1.5; }
.book-navigation { position: fixed; z-index: 20; bottom: 0; left: 0; right: 0; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 1rem; padding: .65rem max(1rem, calc((100vw - 830px) / 2)) calc(.65rem + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--surface); box-shadow: 0 -4px 20px #19191908; }
.book-navigation button { min-height: 48px; border: 1px solid var(--line); padding: .6rem 1rem; background: var(--surface); color: var(--ink); font-size: .9rem; font-weight: 750; }
.book-navigation #book-next { background: var(--ink); color: white; border-color: var(--ink); }
.book-navigation button:disabled { opacity: .35; cursor: default; }
#book-position { min-width: 3rem; text-align: center; font-size: .8rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.chapter-nav { display: flex; gap: .45rem; border-bottom: 2px solid var(--ink); }
.chapter-tab { border: 0; padding: .8rem 1.1rem; background: transparent; font-size: .85rem; font-weight: 850; }
.chapter-tab.active { background: var(--ink); color: white; }
.chapter { padding-top: 2rem; }
.story-layout { display: grid; grid-template-columns: minmax(240px, .7fr) minmax(350px, 1fr); gap: 2rem; align-items: start; }
.chapter-tag { display: inline-block; margin: 0 0 1rem; padding: .25rem .45rem; background: var(--ink); color: white; font-size: .7rem; font-weight: 850; letter-spacing: .1em; }
.story-layout h2 { font-family: var(--display); font-size: clamp(2.5rem, 4vw, 4rem); text-transform: uppercase; }
.chapter-intro { max-width: 530px; color: var(--muted); font-size: 1.04rem; }
.comic-sequence { display: grid; gap: .7rem; }
.comic-panel { position: relative; border: 2px solid var(--ink); padding: 1rem 1rem 1rem 3.9rem; background: var(--surface); }
.comic-panel .panel-index { position: absolute; top: .7rem; left: .9rem; color: var(--blue); font-family: var(--display); font-size: 2rem; }
.comic-panel .narration { margin: 0; color: var(--muted); font-size: .65rem; font-weight: 900; letter-spacing: .1em; text-transform: uppercase; }
.comic-panel h3 { margin: .15rem 0 .3rem; font-size: 1.05rem; }.comic-panel p:last-child { margin: 0; font-size: .88rem; }
.accent-panel { background: #fff0c9; }.dark-panel { background: var(--ink); color: white; }.dark-panel .panel-index { color: var(--yellow); }.dark-panel .narration { color: #d6d6d6; }
.insight-break { display: flex; align-items: center; gap: 1.2rem; margin-top: 1.5rem; border: 2px solid var(--ink); padding: 1.1rem; background: var(--yellow); }
.burst { flex: 0 0 auto; font-family: var(--display); font-size: 1.7rem; }.insight-break p { margin: 0; font-weight: 800; }
.takeaway-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
.takeaway-card { border: 2px solid var(--ink); padding: 1.4rem; background: var(--surface); }.takeaway-card span { color: var(--blue); font-family: var(--display); font-size: 2rem; }.takeaway-card p { margin: .8rem 0 0; font-weight: 750; }

.simulator-shell { max-width: 1000px; border: 2px solid var(--ink); padding: clamp(1rem, 3vw, 2rem); background: var(--surface); }
.simulator-topline { display: flex; justify-content: space-between; gap: 1rem; align-items: start; padding-bottom: 1rem; border-bottom: 1px solid var(--line); }.simulator-topline h3 { margin: 0; font-size: 1.4rem; }
.complexity-pill { border: 1px solid var(--ink); padding: .3rem .5rem; background: var(--green); color: white; font-family: ui-monospace, monospace; font-size: .78rem; font-weight: 900; }
.sim-help { color: var(--muted); font-size: .87rem; }
.grid-stage, .tree-stage { display: grid; grid-template-columns: minmax(250px, 1fr) minmax(175px, .35fr); gap: 1rem; }
.direction-grid { display: grid; grid-template-columns: repeat(2, 1fr); min-height: 330px; border: 2px solid var(--ink); gap: 2px; background: var(--ink); }
.direction-cell { position: relative; display: grid; place-items: center; border: 0; background: #eef4ff; font-size: clamp(2.7rem, 6vw, 4.5rem); font-weight: 900; }.direction-cell small { position: absolute; top: .5rem; left: .6rem; font-family: ui-monospace, monospace; font-size: .7rem; opacity: .6; }
.direction-cell.visited { background: #bed5ff; }.direction-cell.current { background: var(--yellow); outline: 4px solid var(--red); outline-offset: -6px; }.direction-cell.blocked { background: #f6beb5; }
.state-card { border: 1px solid var(--ink); padding: 1rem; background: #f4f0e5; }.state-card > span { display: block; font-size: .65rem; font-weight: 900; letter-spacing: .1em; text-transform: uppercase; }.state-card > strong { display: block; min-height: 3.5em; margin: .5rem 0 1rem; font-size: .94rem; }
.state-card dl { margin: 0; }.state-card dl div { border-top: 1px solid var(--line); padding: .4rem 0; }.state-card dt { color: var(--muted); font-size: .65rem; text-transform: uppercase; }.state-card dd { margin: 0; font-family: ui-monospace, monospace; font-size: .85rem; font-weight: 900; }
.controls { display: flex; flex-wrap: wrap; gap: .6rem; margin-top: 1rem; }.controls button { min-height: 42px; border: 2px solid var(--ink); padding: .5rem .8rem; background: var(--surface); font-size: .82rem; font-weight: 850; }.controls .button-primary { background: var(--red); }.controls button:disabled { opacity: .45; cursor: not-allowed; }
.timeline { height: 8px; margin-top: 1rem; border: 1px solid var(--ink); }.timeline span { display: block; width: 0; height: 100%; background: var(--blue); transition: width .2s; }
.preset-tabs { display: flex; gap: .4rem; margin: 1rem 0; }.preset { border: 1px solid var(--ink); padding: .4rem .6rem; background: white; font-size: .74rem; font-weight: 800; }.preset.active { background: var(--yellow); }
#tree-canvas { width: 100%; min-height: 350px; border: 1px solid var(--ink); background: #fffaf0; }.tree-edge { stroke: #b1ada3; stroke-width: 5; }.tree-edge.oriented { stroke: var(--ink); marker-end: url(#tree-arrow); }.tree-edge.active { stroke: var(--red); stroke-width: 7; }
.tree-node circle { stroke: var(--ink); stroke-width: 4; }.tree-node text { font-family: var(--sans); font-weight: 900; text-anchor: middle; dominant-baseline: central; }.tree-label { font-family: ui-monospace, monospace !important; font-size: 13px; fill: var(--muted); }.tree-node.root circle { stroke: var(--green); stroke-width: 8; }.tree-node.invalid circle { stroke: var(--red); stroke-width: 8; }
.indegree-list { display: grid; grid-template-columns: repeat(2, 1fr); gap: .4rem; }.indegree-chip { border: 1px solid var(--ink); padding: .3rem; background: white; font-family: ui-monospace, monospace; font-size: .7rem; font-weight: 800; text-align: center; }.indegree-chip.zero { background: #ccebdc; }.indegree-chip.over { background: #f6beb5; }
.result-banner { margin-top: 1rem; border: 1px solid var(--ink); padding: .6rem; background: #eee9df; font-size: .84rem; font-weight: 800; }.result-banner.success { background: #ccebdc; }.result-banner.failure { background: #f6beb5; }

footer { display: flex; align-items: center; justify-content: space-between; gap: 1rem; border-top: 2px solid var(--ink); padding: 1.5rem clamp(1.2rem, 4vw, 4rem); background: var(--ink); color: white; }footer .brand-mark { color: var(--ink); }footer p { margin: 0; color: #d7d7d7; font-size: .76rem; }

@media (max-width: 800px) {
  .platform-grid, .takeaway-grid { grid-template-columns: 1fr; }
  .platform-card { min-height: 180px; }
  .story-layout { grid-template-columns: 1fr; }
  .problem-header { display: block; }.problem-actions { margin-top: 1rem; }
  .section-heading { display: block; }.section-heading > p { margin-top: .6rem; }
}
@media (min-width: 621px) and (max-width: 1024px) {
  .solution-book { padding: 2rem; font-size: 1.2rem; }
  .solution-code { font-size: .9rem; }
  .platform-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .platform-card { padding: 1rem; }
}
@media (max-width: 620px) {
  .topbar { align-items: start; flex-direction: column; gap: .45rem; padding: .8rem 1rem .25rem; }.topbar nav { width: 100%; justify-content: space-between; gap: .25rem; }.topbar nav a { display: inline-flex; align-items: center; min-height: 44px; font-size: .75rem; }
  .problem-shell { padding-left: .75rem; padding-right: .75rem; padding-top: 1.25rem; }
  .problem-shell .back-link { margin-bottom: 1.25rem; min-height: 44px; display: inline-flex; align-items: center; }
  .problem-header { padding: 0 .25rem 1rem; }.problem-header p:last-child { font-size: .92rem; }
  .book-toolbar label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .book-navigation { gap: .6rem; }
  .solution-book { padding: 1.2rem 1rem; min-height: 420px; }
  .solution-book .simulator-shell { padding: .75rem; border-width: 1px; }
  .solution-code { margin-left: -.5rem; margin-right: -.5rem; padding: .8rem .3rem; font-size: .8rem; }
  .code-line { gap: .5em; grid-template-columns: 1.8em minmax(0, 1fr); }
  .simulator-topline h3 { font-size: 1.1rem; }
  #tree-canvas { min-height: 0; aspect-ratio: 620 / 360; }
  .controls button, .preset { min-height: 44px; }
  .controls button { flex: 1 1 auto; }
  .hero { padding-top: 3rem; }.hero h1 { font-size: 3.6rem; }
  .archive-hero { align-items: start; }.platform-badge { width: 60px; height: 60px; font-size: 1.1rem; }
  .archive-toolbar label { width: 100%; }.archive-toolbar input { flex: 1; width: auto; }
  .contest-row, .question-row { gap: .7rem; padding: .9rem; }.contest-row .row-count, .question-row .difficulty { display: none; }
  .grid-stage, .tree-stage { grid-template-columns: 1fr; }.direction-grid { min-height: 270px; }
  .preset-tabs { overflow-x: auto; }.preset { flex: 0 0 auto; }
  footer { flex-direction: column; align-items: start; }
}
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } * { transition-duration: .01ms !important; } }
