:root {
  color-scheme: light;
  font-family: system-ui, sans-serif;
  color: #172033;
  background: #fff;
}

* { box-sizing: border-box; }

body { min-width: 320px; margin: 0; }

#topbar {
  position: sticky;
  z-index: 2;
  top: 0;
  display: flex;
  align-items: center;
  gap: 1.25rem;
  min-height: 3.75rem;
  padding: .7rem max(2rem, calc((100vw - 1440px) / 2 + 2rem));
  border-bottom: 1px solid #d8deea;
  background: #fff;
}

.site-title { color: #172033; font-size: 1.05rem; font-weight: 700; text-decoration: none; }
.breadcrumb { padding-left: 1.25rem; border-left: 1px solid #d8deea; color: #526078; }
.site-quiz-link { color: #2457d6; font-weight: 650; text-decoration: none; }
.site-quiz-link:hover, .site-quiz-link[aria-current="page"] { text-decoration: underline; }
.site-search { position: relative; width: min(25rem, 38vw); margin-left: auto; }
.site-search input { width: 100%; padding: .55rem .7rem; border: 1px solid #c8d0df; border-radius: .4rem; background: #fff; color: #172033; font: inherit; }
.site-search input:focus-visible { outline: 3px solid #8baaff; outline-offset: 2px; }
.search-results { position: absolute; z-index: 5; top: calc(100% + .4rem); right: 0; left: 0; max-height: min(70vh, 32rem); overflow-y: auto; padding: .3rem; border: 1px solid #d8deea; border-radius: .5rem; background: #fff; box-shadow: 0 .5rem 1.5rem #17203326; }
.search-result { display: grid; width: 100%; gap: .2rem; padding: .65rem .7rem; border: 0; border-radius: .3rem; background: transparent; color: #172033; font: inherit; text-align: left; cursor: pointer; }
.search-result strong { color: #2457d6; }
.search-result span { overflow: hidden; color: #526078; font-size: .9rem; text-overflow: ellipsis; white-space: nowrap; }
.search-result:hover, .search-result[aria-selected="true"] { background: #e9edf5; }
.search-empty { padding: .75rem; color: #526078; }

.page-layout {
  display: grid;
  grid-template-columns: 15rem minmax(0, 1fr);
  gap: 2rem;
  max-width: 1440px;
  min-height: calc(100vh - 3.75rem);
  margin: 0 auto;
  padding: 2rem;
}

#sidebar {
  position: sticky;
  top: 5.75rem;
  align-self: start;
  max-height: calc(100vh - 7rem);
  overflow-y: auto;
  padding: .4rem 0;
}

.nav-categories,
.nav-topics,
.card-topics { margin: 0; padding: 0; list-style: none; }
.nav-category + .nav-category { margin-top: .4rem; }
.nav-category-toggle {
  width: 100%;
  padding: .65rem .7rem;
  border: 0;
  border-radius: .35rem;
  background: transparent;
  color: #172033;
  font: inherit;
  font-weight: 650;
  text-align: left;
  cursor: pointer;
}
.nav-category-toggle::after { content: "＋"; float: right; color: #526078; }
.nav-category-toggle[aria-expanded="true"]::after { content: "−"; }
.nav-category-toggle:hover, .nav-category-toggle:focus-visible { background: #e9edf5; }
.nav-category-toggle:focus-visible, .nav-topics a:focus-visible, a:focus-visible, button:focus-visible, select:focus-visible {
  outline: 3px solid #8baaff;
  outline-offset: 2px;
}
.nav-topics { padding: .15rem 0 .3rem .65rem; }
.nav-topics a {
  display: block;
  padding: .5rem .65rem;
  border-radius: .35rem;
  color: #2457d6;
  text-decoration: none;
}
.nav-topics a:hover { background: #e9edf5; }
.nav-topics a.is-current { background: #e4eaf8; color: #172033; font-weight: 650; }
.consumer[data-state="dead"] { opacity: 1; background: #e0e4eb; }
.consumer[data-state="dead"] > :not(button) { opacity: .65; }

main { min-width: 0; max-width: 960px; padding-bottom: 3rem; }
h1 { margin: 0 0 .6rem; font-size: clamp(2rem, 4vw, 2.7rem); line-height: 1.2; }
.intro, .note, .hint, .legend { color: #526078; }
.intro { max-width: 54rem; margin: 0 0 2rem; font-size: 1.1rem; line-height: 1.65; }
.notice { max-width: 100%; margin: 1rem 0 1.5rem; padding: .75rem 1rem; border: 1px solid #d8deea; border-left: 3px solid #2457d6; border-radius: .35rem; background: #f0f3f8; color: #526078; }
.notice-title { margin: 0 0 .35rem; color: #172033; font-size: .95rem; line-height: 1.35; }
.notice ul { margin: 0; padding-left: 1.2rem; }
.notice li { line-height: 1.45; overflow-wrap: anywhere; }
.category-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 18rem), 1fr)); gap: 1rem; }
.category-card { padding: 1.25rem; border: 1px solid #d8deea; border-radius: .5rem; background: #fff; }
.category-card h2 { margin: 0 0 .35rem; font-size: 1.2rem; }
.category-description { margin: 0 0 1rem; color: #526078; line-height: 1.5; }
.card-topics li { padding: .85rem 0; border-top: 1px solid #e4e8ef; }
.card-topics a { color: #2457d6; font-weight: 650; text-decoration: none; }
.card-topics a:hover { text-decoration: underline; }
.card-topics p { margin: .3rem 0 0; color: #526078; line-height: 1.45; }

.gateway h1 { margin-bottom: .4rem; }
.gateway .note { color: #526078; }
.gateway .controls { display: flex; flex-wrap: wrap; gap: .6rem; margin: 1.25rem 0; align-items: center; }
.gateway button { padding: .7rem 1rem; border: 0; border-radius: .4rem; background: #2457d6; color: white; font: inherit; cursor: pointer; }
.gateway button:focus-visible { outline: 3px solid #8baaff; outline-offset: 2px; }
.gateway button:disabled { opacity: .6; cursor: default; }
.gateway ol { display: grid; gap: .5rem; padding-left: 1.5rem; }
.gateway #steps { position: relative; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .5rem 1.4rem; margin: 1rem 0 1.5rem; padding: 1.6rem 0 0; list-style: none; }
.gateway #steps li { position: relative; min-width: 0; padding: .6rem; border: 1px solid #d8deea; border-radius: .35rem; background: #f0f3f8; overflow-wrap: anywhere; }
.gateway .flow-tag { display: inline-block; margin-left: .35rem; padding: .05rem .5rem; border-radius: 999px; background: #dde6f5; color: #3d4b66; font-size: 11px; line-height: 1.5; font-weight: 500; vertical-align: baseline; max-width: 100%; overflow-wrap: anywhere; }
.gateway #steps li[data-state="pass"] { background: #e4f5e9; }
.gateway #steps li[data-state="block"] { background: #ffe8e6; }
.gateway #response-steps { list-style: none; padding-left: 0; }
.gateway #response-steps li { padding: .6rem; border: 1px solid #d8deea; border-left: 4px solid #d8deea; border-radius: .35rem; background: #f0f3f8; overflow-wrap: anywhere; transition: background-color .2s ease, border-color .2s ease; }
.gateway #response-steps li[data-state="pass"] { background: #e4f5e9; border-left-color: #26734d; }
.gateway #response-steps li[data-state="block"] { background: #ffe8e6; border-left-color: #a83232; }
.gateway #steps li:not(:first-child)::before { content: ""; position: absolute; top: 50%; left: -1.4rem; width: 1.4rem; height: 2px; background: #d8deea; transform: translateY(-50%); }
.anim-layer { position: relative; }
.anim-chip { position: absolute; top: 0; left: 0; z-index: 1; padding: .15rem .55rem; border-radius: 999px; background: #2457d6; color: #fff; font-size: .75rem; font-weight: 700; white-space: nowrap; pointer-events: none; transition: transform .18s ease; }
.anim-chip[data-state="pass"] { background: #26734d; }
.anim-chip[data-state="block"] { background: #a83232; }
[data-flash="pass"] { background: #e4f5e9; }
[data-flash="block"] { background: #ffe8e6; }
[data-flash] { transition: background-color .2s ease; }
#map { margin: 1rem 0 .4rem; }
.map-legend { margin: 0 0 1rem; font-size: .9rem; color: #4b5563; }
#map .diagram { display: block; width: 100%; height: auto; margin: 0 auto; }
#map .diagram-vertical { max-width: 272px; }
#map .diagram-vertical .diagram-count { font-size: 11px; }
#map .diagram-band { fill: #f6f8fb; stroke: #c9d1df; stroke-width: 1.5; stroke-dasharray: 6 4; }
#map .diagram-band-label { font: 600 11px system-ui, sans-serif; fill: #6b7280; pointer-events: none; }
#map .diagram-band[data-kind="proxy"] { fill: #f3f6fd; stroke: #aebbd6; }
#map .diagram-node { color: #6b7280; }
#map .diagram-return .diagram-shape { fill: #f4f1fa; stroke: #c4bcd8; }
#map .diagram-shape { fill: #f0f3f8; stroke: #b9c2d3; stroke-width: 2; stroke-linejoin: round; transition: fill .18s ease, stroke .18s ease; }
#map .diagram-icon { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
#map .diagram-icon .diagram-dot { fill: currentColor; stroke: none; }
#map .diagram-label { font: 600 14px system-ui, sans-serif; fill: #1f2937; pointer-events: none; }
#map .diagram-node[data-state="pass"] { color: #26734d; }
#map .diagram-node[data-state="pass"] .diagram-shape { fill: #e4f5e9; stroke: #26734d; }
#map .diagram-node[data-state="block"] { color: #a83232; }
#map .diagram-node[data-state="block"] .diagram-shape { fill: #ffe8e6; stroke: #a83232; }
#map .diagram-wire { fill: none; stroke: #d8deea; stroke-width: 2; transition: stroke .18s ease; }
#map .diagram-wire[data-active="true"] { stroke: #2457d6; }
#map .diagram-wire.diagram-rwire { stroke: #c4bcd8; stroke-dasharray: 5 3; }
#map .diagram-wire.diagram-rwire[data-active="pass"] { stroke: #26734d; }
#map .diagram-wire.diagram-rwire[data-active="block"] { stroke: #a83232; }
#map .diagram-arrow { fill: #8a96ad; }
#map .diagram-packet circle { fill: #2457d6; fill-opacity: .85; stroke: #fff; stroke-width: 2; }
#map .diagram-packet[data-state="pass"] circle { fill: #26734d; }
#map .diagram-packet[data-state="block"] circle { fill: #a83232; }
#map .diagram-response { color: #26734d; }
#map .diagram-response[data-state="block"] { color: #a83232; }
#map .diagram-response circle { fill: #fff; fill-opacity: 1; stroke: currentColor; stroke-width: 2.5; }
#map .diagram-response[data-state] circle { fill: #fff; }
#map .diagram-code { font: 700 8.5px system-ui, sans-serif; fill: currentColor; pointer-events: none; }
#map .diagram-count { font: 600 10px system-ui, sans-serif; fill: #4b5563; pointer-events: none; }

@media (prefers-reduced-motion: reduce) {
  .anim-chip { transition: none; }
  #map .diagram-shape, #map .diagram-wire { transition: none; }
  [data-flash] { transition: none; }
  .gateway #response-steps li { transition: none; }
}
@media (max-width: 799px) {
  .gateway #steps { grid-template-columns: minmax(0, 1fr); gap: 2rem .5rem; }
  .gateway #steps li:not(:first-child)::before { top: -1.4rem; left: 50%; width: 2px; height: 1.4rem; transform: translateX(-50%); }
}
.gateway .counts { display: flex; gap: 1.5rem; }
.gateway .result { min-height: 1.5rem; font-weight: 600; }
.gateway code { background: #f0f3f8; padding: .1rem .3rem; }

.quiz-page { max-width: 800px; }
.quiz-picker-group-heading { margin: 1.5rem 0 .5rem; padding-bottom: .4rem; border-bottom: 1px solid #d8deea; color: #526078; font-size: 1rem; }
.quiz-topic-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 16rem), 1fr)); gap: .65rem; margin: 1rem 0; padding: 0; list-style: none; }
.quiz-topic-list li { display: flex; align-items: center; justify-content: space-between; gap: .75rem; padding: .9rem 1rem; border: 1px solid #d8deea; border-radius: .5rem; }
.quiz-topic-list a, .quiz-secondary { color: #2457d6; font-weight: 650; }
.quiz-topic-list a { text-decoration: none; }
.quiz-topic-list a:hover { text-decoration: underline; }
.quiz-topic-count { flex: 0 0 auto; color: #526078; font-size: .9rem; }
.quiz-notice { padding: .75rem 1rem; border: 1px solid #d8deea; border-radius: .4rem; background: #f0f3f8; }
.quiz-progress { margin: 1.5rem 0 .55rem; color: #526078; font-weight: 650; }
.quiz-question { margin: 0 0 1rem; font-size: 1.35rem; line-height: 1.4; }
.quiz-options { display: grid; gap: .65rem; }
.quiz-option { width: 100%; padding: .85rem 1rem; border: 1px solid #c8d0df; border-radius: .45rem; background: #fff; color: #172033; font: inherit; text-align: left; cursor: pointer; }
.quiz-option:hover:not(:disabled) { border-color: #2457d6; background: #f5f7fc; }
.quiz-option:disabled { color: #172033; cursor: default; opacity: 1; }
.quiz-option.is-correct, .quiz-feedback.is-correct { border-color: #26734d; background: #e4f5e9; }
.quiz-option.is-incorrect, .quiz-feedback.is-incorrect { border-color: #a83232; background: #ffe8e6; }
.quiz-feedback { margin: 1rem 0; padding: .85rem 1rem; border: 1px solid #d8deea; border-radius: .45rem; line-height: 1.5; }
.quiz-controls { display: flex; flex-wrap: wrap; align-items: center; gap: .75rem; margin: 1rem 0; }
.quiz-primary { padding: .7rem 1rem; border: 0; border-radius: .4rem; background: #2457d6; color: #fff; font: inherit; font-weight: 650; }
.quiz-primary:hover { background: #1946b5; }
.quiz-secondary { padding: .65rem 0; }
.quiz-score { margin: .5rem 0 1.5rem; font-size: 1.35rem; font-weight: 700; }
.quiz-recap { display: grid; gap: .75rem; padding-left: 1.6rem; }
.quiz-recap li { padding: .85rem 1rem; border: 1px solid #d8deea; border-radius: .45rem; }
.quiz-recap li.is-correct { border-color: #9bc8a8; background: #f1faf3; }
.quiz-recap li.is-incorrect { border-color: #e0aaa6; background: #fff5f4; }
.quiz-recap h4 { margin: 0 0 .5rem; font-size: 1rem; }
.quiz-recap p { margin: .35rem 0 0; line-height: 1.5; }
.quiz-recap-answer { font-weight: 600; }
.quiz-recap-why { color: #526078; }

button, select { font: inherit; }
button { cursor: pointer; }

@media (max-width: 700px) {
  #topbar { flex-wrap: wrap; gap: .75rem; padding: .65rem 1rem; }
  .breadcrumb { padding-left: .75rem; }
  .site-search { order: 3; width: 100%; margin-left: 0; }
  .page-layout { grid-template-columns: minmax(0, 1fr); gap: 1rem; padding: 1rem; }
  #sidebar { position: static; max-height: none; overflow: visible; padding: 0; }
  .nav-categories { display: flex; flex-wrap: wrap; gap: .2rem; }
  .nav-category { flex: 1 1 100%; }
  .nav-category + .nav-category { margin-top: 0; }
  .nav-topics { padding-left: .35rem; }
}
