/* DDI Risk Explorer — story-mode demo UI */

:root {
  --bg: #0b1220;
  --panel: #111a2c;
  --panel-2: #0f1626;
  --border: #1e2a44;
  --ink: #e6edf7;
  --ink-dim: #94a3b8;
  --layer1: #7c5cff;
  --layer1-dim: #4338ca;
  --layer2: #ec4899;
  --layer2-dim: #be185d;
  --good: #22c55e;
  --warn: #f59e0b;
  --bad: #ef4444;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background:
    radial-gradient(1200px 800px at 10% -10%, rgba(124, 92, 255, 0.18), transparent 60%),
    radial-gradient(900px 700px at 110% 110%, rgba(236, 72, 153, 0.14), transparent 60%),
    var(--bg);
  color: var(--ink);
  min-height: 100vh;
  line-height: 1.55;
}

.shell {
  max-width: 1080px;
  margin: 0 auto;
  padding: 32px 24px 56px;
}

/* ==================== HEADER ==================== */
header.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 28px;
  flex-wrap: wrap;
}
header.top h1 {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0;
  background: linear-gradient(90deg, var(--layer1) 0%, var(--layer2) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
header.top .subtitle {
  display: block;
  font-size: 13px;
  color: var(--ink-dim);
  font-weight: 500;
  margin-top: 4px;
}
header.top .links { display: flex; gap: 8px; flex-wrap: wrap; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--panel);
  color: var(--ink);
  font-size: 12px;
  font-weight: 500;
  border: 1px solid var(--border);
  text-decoration: none;
  transition: background 120ms ease, border-color 120ms ease;
}
.pill:hover { background: var(--panel-2); border-color: #2c3b5c; }
.pill.warning { border-color: rgba(245, 158, 11, 0.4); color: var(--warn); }

/* ==================== INPUT CARD ==================== */
.intro {
  margin-bottom: 18px;
  padding: 18px 22px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  font-size: 14px;
  color: var(--ink-dim);
}
.intro strong { color: var(--ink); }

.input-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 24px;
  box-shadow: var(--shadow);
  margin-bottom: 28px;
}

.input-card h2 {
  margin: 0 0 4px 0;
  font-size: 18px;
  font-weight: 700;
}
.input-card .input-sub {
  margin: 0 0 18px 0;
  font-size: 13px;
  color: var(--ink-dim);
}

.row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
@media (max-width: 720px) { .row { grid-template-columns: 1fr; } }

label.field { display: flex; flex-direction: column; gap: 6px; }
label.field span {
  font-size: 12px;
  color: var(--ink-dim);
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

input[type="text"], select {
  appearance: none;
  background: var(--panel-2);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 13px;
  font-size: 14px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  outline: none;
  transition: border-color 120ms ease, background 120ms ease;
}
input[type="text"]:focus { border-color: var(--layer1); background: #0d162a; }
input[type="number"] {
  appearance: none;
  background: var(--panel-2);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 13px;
  font-size: 14px;
  outline: none;
  width: 100%;
}

.controls {
  display: grid;
  grid-template-columns: repeat(3, 1fr) auto;
  gap: 12px;
  align-items: end;
  margin-top: 16px;
}
@media (max-width: 720px) { .controls { grid-template-columns: 1fr; } }

button.run {
  appearance: none;
  border: none;
  cursor: pointer;
  font-weight: 700;
  font-size: 14px;
  color: white;
  padding: 12px 24px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--layer1) 0%, var(--layer2) 100%);
  transition: transform 80ms ease, box-shadow 120ms ease, opacity 120ms ease;
  white-space: nowrap;
}
button.run:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 22px rgba(124, 92, 255, 0.4);
}
button.run:disabled { opacity: 0.55; cursor: wait; }
button.run::before { content: "▶ "; opacity: 0.85; }

.preset {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 14px;
}
.preset-label {
  font-size: 11px;
  color: var(--ink-dim);
  margin-right: 8px;
  align-self: center;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.preset button {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--ink-dim);
  padding: 6px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 12px;
  transition: all 120ms ease;
}
.preset button:hover {
  color: var(--ink);
  border-color: var(--layer1);
  background: rgba(124, 92, 255, 0.08);
}

/* ==================== STORY OUTPUT ==================== */
.story {
  display: none;
  flex-direction: column;
  gap: 18px;
  scroll-margin-top: 20px;
}
.story.show { display: flex; }

.chapter {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 24px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(12px);
  animation: chapter-in 480ms cubic-bezier(0.22, 0.9, 0.34, 1) forwards;
}
.chapter:nth-of-type(1) { animation-delay: 60ms; }
.chapter:nth-of-type(2) { animation-delay: 220ms; }
.chapter:nth-of-type(3) { animation-delay: 380ms; }
.chapter:nth-of-type(4) { animation-delay: 540ms; }

@keyframes chapter-in {
  to { opacity: 1; transform: translateY(0); }
}

.chapter-num {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.16em;
  color: var(--ink-dim);
  text-transform: uppercase;
  margin-bottom: 6px;
}
.chapter-num::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--layer1);
}
.chapter[data-layer="2"] .chapter-num::before { background: var(--layer2); }
.chapter[data-layer="0"] .chapter-num::before { background: var(--ink-dim); }

.chapter h3 {
  margin: 0 0 14px 0;
  font-size: 19px;
  font-weight: 700;
}
.chapter .lede {
  margin: 0 0 16px 0;
  color: var(--ink-dim);
  font-size: 14px;
}

