:root {
    --bg: #f6f7f9;
    --surface: #ffffff;
    --surface-2: #eef0f4;
    --text: #1b1f27;
    --muted: #5d6675;
    --border: #d9dde5;
    --lifeline: #c3c9d4;
    --accent: #0696d7;
    --halo: #ffffff;
    --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 4px 16px rgb(16 24 40 / 6%);
    --mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0f1216;
        --surface: #171b21;
        --surface-2: #1f252d;
        --text: #e6e9ef;
        --muted: #97a0af;
        --border: #2c333d;
        --lifeline: #3a424e;
        --accent: #38b6f0;
        --halo: #171b21;
        --shadow: none;
        color-scheme: dark;
    }
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a {
    color: var(--accent);
}

code {
    font-family: var(--mono);
    font-size: 0.92em;
    background: var(--surface-2);
    padding: 0.05em 0.35em;
    border-radius: 4px;
}

.page {
    max-width: 1500px;
    margin: 0 auto;
    padding: 20px 24px 40px;
}

/* ---------- header ---------- */

.nav {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 14px;
    font-size: 13px;
}

.nav a {
    text-decoration: none;
    color: var(--muted);
    padding: 3px 10px;
    border-radius: 999px;
    border: 1px solid transparent;
}

.nav a:hover {
    border-color: var(--border);
}

.nav a.active {
    color: var(--text);
    background: var(--surface);
    border-color: var(--border);
}

h1 {
    margin: 0 0 4px;
    font-size: 24px;
    letter-spacing: -0.01em;
}

.subtitle {
    margin: 0 0 16px;
    color: var(--muted);
    max-width: 90ch;
}

/* ---------- mode tabs + controls ---------- */

.toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px 20px;
    margin-bottom: 12px;
}

.modes {
    display: inline-flex;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 3px;
    gap: 2px;
}

.modes button {
    border: 0;
    background: transparent;
    color: var(--muted);
    font: inherit;
    font-weight: 600;
    padding: 6px 14px;
    border-radius: 7px;
    cursor: pointer;
}

.modes button[aria-pressed="true"] {
    background: var(--accent);
    color: #fff;
}

.controls {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.controls button {
    font: inherit;
    min-width: 36px;
    height: 34px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
}

.controls button:hover {
    border-color: var(--accent);
}

.controls button.primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
    min-width: 84px;
    font-weight: 600;
}

.controls label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-left: 8px;
    color: var(--muted);
    font-size: 13px;
}

.progress {
    flex: 1 1 200px;
    height: 6px;
    background: var(--surface-2);
    border-radius: 999px;
    overflow: hidden;
    min-width: 120px;
}

.progress > div {
    height: 100%;
    width: 0;
    background: var(--accent);
    transition: width 0.3s ease;
}

.mode-blurb {
    margin: 0 0 14px;
    padding: 10px 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 3px solid var(--accent);
    border-radius: 8px;
    color: var(--text);
}

/* ---------- stage ---------- */

.stage {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 390px;
    gap: 16px;
    align-items: start;
}

@media (max-width: 1150px) {
    .stage {
        grid-template-columns: 1fr;
    }
}

.diagram {
    position: sticky;
    top: 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow);
    padding: 6px;
}

.diagram svg {
    display: block;
    width: 100%;
    height: auto;
    user-select: none;
}

.side {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.panel,
.step-list {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow);
}

.panel {
    padding: 18px 20px;
    min-height: 260px;
}

.panel .meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.chip {
    display: inline-block;
    padding: 1px 8px;
    border-radius: 999px;
    font-weight: 600;
    color: var(--c);
    background: color-mix(in srgb, var(--c) 14%, transparent);
    text-transform: none;
    letter-spacing: 0;
}

.panel h2 {
    margin: 8px 0 6px;
    font-size: 18px;
    line-height: 1.3;
}

.route {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
    font-size: 13px;
    color: var(--muted);
    margin-bottom: 10px;
}

.route .dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--c);
    display: inline-block;
}

.panel .body p {
    margin: 0 0 10px;
}

.panel pre {
    margin: 10px 0;
    padding: 10px 12px;
    background: var(--surface-2);
    border-radius: 8px;
    overflow-x: auto;
    font: 12px/1.5 var(--mono);
    white-space: pre;
}

.panel .ref {
    display: inline-block;
    margin-top: 6px;
    font: 12px var(--mono);
}

.panel .hint {
    margin-top: 16px;
    color: var(--muted);
    font-size: 12px;
}

.step-list {
    list-style: none;
    margin: 0;
    padding: 8px;
    max-height: 420px;
    overflow-y: auto;
    font-size: 13px;
}

.step-list .phase {
    padding: 10px 6px 4px;
    font-size: 12px;
}

.step-list .item {
    display: flex;
    gap: 8px;
    align-items: baseline;
    padding: 4px 8px;
    border-radius: 6px;
    cursor: pointer;
    color: var(--muted);
}

