:root {
  --bg: #eef5fb;
  --panel: #ffffff;
  --text: #14263a;
  --muted: #587086;
  --line: #d5e2ed;
  --accent: #1769aa;
  --accent-soft: #e9f4ff;
  --ok: #047857;
  --ok-bg: #ecfdf5;
  --warn: #a15c08;
  --warn-bg: #fff8e7;
  --bad: #b42318;
  --bad-bg: #fff1f0;
  --shadow: 0 18px 42px rgba(29, 78, 116, 0.09);
  --serif: "Source Serif 4", "Iowan Old Style", Palatino, serif;
  --sans: "IBM Plex Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

html { scroll-behavior: smooth; }

body {
  font-family: var(--sans);
  color: var(--text);
  line-height: 1.55;
  background:
    radial-gradient(circle at 6% 0%, rgba(38, 139, 210, 0.12), transparent 30%),
    linear-gradient(180deg, #fafdff 0%, var(--bg) 100%);
}

a { color: var(--accent); text-decoration: none; }

.app {
  width: min(1320px, calc(100% - 28px));
  margin: 0 auto;
  padding: 22px 0 48px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.brand-mark {
  width: 46px;
  height: 46px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  border-radius: 14px;
  color: #fff;
  background: linear-gradient(145deg, #1769aa, #37a4d9);
  box-shadow: 0 10px 24px rgba(23, 105, 170, 0.24);
  font-weight: 800;
}

.eyebrow,
.architecture {
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.eyebrow { margin: 0 0 3px; }

.topbar h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(1.2rem, 2.2vw, 1.65rem);
  line-height: 1.15;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.ghost-btn,
.source-link {
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #fff;
  color: var(--text);
  font: inherit;
  font-size: 0.88rem;
  font-weight: 650;
}

.ghost-btn { cursor: pointer; }

.study-intro {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 28px;
  margin-bottom: 16px;
  padding: 26px 28px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: linear-gradient(145deg, #ffffff 0%, #f5fbff 100%);
  box-shadow: var(--shadow);
}

.study-intro h2 {
  margin: 0 0 7px;
  font-family: var(--serif);
  font-size: clamp(1.65rem, 3vw, 2.4rem);
  line-height: 1.12;
}

.study-intro p:not(.eyebrow) {
  max-width: 68ch;
  margin: 0;
  color: var(--muted);
}

.study-stats {
  display: grid;
  grid-template-columns: repeat(3, auto);
  gap: 8px;
  margin: 0;
  flex-shrink: 0;
}

.intro-side {
  display: grid;
  gap: 9px;
  flex-shrink: 0;
}

.stream-controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
}

.stream-controls button {
  cursor: pointer;
  padding: 8px 10px;
  border: 1px solid #c8dfef;
  border-radius: 10px;
  background: #fff;
  color: var(--accent);
  font: inherit;
  font-size: 0.74rem;
  font-weight: 750;
}

.stream-controls button:hover {
  border-color: #78b5dc;
  background: var(--accent-soft);
}

.study-stats div {
  min-width: 96px;
  padding: 10px 12px;
  border: 1px solid #c8dfef;
  border-radius: 13px;
  background: #fff;
  text-align: center;
}

.study-stats dt {
  color: var(--accent);
  font-family: var(--serif);
  font-size: 1.3rem;
  font-weight: 700;
  line-height: 1;
}

.study-stats dd {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 700;
  white-space: nowrap;
}

.demo-error {
  margin-bottom: 14px;
  padding: 12px 14px;
  border: 1px solid #fecaca;
  border-radius: 12px;
  background: var(--bad-bg);
  color: var(--bad);
  font-weight: 700;
}

.case-grid {
  display: grid;
  gap: 16px;
}

.scenario-section {
  scroll-margin-top: 18px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.scenario-head {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  gap: 13px;
  align-items: start;
  margin-bottom: 16px;
}

.scenario-index {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 11px;
  background: var(--accent-soft);
  color: var(--accent);
  font-family: var(--serif);
  font-size: 0.9rem;
  font-weight: 750;
}

.scenario-head h2 {
  margin: 0 0 3px;
  font-family: var(--serif);
  font-size: 1.4rem;
  line-height: 1.18;
}

.scenario-head p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.comparison-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.comparison-card {
  position: relative;
  min-width: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding: 17px;
  border: 1px solid var(--line);
  border-radius: 17px;
  background: #fbfdff;
}

.comparison-card::before {
  position: absolute;
  inset: 0 0 auto;
  height: 4px;
  content: "";
}

.bolted-card::before { background: linear-gradient(90deg, #e77f72, #f0b08a); }
.baked-card::before { background: linear-gradient(90deg, #22a06b, #68c998); }

.baked-card {
  border-color: #bce2cf;
  background: linear-gradient(155deg, #f8fffb 0%, #f1fbf6 100%);
}

.card-topline {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 12px;
}

.architecture {
  margin: 2px 0 0;
  line-height: 1.35;
}

.baked-card .architecture { color: var(--ok); }

.outcome {
  flex-shrink: 0;
  border-radius: 999px;
  font-weight: 800;
  white-space: nowrap;
}

.outcome {
  padding: 6px 8px;
  font-size: 0.66rem;
  letter-spacing: 0.035em;
  text-transform: uppercase;
}

.outcome.exploited { background: var(--bad-bg); color: var(--bad); }
.outcome.partial { background: var(--warn-bg); color: var(--warn); }
.outcome.blocked { background: var(--ok-bg); color: var(--ok); }
.outcome.allowed { background: #e5f5ff; color: #0369a1; }

.comparison-card h3 {
  margin: 0 0 7px;
  font-family: var(--serif);
  font-size: 1.18rem;
  line-height: 1.22;
}

.card-summary {
  margin: 0 0 14px;
  color: #465e74;
  font-size: 0.86rem;
  line-height: 1.5;
}

.stream-shell {
  margin-top: auto;
  border: 1px solid #d8e4ee;
  border-radius: 12px;
  background: #fff;
  overflow: hidden;
}

.stream-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-bottom: 1px solid #e2eaf1;
  background: #f7fafc;
}

.stream-label,
.stream-status {
  color: var(--muted);
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

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

.stream-label i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #91a4b5;
}

.is-streaming .stream-label i {
  background: #1ea672;
  box-shadow: 0 0 0 5px rgba(30, 166, 114, 0.12);
  animation: live-pulse 1.3s ease-in-out infinite;
}

.is-streaming .stream-status { color: var(--ok); }

.stream-body {
  height: 236px;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 10px;
  scrollbar-width: thin;
  scrollbar-color: #c4d4e1 transparent;
}

.stream-message {
  display: grid;
  grid-template-columns: 29px minmax(0, 1fr);
  gap: 8px;
  align-items: start;
  margin-bottom: 10px;
  opacity: 0;
  transform: translateY(5px);
  animation: message-enter 0.22s ease forwards;
}

.stream-avatar {
  display: grid;
  place-items: center;
  width: 29px;
  height: 29px;
  border-radius: 9px;
  background: #60758a;
  color: #fff;
  font-size: 0.52rem;
  font-weight: 800;
}

.role-model .stream-avatar { background: #1769aa; }
.role-guard .stream-avatar { background: #8c5a18; }
.role-tan .stream-avatar { background: var(--ok); }
.role-system .stream-avatar { background: #6b7280; }

.stream-copy { min-width: 0; }

.stream-meta {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin-bottom: 3px;
}

.stream-meta strong {
  overflow: hidden;
  font-size: 0.68rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stream-meta span {
  color: #8191a0;
  font-size: 0.55rem;
  font-weight: 750;
  text-transform: uppercase;
}

.stream-text {
  min-height: 18px;
  margin: 0;
  padding: 7px 8px;
  border: 1px solid #dbe6ee;
  border-radius: 8px;
  background: #f8fbfd;
  color: #294057;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.66rem;
  line-height: 1.4;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.role-guard .stream-text {
  border-color: #f0d6ab;
  background: #fffbef;
  color: #85500d;
}

.role-tan .stream-text {
  border-color: #bfe4cf;
  background: #f3fcf7;
  color: #046c50;
}

.role-system .stream-text {
  border-color: #d4dce5;
  background: #f4f6f8;
  color: #3f4d5a;
}

.valid-path {
  display: flex;
  align-items: center;
  margin-top: 11px;
  padding-top: 11px;
  border-top: 1px solid var(--line);
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.valid-path.is-pending {
  opacity: 0.28;
  transform: translateY(3px);
}

.valid-path > div { min-width: 0; }
.valid-path-label {
  display: block;
  margin-bottom: 2px;
  color: var(--ok);
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
.valid-path strong { display: block; font-size: 0.78rem; line-height: 1.3; }

.study-note {
  margin: 15px 4px 0;
  color: var(--muted);
  font-size: 0.8rem;
  text-align: center;
}

body.is-embed { background: transparent; }
body.is-embed .app { width: 100%; padding: 8px; }
body.is-embed .standalone-only { display: none; }
body.is-embed .study-intro { box-shadow: none; }
body.is-embed .scenario-section { box-shadow: 0 8px 26px rgba(29, 78, 116, 0.065); }

@keyframes live-pulse {
  0%, 100% { transform: scale(0.9); opacity: 0.72; }
  50% { transform: scale(1.12); opacity: 1; }
}

@keyframes message-enter {
  to { opacity: 1; transform: none; }
}

@media (max-width: 900px) {
  .study-intro { align-items: stretch; flex-direction: column; }
  .intro-side { width: 100%; }
  .study-stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .study-stats div { min-width: 0; }
  .comparison-grid { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .app { width: calc(100% - 16px); padding-top: 12px; }
  .topbar { align-items: stretch; flex-direction: column; }
  .top-actions { justify-content: flex-start; overflow-x: auto; }
  .source-link,
  .ghost-btn { padding: 8px 10px; font-size: 0.8rem; }
  .study-intro { gap: 18px; padding: 20px 17px; border-radius: 18px; }
  .study-intro h2 { font-size: 1.65rem; }
  .study-stats { gap: 5px; }
  .study-stats div { padding: 8px 5px; }
  .study-stats dd { white-space: normal; line-height: 1.25; }
  .scenario-section { padding: 16px; border-radius: 18px; }
  .scenario-head { grid-template-columns: 34px minmax(0, 1fr); gap: 10px; }
  .scenario-index { width: 34px; height: 34px; }
  .scenario-head h2 { font-size: 1.25rem; }
  .comparison-card { padding: 15px; }
  .stream-body { height: 220px; }
}

@media (prefers-reduced-motion: reduce) {
  .is-streaming .stream-label i,
  .stream-message { animation: none; }
  .stream-message { opacity: 1; transform: none; }
}
