* { box-sizing: border-box; margin: 0; }

[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  font-family: "Vazirmatn", Tahoma, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
button:disabled { cursor: not-allowed; }

select {
  font: inherit; font-size: 14px; color: var(--text);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 5px 10px; max-width: 100%;
}
select:focus-visible, button:focus-visible, textarea:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--accent) 60%, transparent); outline-offset: 2px;
}

/* Icon styling only for our own icons, so charts, RDKit drawings and JSME keep their SVG defaults. */
button > svg, .hero__mark > svg {
  width: 20px; height: 20px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round;
}

h1, h2, h3 { line-height: 1.4; }
code { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: .92em; }
.muted { color: var(--muted); font-size: 14px; }

/* ------------------------------------------------------------ buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 18px; border-radius: 12px; font-weight: 500; font-size: 15px;
  background: var(--surface); border: 1px solid var(--border);
  transition: background .15s, transform .15s, opacity .15s;
}
.btn:hover:not(:disabled) { background: var(--hover); }
.btn:disabled { opacity: .5; }
.btn--primary { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.btn--primary:hover:not(:disabled) { background: var(--accent); transform: translateY(-1px); filter: brightness(1.05); }
.btn--ghost { border-color: transparent; background: none; color: var(--muted); }
.btn--small { padding: 3px 12px; font-size: 13px; border-radius: 9px; }
.link { color: var(--accent); font-size: 12px; margin-inline-start: 8px; }

/* ------------------------------------------------------------- layout */
.app { display: flex; height: 100dvh; overflow: hidden; }

/* Sidebar */
.sidebar {
  width: var(--sidebar-w); flex: none;
  display: flex; flex-direction: column; gap: 14px;
  padding: 14px; background: var(--sidebar-bg);
  border-inline-end: 1px solid var(--border);
}
.sidebar__top { display: flex; align-items: center; justify-content: space-between; padding: 4px 6px; }
#sidebarClose { display: none; }
.sidebar__note { font-size: 12px; color: var(--muted); text-align: center; }

