:root {
  color-scheme: dark;
  --bg: #090b0e;
  --panel: #11151a;
  --panel-raised: #171c22;
  --line: #29313a;
  --text: #f2f5f7;
  --muted: #aeb9c2;
  --cyan: #55d9e8;
  --lime: #b7ed62;
  --amber: #f4c95d;
  --danger: #ff6b78;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { min-width: 320px; margin: 0; color: var(--text); background: radial-gradient(circle at 12% 6%, rgb(85 217 232 / 8%), transparent 28rem), radial-gradient(circle at 88% 46%, rgb(244 201 93 / 6%), transparent 30rem), var(--bg); }
button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .5; }
h1, h2, h3, p { margin-top: 0; }

.site-header { height: 68px; display: flex; align-items: center; justify-content: space-between; padding: 0 clamp(20px, 5vw, 72px); border-bottom: 1px solid var(--line); background: rgb(9 11 14 / 86%); backdrop-filter: blur(16px); }
.brand { display: flex; align-items: center; gap: 11px; color: var(--text); font-weight: 800; letter-spacing: -.02em; text-decoration: none; }
.brand-mark { width: 34px; height: 34px; display: grid; place-items: center; border: 1px solid #47606b; border-radius: 10px; color: var(--cyan); background: #10191d; font-size: 12px; }
.lesson-chip { display: flex; align-items: center; gap: 9px; color: var(--muted); font-size: 12px; letter-spacing: .1em; text-transform: uppercase; }
.lesson-chip span { padding: 6px 9px; border-radius: 999px; color: #172205; background: var(--lime); font-weight: 900; }

main { width: min(1320px, calc(100% - 40px)); margin: 0 auto; padding: 68px 0 78px; }
.eyebrow { margin: 0 0 10px; color: var(--cyan); font-size: 12px; font-weight: 900; letter-spacing: .14em; text-transform: uppercase; }
.intro { max-width: 1000px; margin-bottom: 44px; }
.intro h1 { max-width: 980px; margin-bottom: 18px; font-size: clamp(42px, 6vw, 76px); line-height: 1; letter-spacing: -.055em; }
.intro-copy { max-width: 820px; margin-bottom: 22px; color: var(--text); font-size: 18px; line-height: 1.72; }
.intro-copy code { display: inline-block; padding: 2px 8px; border: 1px solid color-mix(in srgb, var(--lime) 45%, transparent); border-radius: 6px; color: var(--lime); background: color-mix(in srgb, var(--lime) 11%, transparent); font-weight: 700; }
.concept-tags { display: flex; flex-wrap: wrap; gap: 8px; }
.concept-tags span { padding: 7px 11px; border: 1px solid var(--line); border-radius: 999px; color: #d5dde2; background: var(--panel); font-size: 12px; font-weight: 700; }

.lesson-workspace,
.observation,
.architecture-explanation,
.next-lesson { border: 1px solid var(--line); border-radius: 18px; background: color-mix(in srgb, var(--panel) 96%, var(--cyan)); box-shadow: 0 24px 70px rgb(0 0 0 / 20%); }
.lesson-workspace { padding: clamp(22px, 3vw, 38px); }
.workspace-heading { display: flex; align-items: end; justify-content: space-between; gap: 32px; margin-bottom: 30px; padding-bottom: 24px; border-bottom: 1px solid var(--line); }
.workspace-heading h2,
.observation-heading h2,
.architecture-explanation h2,
.next-lesson h2 { margin-bottom: 8px; font-size: clamp(25px, 3vw, 34px); letter-spacing: -.035em; }
.workspace-heading > div:first-child > p:last-child,
.observation-heading > p:last-of-type,
.next-lesson p { max-width: 720px; margin-bottom: 0; color: var(--muted); font-size: 15px; line-height: 1.65; }
.lesson-controls { display: flex; flex: 0 0 auto; flex-wrap: wrap; justify-content: flex-end; gap: 9px; }

.primary-action,
.secondary-action { min-height: 46px; border-radius: 11px; font-weight: 850; }
.primary-action { border: 0; color: #172205; background: var(--lime); }
.primary-action.start { min-width: 142px; padding: 0 20px; }
.primary-action.request-action { width: 100%; margin: 14px 0 0; }
.primary-action span { margin-right: 8px; font-size: 11px; }
.primary-action.sending { animation: buttonPulse .7s ease-in-out infinite alternate; }
.secondary-action { padding: 0 18px; border: 1px solid var(--line); color: var(--text); background: transparent; }
.secondary-action.compact { min-height: 34px; padding: 0 11px; border-radius: 8px; font-size: 11px; }

.architecture-flow { display: grid; grid-template-columns: minmax(340px, 1fr) minmax(120px, .3fr) minmax(400px, 1.08fr); grid-template-rows: auto 86px auto; align-items: stretch; }
.node-card { min-width: 0; padding: 24px; border: 1px solid var(--line); border-radius: 15px; background: linear-gradient(145deg, rgb(23 28 34 / 98%), rgb(13 16 20 / 98%)); box-shadow: 0 18px 55px rgb(0 0 0 / 22%); }
.client-card { grid-column: 1; grid-row: 1; min-height: 540px; display: flex; flex-direction: column; }
.proxy-card { grid-column: 3; grid-row: 1; min-height: 540px; display: flex; flex-direction: column; }
.service-card { grid-column: 3; grid-row: 3; min-height: 270px; display: flex; flex-direction: column; }

.endpoint-box,
.server-identity { display: flex; flex-direction: column; gap: 8px; padding: 14px; border: 1px solid var(--line); border-radius: 11px; background: #0a0d10; }
.endpoint-box span,
.server-identity > span { color: var(--muted); font-size: 11px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.endpoint-box code,
.server-identity code { overflow: auto; color: var(--cyan); font-size: 12px; }
.server-identity small { color: var(--muted); font-size: 11px; }

.client-tooling { min-height: 36px; display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 9px; padding: 6px 7px 6px 11px; border: 1px solid var(--line); border-radius: 9px; color: var(--muted); background: #0b0f12; font-size: 11px; }
.client-tooling button { min-height: 25px; padding: 0 9px; border: 1px solid #3a5962; border-radius: 6px; color: var(--cyan); background: #12191e; font-size: 10px; font-weight: 900; }
.client-response { margin-top: 18px; }
.products { height: 180px; overflow: auto; padding: 9px; border: 1px solid var(--line); border-radius: 11px; background: #0a0d10; }
.products > p { margin: 0; padding: 24px 12px; color: var(--muted); font-size: 13px; line-height: 1.55; text-align: center; }
.products article { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 12px 10px; border-bottom: 1px solid #20272e; }
.products article:last-child { border-bottom: 0; }
.products article div { min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.products article b { font-size: 13px; }
.products article span { overflow: hidden; color: var(--muted); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.products article strong { color: var(--lime); font: 800 12px ui-monospace, Consolas, monospace; }

.connector { position: relative; align-self: center; justify-self: center; color: var(--muted); background: #34444b; }
.connector span { position: absolute; width: max-content; color: var(--muted); font-size: 10px; font-weight: 800; letter-spacing: .09em; text-transform: uppercase; }
.connector-client { grid-column: 2; grid-row: 1; width: 100%; height: 2px; }
.connector-client::after { position: absolute; top: -4px; right: 0; width: 8px; height: 8px; border-top: 2px solid var(--cyan); border-right: 2px solid var(--cyan); content: ""; transform: rotate(45deg); }
.connector-client span { top: -25px; left: 50%; transform: translateX(-50%); }
.connector-upstream { grid-column: 3; grid-row: 2; width: 2px; height: 100%; }
.connector-upstream::after { position: absolute; right: -4px; bottom: 0; width: 8px; height: 8px; border-right: 2px solid var(--cyan); border-bottom: 2px solid var(--cyan); content: ""; transform: rotate(45deg); }
.connector-upstream span { top: 50%; left: 16px; transform: translateY(-50%); }
.packet { position: absolute; top: -4px; left: -7px; width: 10px; height: 10px; border-radius: 50%; background: var(--lime); box-shadow: 0 0 15px var(--lime); opacity: 0; }
.connector-client.flowing .packet { animation: flowHorizontal 1s ease-in-out; }
.connector-upstream .packet { top: -7px; left: -4px; }
.connector-upstream.flowing .packet { animation: flowVertical 1s ease-in-out; }

.proxy-actions { display: flex; justify-content: flex-end; gap: 7px; margin: -2px 0 10px; }
.proxy-route { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: 10px; padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: #090c0f; }
.proxy-route div { min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.proxy-route span { color: var(--muted); font-size: 9px; font-weight: 900; letter-spacing: .08em; text-transform: uppercase; }
.proxy-route code { overflow: auto; color: var(--cyan); font-size: 12px; white-space: nowrap; }
.proxy-route b { color: var(--muted); font-size: 9px; letter-spacing: .06em; text-align: center; text-transform: uppercase; }

.proxy-details { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-top: 10px; padding: 10px; border: 1px solid #34434a; border-radius: 10px; background: #0a0e11; }
.proxy-details[hidden] { display: none; }
.proxy-details > div { min-width: 0; display: flex; flex-direction: column; gap: 4px; padding: 8px; border: 1px solid #222b32; border-radius: 8px; background: #0d1115; }
.proxy-details span { color: var(--muted); font-size: 9px; font-weight: 900; letter-spacing: .08em; text-transform: uppercase; }
.proxy-details code { overflow: auto; color: #d0dbe0; font-size: 10px; white-space: nowrap; }
.proxy-details small { color: var(--muted); font-size: 10px; line-height: 1.4; }
.proxy-details pre { grid-column: 1 / -1; max-height: 90px; margin: 0; overflow: auto; padding: 9px; border: 1px solid #222b32; border-radius: 8px; color: #acd5dc; background: #080b0d; font: 10px/1.5 ui-monospace, Consolas, monospace; }

.proxy-runtime { display: grid; grid-template-columns: 180px minmax(0, 1fr); gap: 10px; align-items: stretch; flex: 1; margin-top: 10px; }
.cache-box { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 11px; border: 1px solid #3a4851; border-radius: 11px; background: #0a0e11; text-align: center; }
.cache-box small { color: var(--muted); font-size: 9px; letter-spacing: .12em; text-transform: uppercase; }
.cache-box strong { margin: 6px 0 3px; color: var(--muted); font: 900 21px ui-monospace, Consolas, monospace; }
.cache-box > span { min-height: 30px; color: var(--muted); font-size: 10px; line-height: 1.4; }
.cache-box[data-status="MISS"] strong { color: var(--amber); }
.cache-box[data-status="HIT"] strong { color: var(--lime); }
.cache-box[data-status="EXPIRED"] strong { color: #fb7185; }
.ttl { width: 100%; height: 4px; margin: 7px 0 5px; overflow: hidden; border-radius: 99px; background: #202830; }
.ttl i { display: block; width: 0; height: 100%; background: var(--lime); transition: width .1s linear; }
.cache-box code { color: #bdc7ce; font-size: 9px; }

.request-log { min-width: 0; display: flex; flex-direction: column; }
.proxy-runtime .request-log { margin: 0; }
.service-card .request-log { flex: 1; margin-top: 15px; }
.section-heading { min-height: 24px; display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 7px; color: var(--muted); font-size: 10px; font-weight: 850; letter-spacing: .08em; text-transform: uppercase; }
.request-log pre { min-height: 92px; flex: 1; margin: 0; overflow: auto; padding: 11px; border: 1px solid var(--line); border-radius: 10px; color: #d2d9de; background: #090b0d; font: 11px/1.55 ui-monospace, SFMono-Regular, Consolas, monospace; white-space: pre; }
.service-card .request-log pre { height: 100px; max-height: 112px; }

.observation { display: grid; grid-template-columns: minmax(270px, .62fr) minmax(0, 1.38fr); gap: clamp(30px, 5vw, 72px); margin-top: 26px; padding: clamp(24px, 3.5vw, 42px); }
.last-result { margin-top: 24px; padding: 15px; border: 1px solid var(--line); border-radius: 11px; background: var(--panel-raised); }
.last-result > span { display: block; margin-bottom: 5px; color: var(--muted); font-size: 10px; font-weight: 900; letter-spacing: .1em; text-transform: uppercase; }
.last-result strong { display: block; color: var(--muted); font: 900 22px ui-monospace, Consolas, monospace; }
.last-result small { display: block; margin-top: 5px; color: var(--muted); font-size: 12px; line-height: 1.45; }
.last-result[data-result="MISS"] strong { color: var(--amber); }
.last-result[data-result="HIT"] strong { color: var(--lime); }
.last-result[data-result="EXPIRED"] strong { color: #fb7185; }

.experiment-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin-bottom: 24px; }
.experiment-stats div { min-width: 0; padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel-raised); }
.experiment-stats span { display: block; min-height: 28px; color: var(--muted); font-size: 10px; font-weight: 800; line-height: 1.35; text-transform: uppercase; }
.experiment-stats strong { display: block; margin-top: 5px; color: var(--cyan); font: 900 21px ui-monospace, Consolas, monospace; }

.request-trace { display: grid; gap: 0; margin: 0; padding: 0; list-style: none; }
.request-trace li { position: relative; display: grid; grid-template-columns: 34px 1fr; gap: 13px; min-height: 61px; color: var(--muted); opacity: 0; animation: revealTrace .3s ease forwards; animation-delay: var(--trace-delay, 0ms); }
.request-trace li:not(:last-child)::after { position: absolute; top: 31px; bottom: 0; left: 16px; width: 1px; background: color-mix(in srgb, var(--lime) 65%, var(--line)); content: ""; }
.request-trace li > span { z-index: 1; width: 34px; height: 34px; display: grid; place-items: center; border: 1px solid var(--lime); border-radius: 50%; color: #172205; background: var(--lime); font: 800 12px ui-monospace, Consolas, monospace; }
.request-trace li div { padding-top: 2px; }
.request-trace strong { display: block; color: var(--text); font-size: 14px; }
.request-trace small { display: block; margin-top: 4px; color: var(--muted); font-size: 12px; line-height: 1.5; }
.request-trace li.pending { opacity: 1; animation: none; }
.request-trace li.pending > span { border-color: var(--line); color: var(--muted); background: var(--panel-raised); }
.request-trace li.pending:not(:last-child)::after { background: var(--line); }

.architecture-explanation { margin-top: 26px; padding: clamp(26px, 4vw, 50px); }
.explanation-copy { max-width: 1040px; }
.explanation-copy > p:not(.eyebrow) { margin-bottom: 16px; color: var(--text); font-size: 17px; line-height: 1.82; }
.responsibility-list { display: flex; flex-wrap: wrap; gap: 9px; margin: 5px 0 22px; padding: 0; list-style: none; }
.responsibility-list li { position: relative; border: 1px solid color-mix(in srgb, var(--amber) 30%, var(--line)); border-radius: 8px; color: #f0e2ba; background: color-mix(in srgb, var(--amber) 8%, transparent); font-size: 13px; }
.setup-example { margin-top: 28px; padding: 22px; border-left: 3px solid var(--cyan); background: color-mix(in srgb, var(--panel-raised) 78%, transparent); }
.setup-example h3 { margin-bottom: 8px; font-size: 20px; }
.setup-example > p:last-child { margin: 0; color: var(--text); font-size: 15px; line-height: 1.75; }
.setup-example code { color: var(--lime); }

.tradeoffs { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-top: 34px; padding-top: 30px; border-top: 1px solid var(--line); }
.tradeoff-card { padding: 24px; border: 1px solid var(--line); border-radius: 13px; background: var(--panel-raised); }
.tradeoff-card.gives { border-top: 3px solid var(--lime); }
.tradeoff-card.problems { border-top: 3px solid var(--danger); }
.tradeoff-label { margin-bottom: 16px; color: var(--text); font-size: 16px; font-weight: 800; }
.tradeoff-card ul { display: grid; gap: 10px; margin: 0; padding: 0; list-style: none; }
.tradeoff-card li { position: relative; padding-left: 18px; color: #d4dde2; font-size: 14px; line-height: 1.55; }
.tradeoff-card li::before { position: absolute; top: .65em; left: 1px; width: 6px; height: 6px; border-radius: 50%; background: var(--lime); content: ""; }
.tradeoff-card.problems li::before { background: var(--danger); }
.tradeoff-card .spof-warning { margin-top: 3px; padding: 11px 12px 11px 30px; border: 1px solid color-mix(in srgb, var(--danger) 42%, var(--line)); border-radius: 9px; color: #ffd7dc; background: color-mix(in srgb, var(--danger) 10%, transparent); }
.tradeoff-card .spof-warning::before { top: 1.15em; left: 13px; box-shadow: 0 0 12px color-mix(in srgb, var(--danger) 55%, transparent); }

.next-lesson { display: flex; align-items: center; justify-content: space-between; gap: 40px; margin-top: 26px; padding: clamp(26px, 4vw, 42px); border-color: color-mix(in srgb, var(--cyan) 38%, var(--line)); }
.next-lesson a { min-height: 50px; display: inline-flex; flex: 0 0 auto; align-items: center; gap: 12px; padding: 0 18px; border: 1px solid color-mix(in srgb, var(--cyan) 45%, var(--line)); border-radius: 11px; color: var(--text); background: rgb(85 217 232 / 9%); font-size: 13px; font-weight: 800; text-decoration: none; }
.next-lesson a:hover { background: rgb(85 217 232 / 15%); }
.next-lesson a span { color: var(--cyan); font-size: 20px; }

.toast-region { position: fixed; right: 22px; bottom: 22px; z-index: 30; display: grid; gap: 8px; }
.toast { max-width: 360px; padding: 12px 15px; border: 1px solid rgb(183 237 98 / 40%); border-radius: 10px; color: var(--text); background: #182111; box-shadow: 0 14px 40px #0008; font-size: 12px; }
.toast.error { border-color: rgb(255 107 120 / 45%); background: #281318; }

html[data-theme="light"] .lesson-workspace,
html[data-theme="light"] .observation,
html[data-theme="light"] .architecture-explanation,
html[data-theme="light"] .next-lesson,
html[data-theme="light"] .tradeoff-card { color: var(--text); background: #fff; box-shadow: 0 18px 48px rgb(25 42 50 / 10%); }
html[data-theme="light"] .concept-tags span,
html[data-theme="light"] .endpoint-box,
html[data-theme="light"] .server-identity,
html[data-theme="light"] .products,
html[data-theme="light"] .request-log pre,
html[data-theme="light"] .proxy-route,
html[data-theme="light"] .proxy-details,
html[data-theme="light"] .proxy-details > div,
html[data-theme="light"] .cache-box,
html[data-theme="light"] .last-result,
html[data-theme="light"] .experiment-stats div,
html[data-theme="light"] .request-trace li > span { border-color: var(--line); color: var(--text); background: #f6f9fa; }
html[data-theme="light"] .concept-tags span,
html[data-theme="light"] .tradeoff-card li,
html[data-theme="light"] .request-trace strong { color: var(--text); }
html[data-theme="light"] .responsibility-list li { color: #644a0d; }
html[data-theme="light"] .tradeoff-card .spof-warning { color: #8e2333; background: #fff0f2; }
html[data-theme="light"] .proxy-details code { color: #075f70; }
html[data-theme="light"] .proxy-details small { color: #465761; }
html[data-theme="light"] .cache-box code { color: #465761; }
html[data-theme="light"] .request-trace li:not(.pending) > span { border-color: var(--lime); color: #172205; background: var(--lime); }
html[data-theme="light"] .primary-action { color: #172205; background: #a9d85c; }
html[data-theme="light"] .secondary-action { color: var(--text); background: var(--panel-raised); }
html[data-theme="light"] .client-tooling { color: var(--muted); background: #f6f9fa; }
html[data-theme="light"] .client-tooling button { color: #075f70; background: #e6f3f5; }
html[data-theme="light"] .next-lesson a { color: var(--text); background: rgb(8 127 147 / 8%); }

@keyframes flowHorizontal { 0% { left: -7px; opacity: 0; } 12% { opacity: 1; } 88% { opacity: 1; } 100% { left: calc(100% - 3px); opacity: 0; } }
@keyframes flowVertical { 0% { top: -7px; opacity: 0; } 12% { opacity: 1; } 88% { opacity: 1; } 100% { top: calc(100% - 3px); opacity: 0; } }
@keyframes buttonPulse { from { filter: brightness(.86); } to { filter: brightness(1.12); } }
@keyframes revealTrace { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }

@media (max-width: 1080px) {
  .workspace-heading,
  .next-lesson { align-items: flex-start; flex-direction: column; }
  .architecture-flow { display: flex; flex-direction: column; gap: 0; }
  .client-card,
  .proxy-card,
  .service-card { width: 100%; min-height: 0; }
  .connector-client,
  .connector-upstream { width: 2px; height: 76px; align-self: center; }
  .connector-client::after,
  .connector-upstream::after { top: auto; right: -4px; bottom: 0; border: 0; border-right: 2px solid var(--cyan); border-bottom: 2px solid var(--cyan); transform: rotate(45deg); }
  .connector-client span,
  .connector-upstream span { top: 50%; left: 16px; transform: translateY(-50%); }
  .connector-client .packet { top: -7px; left: -4px; }
  .connector-client.flowing .packet { animation-name: flowVertical; }
  .observation { grid-template-columns: 1fr; }
}

@media (max-width: 700px) {
  .site-header { padding-inline: 16px; }
  .lesson-chip { font-size: 0; }
  .lesson-chip span { font-size: 10px; }
  main { width: min(100% - 24px, 1320px); padding-top: 42px; }
  .intro h1 { font-size: 42px; }
  .intro-copy { font-size: 16px; }
  .lesson-controls { width: 100%; }
  .lesson-controls button { flex: 1; }
  .node-card { padding: 18px; }
  .client-tooling { align-items: flex-start; flex-direction: column; }
  .proxy-route,
  .proxy-details,
  .proxy-runtime { grid-template-columns: 1fr; }
  .proxy-route b { text-align: left; }
  .proxy-details pre { grid-column: auto; }
  .experiment-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tradeoffs { grid-template-columns: 1fr; }
  .next-lesson a { width: 100%; justify-content: space-between; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