/* ==================== CHAPTER 1 — Meet the molecules ==================== */
.molecules {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
@media (max-width: 720px) { .molecules { grid-template-columns: 1fr; } }

.molecule-card {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.molecule-card .mol-name {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}
.molecule-card .mol-name h4 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
}
.molecule-card .mol-name .mol-side {
  font-size: 11px;
  color: var(--ink-dim);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.molecule-card .mol-svg {
  background: white;
  border-radius: 10px;
  padding: 8px;
  min-height: 180px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.molecule-card .mol-svg svg { max-width: 100%; height: auto; }
.molecule-card .mol-stats {
  display: flex;
  gap: 14px;
  font-size: 12px;
  color: var(--ink-dim);
}
.molecule-card .mol-stats strong { color: var(--ink); font-variant-numeric: tabular-nums; }
.molecule-card .mol-smiles {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  color: var(--ink-dim);
  background: rgba(0, 0, 0, 0.25);
  padding: 8px 10px;
  border-radius: 6px;
  word-break: break-all;
  cursor: copy;
  transition: background 120ms ease;
}
.molecule-card .mol-smiles:hover { background: rgba(124, 92, 255, 0.1); }
.molecule-card .mol-smiles.copied { background: rgba(34, 197, 94, 0.15); color: var(--good); }

/* ==================== CHAPTER 2 / 3 — predictions list ==================== */
ol.predictions {
  list-style: none;
  padding: 0;
  margin: 0;
}
ol.predictions li {
  display: grid;
  grid-template-columns: 32px 1fr auto;
  gap: 14px;
  align-items: center;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel-2);
  margin-bottom: 8px;
  transition: border-color 200ms ease;
}
ol.predictions li:hover { border-color: var(--layer1); }
.chapter[data-layer="2"] ol.predictions li:hover { border-color: var(--layer2); }

ol.predictions .rank {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  background: rgba(124, 92, 255, 0.18);
  color: #c7b8ff;
  flex-shrink: 0;
}
.chapter[data-layer="2"] ol.predictions .rank {
  background: rgba(236, 72, 153, 0.18);
  color: #fbcfe8;
}

.pred-text {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}
.pred-text .label-text { font-size: 14px; word-break: break-word; }

.prob-track {
  position: relative;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}
.prob-fill {
  position: absolute;
  inset: 0 auto 0 0;
  background: linear-gradient(90deg, var(--layer1), var(--layer1-dim));
  border-radius: 3px;
  width: 0%;
  transition: width 800ms cubic-bezier(0.22, 0.9, 0.34, 1);
}
.chapter[data-layer="2"] .prob-fill {
  background: linear-gradient(90deg, var(--layer2), var(--layer2-dim));
}

.prob-text {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 14px;
  color: white;
  width: 64px;
  text-align: right;
  flex-shrink: 0;
}

/* Severity indicator (Layer 1 top-1) */
.severity {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  margin-left: 8px;
  vertical-align: middle;
}
.severity.high { background: rgba(239, 68, 68, 0.15); color: #fca5a5; border: 1px solid rgba(239, 68, 68, 0.4); }
.severity.medium { background: rgba(245, 158, 11, 0.15); color: #fcd34d; border: 1px solid rgba(245, 158, 11, 0.4); }
.severity.low { background: rgba(34, 197, 94, 0.15); color: #86efac; border: 1px solid rgba(34, 197, 94, 0.4); }

/* SE row above-threshold dot */
.above-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--good);
  margin-left: 6px;
}

/* ==================== CHAPTER 4 — How it decided ==================== */
.how-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 14px;
}
@media (max-width: 720px) { .how-grid { grid-template-columns: 1fr; } }

.how-step {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
}
.how-step h4 {
  margin: 0 0 6px 0;
  font-size: 13px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}
.how-step h4 .step-num {
  background: linear-gradient(135deg, var(--layer1), var(--layer2));
  color: white;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
}
.how-step p { margin: 0; font-size: 13px; color: var(--ink-dim); }
.how-step code {
  font-family: ui-monospace, monospace;
  font-size: 11px;
  background: rgba(0, 0, 0, 0.3);
  padding: 1px 6px;
  border-radius: 4px;
  color: var(--ink);
}

/* ==================== misc ==================== */
.disclaimer {
  margin-top: 14px;
  padding: 10px 14px;
  background: rgba(245, 158, 11, 0.08);
  border: 1px solid rgba(245, 158, 11, 0.24);
  color: #fde68a;
  border-radius: 10px;
  font-size: 12px;
  line-height: 1.5;
}

.error {
  color: #fca5a5;
  background: rgba(239, 68, 68, 0.08);
  border: 1px solid rgba(239, 68, 68, 0.32);
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 13px;
}

.loading {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--ink-dim);
}
.loading::before {
  content: "";
  width: 14px;
  height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--layer1);
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Tooltip helper */
[data-tip] {
  position: relative;
  border-bottom: 1px dashed var(--ink-dim);
  cursor: help;
}
[data-tip]:hover::after {
  content: attr(data-tip);
  position: absolute;
  left: 50%;
  bottom: calc(100% + 8px);
  transform: translateX(-50%);
  background: #0a0f1a;
  color: var(--ink);
  border: 1px solid var(--border);
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 500;
  white-space: normal;
  width: max-content;
  max-width: 280px;
  z-index: 10;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  pointer-events: none;
}

footer {
  margin-top: 32px;
  font-size: 12px;
  color: var(--ink-dim);
  text-align: center;
}
footer a { color: var(--ink); text-decoration: none; }
footer a:hover { text-decoration: underline; }