.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; color: inherit; text-decoration: none; }
.brand__mark {
  width: 22px; height: 22px; border-radius: 7px;
  background: conic-gradient(from 200deg, var(--accent), #f3b27a, var(--accent));
}

.new-chat {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; border-radius: 14px;
  background: var(--surface); border: 1px solid var(--border);
  font-weight: 500; transition: background .15s;
}
.new-chat:hover { background: var(--hover); }
.new-chat svg { color: var(--accent); }

.history { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.history__empty { font-size: 13px; color: var(--muted); padding: 10px; }
.history__row { display: flex; align-items: center; border-radius: 10px; }
.history__row:hover { background: var(--hover); }
.history__item {
  flex: 1; min-width: 0; text-align: start; padding: 7px 10px; font-size: 14px;
  display: flex; flex-direction: column; line-height: 1.4;
}
.history__item small {
  color: var(--muted); font-size: 11px; font-family: ui-monospace, Consolas, monospace;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: left;
}
.history__del { width: 26px; height: 26px; border-radius: 8px; color: var(--muted); font-size: 18px; opacity: 0; }
.history__row:hover .history__del, .history__del:focus-visible { opacity: 1; }
.history__del:hover { background: var(--hover); color: var(--bad); }

.scrim { display: none; }

/* Main */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 16px; flex: none; }
#sidebarOpen { visibility: hidden; }
.model-controls { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.model-controls select:last-child { font-family: ui-monospace, Consolas, monospace; font-size: 13px; }

.icon-btn {
  width: 38px; height: 38px; border-radius: 12px;
  display: grid; place-items: center; color: var(--muted); flex: none;
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }

.stage { flex: 1; overflow-y: auto; padding: 0 20px 36px; display: flex; flex-direction: column; align-items: center; gap: 24px; }
.stage > * { width: min(1100px, 100%); flex-shrink: 0; }

/* ---------------------------------------------------------------- hero */
.hero {
  position: relative; display: flex; flex-direction: column; align-items: center;
  gap: 18px; padding-top: 4vh;
}
.hero__glow {
  position: absolute; inset-inline: 0; top: 0; margin-inline: auto;
  width: min(560px, 90%); height: 300px; pointer-events: none;
  background: radial-gradient(closest-side, color-mix(in srgb, var(--accent) 22%, transparent), transparent);
  filter: blur(30px); opacity: .7;
}
.hero__mark {
  position: relative; width: 52px; height: 52px; border-radius: 16px;
  display: grid; place-items: center;
  background: var(--surface); border: 1px solid var(--border);
  box-shadow: var(--shadow); color: var(--accent);
}
.hero__mark svg { width: 26px; height: 26px; }
.hero__title { position: relative; font-size: clamp(22px, 3.6vw, 32px); font-weight: 500; text-align: center; }
.hero__sub { position: relative; color: var(--muted); text-align: center; font-size: 15px; margin-top: -8px; }

.composer {
  position: relative; width: min(760px, 100%);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px 16px 10px;
  transition: border-color .15s, box-shadow .15s;
}
.composer:focus-within, .composer.is-drop {
  border-color: color-mix(in srgb, var(--accent) 55%, var(--border));
  box-shadow: var(--shadow), 0 0 0 4px color-mix(in srgb, var(--accent) 14%, transparent);
}
.composer textarea {
  width: 100%; resize: none; border: 0; outline: 0; background: none;
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 16px; color: var(--text);
  max-height: 200px; padding: 2px 2px 10px; line-height: 1.8; text-align: left;
}
.composer textarea::placeholder { color: var(--muted); font-family: "Vazirmatn", Tahoma, sans-serif; }
.composer__bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.composer__tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.composer__drop {
  display: none; position: absolute; inset: 0; border-radius: inherit;
  align-items: center; justify-content: center; font-weight: 500; color: var(--accent);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
}
.composer.is-drop .composer__drop { display: flex; }

.chip-btn {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: 999px; font-size: 13px; color: var(--muted);
  border: 1px solid var(--border);
}
.chip-btn svg { width: 16px; height: 16px; }
.chip-btn:hover { background: var(--hover); color: var(--text); }

.send {
  width: 38px; height: 38px; border-radius: 12px; flex: none;
  display: grid; place-items: center;
  background: var(--accent); color: var(--accent-contrast);
  transition: opacity .15s, transform .15s;
}
.send:disabled { opacity: .35; }
.send:not(:disabled):hover { transform: translateY(-1px); }

.field-error { color: var(--bad); font-size: 14px; text-align: center; max-width: 760px; }
.params { display: flex; gap: 18px; flex-wrap: wrap; justify-content: center; color: var(--muted); font-size: 14px; }
.params label { display: flex; align-items: center; gap: 8px; }

.suggestions { position: relative; display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 10px; }
.suggestions__label { color: var(--muted); font-size: 14px; }
.suggestion {
  padding: 7px 16px; border-radius: 999px; font-size: 14px;
  background: var(--surface); border: 1px solid var(--border);
  transition: background .15s, border-color .15s, transform .15s;
}
.suggestion:hover { background: var(--hover); border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); transform: translateY(-1px); }

.review, .results {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px;
}
.review h2 { font-size: 19px; margin-bottom: 12px; }

.disclaimer { font-size: 12px; color: var(--muted); text-align: center; margin-top: auto; }

/* -------------------------------------------------------------- status */
.status {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  padding: 14px 18px; border-radius: 14px; color: var(--muted);
  background: var(--surface); border: 1px solid var(--border);
}
.spinner {
  width: 18px; height: 18px; border-radius: 50%; flex: none;
  border: 2px solid var(--border); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* -------------------------------------------------------------- review */
.review[hidden], .results[hidden] { display: none; }
.review__grid { display: grid; grid-template-columns: minmax(240px, 380px) 1fr; gap: 24px; align-items: start; }
.review__figure { display: flex; flex-direction: column; gap: 12px; }
.review__source { max-width: 100%; max-height: 180px; object-fit: contain; border-radius: 12px; border: 1px solid var(--border); background: #fff; }
.review__actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }

.mol-svg { display: grid; place-items: center; background: #fff; border: 1px solid var(--border); border-radius: 14px; padding: 6px; }
.mol-svg svg { width: 100%; height: auto; max-width: 380px; stroke: none; stroke-width: 0; fill: initial; }

.facts { display: grid; gap: 12px; }
.facts > div { display: grid; gap: 2px; }
.facts dt { font-size: 12px; color: var(--muted); }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.facts code { background: var(--hover); padding: 2px 8px; border-radius: 8px; display: inline-block; }

.alerts { list-style: none; padding: 0; display: grid; gap: 6px; margin: 12px 0; }
.alerts li, .alert-line {
  font-size: 14px; padding: 8px 12px; border-radius: 10px;
  background: color-mix(in srgb, var(--warn) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--warn) 40%, transparent);
}
.alert-line { margin-top: 12px; }

.candidates { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; margin-top: 12px; }
.candidate {
  display: flex; flex-direction: column; gap: 6px; padding: 10px; text-align: start;
  border: 1px solid var(--border); border-radius: 16px; background: var(--bg); font-size: 14px;
  transition: border-color .15s, transform .15s;
}
.candidate:hover { border-color: var(--accent); transform: translateY(-2px); }
.candidate code { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; text-align: left; }

/* ------------------------------------------------------------- results */
.res-head { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.res-title { font-size: 22px; font-weight: 600; }
.badge {
  align-self: flex-start; padding: 2px 12px; border-radius: 999px; font-size: 12px; font-weight: 700;
  letter-spacing: .3px; color: var(--accent); direction: ltr;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
}
.res-meta { display: flex; flex-wrap: wrap; gap: 6px 18px; color: var(--muted); font-size: 13px; }

.tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--border); margin-bottom: 18px; overflow-x: auto; overflow-y: hidden; }
.tab {
  padding: 9px 20px; font-weight: 500; color: var(--muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); }

.res-grid { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 22px; align-items: start; }

.panel__head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.panel__head h3 { font-size: 16px; }
.panel__tools { display: flex; align-items: center; gap: 10px; }
.hint { font-size: 12px; color: var(--muted); }
.empty { padding: 30px 0; text-align: center; color: var(--muted); }

.chart-wrap { border: 1px solid var(--border); border-radius: 16px; background: var(--bg); padding: 6px 6px 0; }
.chart { width: 100%; height: auto; display: block; user-select: none; -webkit-user-select: none; touch-action: pan-y; cursor: crosshair; stroke: none; stroke-width: 0; fill: initial; }
.chart .gridline { stroke: var(--border); stroke-width: 1; opacity: .7; }
.chart .axis, .chart .tick { stroke: var(--muted); stroke-width: 1.2; }
.chart .tick-label { fill: var(--muted); font-size: 12px; }
.chart .axis-label { fill: var(--text); font-size: 13px; }
.chart .chart-title { fill: var(--text); font-size: 15px; font-weight: 700; }
.chart .watermark { fill: var(--muted); font-size: 11px; font-style: italic; }
.chart .peak-label { fill: var(--text); font-size: 11px; pointer-events: none; }
.chart .peak .hit { fill: transparent; cursor: pointer; }
.chart .brush { fill: color-mix(in srgb, var(--accent) 18%, transparent); stroke: var(--accent); stroke-width: 1; pointer-events: none; }

.chart .curve { fill: color-mix(in srgb, var(--spec) 16%, transparent); stroke: var(--spec); stroke-width: 1.4; stroke-linejoin: round; }
.chart .stick { stroke: var(--spec); stroke-width: 3; }
.chart .err { stroke: var(--spec); stroke-width: 1.4; opacity: .55; }
.chart .ir-curve { fill: none; stroke: var(--ir); stroke-width: 1.8; stroke-linejoin: round; }
.chart .marker { stroke: var(--hl); stroke-width: 1.4; stroke-dasharray: 4 3; opacity: 0; pointer-events: none; }
.chart .dot { fill: var(--hl); opacity: 0; pointer-events: none; }

.chart .peak:hover .curve { stroke: var(--hl); }
.chart .peak:hover .stick { stroke: var(--hl); }
.chart .peak:hover .marker { opacity: .4; }
.chart .peak:hover .dot { opacity: .6; }
.chart .peak.is-active .curve { fill: color-mix(in srgb, var(--hl) 32%, transparent); stroke: var(--hl); stroke-width: 2; }
.chart .peak.is-active .stick { stroke: var(--hl); stroke-width: 4; }
.chart .peak.is-active .marker, .chart .peak.is-active .dot { opacity: 1; }

.table-wrap { overflow-x: auto; margin-top: 16px; border: 1px solid var(--border); border-radius: 14px; }
.peaks { width: 100%; border-collapse: collapse; font-size: 14px; }
.peaks th { text-align: start; font-weight: 500; font-size: 12px; color: var(--muted); padding: 8px 12px; background: var(--bg); white-space: nowrap; }
.peaks td { padding: 8px 12px; border-top: 1px solid var(--border); white-space: nowrap; }
.peaks tbody tr { cursor: pointer; }
.peaks tbody tr:hover { background: var(--hover); }
.peaks tr.is-active { background: color-mix(in srgb, var(--hl) 20%, transparent); }
.peaks .num { font-variant-numeric: tabular-nums; direction: ltr; text-align: start; }
.peaks small { color: var(--muted); }
.tag { font-size: 11px; padding: 1px 8px; border-radius: 999px; color: var(--warn); border: 1px solid color-mix(in srgb, var(--warn) 50%, transparent); }
.table-note { font-size: 12px; color: var(--muted); margin-top: 8px; }

.conf { display: inline-flex; align-items: center; gap: 8px; }
.conf__bar { width: 54px; height: 6px; border-radius: 999px; background: var(--hover); overflow: hidden; display: inline-block; }
.conf__bar span { display: block; height: 100%; border-radius: inherit; background: var(--ok); }
.conf--mid .conf__bar span { background: var(--warn); }
.conf--low .conf__bar span { background: var(--bad); }
.conf__num { font-size: 13px; font-variant-numeric: tabular-nums; direction: ltr; }

.viewer { position: sticky; top: 0; display: flex; flex-direction: column; gap: 10px; }
.viewer__head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.viewer__head h3 { font-size: 16px; }
.switch { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); cursor: pointer; }
.switch input { accent-color: var(--accent); }
.viewer__svg { transition: opacity .15s; }
.viewer__svg.is-loading { opacity: .55; }
.viewer__caption { font-size: 13px; color: var(--muted); min-height: 2.6em; }

