:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --surface-2: #f0f0ec;
  --text: #16181d;
  --muted: #5b616e;
  --line: #e2e2dc;
  --accent: #4f46e5;
  --accent-soft: #eceafd;
  --guard: #b45309;
  --guard-soft: #fdf1e3;
  --model: #0e7490;
  --model-soft: #e3f4f7;
  --human: #15803d;
  --human-soft: #e5f5ea;
  --radius: 14px;
  --line-strong: #c9c9c1;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: "Inter", system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d0f14; --surface: #151821; --surface-2: #1c202b; --text: #e8eaf0; --muted: #9aa1b2; --line: #262b38; --line-strong: #3a4152;
    --accent: #8b85ff; --accent-soft: #23214a; --guard: #f0a65a; --guard-soft: #33240f; --model: #4cc3d9;
    --model-soft: #10303a; --human: #5fd08a; --human-soft: #12301f;
  }
}
:root[data-theme="dark"] {
  --bg: #0d0f14; --surface: #151821; --surface-2: #1c202b; --text: #e8eaf0; --muted: #9aa1b2; --line: #262b38; --line-strong: #3a4152;
  --accent: #8b85ff; --accent-soft: #23214a; --guard: #f0a65a; --guard-soft: #33240f; --model: #4cc3d9;
  --model-soft: #10303a; --human: #5fd08a; --human-soft: #12301f;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.65 var(--sans); -webkit-font-smoothing: antialiased; }
a { color: inherit; }
main { max-width: 1120px; margin: 0 auto; padding: 0 24px; }
h1, h2, h3 { line-height: 1.2; letter-spacing: -0.02em; margin: 0 0 12px; }
h1 { font-size: clamp(2rem, 4.4vw, 3.3rem); font-weight: 700; }
h2 { font-size: clamp(1.5rem, 2.6vw, 2.1rem); font-weight: 650; }
h3 { font-size: 1.12rem; font-weight: 600; }
code { font-family: var(--mono); font-size: 0.88em; background: var(--surface-2); padding: 0.1em 0.35em; border-radius: 5px; }

.topbar { position: sticky; top: 0; z-index: 10; display: flex; justify-content: space-between; align-items: center; gap: 16px;
  padding: 14px 24px; background: color-mix(in srgb, var(--bg) 85%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.brand { font-weight: 650; text-decoration: none; display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.brand .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.topbar nav { display: flex; align-items: center; gap: 20px; font-size: 0.94rem; }
.topbar nav a { text-decoration: none; color: var(--muted); }
.topbar nav a:hover { color: var(--text); }
.theme { border: 1px solid var(--line); background: var(--surface); color: var(--text); border-radius: 8px; width: 34px; height: 34px; cursor: pointer; font-size: 1rem; }

.eyebrow { font-family: var(--mono); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--accent); margin: 0 0 10px; }
.lead { font-size: 1.15rem; color: var(--muted); max-width: 62ch; }
.actions { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 28px; }
.btn { display: inline-block; padding: 11px 18px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); text-decoration: none; font-weight: 550; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }

.hero { display: grid; grid-template-columns: 1.15fr 0.85fr; gap: 48px; align-items: center; padding: 72px 0 56px; }
.hero-visual { min-width: 0; }

section { padding: 64px 0; border-top: 1px solid var(--line); }
.section-head { max-width: 680px; margin-bottom: 32px; }
.section-head p:not(.eyebrow) { color: var(--muted); margin: 0; }

.shape-tabs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 20px; }
.shape-tabs button { font: 500 0.9rem var(--sans); padding: 8px 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--muted); cursor: pointer; }
.shape-tabs button[aria-selected="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.shape-panel { display: grid; grid-template-columns: minmax(220px, 0.8fr) 1.6fr; gap: 28px; align-items: start; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; min-height: 150px; }
.shape-panel .shape-info p:not(.eyebrow) { color: var(--muted); font-size: 0.95rem; }
.shape-panel h3 a { text-decoration: none; }
.shape-panel h3 a:hover { color: var(--accent); }
.shape-panel .style-tag { margin: 4px 0 16px; }


.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 18px; }
.card { display: flex; flex-direction: column; gap: 8px; padding: 24px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); text-decoration: none; transition: border-color .2s, transform .2s; }
.card:hover { border-color: var(--accent); transform: translateY(-2px); }
.card p { color: var(--muted); margin: 0; font-size: 0.95rem; }
.card-client { font: 500 0.78rem var(--mono); color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.style-tag { font: 500 0.8rem var(--mono); color: var(--accent); }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: auto; padding-top: 8px; }
.tags span { font: 0.74rem var(--mono); padding: 3px 8px; border-radius: 6px; background: var(--surface-2); color: var(--muted); }
.more { font-weight: 600; font-size: 0.9rem; color: var(--accent); }

