/* =========================================================================
   GateAI Core — API Docs
   Design language matched to GateAI Scale reference
   ========================================================================= */

/* ----- Dark theme (default) ----- */
:root,
html.dark {
  --bg-0: #0a0d12;
  --bg-1: #11151c;
  --bg-2: #161b25;
  --bg-3: #1d2330;
  --line: #232a38;
  --line-strong: #2e3648;
  --text: #e7eaf0;
  --text-dim: #99a3b3;
  --text-mute: #5e6878;
  --accent: #7afcb1;
  --accent-2: #4ad7ff;
  --accent-warm: #ffb359;
  --danger: #ff6b6b;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.55);
  --radius: 14px;
  --radius-sm: 10px;
  --code-bg: #0d1117;
}

/* ----- Light theme ----- */
html.light {
  --bg-0: #f7f8fa;
  --bg-1: #ffffff;
  --bg-2: #f0f1f4;
  --bg-3: #e4e6eb;
  --line: #d8dbe2;
  --line-strong: #c5c9d2;
  --text: #1a1d24;
  --text-dim: #555d6e;
  --text-mute: #8a92a1;
  --accent: #0d9f5a;
  --accent-2: #0a7fc2;
  --accent-warm: #d48a20;
  --danger: #d44040;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.08);
  --code-bg: #f4f5f7;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  overflow-x: hidden;
  max-width: 100%;
}
img, video, canvas, pre, code, table { max-width: 100%; }
h1, h2, h3, h4, p { word-wrap: break-word; overflow-wrap: anywhere; }

/* ----- Custom scrollbars ----- */
* {
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,.08) transparent;
}
html.light * {
  scrollbar-color: rgba(0,0,0,.1) transparent;
}
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,.06);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
  transition: background .15s;
}
*::-webkit-scrollbar-thumb:hover {
  background: rgba(255,255,255,.18);
  background-clip: padding-box;
  border: 2px solid transparent;
}
html.light *::-webkit-scrollbar-thumb { background: rgba(0,0,0,.08); background-clip: padding-box; border: 2px solid transparent; }
html.light *::-webkit-scrollbar-thumb:hover { background: rgba(0,0,0,.16); background-clip: padding-box; border: 2px solid transparent; }
*::-webkit-scrollbar-corner { background: transparent; }

body {
  background:
    radial-gradient(1100px 600px at 80% -10%, rgba(122, 252, 177, 0.08), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(74, 215, 255, 0.06), transparent 60%),
    var(--bg-0);
  color: var(--text);
  font-family: 'Space Grotesk', system-ui, sans-serif;
  font-size: 15px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
html.light body {
  background:
    radial-gradient(1100px 600px at 80% -10%, rgba(13, 159, 90, 0.04), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(10, 127, 194, 0.03), transparent 60%),
    var(--bg-0);
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }

/* ----- Top bar ----- */
.topbar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 24px;
  align-items: center;
  padding: 14px 32px;
  border-bottom: 1px solid var(--line);
  background: rgba(10, 13, 18, 0.96);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  position: sticky;
  top: 0;
  z-index: 50;
}
html.light .topbar {
  background: rgba(247, 248, 250, 0.96);
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 18px;
  letter-spacing: -0.01em;
}
.brand-text b { font-weight: 700; }
.brand-dim {
  color: var(--text-mute);
  font-size: 12px;
  margin-left: 4px;
}

.nav {
  display: flex;
  gap: 4px;
  justify-content: center;
}
.nav a {
  padding: 8px 14px;
  border-radius: 8px;
  color: var(--text-dim);
  font-weight: 500;
  font-size: 14px;
  transition: all .15s ease;
}
.nav a:hover { color: var(--text); background: var(--bg-2); }
.nav a.active {
  color: var(--text);
  background: var(--bg-3);
}

.topbar-right {
  display: flex;
  gap: 12px;
  align-items: center;
}