/* -------------------------------------------------------------- editor */
/* "* { margin: 0 }" above would pin the dialog to a corner, so it is centred explicitly. */
.editor {
  margin: auto; padding: 0; overflow: hidden;
  width: min(94vw, 1100px); height: min(90vh, 780px);
  border: 1px solid var(--border); border-radius: 24px;
  background: var(--surface); color: var(--text);
  box-shadow: 0 30px 90px rgba(0, 0, 0, .45);
}
.editor[open] { display: flex; flex-direction: column; animation: rise .3s ease both; }
.editor::backdrop { background: rgba(12, 9, 6, .55); backdrop-filter: blur(6px); }

.editor__head { display: flex; align-items: center; gap: 14px; padding: 16px 22px; border-bottom: 1px solid var(--border); }
.editor__badge {
  display: grid; place-items: center; flex: none; width: 42px; height: 42px; border-radius: 13px;
  color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, transparent);
}
.editor__badge svg { width: 22px; height: 22px; }
.editor__titles { flex: 1; min-width: 0; }
.editor__titles h2 { font-size: 18px; font-weight: 600; }
.editor__titles p { font-size: 13px; color: var(--muted); }

.editor__body { flex: 1; display: flex; gap: 16px; padding: 16px 22px; min-height: 0; }
.editor__side {
  width: 230px; flex: none; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding: 14px;
  border: 1px solid var(--border); border-radius: 16px; background: var(--bg); font-size: 13px; color: var(--muted);
}
.editor__side[hidden] { display: none; }
.editor__side img { width: 100%; border-radius: 12px; border: 1px solid var(--border); background: #fff; }
.editor__conf b { color: var(--text); }
.editor__canvas {
  flex: 1; min-width: 0; min-height: 0; overflow: hidden; display: grid; place-items: center;
  background: #fff; color: #555; border: 1px solid var(--border); border-radius: 16px;
}
.editor .field-error { padding: 0 22px 8px; text-align: start; max-width: none; }
.editor__foot { display: flex; align-items: center; gap: 10px; padding: 14px 22px; border-top: 1px solid var(--border); background: var(--bg); }
.editor__foot [data-first] { margin-inline-end: auto; }

/* -------------------------------------------------------------- mobile */
/* Layout follows the card width, not the window, because the sidebar takes space too. */
.results { container: results / inline-size; }
.review { container: review / inline-size; }

@container results (max-width: 900px) {
  .res-grid { grid-template-columns: minmax(0, 1fr); }
  .viewer {
    position: static; order: -1;
    display: grid; grid-template-columns: minmax(0, 240px) minmax(0, 1fr);
    grid-template-areas: "svg head" "svg cap" "svg btn";
    grid-template-rows: auto auto 1fr; column-gap: 16px; align-items: start;
  }
  .viewer__head { grid-area: head; }
  .viewer__svg { grid-area: svg; }
  .viewer__caption { grid-area: cap; }
  .viewer > .btn { grid-area: btn; justify-self: start; }
}

@container results (max-width: 560px) {
  .viewer { grid-template-columns: minmax(0, 1fr); grid-template-areas: "head" "svg" "cap" "btn"; }
}

@container review (max-width: 700px) {
  .review__grid { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 860px) {
  .sidebar {
    position: fixed; inset-block: 0; inset-inline-start: 0; z-index: 20;
    transform: translateX(100%); transition: transform .25s ease; box-shadow: var(--shadow);
  }
  .sidebar.is-open { transform: none; }
  #sidebarClose { display: grid; }
  #sidebarOpen { visibility: visible; }

  .scrim {
    display: block; position: fixed; inset: 0; z-index: 10;
    background: rgba(0, 0, 0, .4); opacity: 0; pointer-events: none; transition: opacity .25s;
  }
  .scrim.is-open { opacity: 1; pointer-events: auto; }

  .stage { padding-inline: 14px; }
  .review, .results { padding: 16px; }
  .editor { width: 100vw; height: 100dvh; max-width: none; border-radius: 0; border: 0; }
  .editor__head, .editor__foot { padding-inline: 14px; }
  .editor__body { flex-direction: column; padding: 12px 14px; gap: 10px; }
  .editor__side { width: auto; max-height: 130px; flex-direction: row; align-items: center; }
  .editor__side img { width: 100px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation-duration: 0s !important; }
}

.viewer .mol-svg svg { max-width: 300px; }

.field-error.is-note { color: var(--muted); font-size: 13px; }

/* ---------------------------------------------------- language / direction */
.topbar__end { display: flex; align-items: center; gap: 6px; }
#langSelect { max-width: 120px; }

@media (max-width: 860px) {
  /* The drawer slides in from the reading-start edge, which flips with the direction. */
  :root[dir="ltr"] .sidebar:not(.is-open) { transform: translateX(-100%); }
}

/* conditions chosen after the structure check */
.review .params { justify-content: flex-start; margin-top: 18px; }
.review .params select { min-width: 140px; }
.params__note { margin-top: 8px; }
.panel__meta { font-size: 13px; color: var(--muted); margin-bottom: 8px; }

/* ------------------------------------------------------------- processing card */
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes slide { 0% { background-position: -60% 0; } 100% { background-position: 160% 0; } }
@keyframes scan { 0% { transform: translateY(-100%); } 100% { transform: translateY(260%); } }
@keyframes pulse { 0%, 100% { transform: scale(.65); opacity: .75; } 50% { transform: scale(1); opacity: 1; } }
@keyframes ping { 0% { transform: scale(.8); opacity: .55; } 100% { transform: scale(1.55); opacity: 0; } }

.review:not([hidden]), .results:not([hidden]) { animation: rise .45s ease both; }

.run {
  container: run / inline-size; position: relative; overflow: hidden;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 24px 22px 20px;
  animation: rise .4s ease both;
}
.run__bar {
  position: absolute; inset-inline: 0; top: 0; height: 3px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent) no-repeat;
  background-size: 50% 100%; animation: slide 1.6s ease-in-out infinite;
}
.run.is-done .run__bar { animation: none; background: var(--ok); }
.run.is-failed .run__bar { animation: none; background: var(--bad); }

.run__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.run__head h2 { font-size: 19px; }
.run__time {
  font-size: 13px; color: var(--muted); direction: ltr; padding: 2px 12px;
  border-radius: 999px; background: var(--hover); font-variant-numeric: tabular-nums;
}

.run__body { display: grid; grid-template-columns: minmax(200px, 340px) minmax(0, 1fr); gap: 30px; align-items: center; }
.run__label { font-size: 12px; color: var(--muted); margin-bottom: 6px; letter-spacing: .04em; }
.run__tile {
  position: relative; display: grid; place-items: center; overflow: hidden;
  background: #fff; border: 1px solid var(--border); border-radius: 14px; padding: 6px;
}
.run__tile svg, .run__tile img { display: block; width: 100%; max-width: 340px; height: auto; max-height: 260px; object-fit: contain; }
.run__scan {
  position: absolute; inset-inline: 0; top: 0; height: 38%; pointer-events: none;
  background: linear-gradient(to bottom, transparent, color-mix(in srgb, var(--accent) 26%, transparent));
  border-bottom: 2px solid color-mix(in srgb, var(--accent) 70%, transparent);
  animation: scan 2.4s ease-in-out infinite;
}
.run:not(.is-running) .run__scan { display: none; }

.run__caption { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; margin-top: 10px; }
.run__formula { font-weight: 700; }
.run__caption code { background: var(--hover); padding: 1px 8px; border-radius: 8px; overflow-wrap: anywhere; }
.run__file { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.run__chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.run__chip {
  font-size: 12px; padding: 2px 10px; border-radius: 999px;
  color: var(--muted); background: var(--bg); border: 1px solid var(--border);
}

.run__steps { list-style: none; padding: 0; display: grid; gap: 2px; }
.run__step {
  position: relative; display: flex; align-items: center; gap: 14px; padding: 9px 0;
  animation: rise .45s ease both; animation-delay: calc(var(--i) * 80ms);
}
.run__step:not(:last-child)::before {
  content: ''; position: absolute; inset-inline-start: 13px; top: calc(50% + 14px); height: calc(100% - 28px + 2px);
  width: 2px; background: var(--border); transition: background .3s;
}
.run__step[data-state="done"]::before { background: var(--ok); }
.run__dot {
  position: relative; display: grid; place-items: center; flex: none; width: 28px; height: 28px;
  border-radius: 50%; border: 2px solid var(--border); color: #fff; transition: background .3s, border-color .3s;
}
.run__dot svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2.8; stroke-linecap: round; stroke-linejoin: round; }
.run__step[data-state="done"] .run__dot { background: var(--ok); border-color: var(--ok); }
.run__step[data-state="error"] .run__dot { background: var(--bad); border-color: var(--bad); }
.run__step[data-state="active"] .run__dot { border-color: var(--accent); }
.run__step[data-state="active"] .run__dot::after {
  content: ''; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); animation: pulse 1.2s ease-in-out infinite;
}
.run__step[data-state="active"] .run__dot::before {
  content: ''; position: absolute; inset: -2px; border-radius: 50%; border: 2px solid var(--accent); animation: ping 1.6s ease-out infinite;
}
.run__text { transition: color .3s; }
.run__step[data-state="pending"] .run__text { color: var(--muted); }
.run__step[data-state="active"] .run__text { font-weight: 600; }

