:root {
  --bg: #0a0c10;
  --bg-2: #11151c;
  --panel: #141923;
  --panel-2: #1a2030;
  --line: #242c3a;
  --line-soft: #1c2230;
  --ink: #eef2f8;
  --ink-dim: #9aa6b8;
  --ink-faint: #66718a;
  --amber: #f5a623;
  --cyan: #34d3ff;
  --host-a: #f5a623;
  --host-b: #34d3ff;
  --danger: #ff6b6b;
  --ok: #4ade80;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 18px 50px -20px rgba(0, 0, 0, 0.8);
  --maxw: 760px;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(52, 211, 255, 0.08), transparent 60%),
    radial-gradient(900px 500px at -10% 10%, rgba(245, 166, 35, 0.07), transparent 55%),
    var(--bg);
  color: var(--ink);
  font-family: "Spline Sans", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  min-height: 100vh;
}

.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.5;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.035'/%3E%3C/svg%3E");
  mix-blend-mode: overlay;
}

.wrap {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 18px 64px;
}

/* ---------- Masthead ---------- */
.masthead {
  position: relative;
  z-index: 1;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 20px 18px 6px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.masthead__brand { display: flex; align-items: center; gap: 9px; }
.masthead__kicker {
  font-family: "Bricolage Grotesque", sans-serif;
  font-weight: 800;
  letter-spacing: -0.01em;
  font-size: 1.05rem;
}
.dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--amber);
  box-shadow: 0 0 0 4px rgba(245, 166, 35, 0.16);
}
.masthead__tag {
  margin: 0;
  color: var(--ink-faint);
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
}

/* ---------- Hero ---------- */
.hero {
  margin-top: 14px;
  display: grid;
  gap: 18px;
  animation: rise 0.6s ease both;
}
.hero__media {
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  aspect-ratio: 16 / 10;
}
.hero__media img { width: 100%; height: 100%; object-fit: cover; display: block; }
.hero__copy h1 {
  font-family: "Bricolage Grotesque", sans-serif;
  font-weight: 800;
  font-size: clamp(1.9rem, 7vw, 2.9rem);
  line-height: 1.04;
  letter-spacing: -0.02em;
  margin: 0 0 12px;
}
.hero__copy p {
  margin: 0;
  color: var(--ink-dim);
  max-width: 46ch;
}

@media (min-width: 720px) {
  .hero {
    grid-template-columns: 1.05fr 1fr;
    align-items: center;
    gap: 28px;
    margin-top: 22px;
  }
}

/* ---------- Panels ---------- */
.panel {
  margin-top: 26px;
  background: linear-gradient(180deg, var(--panel), var(--bg-2));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
  animation: rise 0.5s ease both;
}
.panel__title {
  font-family: "Bricolage Grotesque", sans-serif;
  font-weight: 700;
  font-size: 1.15rem;
  margin: 0 0 16px;
  letter-spacing: -0.01em;
}

/* ---------- Form ---------- */
.field { margin-bottom: 18px; }
.field label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink-dim);
  margin-bottom: 8px;
}
.field__hint { margin: 8px 0 0; font-size: 0.8rem; color: var(--ink-faint); }

input[type="text"], textarea, .select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: var(--radius-sm);
  padding: 13px 14px;
  font: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
  resize: vertical;
}
input[type="text"]:focus, textarea:focus, .select:focus {
  outline: none;
  border-color: var(--cyan);
  box-shadow: 0 0 0 3px rgba(52, 211, 255, 0.16);
}
.select {
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%239aa6b8' stroke-width='2.5'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 40px;
}
.select option { background: var(--bg-2); color: var(--ink); }
textarea { min-height: 84px; }

/* combobox */
.combo { position: relative; }
.combo__list {
  position: absolute;
  z-index: 30;
  top: calc(100% + 6px);
  left: 0; right: 0;
  margin: 0; padding: 6px;
  list-style: none;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  max-height: 280px;
  overflow-y: auto;
}
.combo__opt {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.95rem;
}
.combo__opt:hover, .combo__opt[aria-selected="true"] {
  background: rgba(52, 211, 255, 0.12);
}
.combo__logo {
  width: 24px; height: 24px; object-fit: contain;
  flex: 0 0 auto;
}
.combo__swatch {
  width: 10px; height: 24px; border-radius: 3px; flex: 0 0 auto;
}
.combo__none { padding: 12px 10px; color: var(--ink-faint); font-size: 0.9rem; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  font: inherit;
  font-weight: 600;
  border-radius: var(--radius-sm);
  padding: 13px 20px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform 0.12s, filter 0.15s, background 0.15s;
  min-height: 46px;
}
.btn:active { transform: translateY(1px); }
.btn--primary {
  width: 100%;
  background: linear-gradient(135deg, var(--amber), #ffce6b);
  color: #1a1205;
}
.btn--primary:hover { filter: brightness(1.05); }
.btn--primary[disabled] { opacity: 0.55; cursor: progress; }
.btn--ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--ink);
}
.btn--ghost:hover { background: var(--panel-2); }
.btn--ghost.is-done { color: var(--ok); border-color: rgba(74,222,128,0.4); }