/* ----- API key pill ----- */
.api-key-pill {
  display: flex;
  gap: 6px;
  align-items: center;
  background: var(--bg-2);
  padding: 4px 4px 4px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
}
.api-key-pill input {
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  width: 180px;
}
.api-key-pill input::placeholder { color: var(--text-mute); }
.api-key-pill button {
  background: var(--accent);
  color: #0a0d12;
  border: none;
  padding: 6px 14px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 12px;
  transition: background .12s ease;
}
.api-key-pill button:hover { filter: brightness(1.1); }
.api-key-pill .api-key-icon {
  background: transparent;
  color: var(--text-dim);
  padding: 4px;
  width: 26px;
  height: 26px;
  display: none;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  transition: color .12s ease, background .12s ease;
}
.api-key-pill .api-key-icon:hover {
  background: var(--bg-3);
  color: var(--text);
}
.api-key-pill #api-key-clear:hover { color: var(--danger); }
.api-key-pill.saved .api-key-icon { display: inline-flex; }
.api-key-pill.saved #api-key-save { display: none; }
.api-key-pill.saved input { color: var(--text-dim); cursor: default; }
.api-key-pill.saved.revealed input { color: var(--text); }

/* ----- Theme toggle ----- */
.theme-toggle {
  background: var(--bg-2);
  border: 1px solid var(--line);
  color: var(--text-dim);
  width: 36px;
  height: 36px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: color .15s, background .15s;
  padding: 0;
}
.theme-toggle:hover { color: var(--text); background: var(--bg-3); }
html.dark .icon-sun { display: none; }
html.dark .icon-moon { display: block; }
html.light .icon-sun { display: block; }
html.light .icon-moon { display: none; }

/* ----- Main view ----- */
main {
  flex: 1;
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: 36px 32px 64px;
}

/* ----- Hero / overview ----- */
.hero-section { margin-bottom: 48px; }
.hero-section h1 {
  font-size: 44px;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.1;
  margin: 0 0 14px;
}
.hero-section h1 em {
  font-style: normal;
  background: linear-gradient(120deg, var(--accent) 0%, var(--accent-2) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.hero-section .subtitle {
  color: var(--text-dim);
  font-size: 17px;
  line-height: 1.55;
  max-width: 600px;
  margin: 0;
}

/* ----- Stats grid ----- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin: 32px 0;
}
.stat-card {
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  position: relative;
  overflow: hidden;
}
.stat-card::after {
  content: '';
  position: absolute;
  top: 0; right: 0; width: 80px; height: 80px;
  background: radial-gradient(circle at 100% 0%, rgba(122,252,177,.1), transparent 70%);
  pointer-events: none;
}
html.light .stat-card::after {
  background: radial-gradient(circle at 100% 0%, rgba(13,159,90,.06), transparent 70%);
}
.stat-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-mute);
  margin-bottom: 8px;
}
.stat-value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.02em;
}
.stat-sub {
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-dim);
}

/* ----- Section ----- */
.section {
  margin-bottom: 48px;
}
.section-title {
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin: 0 0 6px;
}
.section-desc {
  color: var(--text-dim);
  font-size: 14px;
  line-height: 1.6;
  margin: 0 0 20px;
}

/* ----- Cards ----- */
.card {
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  margin-bottom: 16px;
}
.card-header {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 10px;
}
.card-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

/* ----- Quick-start steps ----- */
.steps-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin: 24px 0;
}
.step-card {
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
}
.step-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: rgba(122, 252, 177, 0.12);
  color: var(--accent);
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 10px;
}
html.light .step-num {
  background: rgba(13, 159, 90, 0.1);
}
.step-card h4 {
  margin: 0 0 6px;
  font-size: 14px;
  font-weight: 600;
}
.step-card p {
  margin: 0;
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.5;
}

/* ----- Code tabs ----- */
.code-tabs {
  display: flex;
  gap: 2px;
  background: var(--bg-3);
  padding: 3px;
  border-radius: 999px;
  border: 1px solid var(--line);
  width: fit-content;
  margin-bottom: 12px;
}
.code-tabs button {
  background: transparent;
  border: none;
  color: var(--text-mute);
  padding: 5px 12px;
  border-radius: 999px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  transition: all .15s ease;
}
.code-tabs button:hover { color: var(--text); }
.code-tabs button.active {
  background: var(--bg-1);
  color: var(--text);
  box-shadow: 0 1px 0 0 rgba(255,255,255,.04), inset 0 0 0 1px var(--line-strong);
}
html.light .code-tabs button.active {
  box-shadow: 0 1px 3px rgba(0,0,0,.06), inset 0 0 0 1px var(--line-strong);
}