.run__hint { margin-top: 14px; font-size: 13px; color: var(--muted); }
.run__error {
  display: flex; flex-direction: column; align-items: flex-start; gap: 10px; margin-top: 16px; padding: 14px 16px;
  border-radius: 12px; background: color-mix(in srgb, var(--bad) 10%, transparent); border: 1px solid color-mix(in srgb, var(--bad) 40%, transparent);
}

@container run (max-width: 640px) {
  .run__body { grid-template-columns: minmax(0, 1fr); gap: 20px; }
  .run__tile svg, .run__tile img { max-height: 200px; }
}

/* ------------------------------------------- spectra selection + settings (review step) */
.opts { display: grid; gap: 14px; margin-top: 18px; }
.opts__group {
  min-width: 0; margin: 0; padding: 14px 16px 12px;
  border: 1px solid var(--border); border-radius: 14px; background: var(--bg);
}
.opts__group legend { padding: 0 8px; font-size: 13px; font-weight: 600; color: var(--muted); }
.opts__group[hidden] { display: none; }

.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 15px; user-select: none; }
.check input { width: 18px; height: 18px; margin: 0; accent-color: var(--accent); cursor: pointer; }
.check--all { margin-bottom: 10px; padding-bottom: 10px; border-bottom: 1px dashed var(--border); display: flex; font-weight: 600; }
.check-grid { display: flex; flex-wrap: wrap; gap: 8px 26px; }

