:root {
  --ink: #090b0d;
  --paper: #fbfbfa;
  --panel: #ffffff;
  --line: #ccd7db;
  --teal: #2d85a8;
  --teal-deep: #17627e;
  --teal-pale: #e8f6fa;
  --magenta: #e15bb7;
  --magenta-pale: #ffe4f6;
  --slate: #11171a;
  --slate-2: #182126;
  --muted: #5e6b70;
  --warning: #b7452e;
  --ok: #257c50;
  --shadow: 7px 7px 0 var(--ink);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--paper);
}

body {
  margin: 0;
  min-height: 100dvh;
  overflow-x: hidden;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(45, 133, 168, 0.05), transparent 220px),
    var(--paper);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.frame-edge {
  position: fixed;
  top: 0;
  bottom: 0;
  width: 72px;
  background: var(--teal);
  z-index: 1;
  pointer-events: none;
}

.frame-edge-left {
  left: 0;
  clip-path: polygon(0 0, 72% 0, 24% 100%, 0 100%);
}

.frame-edge-right {
  right: 0;
  clip-path: polygon(76% 0, 100% 0, 100% 100%, 28% 100%);
}

body::before,
body::after {
  content: "";
  position: fixed;
  left: 0;
  right: 0;
  height: 24px;
  background: var(--magenta);
  z-index: 0;
  pointer-events: none;
}

body::before {
  top: 0;
  clip-path: polygon(0 0, 42% 0, 0 100%);
}

body::after {
  bottom: 0;
  clip-path: polygon(58% 100%, 100% 0, 100% 100%);
}

.shell {
  position: relative;
  z-index: 2;
  width: min(1280px, calc(100vw - 132px));
  min-height: 100dvh;
  margin: 0 auto;
  padding: 28px 0 34px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 22px;
}

.masthead {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 380px);
  align-items: end;
  gap: 24px;
}

.brand {
  min-width: 0;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 18px;
}

.brand-mark-shell {
  display: grid;
  place-items: center;
}

.brand-mark {
  height: 136px;
  width: auto;
  display: block;
}

.lab-tag,
.eyebrow {
  margin: 0;
  color: var(--teal-deep);
  font-size: 0.74rem;
  font-weight: 850;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  margin-top: 4px;
  max-width: 12ch;
  font-size: 3.7rem;
  line-height: 0.92;
  font-weight: 930;
}

.brand-line {
  margin: 10px 0 0;
  color: #263238;
  font-size: 0.98rem;
  font-weight: 760;
  letter-spacing: 0.01em;
}

h2 {
  margin-top: 7px;
  font-size: 1.2rem;
  line-height: 1.08;
  font-weight: 880;
}

.token-bar {
  width: 100%;
  min-width: 0;
  border: 3px solid var(--ink);
  background: var(--panel);
  box-shadow: 5px 5px 0 var(--teal-deep);
}

.token-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 34px;
  padding: 8px 12px;
  border-bottom: 2px solid var(--ink);
  background: var(--magenta-pale);
}

.token-label label,
.token-label span {
  min-width: 0;
  font-size: 0.76rem;
  font-weight: 870;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.token-label span {
  color: var(--teal-deep);
  text-align: right;
}

.token-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 74px;
  min-height: 44px;
}

input,
textarea,
button {
  font: inherit;
}

input,
textarea {
  color: var(--ink);
  background: #fff;
}

input:focus,
textarea:focus,
button:focus-visible {
  outline: 3px solid rgba(225, 91, 183, 0.34);
  outline-offset: 2px;
}

.token-controls input {
  min-width: 0;
  width: 100%;
  height: 44px;
  border: 0;
  border-right: 2px solid var(--ink);
  border-radius: 0;
  padding: 0 12px;
}

button {
  min-width: 0;
  min-height: 40px;
  border: 2px solid var(--ink);
  border-radius: 0;
  background: var(--ink);
  color: #fff;
  padding: 0 14px;
  font-weight: 870;
  cursor: pointer;
  white-space: nowrap;
}