/* ----- Code blocks ----- */
pre {
  background: var(--code-bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0;
  overflow-x: auto;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12.5px;
  line-height: 1.65;
  margin: 12px 0 18px;
  position: relative;
}
pre code,
pre code.hljs {
  display: block;
  padding: 16px 18px !important;
  background: transparent !important;
  border: none !important;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12.5px;
  line-height: 1.65;
  color: #c9d1d9;
  white-space: pre;
}
html.light pre code,
html.light pre code.hljs {
  color: #24292f;
}

/* Inline code */
code {
  font-family: 'JetBrains Mono', monospace;
  background: var(--bg-2);
  padding: 1px 7px;
  border-radius: 5px;
  font-size: 0.86em;
  border: 1px solid var(--line);
}
pre code { border: none; background: none; padding: 0; }

/* Copy button */
.copy-btn {
  position: absolute;
  top: 10px;
  right: 12px;
  z-index: 2;
  background: rgba(22, 27, 37, 0.92);
  border: 1px solid var(--line-strong);
  color: var(--text);
  padding: 5px 12px;
  border-radius: 7px;
  font-size: 11px;
  font-weight: 600;
  font-family: 'JetBrains Mono', monospace;
  cursor: pointer;
  transition: all .15s ease;
  backdrop-filter: blur(6px);
}
.copy-btn:hover { border-color: var(--accent); color: var(--accent); }
.copy-btn.ok { background: rgba(122, 252, 177, 0.18); color: var(--accent); border-color: var(--accent); }
html.light .copy-btn {
  background: rgba(255,255,255,.92);
  color: var(--text);
}

/* ----- Method badges ----- */
.method-badge {
  display: inline-block;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 3px 10px;
  border-radius: 6px;
  text-transform: uppercase;
}
.method-badge.post {
  background: rgba(122, 252, 177, 0.15);
  color: var(--accent);
}
.method-badge.get {
  background: rgba(74, 215, 255, 0.15);
  color: var(--accent-2);
}
html.light .method-badge.post {
  background: rgba(13, 159, 90, 0.1);
}
html.light .method-badge.get {
  background: rgba(10, 127, 194, 0.1);
}

.endpoint-path {
  font-family: 'JetBrains Mono', monospace;
  font-size: 15px;
  font-weight: 600;
}
.endpoint-desc {
  color: var(--text-dim);
  font-size: 13px;
  margin: 8px 0 14px;
  line-height: 1.5;
}

/* Collapsible sections inside endpoint cards */
.collapse-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 600;
  padding: 8px 0;
  cursor: pointer;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  transition: color .12s;
}
.collapse-toggle:hover { color: var(--text); }
.collapse-toggle::before {
  content: '▸';
  font-size: 10px;
  display: inline-block;
  transition: transform .15s ease;
}
.collapse-toggle.open::before { transform: rotate(90deg); }
.collapse-body {
  display: none;
  margin-top: 8px;
}
.collapse-body.open { display: block; }

/* ----- Models page ----- */
.filter-bar {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.filter-tabs {
  display: flex;
  gap: 2px;
  background: var(--bg-2);
  padding: 3px;
  border-radius: 999px;
  border: 1px solid var(--line);
}
.filter-tabs button {
  background: transparent;
  border: none;
  color: var(--text-mute);
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  transition: all .15s ease;
}
.filter-tabs button:hover { color: var(--text); }
.filter-tabs button.active {
  background: var(--bg-3);
  color: var(--text);
}
.filter-search {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  padding: 8px 14px;
  font-size: 13px;
  outline: none;
  flex: 1;
  min-width: 180px;
  max-width: 320px;
  font-family: inherit;
}
.filter-search:focus { border-color: var(--accent); }
.filter-search::placeholder { color: var(--text-mute); }

.sort-select {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  padding: 8px 12px;
  font-size: 12px;
  font-family: inherit;
  outline: none;
}
.sort-select:focus { border-color: var(--accent); }

.models-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
}

.model-card {
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.model-card:hover {
  border-color: var(--line-strong);
  background: var(--bg-2);
}
.model-card .mc-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 6px;
}
.model-card .mc-head h4 {
  margin: 0;
  font-family: 'JetBrains Mono', monospace;
  font-size: 14px;
  color: var(--text);
}
.type-badge {
  font-size: 10px;
  padding: 2px 8px;
  background: var(--bg-3);
  border-radius: 999px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}