.opts .params { justify-content: flex-start; margin-top: 4px; }
.opts .params select, .opts .params input { min-width: 140px; }
.opts input[type="number"] {
  font: inherit; font-size: 14px; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; padding: 5px 10px; width: 140px;
}
.params__note { margin-top: 8px; }
.params__carbon { margin-top: 6px; font-size: 14px; color: var(--accent); font-weight: 500; }
.opts .field-error, .opts .alert-line { text-align: start; max-width: none; margin-top: 8px; }

/* ------------------------------------------------------------ results summary / honesty */
.run__tag {
  margin-inline-start: auto; font-size: 12px; padding: 1px 10px; border-radius: 999px; white-space: nowrap;
  color: var(--muted); background: var(--bg); border: 1px solid var(--border); transition: color .3s, background .3s, border-color .3s;
}
.run__step[data-state="active"] .run__tag { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 50%, var(--border)); }
.run__step[data-state="done"] .run__tag { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 50%, var(--border)); }
.run__step[data-state="error"] .run__tag { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 50%, var(--border)); }

.res-summary { display: grid; grid-template-columns: minmax(150px, 230px) minmax(0, 1fr); gap: 22px; align-items: start; margin-bottom: 14px; }
.res-summary__figure svg { width: 100%; height: auto; max-width: 230px; }
.res-summary__body { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.res-summary__body h2 { font-size: 22px; font-weight: 600; }
.facts--grid { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px 22px; }
.facts--grid code { overflow-wrap: anywhere; }

.notice {
  margin: 4px 0 12px; padding: 10px 14px; border-radius: 12px; font-size: 14px;
  background: color-mix(in srgb, var(--warn) 12%, transparent); border: 1px solid color-mix(in srgb, var(--warn) 40%, transparent);
}
.na { color: var(--muted); font-size: 13px; font-style: italic; }
.pm { color: var(--muted); font-size: .9em; }
.tab--failed::after { content: '!'; margin-inline-start: 6px; color: var(--bad); font-weight: 700; }
.panel__busy { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 34px 0; color: var(--muted); }
.panel .run__error { margin-top: 8px; }

@container results (max-width: 640px) {
  .res-summary { grid-template-columns: minmax(0, 1fr); }
  .res-summary__figure { max-width: 230px; }
}

/* reference example chip + shifts toggle */
.suggestion--ref { border-style: dashed; color: var(--muted); }
.switch--block { display: flex; margin-top: -4px; }

/* ------------------------------------------------------------------ PDF / print */
.pdf-btn { align-self: flex-start; display: inline-flex; align-items: center; gap: 6px; }
.pdf-btn svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.report { display: none; }

@media print {
  /* The report follows the theme: a dark page prints dark (backgrounds must be printed exactly). */
  @page { margin: 0; }
  html, body { height: auto !important; background: var(--bg) !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  body > *:not(#printReport) { display: none !important; }
  .report { display: block; box-sizing: border-box; min-height: 100vh; padding: 14mm; background: var(--bg); color: var(--text); font-size: 12px; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .report__head { display: flex; justify-content: space-between; padding-bottom: 8px; margin-bottom: 14px; border-bottom: 1px solid var(--border); font-size: 13px; }
  .report .res-summary { display: flex; gap: 18px; align-items: flex-start; margin-bottom: 10px; }
  .report .res-summary__figure { width: 180px; flex: none; }
  .report .notice, .report .alerts { margin: 8px 0; }
  .report__spec { break-inside: avoid-page; margin-top: 18px; }
  .report__spec h3 { font-size: 15px; margin-bottom: 4px; }
  .report .hint, .report .btn { display: none !important; }
  .report table { width: 100%; border-collapse: collapse; }
  .report tr { break-inside: avoid; }
  .report__fail { color: var(--bad); }
  .report * { box-shadow: none !important; }
}

.dl-row { display: flex; flex-wrap: wrap; gap: 8px; }
