:root {
  color-scheme: dark;
  --bg: #0e1014;
  --card: #171a21;
  --line: #2a3140;
  --text: #e8edf5;
  --muted: #8b95a8;
  --accent: #3ecfb2;
  --danger: #ff7b7b;
  --font: system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 var(--font);
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--line);
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

h1, h2 { margin: 0; font-weight: 600; }
h1 { font-size: 1.15rem; letter-spacing: 0.04em; }
h2 { font-size: 0.95rem; color: var(--muted); font-weight: 500; }

main {
  max-width: 52rem;
  margin: 0 auto;
  padding: 1.5rem;
  display: grid;
  gap: 1rem;
}

.lede {
  margin: 0;
  color: var(--muted);
  font-size: 0.98rem;
  line-height: 1.55;
}

.lede strong { color: var(--text); font-weight: 650; }

footer {
  max-width: 52rem;
  margin: 0 auto;
  padding: 0 1.5rem 2rem;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.55;
}

footer p { margin: 0; }
footer strong { color: var(--text); font-weight: 650; }
footer a { color: var(--accent); text-decoration: none; }
footer a:hover { text-decoration: underline; }

button {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.4rem 0.8rem;
  cursor: pointer;
  font: inherit;
  line-height: inherit;
}

button:hover { border-color: var(--accent); }

a.header-link {
  display: inline-flex;
  align-items: center;
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.4rem 0.8rem;
  text-decoration: none;
  font: inherit;
  line-height: inherit;
}

a.header-link:hover { border-color: var(--accent); }

#drop {
  display: grid;
  place-items: center;
  min-height: 8rem;
  border: 1px dashed var(--line);
  border-radius: 12px;
  background: var(--card);
  cursor: pointer;
  padding: 1.25rem;
  text-align: center;
  color: var(--muted);
}

#drop.compact {
  min-height: 0;
  padding: 0.65rem 1rem;
  justify-items: start;
}

#drop.over { border-color: var(--accent); color: var(--accent); }
#drop input { display: none; }

#job { display: grid; gap: 0.85rem; }
#job[hidden] { display: none; }

.chip {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.55rem 0.75rem;
}

#thumb-btn {
  padding: 0;
  border: 0;
  background: #000;
  border-radius: 8px;
  overflow: hidden;
  width: 56px;
  height: 56px;
  flex: 0 0 56px;
}

#preview {
  display: block;
  width: 56px;
  height: 56px;
  object-fit: cover;
}

.chip-text {
  display: grid;
  gap: 0.1rem;
  min-width: 0;
}

.chip-text strong {
  font-size: 0.95rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chip-text span {
  color: var(--muted);
  font-size: 0.82rem;
}

#progress {
  display: flex;
  gap: 0.9rem;
  align-items: flex-start;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.9rem 1rem;
}

#progress[hidden] { display: none; }

.spinner {
  width: 1.15rem;
  height: 1.15rem;
  margin-top: 0.2rem;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex: 0 0 auto;
}

@keyframes spin { to { transform: rotate(360deg); } }

.progress-copy { min-width: 0; flex: 1; }
#status { margin: 0; font-weight: 550; }
#status.err { color: var(--danger); }
#elapsed { margin: 0.15rem 0 0.7rem; color: var(--muted); font-size: 0.85rem; }

#steps {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.3rem;
  font-size: 0.88rem;
  color: var(--muted);
}

#steps li[data-state="done"] { color: var(--accent); }
#steps li[data-state="active"] { color: var(--text); }
#steps li[data-state="active"]::before { content: "→ "; color: var(--accent); }
#steps li[data-state="done"]::before { content: "✓ "; }
#steps li[data-state="pending"]::before { content: "· "; }

#result {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1rem 1.15rem;
  display: grid;
  gap: 0.65rem;
}

#result[hidden] { display: none; }

.think {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: color-mix(in srgb, var(--bg) 55%, var(--card));
  overflow: hidden;
}

.think[hidden] { display: none; }

.think > summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.55rem 0.75rem;
  color: var(--muted);
  font-size: 0.88rem;
  user-select: none;
}