.type-badge.type-image { background: rgba(59, 130, 246, 0.15); color: #60a5fa; }
.type-badge.type-video { background: rgba(168, 85, 247, 0.15); color: #c084fc; }
.type-badge.type-upscale { background: rgba(245, 158, 11, 0.15); color: #fbbf24; }
.type-badge.type-3d { background: rgba(16, 185, 129, 0.15); color: #34d399; }
.model-card .mc-name {
  font-size: 12px;
  color: var(--text-mute);
  margin-bottom: 8px;
}
.model-card .mc-meta {
  display: flex;
  gap: 14px;
  font-size: 11px;
  color: var(--text-dim);
}
.model-card .mc-meta span {
  font-family: 'JetBrains Mono', monospace;
}

/* Model detail (expanded) */
.model-detail {
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 20px;
}
.model-detail .md-head {
  display: flex;
  align-items: baseline;
  gap: 14px;
  margin-bottom: 16px;
}
.model-detail .md-head h3 {
  margin: 0;
  font-family: 'JetBrains Mono', monospace;
  font-size: 18px;
}
.model-detail .md-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-dim);
  font-size: 12px;
  margin-bottom: 14px;
  cursor: pointer;
  border: none;
  background: none;
  font-family: inherit;
  padding: 0;
  transition: color .12s;
}
.model-detail .md-back:hover { color: var(--accent); }

/* ----- Params table ----- */
table.params-table {
  width: 100%;
  border-collapse: collapse;
  margin: 10px 0 22px;
  font-size: 13px;
}
.params-table th {
  text-align: left;
  font-size: 11px;
  color: var(--text-mute);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
}
.params-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
.params-table .pname {
  font-family: 'JetBrains Mono', monospace;
  color: var(--text);
}
.params-table .ptype {
  font-family: 'JetBrains Mono', monospace;
  color: var(--accent-2);
  font-size: 12px;
}
.params-table .preq {
  font-size: 10px;
  color: var(--accent-warm);
  letter-spacing: 0.06em;
  margin-left: 6px;
}
.params-table .pdesc { color: var(--text-dim); }
.params-table .pconstraint {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--text-mute);
}

/* ----- Playground ----- */
.pg-grid {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 24px;
}
.pg-sidebar {
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 10px 16px 16px;
  position: sticky;
  top: 90px;
  align-self: start;
  max-height: calc(100vh - 110px);
  overflow-y: auto;
  overflow-x: hidden;
}
.pg-sidebar::-webkit-scrollbar { width: 6px; }
.pg-sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,.05); border: none; }
.pg-sidebar:hover::-webkit-scrollbar-thumb { background: rgba(255,255,255,.14); }

.pg-search {
  width: 100%;
  background: var(--bg-2);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 9px 12px;
  border-radius: 8px;
  outline: none;
  font-size: 13px;
  margin-bottom: 14px;
  font-family: inherit;
}
.pg-search:focus { border-color: var(--accent); }
.pg-search::placeholder { color: var(--text-mute); }

.pg-section-label {
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-mute);
  padding: 14px 6px 8px;
}
.pg-model-btn {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-dim);
  padding: 9px 10px;
  border-radius: 8px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12.5px;
  margin-bottom: 2px;
  transition: background .15s;
}
.pg-model-btn:hover { background: var(--bg-2); color: var(--text); }
.pg-model-btn.active {
  background: var(--bg-3);
  color: var(--text);
  border-color: var(--line-strong);
}
.pg-model-name {
  display: block;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 11px;
  color: var(--text-mute);
  margin-top: 2px;
}

.pg-main {
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 26px 28px;
  min-height: 420px;
  min-width: 0;
  overflow: hidden;
}
.pg-title {
  display: flex;
  align-items: baseline;
  gap: 14px;
  margin-bottom: 6px;
}
.pg-title h2 {
  margin: 0;
  font-size: 22px;
  font-weight: 600;
}
.pg-title .badge {
  font-size: 10px;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--bg-3);
  color: var(--text-dim);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-weight: 600;
}
.pg-id {
  font-family: 'JetBrains Mono', monospace;
  color: var(--text-mute);
  font-size: 12px;
  margin-bottom: 22px;
}

