:root {
  --bg: #0a0e16;
  --panel: #121a2a;
  --panel2: #172036;
  --line: #2b3a5c;
  --text: #f1f5fb;
  --muted: #a8b6cd;
  --ok: #3ddc97;
  --block: #ff5d6c;
  --warn: #ffb84d;
  --info: #7aa7ff;
  --sens-bg: #5b2a0d; --sens-fg: #ffd9b8; --sens-bd: #ff8a3d;
  --tok-bg: #07394a; --tok-fg: #a5efff; --tok-bd: #25cbe9;
  --res-bg: #0e4029; --res-fg: #a8f7cd; --res-bd: #3ddc97;
  --blk-bg: #54141f; --blk-fg: #ffc2c8; --blk-bd: #ff5d6c;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --radius: 14px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html { font-size: 18px; -webkit-text-size-adjust: 100%; }
@media (min-width: 1600px) { html { font-size: 21px; } }
@media (max-width: 600px) { html { font-size: 17px; } }
body { margin: 0; background: radial-gradient(1200px 600px at 20% -10%, #14213d 0%, var(--bg) 55%); color: var(--text); font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; line-height: 1.45; min-height: 100vh; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid #ffe08a; outline-offset: 2px; border-radius: 6px; }

#app { max-width: 1760px; margin: 0 auto; padding: 0 1.1rem 1.5rem; }

/* header */
.top { display: flex; flex-wrap: wrap; gap: 1rem 2rem; justify-content: space-between; align-items: flex-end; padding: 1.1rem 0 0.9rem; border-bottom: 1px solid var(--line); }
.top h1 { margin: 0; font-size: 1.6rem; line-height: 1.2; letter-spacing: -0.01em; }
.tagline { margin: 0.3rem 0 0; color: var(--muted); font-size: 0.9rem; max-width: 60ch; }
.top-controls { display: flex; flex-wrap: wrap; gap: 0.8rem 1.2rem; }
.ctl { display: flex; flex-direction: column; gap: 0.2rem; }
.ctl-label { font-size: 0.7rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }
.seg-btns { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--panel); }
.seg-btns button { background: transparent; color: var(--text); border: 0; border-right: 1px solid var(--line); padding: 0.45rem 0.85rem; font: inherit; font-size: 0.85rem; cursor: pointer; min-height: 40px; }
.seg-btns button:last-child { border-right: 0; }
.seg-btns button[aria-pressed="true"] { background: #274a8a; color: #fff; font-weight: 600; }
.seg-btns button:hover { background: #20315a; }
.seg-btns button[aria-pressed="true"]:hover { background: #2d58a3; }

/* buttons */
.btn { font: inherit; font-size: 0.9rem; color: var(--text); background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 0.55rem 1.1rem; cursor: pointer; min-height: 44px; }
.btn:hover:not(:disabled) { background: #20315a; }
.btn.primary { background: #2a5bd7; border-color: #4a7bff; font-weight: 600; }
.btn.primary:hover:not(:disabled) { background: #3a6cf0; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* scenarios */
.scenarios { margin: 1rem 0 0.8rem; }
.scenario-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 0.6rem; }
.scn { text-align: left; font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 0.7rem 0.9rem; cursor: pointer; display: flex; flex-direction: column; gap: 0.2rem; min-height: 78px; transition: border-color .15s, background .15s, transform .15s; }
.scn:hover:not(:disabled) { background: #19243d; border-color: #4a6bb5; transform: translateY(-1px); }
.scn[aria-pressed="true"] { border-color: #5b8cff; background: #1a2a52; box-shadow: 0 0 0 2px rgba(91, 140, 255, 0.35); }
.scn:disabled { opacity: 0.45; cursor: not-allowed; }
.scn.busy { opacity: 0.7; }
.scn-title { font-weight: 700; font-size: 1rem; }
.scn-sub { font-size: 0.8rem; color: var(--muted); line-height: 1.3; }
.start-msg { margin: 0.6rem 0 0; padding: 0.6rem 0.9rem; border: 1px solid var(--warn); background: #3a2a0a; color: #ffe2a6; border-radius: 10px; }

/* stage */
.stage { background: linear-gradient(180deg, rgba(18, 26, 42, 0.9), rgba(12, 17, 28, 0.9)); border: 1px solid var(--line); border-radius: 18px; padding: 1rem 1.1rem 1.1rem; margin: 0.4rem 0 1.2rem; }
.idle-hint { text-align: center; padding: 2.2rem 1rem; font-size: 1.15rem; }
.idle-hint p { margin: 0.3rem auto; max-width: 52ch; }
.runhead h2 { margin: 0; font-size: 1.25rem; }
.runhead p { margin: 0.25rem 0 0.9rem; color: var(--muted); max-width: 90ch; font-size: 0.95rem; }
.stage-grid { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 1.1rem 1.4rem; align-items: start; }
@media (max-width: 1050px) { .stage-grid { grid-template-columns: minmax(0, 1fr); } }

.diagram { position: relative; width: 100%; container-type: inline-size; background: #0d1422; border: 1px solid var(--line); border-radius: 16px; overflow: hidden; }
.dg-svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 2; overflow: visible; }
.dg-nodes { position: absolute; inset: 0; z-index: 1; }
.dg-edge { fill: none; stroke: #2e3f66; stroke-width: 3; stroke-dasharray: 2 8; stroke-linecap: round; transition: stroke .3s; }
.dg-edge.on { stroke-dasharray: none; stroke-width: 4; }
.dg-edge.on.tone-ok { stroke: var(--ok); } .dg-edge.on.tone-info { stroke: var(--info); }
.dg-edge.on.tone-warn { stroke: var(--warn); } .dg-edge.on.tone-block { stroke: var(--block); }
.dg-packet { --tone: var(--info); }
.dg-packet.tone-ok { --tone: var(--ok); } .dg-packet.tone-warn { --tone: var(--warn); } .dg-packet.tone-block { --tone: var(--block); }
.dg-packet .halo { fill: var(--tone); opacity: 0.28; }
.dg-packet .core { fill: var(--tone); stroke: #0a0e16; stroke-width: 2; }
.dg-packet .glyph { fill: #0a0e16; font: 700 15px system-ui, sans-serif; }

.dg-node { position: absolute; transform: translate(-50%, -50%); background: #162038; border: 2px solid #31416a; border-radius: 14px; padding: 0.55em 0.7em 0.6em; font-size: clamp(11px, 2.15cqw, 26px); transition: border-color .25s, box-shadow .25s, background .25s; text-align: left; }
.diagram[data-layout="narrow"] .dg-node { font-size: clamp(11px, 4cqw, 18px); padding: 0.45em 0.55em; }
.diagram[data-layout="narrow"] .lane-tools .dg-sub, .diagram[data-layout="narrow"] .lane-docs .dg-sub, .diagram[data-layout="narrow"] .lane-verdict .dg-sub, .diagram[data-layout="narrow"] .lane-backup .dg-sub { display: none; }
.dg-title { overflow-wrap: break-word; }
.dg-head { display: flex; align-items: center; gap: 0.45em; }
.dg-head .ico { width: 1.5em; height: 1.5em; flex: 0 0 auto; color: #9dbaf5; }
.dg-title { font-weight: 700; line-height: 1.15; font-size: 1em; }
.dg-sub { display: block; margin-top: 0.25em; font-size: 0.74em; color: var(--muted); line-height: 1.25; }
.dg-node.lane-gateway { background: #14284a; border-color: #3f68b8; }
.dg-node.lane-provider .ico, .dg-node.lane-backup .ico { color: #c4a6ff; }
.dg-node.lane-gateway .ico { color: #6fe0b5; }
.dg-node.active { border-color: var(--tone, var(--info)); box-shadow: 0 0 0 3px color-mix(in srgb, var(--tone, var(--info)) 30%, transparent), 0 0 26px color-mix(in srgb, var(--tone, var(--info)) 45%, transparent); }
.dg-node.tone-ok { --tone: var(--ok); } .dg-node.tone-info { --tone: var(--info); }
.dg-node.tone-warn { --tone: var(--warn); } .dg-node.tone-block { --tone: var(--block); }
.dg-node.src:not(.dst) { opacity: 0.95; }
.dg-node.pulse { animation: pulse 1.1s ease-out 1; }
.dg-node.shake { animation: shake .5s ease-in-out 1; }
.dg-node.waiting::after { content: ""; position: absolute; inset: -8px; border-radius: 20px; border: 2px dashed var(--warn); animation: breathe 1.8s ease-in-out infinite; pointer-events: none; }
.dg-badge { position: absolute; right: -0.55em; top: -0.7em; width: 1.7em; height: 1.7em; border-radius: 50%; display: none; align-items: center; justify-content: center; font-weight: 800; font-size: 1em; color: #0a0e16; }
.dg-badge.on { display: flex; animation: pop .35s ease-out; }
.dg-badge.block { background: var(--block); } .dg-badge.ok { background: var(--ok); }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--tone) 70%, transparent); } 100% { box-shadow: 0 0 0 28px transparent; } }
@keyframes shake { 0%,100% { transform: translate(-50%, -50%); } 20% { transform: translate(calc(-50% - 7px), -50%); } 40% { transform: translate(calc(-50% + 7px), -50%); } 60% { transform: translate(calc(-50% - 5px), -50%); } 80% { transform: translate(calc(-50% + 5px), -50%); } }
@keyframes breathe { 0%,100% { opacity: 0.25; transform: scale(0.99); } 50% { opacity: 1; transform: scale(1.02); } }
@keyframes pop { from { transform: scale(0.2); } to { transform: scale(1); } }

/* browser simulation */
.dg-node.mock { padding: 0; background: #eef1f6; color: #1a2233; border-color: #8fa0c0; overflow: visible; display: flex; flex-direction: column; transform: translate(-50%, -50%); }
.mock-bar { display: flex; align-items: center; gap: 0.35em; padding: 0.45em 0.6em; background: #cfd6e4; border-radius: 12px 12px 0 0; border-bottom: 1px solid #a9b4cb; }
.mock-bar i { width: 0.7em; height: 0.7em; border-radius: 50%; background: #8a96ae; display: inline-block; }
.mock-url { flex: 1; margin-left: 0.4em; background: #fff; border-radius: 999px; padding: 0.1em 0.7em; font-size: 0.78em; color: #44506b; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mock-sim { background: #ffb84d; color: #2a1b00; font-weight: 800; font-size: 0.7em; padding: 0.15em 0.6em; border-radius: 999px; text-transform: uppercase; letter-spacing: 0.04em; white-space: nowrap; }
.mock-sim.tiny { position: absolute; left: 0.6em; bottom: -0.9em; }
.mock-body { flex: 1; min-height: 0; padding: 0.6em; display: flex; flex-direction: column; gap: 0.5em; overflow: hidden; }
.mock-row b { font-size: 0.68em; color: #5a6784; text-transform: uppercase; letter-spacing: 0.05em; }
.mock-bubble { margin-top: 0.15em; background: #fff; border: 1px solid #c7cfdf; border-radius: 10px; padding: 0.4em 0.6em; font-size: 0.78em; line-height: 1.3; max-height: 7.2em; overflow: hidden; word-break: break-word; position: relative; }
.mock-row.you .mock-bubble { background: #e3ecff; }
.mock-row.empty .mock-bubble { min-height: 2em; opacity: 0.55; }
.mock-bubble::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 1.3em; background: linear-gradient(transparent, rgba(255,255,255,.9)); pointer-events: none; }
.mock .seg, .mock-bubble .seg { color: inherit; }
.mock-bubble .k-sensitive { background: #ffdcc0; color: #7a2800; border-color: #e0691a; }
.mock-bubble .k-token { background: #c9f3fc; color: #04485c; border-color: #17a9c7; }
.mock-bubble .k-restored { background: #cdf7df; color: #0c5a35; border-color: #2fbf7b; }
.lane-extension .ext-state { display: inline-flex; align-items: center; gap: 0.4em; margin-top: 0.4em; font-size: 0.74em; color: #9fe9c5; }
.lane-extension .dot { width: 0.6em; height: 0.6em; border-radius: 50%; background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.lane-extension { display: flex; flex-direction: column; }

/* caption, waiting, controls */
.caption { margin: 0.9rem 0 0.4rem; font-size: 1.6rem; line-height: 1.3; font-weight: 600; min-height: 2.6em; border-left: 6px solid var(--info); padding-left: 0.8rem; }
.caption[data-tone="ok"] { border-color: var(--ok); } .caption[data-tone="warn"] { border-color: var(--warn); } .caption[data-tone="block"] { border-color: var(--block); }
@media (max-width: 600px) { .caption { font-size: 1.3rem; } }
.waiting { display: flex; align-items: center; gap: 0.6rem; margin: 0.2rem 0 0.4rem; color: #ffd98a; font-size: 1.05rem; font-weight: 600; }
.dots { display: inline-flex; gap: 5px; } .dots i { width: 9px; height: 9px; border-radius: 50%; background: var(--warn); animation: bounce 1.2s infinite ease-in-out both; }
.dots i:nth-child(2) { animation-delay: .2s; } .dots i:nth-child(3) { animation-delay: .4s; }
@keyframes bounce { 0%, 80%, 100% { transform: scale(0.5); opacity: 0.4; } 40% { transform: scale(1); opacity: 1; } }
.net-msg { color: #ffd98a; margin: 0.2rem 0; font-size: 0.9rem; }
.fail-box { display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem 1rem; padding: 0.7rem 0.9rem; border: 1px solid var(--block); background: #3a1018; border-radius: 12px; margin: 0.5rem 0; }
.fail-box strong { color: #ffb3bb; }
.controls { display: flex; align-items: center; gap: 0.8rem; margin-top: 0.6rem; flex-wrap: wrap; }
.step-count { color: var(--muted); font-size: 0.9rem; min-width: 8ch; }

/* card */
.card-col { position: sticky; top: 0.6rem; }
@media (max-width: 1050px) { .card-col { position: static; } }
.card, .card-empty { background: var(--panel); border: 1px solid var(--line); border-left: 6px solid var(--info); border-radius: var(--radius); padding: 0.9rem 1rem 1rem; animation: cardin .35s ease-out; }
.card[data-tone="ok"] { border-left-color: var(--ok); } .card[data-tone="warn"] { border-left-color: var(--warn); } .card[data-tone="block"] { border-left-color: var(--block); }
.card-empty { color: var(--muted); } .card-empty strong { color: var(--text); font-size: 1.05rem; } .card-empty.intro { font-size: 1.05rem; color: var(--text); }
@keyframes cardin { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.card-title { margin: 0 0 0.6rem; font-size: 1.05rem; font-weight: 700; }
.card-body { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.6; max-height: 62vh; overflow: auto; border-radius: 8px; }
.card-body.fmt-json { font-family: var(--mono); font-size: 0.8rem; background: #0b111d; padding: 0.7rem 0.8rem; border: 1px solid #22304f; }
.card-body.fmt-text { font-size: 1rem; }
.card-note { margin: 0.6rem 0 0; font-size: 0.82rem; color: var(--muted); }
.card-img { margin: 0 0 0.7rem; } .card-img img { max-width: 100%; border-radius: 8px; border: 1px solid var(--line); background: #fff; display: block; } .card-img figcaption { font-size: 0.75rem; color: var(--muted); margin-top: 0.2rem; }
.chips { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0.6rem 0 0; }
.chip { display: inline-block; background: #1d2a47; border: 1px solid #3a4d7c; border-radius: 999px; padding: 0.25rem 0.8rem; font-size: 0.85rem; }

/* highlights */
.seg { border-radius: 6px; padding: 0.05em 0.3em; border: 1px solid transparent; box-decoration-break: clone; -webkit-box-decoration-break: clone; font-weight: 600; }
.seg-c { display: inline-block; margin-left: 0.4em; padding: 0 0.4em; font-family: system-ui, sans-serif; font-size: 0.62em; font-weight: 800; letter-spacing: 0.05em; border-radius: 4px; background: rgba(0,0,0,0.35); vertical-align: 0.2em; user-select: none; }
.k-sensitive { background: var(--sens-bg); color: var(--sens-fg); border-color: var(--sens-bd); }
.k-token { background: var(--tok-bg); color: var(--tok-fg); border-color: var(--tok-bd); }
.k-restored { background: var(--res-bg); color: var(--res-fg); border-color: var(--res-bd); position: relative; }
.k-ok { background: var(--res-bg); color: var(--res-fg); border-color: var(--res-bd); }
.k-blocked { background: var(--blk-bg); color: var(--blk-fg); border-color: var(--blk-bd); text-decoration: underline wavy var(--blk-bd) 1px; text-underline-offset: 3px; }
.k-restored[data-ref]:hover::after, .k-restored[data-ref]:focus::after { content: "← " attr(data-ref); position: absolute; left: 0; top: 100%; margin-top: 4px; z-index: 5; white-space: nowrap; font-family: var(--mono); font-size: 0.75rem; font-weight: 600; background: var(--tok-bg); color: var(--tok-fg); border: 1px solid var(--tok-bd); border-radius: 6px; padding: 0.15rem 0.5rem; }
.legend { list-style: none; margin: 0.7rem 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 0.5rem 0.9rem; font-size: 0.8rem; }

/* trail */
.trail-wrap { margin-top: 1rem; }
.trail-title { margin: 0 0 0.4rem; font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-weight: 700; }
.trail-title small { text-transform: none; letter-spacing: 0; font-weight: 400; margin-left: 0.5rem; }
.trail { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 0.4rem; }
.trail-item { display: inline-flex; align-items: center; gap: 0.5rem; font: inherit; font-size: 0.85rem; color: var(--text); background: var(--panel2); border: 1px solid var(--line); border-left: 5px solid var(--info); border-radius: 10px; padding: 0.4rem 0.7rem; cursor: pointer; min-height: 40px; }
.trail-item.tone-ok { border-left-color: var(--ok); } .trail-item.tone-warn { border-left-color: var(--warn); } .trail-item.tone-block { border-left-color: var(--block); }
.trail-item:hover { background: #20315a; }
.trail-item.cur { background: #28427f; border-color: #6b95ff; font-weight: 700; }
.trail-n { color: var(--muted); font-variant-numeric: tabular-nums; } .trail-item.cur .trail-n { color: #fff; }

/* summary */
.summary { margin-top: 1rem; padding: 1rem 1.2rem; border: 1px solid #2f6e55; background: linear-gradient(180deg, #0f2b22, #0d1f1a); border-radius: var(--radius); animation: cardin .4s ease-out; }
.summary h3 { margin: 0 0 0.4rem; font-size: 1.05rem; color: #9bf5c4; }
.summary ul { margin: 0 0 0.8rem; padding-left: 1.2rem; font-size: 1.1rem; } .summary li { margin: 0.3rem 0; }

/* chat */
.chat { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 1rem 1.1rem 1.2rem; }
.chat h2 { margin: 0; font-size: 1.25rem; }
.chat-sub { margin: 0.3rem 0 0.6rem; color: var(--muted); font-size: 0.95rem; }
.chat-notice { margin: 0 0 0.8rem; padding: 0.6rem 0.9rem; border: 1px solid var(--warn); background: #33260a; color: #ffe2a6; border-radius: 10px; font-size: 0.95rem; }
.chat-log { max-height: 340px; overflow: auto; display: flex; flex-direction: column; gap: 0.5rem; margin-bottom: 0.8rem; padding: 0.2rem; }
.bubble { max-width: 86%; padding: 0.55rem 0.85rem; border-radius: 14px; font-size: 0.98rem; white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble b { display: block; font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.06em; opacity: 0.75; margin-bottom: 0.1rem; }
.bubble.you { align-self: flex-end; background: #25407a; border-bottom-right-radius: 4px; }
.bubble.bot { align-self: flex-start; background: #1d2a44; border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.bubble.bot.blocked { border-color: var(--block); background: #3a1018; }
.bubble.pending span { color: var(--muted); font-style: italic; }
.chat-form textarea { width: 100%; font: inherit; font-size: 1rem; color: var(--text); background: #0b111d; border: 1px solid #3a4d7c; border-radius: 12px; padding: 0.7rem 0.85rem; resize: vertical; min-height: 5.2rem; }
.chat-row { display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem 0.9rem; margin-top: 0.5rem; }
.chat-count, .chat-turns { font-size: 0.85rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.chat-row .primary { margin-left: auto; }
.chat-msg { margin: 0.6rem 0 0; padding: 0.55rem 0.85rem; border: 1px solid var(--warn); background: #3a2a0a; color: #ffe2a6; border-radius: 10px; }
.ts-box { margin-top: 0.4rem; }

.foot { display: flex; flex-wrap: wrap; gap: 0.3rem 1.2rem; justify-content: space-between; padding: 1rem 0 0.4rem; font-size: 0.85rem; border-top: 1px solid var(--line); margin-top: 1.4rem; }

@media (max-width: 600px) {
  #app { padding: 0 0.7rem 1rem; }
  .top h1 { font-size: 1.25rem; }
  .scenario-grid { grid-template-columns: 1fr 1fr; }
  .scn { padding: 0.55rem 0.65rem; min-height: 84px; }
  .scn-sub { font-size: 0.74rem; }
  .stage { padding: 0.7rem; }
  .bubble { max-width: 94%; }
  .chat-row .primary { margin-left: 0; width: 100%; }
}
@media (max-width: 380px) { .scenario-grid { grid-template-columns: 1fr; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; scroll-behavior: auto !important; }
  .dg-node.waiting::after { animation: none; opacity: 0.8; }
  .dots i { animation: none; opacity: 0.8; transform: none; }
}