.step-list .item:hover {
    background: var(--surface-2);
}

.step-list .item.done {
    color: var(--text);
}

.step-list .item.current {
    background: color-mix(in srgb, var(--accent) 14%, transparent);
    color: var(--text);
    font-weight: 600;
}

.step-list .n {
    flex: none;
    width: 22px;
    text-align: right;
    font: 11px var(--mono);
    color: var(--muted);
}

kbd {
    font: 11px var(--mono);
    border: 1px solid var(--border);
    border-bottom-width: 2px;
    border-radius: 4px;
    padding: 0 5px;
    background: var(--surface-2);
}

.legend {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 18px;
    margin-top: 12px;
    color: var(--muted);
    font-size: 12px;
}

.swatch {
    display: inline-block;
    vertical-align: middle;
    margin-right: 6px;
}

.packet-swatch {
    width: 22px;
    height: 12px;
    border-radius: 6px;
    background: var(--accent);
}

.badge-swatch {
    width: 22px;
    height: 12px;
    border-radius: 6px;
    border: 1px solid var(--accent);
    background: color-mix(in srgb, var(--accent) 15%, var(--surface));
}

.edge-swatch {
    width: 26px;
    height: 0;
    border-top: 2px solid var(--muted);
}

/* ---------- SVG diagram ---------- */

.zone rect {
    fill: color-mix(in srgb, var(--c) 5%, transparent);
    stroke: color-mix(in srgb, var(--c) 45%, transparent);
    stroke-width: 1.2;
    stroke-dasharray: 6 5;
}

.zone text {
    fill: var(--c);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.zone.minor rect {
    fill: none;
    stroke-dasharray: 2 4;
}

.zone.minor text {
    font-size: 10.5px;
}

.node rect {
    fill: color-mix(in srgb, var(--c) 10%, var(--surface));
    stroke: var(--c);
    stroke-width: 1.5;
    transition: fill 0.25s, stroke-width 0.25s;
}

.node rect.stripe {
    fill: var(--c);
    stroke: none;
}

.node.active rect:not(.stripe) {
    fill: color-mix(in srgb, var(--c) 30%, var(--surface));
    stroke-width: 2.5;
}

.node .n-label {
    font-weight: 700;
    font-size: 13.5px;
    fill: var(--text);
}

.node .n-sub {
    font-size: 11px;
    fill: var(--muted);
}

.node {
    transition: opacity 0.3s;
}

.node.client {
    cursor: pointer;
}

.node.dim {
    opacity: 0.4;
}

.node.dim:hover {
    opacity: 0.75;
}

.edge {
    fill: none;
    stroke: var(--lifeline);
    stroke-width: 1.5;
    stroke-dasharray: 3 5;
    transition: stroke 0.3s;
}

.edge.used {
    stroke: var(--muted);
    stroke-dasharray: none;
}

.edge.current {
    stroke: var(--c);
    stroke-width: 3;
    stroke-dasharray: none;
}

.edge.current.res {
    stroke-dasharray: 8 5;
}

.packet rect {
    fill: var(--c);
    filter: drop-shadow(0 1px 3px rgb(0 0 0 / 35%));
}

.packet text {
    fill: #fff;
    font: 700 11px var(--mono);
}

.caption rect {
    fill: var(--surface);
    stroke: var(--c);
    stroke-width: 1.2;
}

.caption text {
    fill: var(--text);
    font-size: 12px;
    font-weight: 600;
}

.badge rect {
    fill: color-mix(in srgb, var(--c) 14%, var(--surface));
    stroke: color-mix(in srgb, var(--c) 70%, transparent);
}

.badge text {
    fill: var(--text);
    font: 11px var(--mono);
}

.banner rect {
    fill: color-mix(in srgb, #f5b400 18%, var(--surface));
    stroke: color-mix(in srgb, #f5b400 70%, transparent);
}

.banner text {
    fill: var(--text);
    font-size: 13px;
    font-style: italic;
}

.ring {
    fill: none;
    stroke: var(--c);
    stroke-width: 2;
}


/* ---------- index page ---------- */

.cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 16px;
    margin: 20px 0 28px;
}

.card {
    display: block;
    text-decoration: none;
    color: inherit;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 18px 20px;
    box-shadow: var(--shadow);
    transition: border-color 0.2s, transform 0.2s;
}

.card:hover {
    border-color: var(--accent);
    transform: translateY(-2px);
}

.card h2 {
    margin: 0 0 6px;
    font-size: 17px;
}

.card p {
    margin: 0 0 10px;
    color: var(--muted);
}

.card .tag {
    font: 12px var(--mono);
    color: var(--accent);
}

table.matrix {
    border-collapse: collapse;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    width: 100%;
}

table.matrix th,
table.matrix td {
    text-align: left;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}

table.matrix th {
    background: var(--surface-2);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
}

table.matrix tr:last-child td {
    border-bottom: 0;
}

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