/* ----- Form fields ----- */
.field {
  display: block;
  margin-bottom: 14px;
  min-width: 0;
}
.field-label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 16px;
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 5px;
  flex-wrap: wrap;
}
.field-label > span:first-child {
  font-family: 'JetBrains Mono', monospace;
  white-space: nowrap;
}
.field-label .req { color: var(--accent-warm); font-size: 10px; margin-left: 4px; }
.field-help {
  color: var(--text-mute);
  font-size: 11px;
  text-align: right;
  flex: 1;
  min-width: 0;
  line-height: 1.4;
}
.field input[type=text],
.field input[type=number],
.field textarea,
.field select {
  width: 100%;
  max-width: 100%;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  padding: 10px 12px;
  font-family: inherit;
  font-size: 13px;
  outline: none;
  transition: border-color .15s;
}
.field input:focus, .field textarea:focus, .field select:focus {
  border-color: var(--accent);
}
.field textarea {
  resize: vertical;
  min-height: 84px;
  font-family: 'Space Grotesk', sans-serif;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  line-height: 1.5;
}
.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

/* Submit row */
.submit-row {
  display: flex;
  gap: 10px;
  margin-top: 22px;
}
.btn-primary {
  padding: 12px 22px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 14px;
  border: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: all .15s ease;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
  color: #0a0d12;
  cursor: pointer;
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}
.btn-secondary {
  padding: 12px 22px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 14px;
  border: 1px solid var(--line-strong);
  background: var(--bg-2);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: all .15s ease;
  cursor: pointer;
}
.btn-secondary:hover { background: var(--bg-3); }

/* Snippet panel */
.snippet-panel {
  margin-top: 28px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.snippet-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  gap: 12px;
  flex-wrap: wrap;
}
.snippet-title {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.snippet-title > span:first-child {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.snippet-meta { color: var(--text-mute); font-size: 11px; }
.snippet-body { position: relative; }
.snippet-body pre {
  margin: 0;
  border-radius: 0;
  border: none;
  border-top: 0;
  max-height: 380px;
}

/* ----- Result ----- */
.result {
  margin-top: 28px;
  padding: 18px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.result-status {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 10px;
  display: flex;
  gap: 10px;
  align-items: center;
}
.result-status .pulse {
  width: 8px; height: 8px; border-radius: 999px;
  background: var(--accent-2);
  box-shadow: 0 0 0 0 rgba(74,215,255,0.7);
  animation: pulse 1.5s infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(74,215,255,.7); }
  70% { box-shadow: 0 0 0 12px rgba(74,215,255,0); }
  100% { box-shadow: 0 0 0 0 rgba(74,215,255,0); }
}
.result-media {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
  margin-top: 12px;
}
.result-media img, .result-media video {
  width: 100%;
  border-radius: 8px;
  background: #000;
  display: block;
}
.result-error {
  color: var(--danger);
  font-size: 13px;
  padding: 10px 12px;
  background: rgba(255,107,107,.08);
  border-radius: 8px;
}
.result-success {
  color: var(--accent);
  font-size: 13px;
  padding: 10px 12px;
  background: rgba(122,252,177,.08);
  border-radius: 8px;
}

/* Live status */
.pg-status {
  margin: 14px 0 18px;
  padding: 10px 14px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  display: flex;
  gap: 10px;
  align-items: center;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg-2);
  color: var(--text-dim);
  transition: background .2s, border-color .2s, color .2s;
}
.pg-status[hidden] { display: none; }
.pg-status .pulse { flex: 0 0 auto; }
.pg-status.pending, .pg-status.running {
  border-color: rgba(74,215,255,.35);
  background: rgba(74,215,255,.06);
  color: var(--text);
}
.pg-status.success {
  border-color: rgba(102,210,150,.4);
  background: rgba(102,210,150,.08);
  color: var(--text);
}
.pg-status.success .pulse { display: none; }
.pg-status.error {
  border-color: rgba(255,107,107,.45);
  background: rgba(255,107,107,.08);
  color: var(--danger);
}
.pg-status.error .pulse { display: none; }

/* ----- Cost table ----- */
.cost-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin: 12px 0;
}
.cost-table th {
  text-align: left;
  font-size: 11px;
  color: var(--text-mute);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
}
.cost-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
}
.cost-table td:last-child { color: var(--accent); }

/* ----- Auth section ----- */
.auth-section code {
  font-size: 13px;
}

/* ----- Empty ----- */
.empty {
  text-align: center;
  padding: 40px;
  color: var(--text-mute);
  font-size: 13px;
}