.btn__spinner {
  width: 16px; height: 16px;
  border: 2px solid rgba(26,18,5,0.35);
  border-top-color: #1a1205;
  border-radius: 50%;
  display: none;
  animation: spin 0.7s linear infinite;
}
.btn.is-loading .btn__spinner { display: inline-block; }
.btn.is-loading .btn__label { opacity: 0.85; }

/* ---------- Status ---------- */
.status { margin: 14px 0 0; font-size: 0.88rem; color: var(--ink-dim); min-height: 1.2em; }
.status.is-error { color: var(--danger); }
.status.is-ok { color: var(--ok); }

/* ---------- Context cards ---------- */
.context { margin-top: 26px; }
.context__grid {
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr;
}
@media (min-width: 560px) {
  .context__grid { grid-template-columns: repeat(3, 1fr); }
}
.ccard {
  background: linear-gradient(180deg, var(--panel), var(--bg-2));
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 14px;
  animation: rise 0.4s ease both;
}
.ccard__title {
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink-dim);
  margin: 0 0 6px;
  font-weight: 600;
}
.ccard__val { font-size: 1.5rem; font-weight: 700; font-family: "Bricolage Grotesque", sans-serif; }
.ccard__sub { font-size: 0.82rem; color: var(--ink-faint); margin-top: 2px; }
.ccard[data-state="empty"] .ccard__val { color: var(--ink-faint); }
.ccard[data-state="failed"] {
  border-color: rgba(255,107,107,0.4);
  background: linear-gradient(180deg, rgba(255,107,107,0.07), var(--bg-2));
}
.ccard[data-state="failed"] .ccard__val { color: var(--danger); font-size: 1.05rem; }
.ccard__badge {
  display: inline-block;
  font-size: 0.66rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: 999px;
  margin-top: 8px;
}
.badge-data { background: rgba(74,222,128,0.14); color: var(--ok); }
.badge-empty { background: rgba(102,113,138,0.18); color: var(--ink-dim); }
.badge-failed { background: rgba(255,107,107,0.16); color: var(--danger); }

/* ---------- Script output ---------- */
.output__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.output__head .panel__title { margin: 0; }
.script {
  display: grid;
  gap: 16px;
}
.seg {
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--bg);
}
.seg__title {
  font-family: "Bricolage Grotesque", sans-serif;
  font-weight: 700;
  font-size: 0.95rem;
  padding: 11px 15px;
  background: var(--panel-2);
  border-bottom: 1px solid var(--line-soft);
  letter-spacing: -0.01em;
}
.line {
  display: grid;
  grid-template-columns: 64px 1fr;
  gap: 12px;
  padding: 12px 15px;
}
.line + .line { border-top: 1px dashed var(--line-soft); }
.line__host {
  font-weight: 700;
  font-size: 0.78rem;
  letter-spacing: 0.02em;
  padding-top: 2px;
}
.line--a .line__host { color: var(--host-a); }
.line--b .line__host { color: var(--host-b); }
.line__text { color: var(--ink); }
.line__text :is(strong) { color: #fff; }
.output__note {
  margin: 18px 0 0;
  font-size: 0.8rem;
  color: var(--ink-faint);
  border-top: 1px solid var(--line-soft);
  padding-top: 14px;
}

/* raw markdown fallback */
.script--raw {
  white-space: pre-wrap;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.88rem;
  line-height: 1.6;
  color: var(--ink);
  display: block;
}

/* ---------- Empty / fallback ---------- */
.empty h3 {
  font-family: "Bricolage Grotesque", sans-serif;
  margin: 0 0 8px;
  font-size: 1.1rem;
}
.empty p { margin: 0 0 10px; color: var(--ink-dim); }
.empty code {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 2px 7px;
  font-size: 0.85em;
  color: var(--cyan);
}

/* ---------- Footer ---------- */
.foot {
  position: relative;
  z-index: 1;
  text-align: center;
  color: var(--ink-faint);
  font-size: 0.8rem;
  padding: 8px 18px 40px;
}

/* ---------- Animations ---------- */
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes spin { to { transform: rotate(360deg); } }

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