:root {
  color-scheme: light dark;
  --page: light-dark(#eef2f0, #101917);
  --panel: light-dark(#ffffff, #17231f);
  --panel-soft: light-dark(#f6f8f7, #1d2d27);
  --text: light-dark(#182b26, #eff6f2);
  --muted: light-dark(#526b61, #abc2b6);
  --border: light-dark(#dce5df, #34473d);
  --brand: light-dark(#087568, #147b6c);
  --brand-strong: light-dark(#075e54, #106859);
  --brand-soft: light-dark(#e4f2ec, #173d31);
  --link: light-dark(#087568, #8cdbc1);
  --on-brand: #ffffff;
  --good: light-dark(#17613e, #8fddba);
  --good-soft: light-dark(#e8f4ec, #213e30);
  --bad: light-dark(#a72d24, #ffb4a9);
  --bad-soft: light-dark(#fff0ed, #452c27);
}

body[data-role="Bob"] {
  --brand: light-dark(#326793, #396f9c);
  --brand-strong: light-dark(#28547a, #2c5a83);
  --brand-soft: light-dark(#e8eff7, #1c3148);
  --link: light-dark(#2b608d, #a8cfee);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 16px; }
body { margin: 0; color: var(--text); background: var(--page); font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; font-size: 15px; line-height: 1.5; }
button, textarea { font: inherit; }
button, summary { cursor: pointer; }
button:disabled { cursor: not-allowed; }
a { color: var(--link); text-underline-offset: 4px; }
h1, h2, h3, p, dl, dd { margin: 0; }
button, textarea, a, summary { -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 3px solid var(--brand); outline-offset: 4px; }
[hidden] { display: none !important; }

.skip-link { position: fixed; top: 8px; left: 8px; z-index: 10; padding: 12px 16px; color: var(--on-brand); background: var(--brand); transform: translateY(-160%); }
.skip-link:focus { transform: translateY(0); }
.app-shell { display: flex; flex-direction: column; width: 100%; height: 100dvh; min-height: 560px; background: var(--panel); }
.topbar { flex-shrink: 0; display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 16px; padding: 20px 28px; border-bottom: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 12px; color: var(--text); text-decoration: none; font-size: 20px; font-weight: 750; letter-spacing: -.04em; }
.brand-mark { display: grid; place-items: center; width: 44px; height: 44px; color: var(--on-brand); background: var(--brand); border-radius: 12px; font-size: 24px; }
.brand small { display: block; color: var(--muted); font-size: 12px; font-weight: 500; letter-spacing: 0; }
.connection { display: grid; justify-items: end; gap: 4px; min-width: 0; text-align: right; }
.role-label { color: var(--muted); font-size: 12px; }
.role-label strong { color: var(--text); }
.peer-status { display: flex; align-items: center; justify-content: flex-end; gap: 6px; min-width: 0; color: var(--good); font-size: 13px; font-weight: 650; overflow-wrap: anywhere; }
.peer-status.offline { color: var(--bad); }
.status-dot { width: 7px; height: 7px; flex-shrink: 0; border-radius: 50%; background: currentColor; }
.workspace { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) 352px; }
.chat-panel { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.chat-header { display: flex; align-items: center; gap: 16px; padding: 24px 28px 16px; }
.avatar, .message-avatar { display: grid; place-items: center; flex-shrink: 0; width: 44px; height: 44px; border-radius: 50%; color: var(--link); background: var(--brand-soft); font-weight: 700; }
.chat-identity { min-width: 0; flex: 1; }
.eyebrow { color: var(--muted); font-size: 11px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; }
h1 { margin-top: 2px; font-size: 24px; line-height: 1.25; font-weight: 700; letter-spacing: -.04em; overflow-wrap: anywhere; }
.chat-identity > p:last-child { margin-top: 4px; color: var(--muted); font-size: 13px; }
.security-badge { flex-shrink: 0; padding: 6px 10px; border: 1px solid var(--border); border-radius: 6px; color: var(--muted); font-size: 12px; font-weight: 600; }
.conversation-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 28px 4px; color: var(--muted); font-size: 12px; }
.text-button { display: inline-flex; align-items: center; justify-content: center; min-width: 44px; min-height: 44px; padding: 8px; border: 0; border-radius: 6px; color: var(--link); background: transparent; font-size: 13px; font-weight: 600; }
.text-button:hover { background: var(--brand-soft); }
.conversation { display: flex; flex: 1 1 0; flex-direction: column; gap: 24px; height: 0; min-height: 0; padding: 24px 28px; overflow-y: auto; overscroll-behavior-y: contain; scrollbar-color: var(--border) transparent; scrollbar-gutter: stable; background: var(--panel-soft); border-block: 1px solid var(--border); }
.empty-state { display: grid; gap: 8px; justify-items: center; width: 100%; max-width: 350px; margin: auto; align-self: center; text-align: center; color: var(--muted); }
.empty-symbol { display: grid; place-items: center; width: 64px; height: 64px; margin-bottom: 12px; border: 1px solid var(--border); border-radius: 16px; background: var(--panel); color: var(--brand); font-size: 32px; }
.empty-state strong { color: var(--text); font-size: 22px; font-weight: 650; letter-spacing: -.03em; }
.empty-state > p:not(.eyebrow) { font-size: 14px; line-height: 1.65; }
.message { display: flex; align-items: flex-start; gap: 10px; align-self: flex-start; max-width: 88%; min-width: 0; }
.message-sent { align-self: flex-end; flex-direction: row-reverse; }
.message-avatar { width: 32px; height: 32px; font-size: 12px; }
.message-content { min-width: 0; display: grid; gap: 6px; }
.message-sent .message-content { justify-items: end; }
.message-bubble { max-width: 100%; padding: 12px 16px; white-space: pre-wrap; overflow-wrap: anywhere; background: var(--panel); border: 1px solid var(--border); border-radius: 4px 12px 12px; font-size: 15px; line-height: 1.6; }
.message-sent .message-bubble { color: var(--on-brand); background: var(--brand); border-color: var(--brand); border-radius: 12px 4px 12px 12px; }
.message-meta { display: flex; flex-wrap: wrap; gap: 4px 8px; color: var(--muted); font-size: 12px; }
.message-details { min-width: 0; max-width: 100%; color: var(--muted); font-size: 12px; }
.message-details summary { display: list-item; min-height: 44px; padding: 10px 0; overflow-wrap: anywhere; }
.message-details dl { display: grid; gap: 8px; max-width: 100%; padding: 12px; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; }
.message-details dl div { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); gap: 12px; }
.message-details dd { text-align: end; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.composer-area { padding: 20px 28px 16px; }
.composer-label { display: block; margin-bottom: 8px; color: var(--text); font-size: 13px; font-weight: 650; }
.composer { display: flex; align-items: flex-end; gap: 8px; padding: 8px; border: 1px solid var(--border); border-radius: 12px; background: var(--panel); }
.composer:focus-within { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand-soft); }
.composer textarea { display: block; flex: 1; min-width: 0; width: 100%; min-height: 44px; max-height: 144px; margin: 0; padding: 10px 8px; resize: none; border: 0; outline: 0; border-radius: 4px; color: var(--text); background: transparent; font-size: 16px; line-height: 24px; }
.composer textarea::placeholder { color: var(--muted); }
.composer button { display: inline-flex; flex-shrink: 0; align-items: center; justify-content: center; gap: 12px; min-width: 44px; min-height: 44px; padding: 10px 16px; border: 0; border-radius: 8px; color: var(--on-brand); background: var(--brand); font-size: 14px; font-weight: 650; white-space: nowrap; }
.composer button:hover:not(:disabled) { background: var(--brand-strong); }
.composer button:disabled { color: var(--muted); background: var(--panel-soft); }
.composer-meta { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 12px; margin-top: 8px; color: var(--muted); font-size: 11px; }
#character-count { margin-left: auto; font-variant-numeric: tabular-nums; }
.action-note { min-height: 20px; margin-top: 8px; color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.action-note.error { color: var(--bad); }
.composer-progress { display: none; }
.learning-rail { min-width: 0; overflow-y: auto; padding: 28px 24px; border-left: 1px solid var(--border); }
h2 { margin-top: 6px; font-size: 22px; line-height: 1.3; font-weight: 650; letter-spacing: -.035em; }
.learning-header > p:last-child { margin-top: 12px; color: var(--muted); font-size: 13px; line-height: 1.6; }
.protocol-overview { margin-top: 24px; }
.progress-copy { display: flex; justify-content: space-between; gap: 12px; color: var(--muted); font-size: 12px; }
#protocol-status { color: var(--text); font-weight: 600; }
#protocol-count { flex-shrink: 0; font-variant-numeric: tabular-nums; }
.progress-track { height: 4px; margin-top: 10px; overflow: hidden; border-radius: 4px; background: var(--border); }
.progress-track span { display: block; width: 0; height: 100%; background: var(--brand); transition: width .2s ease; }
.protocol-steps { display: grid; gap: 0; margin: 24px 0; padding: 0; list-style: none; }
.protocol-steps li { display: grid; position: relative; grid-template-columns: 28px minmax(0, 1fr); gap: 12px; min-height: 48px; padding-bottom: 16px; }
.protocol-steps li:last-child { min-height: 28px; padding-bottom: 0; }
.protocol-steps li:not(:last-child)::after { position: absolute; top: 28px; bottom: 0; left: 13px; width: 1px; content: ""; background: var(--border); }
.step-marker { display: grid; position: relative; z-index: 1; place-items: center; width: 28px; height: 28px; border: 1px solid var(--border); border-radius: 50%; background: var(--panel); color: var(--muted); font-size: 11px; font-weight: 650; }
.step-heading { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 0 8px; padding-top: 4px; }
.step-heading strong { font-size: 13px; font-weight: 600; }
.step-state { color: var(--muted); font-size: 11px; }
.protocol-steps p { display: none; margin-top: 6px; color: var(--muted); font-size: 12px; line-height: 1.6; }
.protocol-steps li.current p { display: block; }
.protocol-steps li.current strong { color: var(--text); }
.protocol-steps li.current .step-marker { border-color: var(--brand); color: var(--on-brand); background: var(--brand); }
.protocol-steps li.complete .step-marker { border-color: transparent; color: var(--good); background: var(--good-soft); font-size: 0; }
.protocol-steps li.complete .step-marker::after { content: "✓"; font-size: 13px; }
.protocol-steps li.complete:not(:last-child)::after { background: var(--good); }
.protocol-steps li.failed .step-marker { border-color: var(--bad); color: var(--bad); background: var(--bad-soft); }
.metrics { padding-top: 20px; border-top: 1px solid var(--border); }
h3 { font-size: 13px; font-weight: 650; }
.metrics > p { margin-top: 4px; color: var(--muted); font-size: 12px; }
.metrics dl { display: grid; gap: 10px; margin-top: 16px; }
.metrics dl div { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 16px; font-size: 13px; }
.metrics dt { color: var(--muted); }
.metrics dd { font-weight: 650; font-variant-numeric: tabular-nums; }
footer { flex-shrink: 0; display: flex; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; gap: 8px 24px; padding: 16px 28px; border-top: 1px solid var(--border); color: var(--muted); font-size: 12px; }
footer strong { color: var(--text); font-weight: 600; }
.network-details { min-width: 0; max-width: 100%; }
.network-details summary { min-height: 44px; padding: 0 0 16px; }
.network-details p { max-width: 360px; padding-bottom: 8px; overflow-wrap: anywhere; }

@media (max-width: 1000px) {
  .topbar { padding: 16px 20px; }
  .workspace { grid-template-columns: minmax(0, 1fr) 312px; }
  .chat-header { padding: 20px 20px 12px; }
  .chat-header .security-badge { display: none; }
  .conversation-toolbar { padding-inline: 20px; }
  .conversation { padding: 20px; }
  .composer-area { padding: 16px 20px; }
  .learning-rail { padding: 24px 20px; }
}

@media (max-width: 800px) {
  .app-shell { height: auto; min-height: 100dvh; }
  .topbar { min-height: 80px; gap: 12px; padding: 16px 20px 8px; }
  .brand { font-size: 18px; }
  .brand-mark { width: 40px; height: 40px; font-size: 22px; }
  .brand small { font-size: 11px; }
  .connection { max-width: 45%; }
  .peer-status { font-size: 12px; }
  .workspace { grid-template-columns: minmax(0, 1fr); }
  .chat-panel { height: calc(100dvh - 80px); min-height: 440px; }
  .composer-progress { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 4px 12px; min-height: 44px; margin-top: 4px; font-size: 12px; }
  .learning-rail { border-top: 1px solid var(--border); border-left: 0; padding: 28px 24px; }
  .protocol-steps { max-width: 620px; }
  .step-heading strong { font-size: 14px; }
  .step-state { font-size: 12px; }
  .protocol-steps p { font-size: 13px; }
  .metrics { max-width: 620px; }
  footer { padding: 16px 24px; }
}

@media (max-width: 400px) {
  .topbar { padding-inline: 16px; }
  .brand { gap: 8px; }
  .brand small { display: none; }
  .chat-header { gap: 12px; padding-inline: 16px; }
  h1 { font-size: 22px; }
  .chat-identity > p:last-child { font-size: 12px; }
  .conversation-toolbar { padding-inline: 16px; }
  .conversation { padding: 16px; }
  .message { max-width: 100%; gap: 8px; }
  .message-avatar { width: 28px; height: 28px; }
  .message-bubble { padding: 10px 12px; font-size: 14px; }
  .composer-area { padding: 12px 16px; }
  .composer { gap: 0; padding: 4px; }
  .composer button { gap: 8px; padding-inline: 10px; font-size: 12px; }
  .learning-rail { padding: 24px 20px; }
}

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