/* ----- Loading ----- */
.loading {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-mute);
  font-size: 14px;
}
.loading::before {
  content: '';
  display: block;
  width: 32px;
  height: 32px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  margin: 0 auto 14px;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ----- Footer ----- */
.footer {
  padding: 16px 32px;
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-mute);
}
.footer-link {
  font-family: 'JetBrains Mono', monospace;
  color: var(--text-dim);
  transition: color .12s;
}
.footer-link:hover { color: var(--accent); }

/* ----- Mobile menu toggle ----- */
.menu-toggle {
  display: none;
  background: var(--bg-2);
  border: 1px solid var(--line);
  color: var(--text);
  width: 38px;
  height: 38px;
  border-radius: 10px;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
}
.menu-toggle svg { width: 18px; height: 18px; display: block; }

/* =========================================================================
   Responsive
   ========================================================================= */

@media (max-width: 1024px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .steps-grid { grid-template-columns: 1fr; }
  .pg-grid { grid-template-columns: 1fr; gap: 16px; }
  .pg-sidebar { position: static; max-height: 280px; padding: 14px; }
  .models-grid { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
}

@media (max-width: 860px) {
  .topbar {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    padding: 12px 18px;
  }
  .topbar > .brand { margin-right: auto; }
  .nav {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    flex-direction: column;
    background: var(--bg-1);
    border-bottom: 1px solid var(--line);
    padding: 8px 16px 16px;
    gap: 2px;
    transform: translateY(-110%);
    transition: transform .25s ease;
    pointer-events: none;
    box-shadow: 0 12px 30px rgba(0,0,0,0.35);
    z-index: 60;
    visibility: hidden;
  }
  .nav.open {
    transform: translateY(0);
    pointer-events: auto;
    visibility: visible;
  }
  .nav a { padding: 12px 14px; }
  body.menu-open { overflow: hidden; }
  .menu-toggle { display: inline-flex; }
  .brand-dim { display: none; }
  .brand { font-size: 16px; }
  .topbar-right { gap: 8px; }
  .api-key-pill { padding: 3px 3px 3px 10px; }
  .api-key-pill input { width: 110px; font-size: 11px; }
  .api-key-pill button { padding: 5px 12px; font-size: 11px; }
  .api-key-pill .api-key-icon { width: 24px; height: 24px; padding: 3px; }
  .hero-section h1 { font-size: 32px; }
  .footer { flex-direction: column; gap: 6px; text-align: center; padding: 14px 18px; }
  .field-row { grid-template-columns: 1fr; }
  .pg-main { padding: 20px; }
}

@media (max-width: 640px) {
  main { padding: 22px 14px 48px; }
  .topbar { padding: 10px 14px; gap: 10px; }
  .api-key-pill input { width: 80px; }
  .stats-grid { grid-template-columns: 1fr; }
  .stat-value { font-size: 24px; }
  .hero-section h1 { font-size: 28px; }
  .models-grid { grid-template-columns: 1fr; }
  pre, pre code, pre code.hljs { font-size: 11px; }
  pre code, pre code.hljs {
    padding: 12px 14px !important;
    white-space: pre-wrap;
    word-break: break-word;
  }
  .result-media { grid-template-columns: 1fr; }
}

@media (max-width: 460px) {
  .brand-text { display: none; }
  .api-key-pill input { width: 60px; }
  .api-key-pill { padding: 3px 3px 3px 8px; }
  .api-key-pill button { padding: 4px 9px; }
}

/* iOS safe-area */
@supports (padding: env(safe-area-inset-bottom)) {
  body { padding-bottom: env(safe-area-inset-bottom); }
  .topbar { padding-top: max(14px, env(safe-area-inset-top)); }
}

@media (hover: none) {
  .stat-card::after { display: none; }
  .btn-primary:hover { transform: none; }
}

/* ----- hljs light theme override ----- */
html.light pre code.hljs,
html.light pre code {
  color: #24292f;
}
html.light .hljs-comment,
html.light .hljs-quote { color: #6a737d; }
html.light .hljs-keyword,
html.light .hljs-selector-tag { color: #cf222e; }
html.light .hljs-string,
html.light .hljs-attr { color: #0a3069; }
html.light .hljs-number,
html.light .hljs-literal { color: #0550ae; }
html.light .hljs-title,
html.light .hljs-section { color: #953800; }
html.light .hljs-built_in { color: #8250df; }
html.light .hljs-name { color: #116329; }
html.light .hljs-attribute { color: #0550ae; }

/* ── Live Dashboard ────────────────────────────────────────── */
.live-dashboard { margin-bottom: 40px; }
.dash-header { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.dash-header .section-title { margin: 0; }
.dash-pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); animation: pulse 2s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }

.stats-grid-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 860px) { .stats-grid-4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 460px) { .stats-grid-4 { grid-template-columns: 1fr; } }

.dash-panels { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 16px; }
@media (max-width: 860px) { .dash-panels { grid-template-columns: 1fr; } }

.dash-panel {
  background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; min-height: 180px;
}
.dash-panel h3 { margin: 0 0 14px; font-size: 14px; color: var(--text-dim); font-weight: 500; text-transform: uppercase; letter-spacing: 0.5px; }

.dash-list { display: flex; flex-direction: column; gap: 8px; }
.dash-row { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.dash-model { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-family: 'JetBrains Mono', monospace; font-size: 12px; }
.dash-count { color: var(--text-dim); font-size: 12px; white-space: nowrap; }
.dash-meta { color: var(--text-dim); font-size: 12px; margin-left: auto; white-space: nowrap; }
.dash-empty { color: var(--text-mute); font-size: 13px; font-style: italic; }

.dash-bar-wrap { flex: 1; height: 6px; background: var(--bg-3); border-radius: 3px; overflow: hidden; max-width: 120px; }
.dash-bar { height: 100%; background: var(--accent); border-radius: 3px; transition: width 0.3s ease; }

.badge-sm { font-size: 10px; padding: 2px 6px; border-radius: 4px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.3px; }
.badge-ok { background: rgba(122, 252, 177, 0.15); color: var(--accent); }
.badge-proc { background: rgba(74, 215, 255, 0.15); color: var(--accent-2); }
.badge-fail { background: rgba(255, 107, 107, 0.15); color: var(--danger); }

html.light .dash-panel { background: #f6f8fa; border-color: #d0d7de; }
html.light .dash-bar-wrap { background: #e1e4e8; }
html.light .badge-ok { background: rgba(26, 127, 55, 0.1); color: #1a7f37; }
html.light .badge-proc { background: rgba(9, 105, 218, 0.1); color: #0969da; }
html.light .badge-fail { background: rgba(207, 34, 46, 0.1); color: #cf222e; }

/* ── Image Upload ── */
.upload-zone {
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  min-height: 80px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.upload-zone:hover, .upload-zone.dragover {
  border-color: var(--accent);
  background: rgba(122, 252, 177, 0.04);
}
.upload-zone.upload-required {
  border-color: rgba(245, 158, 11, 0.5);
}
.upload-zone.upload-required:hover {
  border-color: rgba(245, 158, 11, 0.8);
  background: rgba(245, 158, 11, 0.04);
}
.upload-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  color: var(--text-dim);
  font-size: 13px;
}
.upload-placeholder svg { opacity: 0.5; }
.upload-placeholder a { color: var(--accent); text-decoration: none; }
.upload-placeholder a:hover { text-decoration: underline; }
.upload-hint { font-size: 11px; color: var(--text-mute); }

.prompt-counter {
  font-size: 11px;
  color: var(--text-muted, #888);
  text-align: right;
  margin-top: 3px;
}
.prompt-counter--warn { color: #f59e0b; }
.prompt-counter--over { color: #ef4444; font-weight: 600; }

.pg-tip {
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 12px;
  line-height: 1.5;
}

.upload-previews {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}
.upload-thumb {
  position: relative;
  width: 72px;
  height: 72px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--line);
}
.upload-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.upload-remove {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 20px;
  height: 20px;
  border: 1.5px solid rgba(255,255,255,0.8);
  border-radius: 50%;
  background: rgba(0,0,0,0.75);
  color: #fff;
  font-size: 13px;
  font-weight: bold;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  z-index: 10;
  transition: background 0.15s, transform 0.1s;
}
.upload-remove:hover { background: var(--danger); transform: scale(1.15); }
.upload-spinner {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
}
.upload-spinner::after {
  content: '';
  width: 20px;
  height: 20px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.upload-ok-badge {
  position: absolute;
  bottom: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  color: #000;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}
.upload-error-badge {
  position: absolute;
  bottom: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}
.upload-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
}
.upload-controls select {
  background: var(--bg-2);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 12px;
}
.btn-sm { padding: 4px 10px !important; font-size: 12px !important; }