button:hover:not(:disabled) {
  background: var(--magenta);
  color: var(--ink);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

.token-controls button {
  height: 44px;
  border: 0;
}

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 0.96fr) minmax(0, 1.04fr);
  gap: 22px;
  align-items: stretch;
}

.panel {
  min-width: 0;
  min-height: 580px;
  /* Cap height to the viewport so long procedures/XDL scroll inside the panel
     (pre / editor / textarea / chat-log all scroll) instead of stretching the page. */
  max-height: calc(100dvh - 230px);
  border: 3px solid var(--ink);
  background: var(--panel);
  box-shadow: var(--shadow);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.panel-head {
  min-width: 0;
  min-height: 78px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 16px;
  border-bottom: 3px solid var(--ink);
  padding: 15px 16px;
  background:
    linear-gradient(90deg, var(--teal-pale), #fff 68%),
    #fff;
}

.panel-head > div {
  min-width: 0;
}

.primary-action {
  min-width: 142px;
  height: 44px;
}

.input-panel textarea {
  width: 100%;
  height: 100%;
  min-height: 0;
  resize: none;
  border: 0;
  border-radius: 0;
  padding: 18px;
  line-height: 1.55;
  font-size: 0.98rem;
}

.output-panel {
  color: #f6fbfc;
  background: var(--slate);
  grid-template-rows: auto auto minmax(0, 1fr) auto;
}

.output-panel .panel-head,
.chat-panel .panel-head {
  color: var(--ink);
  background:
    linear-gradient(90deg, #fff, var(--magenta-pale) 100%),
    #fff;
}

.output-actions {
  min-width: 0;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.output-actions button {
  height: 40px;
  min-width: 86px;
}

.status-rail {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  min-height: 42px;
  border-bottom: 1px solid #304047;
  background: var(--slate-2);
}

.status-rail span {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px 8px;
  color: #91a4aa;
  border-right: 1px solid #304047;
  font-size: 0.76rem;
  font-weight: 870;
  letter-spacing: 0.08em;
  text-align: center;
  text-transform: uppercase;
}

.status-rail span:last-child {
  border-right: 0;
}

.status-rail[data-status="queued"] [data-step="queued"],
.status-rail[data-status="running"] [data-step="queued"],
.status-rail[data-status="running"] [data-step="running"],
.status-rail[data-status="succeeded"] span {
  color: #fff;
  background: var(--teal-deep);
}

.status-rail[data-status="failed"] span {
  color: #fff;
  background: var(--warning);
}

/* Subtle indeterminate progress sliver along the rail's lower edge while a
   translation is queued or running; invisible once it settles. */
.status-rail {
  position: relative;
}

.status-rail::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 3px;
  background: linear-gradient(90deg, transparent, var(--teal), var(--magenta), transparent);
  background-size: 38% 100%;
  background-repeat: no-repeat;
  background-position: -40% 0;
  opacity: 0;
  pointer-events: none;
}

.status-rail[data-status="queued"]::after,
.status-rail[data-status="running"]::after {
  opacity: 1;
  animation: acra-progress 1.3s ease-in-out infinite;
}

@keyframes acra-progress {
  0% {
    background-position: -40% 0;
  }
  100% {
    background-position: 140% 0;
  }
}

pre {
  margin: 0;
  min-height: 0;
  padding: 18px;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-family: "JetBrains Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 0.84rem;
  line-height: 1.55;
  tab-size: 2;
}

pre[data-empty="true"]::before {
  content: "XDL output will appear here.";
  color: #7f949b;
  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
  font-size: 0.95rem;
  font-weight: 760;
}

.message {
  min-height: 48px;
  margin: 0;
  padding: 12px 18px;
  border-top: 1px solid #304047;
  color: #cce1e7;
  font-size: 0.9rem;
  line-height: 1.35;
}

.message[data-tone="error"] {
  color: #ffd0c6;
}

.message[data-tone="ok"] {
  color: #caffdf;
}

.reference-strip {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  color: #53636a;
  font-size: 0.76rem;
  font-weight: 760;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.reference-strip a {
  color: var(--teal-deep);
  text-decoration: none;
  border-bottom: 2px solid transparent;
}

.reference-strip a:hover {
  border-bottom-color: var(--magenta);
}

.reference-strip span {
  min-width: 0;
  color: #6a777d;
}

.ref-icons {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.reference-strip .ref-icons a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: 2px solid var(--ink);
  border-bottom: 2px solid var(--ink);
  background: #fff;
  color: var(--teal-deep);
}

.reference-strip .ref-icons a:hover {
  background: var(--magenta);
  color: var(--ink);
  border-bottom-color: var(--ink);
}

.ref-icons svg {
  width: 18px;
  height: 18px;
  display: block;
}

/* Footer entry into the acknowledgements slide */
.ack-link {
  border: 0;
  background: none;
  cursor: pointer;
  padding: 0;
  font: inherit;
  color: var(--teal-deep);
  letter-spacing: 0.04em;
  border-bottom: 2px solid transparent;
}
.ack-link:hover {
  border-bottom-color: var(--magenta);
}

/* ---------------- Acknowledgements slide ---------------- */
.about-panel {
  grid-template-rows: auto minmax(0, 1fr);
}
.about-body {
  min-height: 0;
  overflow: auto;
  padding: 22px;
  display: grid;
  grid-template-columns: minmax(0, 340px) minmax(0, 1fr);
  gap: 26px;
}
.about-aside {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.group-photo {
  margin: 0;
}
.group-photo img {
  width: 100%;
  display: block;
  border: 3px solid var(--ink);
  box-shadow: var(--shadow);
}
.group-photo figcaption {
  margin-top: 10px;
  font-size: 0.74rem;
  font-weight: 760;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
}
.about-intro {
  margin: 0;
  font-size: 0.95rem;
  line-height: 1.5;
  color: var(--slate);
}
.pub-all {
  align-self: flex-start;
  font-size: 0.82rem;
  font-weight: 820;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--teal-deep);
  text-decoration: none;
  border-bottom: 2px solid var(--teal);
  padding-bottom: 2px;
}
.pub-all:hover {
  border-bottom-color: var(--magenta);
  color: var(--magenta);
}

/* Token bar is irrelevant on the acknowledgements slide */
body[data-slide="3"] .token-bar {
  display: none;
}

/* Click-to-expand group photo */
.group-photo img {
  cursor: zoom-in;
}
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4vmin;
  background: rgba(9, 11, 13, 0.86);
  cursor: zoom-out;
}
.lightbox[hidden] {
  display: none;
}
.lightbox img {
  max-width: 96vw;
  max-height: 92vh;
  border: 3px solid #fff;
  box-shadow: 12px 12px 0 rgba(0, 0, 0, 0.45);
}
.credits {
  margin: 0;
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.6;
}
.credits a {
  color: var(--teal-deep);
  font-weight: 760;
  text-decoration: none;
  border-bottom: 2px solid transparent;
}
.credits a:hover {
  border-bottom-color: var(--magenta);
}

.pub-list {
  min-width: 0;
  list-style: none;
  counter-reset: pub;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.pub-item {
  counter-increment: pub;
}
.pub-item > a {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr);
  align-items: baseline;
  gap: 12px;
  padding: 11px 13px;
  text-decoration: none;
  color: var(--ink);
  border: 2px solid var(--line);
  background: #fff;
  transition: border-color 0.12s, background 0.12s, transform 0.12s;
}
.pub-item > a::before {
  content: counter(pub);
  font-weight: 880;
  font-size: 0.9rem;
  color: var(--teal);
  font-variant-numeric: tabular-nums;
}
.pub-item > a:hover {
  border-color: var(--ink);
  background: var(--teal-pale);
  transform: translateX(2px);
}
.pub-title {
  font-weight: 740;
  line-height: 1.34;
  font-size: 0.92rem;
}
.pub-meta {
  grid-column: 2;
  margin-top: 3px;
  font-size: 0.74rem;
  font-weight: 740;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--magenta);
}

@media (max-width: 860px) {
  .about-body {
    grid-template-columns: minmax(0, 1fr);
    gap: 20px;
  }
}

@media (max-width: 1100px) {
  .shell {
    width: min(1000px, calc(100vw - 104px));
  }

  .masthead {
    grid-template-columns: 1fr;
    align-items: start;
  }

  .token-bar {
    max-width: 520px;
  }

  h1 {
    max-width: none;
    font-size: 3rem;
    line-height: 0.98;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .panel {
    min-height: 500px;
  }
}

@media (max-width: 720px) {
  .frame-edge {
    width: 34px;
  }

  .frame-edge-left {
    clip-path: polygon(0 0, 100% 0, 46% 100%, 0 100%);
  }

  .frame-edge-right {
    clip-path: polygon(54% 0, 100% 0, 100% 100%, 0 100%);
  }

  body::before,
  body::after {
    left: 0;
    right: 0;
    height: 16px;
  }

  .shell {
    width: calc(100vw - 56px);
    padding: 18px 0 26px;
    gap: 16px;
  }

  .brand {
    grid-template-columns: auto minmax(0, 1fr);
    gap: 12px;
  }

  .brand-mark {
    height: 92px;
  }

  .lab-tag,
  .eyebrow {
    font-size: 0.66rem;
    letter-spacing: 0.1em;
  }

  h1 {
    font-size: 2rem;
    line-height: 1;
  }

  .brand-line {
    margin-top: 7px;
    font-size: 0.86rem;
  }

  .token-controls {
    grid-template-columns: minmax(0, 1fr) 64px;
  }

  .panel {
    min-height: 430px;
    box-shadow: 4px 4px 0 var(--ink);
  }

  .panel-head {
    grid-template-columns: 1fr;
    gap: 12px;
    min-height: 0;
    padding: 14px;
  }

  .primary-action,
  .output-actions {
    width: 100%;
  }

  .output-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .output-actions button,
  .primary-action {
    min-width: 0;
  }

  .input-panel textarea,
  pre {
    padding: 15px;
  }

  .reference-strip {
    align-items: flex-start;
    flex-direction: column;
    gap: 6px;
    font-size: 0.7rem;
  }
}

/* ===================== Presentation deck / slides ===================== */
.deck {
  min-width: 0;
  overflow: hidden;            /* hard-clip the off-screen slide */
}

.slides-track {
  display: flex;
  align-items: flex-start;
  transition: transform 0.55s cubic-bezier(0.66, 0, 0.2, 1);
  will-change: transform;
}

.slide {
  flex: 0 0 100%;
  min-width: 100%;
  /* keep both slides aligned to the top of the deck during the slide */
  align-self: stretch;
  /* right/bottom gutter so the panels' offset shadows render inside the slide
     (the deck hard-clips, so shadows must live within the slide's own box) */
  padding: 0 14px 16px 0;
}

.deck[data-slide="2"] .slides-track {
  transform: translateX(-100%);
}

.deck[data-slide="3"] .slides-track {
  transform: translateX(-200%);
}

/* Forward CTA inside the (dark) output panel */
.slide-nav.next {
  width: 100%;
  height: 52px;
  border: 0;
  border-top: 3px solid var(--ink);
  background: var(--teal-deep);
  color: #fff;
  font-weight: 880;
  letter-spacing: 0.04em;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.slide-nav.next:hover:not(:disabled) {
  background: var(--magenta);
  color: var(--ink);
}

.slide-nav.prev {
  height: 44px;
  background: #fff;
  color: var(--ink);
}

.workbench-bar {
  display: flex;
  align-items: center;
  gap: 18px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

/* Subtle row of extracted chemicals on the workbench */
.chem-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: -6px 0 16px;
}

.chem-strip:empty {
  display: none;
}

.chem-chip {
  font-size: 0.72rem;
  font-weight: 760;
  letter-spacing: 0.01em;
  padding: 3px 9px;
  border: 1.5px solid var(--line);
  background: #fff;
  color: var(--muted);
  text-decoration: none;
  white-space: nowrap;
}

.chem-chip.resolved {
  color: var(--teal-deep);
  border-color: var(--teal);
}

.chem-chip.resolved:hover {
  background: var(--teal-pale);
}

.chem-chip.placeholder {
  border-style: dashed;
}

/* ===================== Workbench (slide 2) ===================== */
.workbench {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1.18fr) minmax(0, 0.82fr);
  gap: 22px;
  align-items: stretch;
}

.editor-panel {
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.chat-panel {
  grid-template-rows: auto minmax(0, 1fr) auto;
}

/* CodeMirror fills the editor row */
.editor-panel .CodeMirror {
  height: 100%;
  font-family: "JetBrains Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 0.86rem;
  line-height: 1.5;
}

/* Simulation bar under the editor */
.sim-bar {
  border-top: 3px solid var(--ink);
  padding: 12px 16px;
  background: #fff;
  display: grid;
  gap: 8px;
}

.sim-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.file-pick {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 40px;
  padding: 0 12px;
  border: 2px solid var(--ink);
  background: var(--teal-pale);
  font-weight: 760;
  font-size: 0.86rem;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-pick:hover {
  background: var(--magenta-pale);
}

.file-pick input {
  display: none;
}

#sim-result {
  min-height: 0;
  margin: 0;
  padding: 0;
  border: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.4;
}

#sim-result[data-tone="error"] { color: var(--warning); }
#sim-result[data-tone="ok"] { color: var(--ok); }

/* ===================== Chat panel ===================== */
.chat-log {
  min-height: 0;
  padding: 14px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--paper);
}

.chat-log:empty::before {
  content: "Ask the assistant to change the XDL — e.g. 'add a reflux at 80 °C for 2 h'.";
  color: #7f949b;
  font-size: 0.9rem;
  font-weight: 600;
}

.chat-msg {
  max-width: 90%;
  padding: 9px 12px;
  border: 2px solid var(--ink);
  font-size: 0.9rem;
  line-height: 1.42;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.chat-msg.user {
  align-self: flex-end;
  background: var(--magenta-pale);
}

.chat-msg.assistant {
  align-self: flex-start;
  background: #fff;
}

.chat-msg[data-transient="true"] {
  opacity: 0.6;
}

.chat-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  border-top: 3px solid var(--ink);
}

.chat-form textarea {
  border: 0;
  border-radius: 0;
  padding: 12px;
  resize: none;
  line-height: 1.45;
  font-size: 0.92rem;
}

.chat-form button {
  border: 0;
  border-left: 2px solid var(--ink);
  min-width: 96px;
}

@media (max-width: 1100px) {
  .workbench {
    grid-template-columns: 1fr;
  }
}

/* ===================== CodeMirror theme: cm-s-acra ===================== */
.cm-s-acra.CodeMirror {
  background: var(--paper);
  color: var(--ink);
}
.cm-s-acra .CodeMirror-gutters {
  background: var(--teal-pale);
  border-right: 2px solid var(--ink);
}
.cm-s-acra .CodeMirror-linenumber { color: var(--muted); }
.cm-s-acra .CodeMirror-cursor { border-left: 2px solid var(--magenta); }
.cm-s-acra div.CodeMirror-selected { background: var(--magenta-pale); }
.cm-s-acra .CodeMirror-line::selection,
.cm-s-acra .CodeMirror-line > span::selection { background: var(--magenta-pale); }
.cm-s-acra .CodeMirror-activeline-background { background: rgba(45, 133, 168, 0.07); }
.cm-s-acra .cm-tag { color: var(--teal-deep); font-weight: 700; }
.cm-s-acra .cm-attribute { color: var(--magenta); }
.cm-s-acra .cm-string { color: var(--ok); }
.cm-s-acra .cm-comment { color: var(--muted); font-style: italic; }
.cm-s-acra .cm-bracket,
.cm-s-acra .cm-meta { color: var(--ink); }