.principle-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 18px; }
.principle { position: relative; padding: 26px 24px 24px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); transition: border-color .2s, transform .2s; }
.principle:hover { border-color: var(--accent); transform: translateY(-2px); }
.principle-icon { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 12px; background: var(--accent-soft); color: var(--accent); margin-bottom: 16px; }
.principle-icon svg { width: 24px; height: 24px; }
.principle-num { position: absolute; top: 24px; right: 24px; font: 500 0.8rem var(--mono); color: var(--line-strong); }
.principle h3 { margin-bottom: 8px; }
.principle p { color: var(--muted); margin: 0; font-size: 0.95rem; }

.oss-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 18px; }
.oss-card { padding: 22px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); text-decoration: none; }
.oss-card:hover { border-color: var(--accent); }
.oss-card code { font-size: 1rem; background: none; padding: 0; color: var(--accent); }
.oss-card p { color: var(--muted); margin: 8px 0 0; font-size: 0.95rem; }

.case { max-width: 780px; padding-top: 40px; padding-bottom: 64px; }
.back { display: inline-block; margin-bottom: 28px; color: var(--muted); text-decoration: none; font-size: 0.92rem; }
.back:hover { color: var(--accent); }
.facts { display: grid; gap: 10px; margin: 28px 0; padding: 18px 20px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); font-size: 0.95rem; }
.facts span { display: block; font: 500 0.74rem var(--mono); text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.diagram { padding: 22px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 40px; }
.case h2 { margin-top: 40px; }
.blog h3 { margin-top: 32px; }
.blog h4 { margin: 24px 0 8px; font-size: 1.02rem; }
.blog p, .blog li { color: color-mix(in srgb, var(--text) 88%, var(--muted)); }
.blog li { margin-bottom: 6px; }

.footer { max-width: 1120px; margin: 0 auto; padding: 32px 24px 48px; display: flex; justify-content: space-between; gap: 16px; color: var(--muted); font-size: 0.9rem; border-top: 1px solid var(--line); }

@media (max-width: 820px) {
  .shape-panel { grid-template-columns: 1fr; }
  .hero { grid-template-columns: 1fr; padding-top: 48px; gap: 32px; }
  .topbar nav a:not(:first-child) { display: none; }
}
@media (max-width: 480px) {
  main { padding: 0 16px; }
  .topbar { padding: 12px 16px; }
  .grid, .oss-grid, .principle-grid { grid-template-columns: 1fr; }
  .footer { flex-direction: column; padding: 28px 16px 40px; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
}

/* ---------------------------------------------------------------- diagrams */
.k-code  { --kf: var(--surface-2); --ks: var(--line-strong); --kt: var(--text); }
.k-guard { --kf: var(--guard-soft); --ks: var(--guard); --kt: var(--guard); }
.k-model { --kf: var(--model-soft); --ks: var(--model); --kt: var(--model); }
.k-agent { --kf: var(--accent-soft); --ks: var(--accent); --kt: var(--accent); }
.k-human { --kf: var(--human-soft); --ks: var(--human); --kt: var(--human); }

.diagram-host { overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 4px; }
.dg-svg { display: block; width: 100%; height: auto; margin: 0 auto; font-family: var(--sans); }
.dg-node rect, .dg-node polygon, .dg-actor rect, .dg-note { fill: var(--kf); stroke: var(--ks); stroke-width: 1.4; transition: stroke-width .25s, filter .25s, opacity .25s; }
.dg-decision polygon { stroke-dasharray: 5 3; }
.dg-terminal rect { stroke-width: 1.8; }
.dg-text { font: 500 12.5px var(--sans); fill: var(--kt, var(--text)); }
.dg-node .dg-text, .dg-actor .dg-text { fill: var(--kt); }
.dg-actor .dg-text { font: 600 12px var(--mono); text-transform: uppercase; letter-spacing: .04em; }
.dg-edge { fill: none; stroke: var(--muted); stroke-width: 1.4; }
.dg-loop { stroke-dasharray: 5 4; }
.dg-arrowhead { fill: var(--muted); }
.dg-elabel { font: 500 11px var(--mono); fill: var(--muted); paint-order: stroke; stroke: var(--surface); stroke-width: 4px; stroke-linejoin: round; }
.hero .dg-elabel { stroke: var(--bg); }
.dg-lane { fill: transparent; }
.dg-lane.odd { fill: var(--surface-2); opacity: .55; }
.dg-lanelabel { font: 600 10.5px var(--mono); text-transform: uppercase; letter-spacing: .06em; fill: var(--kt); }
.dg-lifeline { stroke: var(--line-strong); stroke-dasharray: 3 5; }
.dg-frame { fill: none; stroke: var(--line-strong); stroke-dasharray: 2 3; }
.dg-frametag { font: 600 10.5px var(--mono); fill: var(--muted); }
.dg-mini { fill: var(--surface); stroke: var(--muted); }
.dg-msg .dg-elabel { fill: var(--text); }

/* sections inside a diagram */
.dg-group rect { fill: var(--kf); stroke: var(--ks); stroke-opacity: .45; stroke-dasharray: 4 4; fill-opacity: .45; }
.dg-group text { font: 600 10.5px var(--mono); text-transform: uppercase; letter-spacing: .06em; fill: var(--kt); }

/* run animation: the current step is solid and pulsing, finished steps stay clear, the rest fades back */
.running [data-seq] { transition: opacity .35s; opacity: .38; }
.running [data-seq].done { opacity: .85; }
.running [data-seq].on { opacity: 1; }
.running .dg-node.on rect, .running .dg-node.on polygon { fill: var(--ks); stroke: var(--ks); stroke-width: 3; filter: drop-shadow(0 0 10px var(--ks)); animation: dg-pulse 1.1s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
.running .dg-node.on .dg-text { fill: #fff; font-weight: 700; }
.running .dg-node.k-code.on rect, .running .dg-node.k-code.on polygon { fill: var(--text); stroke: var(--text); filter: drop-shadow(0 0 8px var(--muted)); }
.running .dg-node.k-code.on .dg-text { fill: var(--bg); }
.running .dg-edge { stroke-dasharray: 6 5; animation: dg-flow .9s linear infinite; }
.running .dg-loop { stroke-dasharray: 3 5; }
.running .dg-msg.on .dg-edge { stroke: var(--accent); stroke-width: 2.6; }
.running .dg-msg.on .dg-elabel { fill: var(--accent); }
.running .st-main.on .st-num, .running .st-side.on .st-sidelabel { box-shadow: 0 0 0 4px var(--kf), 0 0 14px var(--ks); }
@keyframes dg-pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.06); } }
@keyframes dg-flow { to { stroke-dashoffset: -11; } }

/* steps */
.dg-steps { list-style: none; margin: 0; padding: 0; counter-reset: none; }
.st-item { position: relative; padding: 0 0 18px 0; }
.st-item:not(:last-child)::before { content: ""; position: absolute; left: 15px; top: 34px; bottom: 2px; width: 2px; background: var(--line); }
.st-main { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.st-num { flex: none; width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; font: 600 0.85rem var(--mono); background: var(--kf); color: var(--kt); border: 1.5px solid var(--ks); transition: box-shadow .25s; }
.st-decision .st-num { border-radius: 8px; transform: rotate(45deg); }
.st-decision .st-num { font-size: 0; }
.st-decision .st-num::after { content: "?"; font: 700 0.9rem var(--mono); transform: rotate(-45deg); color: var(--kt); }
.st-label { font-weight: 600; }
.st-kind { font: 500 0.7rem var(--mono); text-transform: uppercase; letter-spacing: .05em; color: var(--kt); background: var(--kf); padding: 2px 7px; border-radius: 5px; }
.st-branches { margin: 8px 0 0 44px; display: grid; gap: 6px; }
.st-branch { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; font-size: 0.9rem; color: var(--muted); }
.st-branch b { font: 600 0.78rem var(--mono); color: var(--text); background: var(--surface-2); border: 1px solid var(--line); padding: 1px 7px; border-radius: 5px; }
.st-arrow { color: var(--muted); }
.st-sidelabel { font-weight: 600; color: var(--kt); background: var(--kf); border: 1px solid var(--ks); padding: 2px 9px; border-radius: 6px; transition: box-shadow .25s; }
.st-end, .st-back { font: 500 0.75rem var(--mono); color: var(--muted); }

/* legend */
.legend { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 16px; font: 500 0.75rem var(--mono); color: var(--muted); }
.lg { display: inline-flex; align-items: center; gap: 6px; }
.lg::before { content: ""; width: 12px; height: 12px; border-radius: 3px; background: var(--kf); border: 1.5px solid var(--ks); }
.lg-decision::before { background: transparent; border: 1.5px dashed var(--muted); transform: rotate(45deg) scale(.85); border-radius: 2px; }
.diagram-head { margin-bottom: 12px; }

/* hero layout per style: wide styles get the full width under the text */
body[data-diagram-style="swimlanes"] .hero,
body[data-diagram-style="sequence"] .hero { grid-template-columns: 1fr; }
body[data-diagram-style="swimlanes"] .hero-text,
body[data-diagram-style="sequence"] .hero-text { max-width: 760px; }
body[data-diagram-style="steps"] .hero-visual { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; }

/* style switcher */
.style-switch { position: fixed; right: 16px; bottom: 16px; z-index: 20; display: flex; align-items: center; gap: 4px; padding: 5px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 6px 24px rgba(0,0,0,.12); }
.style-switch span { font: 500 0.72rem var(--mono); text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 0 8px; }
.style-switch button { font: 500 0.82rem var(--sans); border: 0; background: transparent; color: var(--muted); padding: 7px 11px; border-radius: 8px; cursor: pointer; }
.style-switch button[aria-pressed="true"] { background: var(--accent); color: #fff; }
@media (max-width: 640px) {
  .style-switch { left: 12px; right: 12px; bottom: 12px; justify-content: space-between; }
  .style-switch span { display: none; }
  .style-switch button { padding: 7px 6px; font-size: 0.78rem; }
  .footer { padding-bottom: 88px; }
}

/* wide diagram styles: the chart goes under the project text */
body[data-diagram-style="swimlanes"] .shape-panel,
body[data-diagram-style="sequence"] .shape-panel { grid-template-columns: 1fr; }
body[data-diagram-style="swimlanes"] .shape-info,
body[data-diagram-style="sequence"] .shape-info { max-width: 720px; }
.shape-info h3 { font-size: 1.35rem; }
.shape-info .more { text-decoration: none; }

/* hero: text and portrait on top, the run diagram below */
.hero { display: block; padding: 64px 0 48px; }
.hero-top { display: grid; grid-template-columns: 1fr minmax(220px, 300px); gap: 48px; align-items: end; }
.hero h1 { font-size: clamp(2.2rem, 5vw, 3.6rem); }
.h1-sub { color: var(--accent); }
.hero-photo { margin: 0; }
.hero-photo img { display: block; width: 100%; height: auto; aspect-ratio: 1; object-fit: cover; border-radius: 20px; box-shadow: 0 18px 40px rgba(0,0,0,.18); }
.hero-text .actions { margin-bottom: 0; }
.hero-visual { margin-top: 56px; padding: 24px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
@media (max-width: 820px) {
  .hero-top { grid-template-columns: 1fr; gap: 28px; }
  .hero-photo { max-width: 260px; order: -1; }
}

/* ---------------------------------------------------------------- flow style: cards on the page, no box, no scrolling */
.diagram-host[data-style="flow"] { overflow: visible; padding: 0; }
.fl-svg { display: block; margin: 0 auto; max-width: 100%; height: auto; overflow: visible; font-family: var(--sans); }
.fl-node.k-code { --ks: var(--muted); --kt: var(--muted); }
.fl-group rect { fill: var(--kf); fill-opacity: .55; stroke: var(--ks); stroke-opacity: .18; }
.fl-group text { font: 600 10px var(--mono); text-transform: uppercase; letter-spacing: .07em; fill: var(--kt); }
.fl-card { fill: var(--surface); stroke: var(--line); stroke-width: 1; transition: stroke .3s, stroke-width .3s, fill .3s; }
.fl-node { filter: drop-shadow(0 1px 1px rgba(16,18,28,.05)) drop-shadow(0 6px 14px rgba(16,18,28,.07)); transition: filter .3s; }
.fl-chip { fill: var(--kf); transition: fill .3s; }
.fl-icon { fill: none; stroke: var(--kt); stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; transition: stroke .3s; }
.fl-kind { font: 600 9.5px var(--mono); text-transform: uppercase; letter-spacing: .07em; fill: var(--kt); }
.fl-label { font: 600 12.5px var(--sans); fill: var(--text); }
.fl-edge { fill: none; stroke: var(--line-strong); stroke-width: 1.6; stroke-linecap: round; transition: stroke .4s; }
.fl-arrow { fill: none; stroke: context-stroke; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.fl-port { fill: var(--bg); stroke: var(--line-strong); stroke-width: 1.5; }
.fl-elabel { font: 600 10px var(--mono); fill: var(--muted); }
.fl-edge { transition: stroke 1.2s ease; }
.fl-card, .fl-chip, .fl-icon, .fl-node { transition-duration: .9s; transition-timing-function: ease; }
.fl-edge.lit { stroke: color-mix(in srgb, var(--accent) 55%, var(--line-strong)); }
.fl-comet { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linecap: round; stroke-dasharray: .3 1.4; stroke-dashoffset: .3; opacity: 0; }
.fl-comet.go { animation: fl-travel 1.3s ease-in-out forwards; }
@keyframes fl-travel { 0% { stroke-dashoffset: .3; opacity: 0; } 20% { opacity: .7; } 80% { opacity: .7; } 100% { stroke-dashoffset: -1.02; opacity: 0; } }
.fl-node.done .fl-card { stroke: var(--ks); stroke-opacity: .4; }
.fl-node.on .fl-card { stroke: var(--ks); stroke-width: 1.5; fill: color-mix(in srgb, var(--kf) 35%, var(--surface)); transition-delay: .8s; }
.fl-node.on { filter: drop-shadow(0 1px 1px rgba(16,18,28,.05)) drop-shadow(0 6px 16px color-mix(in srgb, var(--ks) 22%, transparent)); transition-delay: .8s; }

/* hero and project panel without boxes */
.hero-visual { background: none; border: 0; padding: 0; }
.shape-panel { display: block; background: none; border: 0; padding: 0; }
.shape-info { display: grid; grid-template-columns: 1fr 1fr; gap: 20px 56px; max-width: none !important; margin: 8px 0 28px; }
.shape-info h3 { font-size: 1.3rem; margin-bottom: 8px; }
.shape-info p:not(.eyebrow) { color: var(--muted); font-size: 1rem; margin: 0 0 10px; max-width: 54ch; }
.shape-info .eyebrow { color: var(--muted); margin-bottom: 8px; }
.shape-panel .style-tag { margin: 0; }
.shape-panel .more { display: inline-block; margin-top: 24px; text-decoration: none; }
.case .diagram { background: none; border: 0; padding: 0; width: min(1072px, 100vw - 48px); margin-left: 50%; transform: translateX(-50%); }
@media (max-width: 820px) { .shape-info { grid-template-columns: 1fr; } }
@media (max-width: 480px) { .case .diagram { width: calc(100vw - 32px); } }