.think > summary::-webkit-details-marker { display: none; }

.think > summary::before {
  content: "";
  width: 0.4rem;
  height: 0.4rem;
  border-right: 1.5px solid var(--muted);
  border-bottom: 1.5px solid var(--muted);
  transform: rotate(-45deg);
  transition: transform 0.15s ease;
  flex: 0 0 auto;
}

.think[open] > summary::before {
  transform: rotate(45deg);
}

.think.streaming > summary {
  color: var(--accent);
}

.think.streaming > summary::after {
  content: "";
  width: 0.45rem;
  height: 0.45rem;
  margin-left: 0.15rem;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
  50% { opacity: 0.25; }
}

.think-body {
  margin: 0;
  padding: 0 0.75rem 0.75rem;
  max-height: 14rem;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--muted);
  font: 0.82rem/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

#result.streaming .think.streaming .think-body::after {
  content: "▍";
  margin-left: 0.1em;
  color: var(--accent);
  animation: caret 0.9s step-end infinite;
}

.prose { margin: 0; }
.prose p { margin: 0 0 0.75rem; }
.prose p:last-child { margin-bottom: 0; }
.prose h3, .prose h4, .prose h5 {
  margin: 1rem 0 0.35rem;
  font-size: 1rem;
  color: var(--text);
}
.prose ul { margin: 0 0 0.75rem; padding-left: 1.2rem; }
.prose li { margin: 0.2rem 0; }
.prose strong { font-weight: 650; color: #fff; }
#result.streaming .prose > :last-child::after {
  content: "▍";
  margin-left: 0.1em;
  color: var(--accent);
  animation: caret 0.9s step-end infinite;
}
@keyframes caret {
  50% { opacity: 0; }
}
#meta { margin: 0; color: var(--muted); font-size: 0.85rem; }

#lightbox {
  position: fixed;
  inset: 0;
  background: rgb(0 0 0 / 72%);
  display: grid;
  place-items: center;
  padding: 1.5rem;
  cursor: zoom-out;
  z-index: 20;
}

#lightbox[hidden] { display: none; }

#full-preview {
  max-width: min(90vw, 56rem);
  max-height: 85vh;
  width: auto;
  height: auto;
  border-radius: 10px;
}

#gate {
  position: fixed;
  inset: 0;
  background: rgb(0 0 0 / 72%);
  display: grid;
  place-items: center;
  padding: 1rem;
  z-index: 40;
}

#gate[hidden] { display: none; }

.gate-copy { margin: 0 0 0.85rem; color: var(--muted); }

.gate-field {
  display: grid;
  gap: 0.35rem;
  color: var(--muted);
  font-size: 0.9rem;
}

#gate-secret {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.5rem 0.65rem;
  font: inherit;
}

#gate-err {
  min-height: 1.2em;
  color: var(--danger);
  font-size: 0.9rem;
}

#gate-go { margin-top: 0.35rem; }

#modal, #about-modal {
  position: fixed;
  inset: 0;
  background: rgb(0 0 0 / 55%);
  display: grid;
  place-items: center;
  padding: 1rem;
  z-index: 30;
}

#modal[hidden], #about-modal[hidden] { display: none; }

.modal-card {
  width: min(32rem, 100%);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1rem;
}

.metrics-card {
  width: min(56rem, 100%);
  max-height: min(94vh, 64rem);
  overflow: auto;
  padding: 1rem 1.25rem 1.15rem;
}

.metrics-charts {
  display: grid;
  gap: 1.25rem;
  grid-template-columns: 1fr;
}

.chart-wrap {
  position: relative;
  height: 14rem;
  min-height: 14rem;
}

.chart-wrap canvas {
  display: block;
}

.about-card {
  width: min(42rem, 100%);
  max-height: min(90vh, 40rem);
  overflow: auto;
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}

.about-body {
  display: grid;
  gap: 0.85rem;
  color: var(--muted);
  line-height: 1.55;
}

.about-body p { margin: 0; }
.about-body strong { color: var(--text); }
.about-body code {
  font-size: 0.9em;
  color: var(--accent);
}
