:root {
  --bg: #0b0d12;
  --surface: #151922;
  --surface-2: #1d2330;
  --border: rgba(148, 163, 184, 0.14);
  --text: #eef1f6;
  --muted: #94a3b8;
  --accent: #818cf8;
  --accent-2: #a78bfa;
  --success: #34d399;
  --danger: #f87171;
  --radius: 16px;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "DM Sans", system-ui, sans-serif;
}
body {
  background:
    radial-gradient(900px 500px at 0% -10%, rgba(129, 140, 248, 0.18), transparent 55%),
    radial-gradient(700px 420px at 100% 0%, rgba(167, 139, 250, 0.12), transparent 50%),
    var(--bg);
}

#app {
  max-width: 1120px;
  margin: 0 auto;
  min-height: 100vh;
  padding: 1rem 1rem 5.5rem;
}

.topbar {
  align-items: center;
  display: flex;
  gap: 1rem;
  justify-content: space-between;
  margin-bottom: 1rem;
}
.brand { align-items: center; display: flex; gap: 0.8rem; }
.logo {
  align-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-radius: 14px;
  color: white;
  display: flex;
  font-weight: 700;
  height: 44px;
  justify-content: center;
  width: 44px;
}
.brand h1 {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0;
}
.subtitle { color: var(--muted); font-size: 0.8rem; margin: 0.15rem 0 0; }

.status-pill {
  background: rgba(129, 140, 248, 0.12);
  border: 1px solid rgba(129, 140, 248, 0.28);
  border-radius: 999px;
  color: #c7d2fe;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.35rem 0.7rem;
  white-space: nowrap;
}
.status-pill.ok {
  background: rgba(52, 211, 153, 0.12);
  border-color: rgba(52, 211, 153, 0.35);
  color: var(--success);
}
.status-pill.err {
  background: rgba(248, 113, 113, 0.12);
  border-color: rgba(248, 113, 113, 0.35);
  color: var(--danger);
}

.nav {
  display: flex;
  gap: 0.45rem;
  margin-bottom: 1rem;
}
.nav-btn {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 999px;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0.55rem 1rem;
}
.nav-btn.active {
  background: rgba(129, 140, 248, 0.16);
  border-color: rgba(129, 140, 248, 0.25);
  color: #e0e7ff;
}
.mobile-nav { display: none; }

.section { margin-bottom: 1.2rem; }
.section-head h2 {
  font-size: 1.15rem;
  margin: 0 0 0.25rem;
}
.section-head p {
  color: var(--muted);
  font-size: 0.86rem;
  margin: 0 0 0.85rem;
}

.card {
  background: rgba(21, 25, 34, 0.92);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
}
.runtime-card { margin-bottom: 1rem; }
.card-head {
  align-items: center;
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}
.card h3 { font-size: 0.98rem; margin: 0 0 0.75rem; }

.gpu-grid {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  margin-bottom: 1rem;
}
.gpu-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0.85rem;
}
.gpu-card h4 { font-size: 0.92rem; margin: 0 0 0.35rem; }
.gpu-meta { color: var(--muted); font-size: 0.78rem; line-height: 1.45; }

.form-grid {
  display: grid;
  gap: 0.8rem;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}
.span-full { grid-column: 1 / -1; }
.span-2 { grid-column: span 2; }
@media (max-width: 768px) {
  .span-2 { grid-column: 1 / -1; }
}

.field-label {
  color: var(--muted);
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  margin-bottom: 0.45rem;
}

.compile-components { margin-top: 0.15rem; }
.chip-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.chip-check {
  align-items: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  flex-direction: row;
  font-size: 0.82rem;
  font-weight: 500;
  gap: 0.4rem;
  margin: 0;
  padding: 0.42rem 0.75rem;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.chip-check:has(input:checked) {
  background: rgba(129, 140, 248, 0.14);
  border-color: rgba(129, 140, 248, 0.45);
  color: #e0e7ff;
}
.chip-check input { width: auto; margin: 0; }

.load-card { margin-top: 0; }
.exp-panel {
  background: rgba(15, 18, 26, 0.72);
  border: 1px solid var(--border);
  border-radius: 14px;
  margin-top: 0.9rem;
  padding: 0.9rem;
}
.exp-panel.hidden { display: none; }
.exp-panel-head {
  align-items: center;
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}
.exp-count {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
}
.alias-card { margin-top: 0; }
.alias-divider {
  border-top: 1px solid var(--border);
  margin: 1rem 0 0.85rem;
}
.alias-section-label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  margin: 0.85rem 0 0.65rem;
  text-transform: uppercase;
}
.experiment-original {
  font-size: 0.78rem;
  line-height: 1.45;
  margin-top: 0.35rem;
  word-break: break-all;
}
.alias-list {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}
.alias-item {
  align-items: center;
  background: rgba(148, 163, 184, 0.05);
  border: 1px solid var(--border);
  border-radius: 12px;
  display: flex;
  gap: 0.75rem;
  justify-content: space-between;
  padding: 0.65rem 0.75rem;
}
.alias-item-actions {
  display: flex;
  flex-shrink: 0;
  flex-wrap: wrap;
  gap: 0.4rem;
}
.alias-item-name {
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 700;
}
.alias-item-original {
  color: var(--muted);
  font-size: 0.74rem;
  margin-top: 0.15rem;
  word-break: break-all;
}
.manual-ckpt {
  color: var(--muted);
  font-size: 0.82rem;
  margin-top: 0.75rem;
}
.manual-ckpt summary {
  cursor: pointer;
  font-weight: 600;
  margin-bottom: 0.5rem;
}
.manual-ckpt[open] summary { margin-bottom: 0.65rem; }

.slider-field {
  gap: 0.55rem;
}
.slider-head {
  display: block;
  width: 100%;
}
.slider-row {
  align-items: center;
  display: grid;
  gap: 0.65rem;
  grid-template-columns: minmax(0, 1fr) 92px;
  width: 100%;
}
.slider-input {
  padding: 0.55rem 0.65rem;
  text-align: center;
}
.sampling-grid {
  margin-bottom: 0.15rem;
}
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  background: rgba(148, 163, 184, 0.16);
  border-radius: 999px;
  cursor: pointer;
  height: 6px;
  margin: 0.35rem 0 0.15rem;
  padding: 0;
  width: 100%;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  background: linear-gradient(180deg, #c7d2fe 0%, #818cf8 100%);
  border: 2px solid rgba(15, 18, 26, 0.9);
  border-radius: 50%;
  box-shadow: 0 2px 10px rgba(99, 102, 241, 0.35);
  height: 18px;
  width: 18px;
}
input[type="range"]::-moz-range-thumb {
  background: linear-gradient(180deg, #c7d2fe 0%, #818cf8 100%);
  border: 2px solid rgba(15, 18, 26, 0.9);
  border-radius: 50%;
  box-shadow: 0 2px 10px rgba(99, 102, 241, 0.35);
  height: 18px;
  width: 18px;
}
input[type="range"]::-moz-range-track {
  background: rgba(148, 163, 184, 0.16);
  border: 0;
  border-radius: 999px;
  height: 6px;
}
input[type="range"]:focus-visible {
  outline: 2px solid rgba(129, 140, 248, 0.45);
  outline-offset: 4px;
}
input.plain-number {
  font-variant-numeric: tabular-nums;
}
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
input[type="number"] {
  -moz-appearance: textfield;
  appearance: textfield;
}

label {
  color: var(--muted);
  display: flex;
  flex-direction: column;
  font-size: 0.78rem;
  font-weight: 600;
  gap: 0.4rem;
}
input, select, textarea {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  font: inherit;
  padding: 0.7rem 0.8rem;
  width: 100%;
}
textarea { resize: vertical; }
.form-section {
  border-top: 1px solid var(--border);
  margin-top: 0.9rem;
  padding-top: 0.9rem;
}
.section-label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  margin-bottom: 0.65rem;
  text-transform: uppercase;
}
.inference-details {
  background: rgba(148, 163, 184, 0.04);
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-top: 0.65rem;
  padding: 0.75rem 0.85rem;
}
.inference-details summary {
  cursor: pointer;
  font-weight: 600;
}
.inference-summary,
.schedule-error {
  font-size: 0.82rem;
  margin-top: 0.65rem;
}
.schedule-error {
  color: #fbbf24;
}
.prompt-token-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-top: -0.15rem;
  min-height: 1.4rem;
}
.token-chip {
  background: rgba(148, 163, 184, 0.08);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.78rem;
  line-height: 1.2;
  padding: 0.28rem 0.62rem;
}
.token-chip strong {
  font-weight: 700;
  margin-right: 0.25rem;
}
.token-chip-truncated {
  border-color: rgba(251, 191, 36, 0.45);
  color: #fde68a;
}
.checkbox-row {
  align-items: center;
  flex-direction: row;
  gap: 0.5rem;
  padding-top: 1.4rem;
}
.checkbox-row input { width: auto; }

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-top: 0.9rem;
}
.btn {
  border: 0;
  border-radius: 12px;
  cursor: pointer;
  font: inherit;
  font-weight: 600;
  min-height: 42px;
  padding: 0.55rem 1rem;
}
.btn.primary {
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: white;
}
.btn.secondary {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
}
.btn.ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  min-height: 34px;
  padding: 0.35rem 0.7rem;
}
.btn.small {
  font-size: 0.78rem;
  min-height: 32px;
  padding: 0.3rem 0.65rem;
}

.model-list, .exp-results, .history-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-top: 0.9rem;
}
.history-stats {
  font-size: 0.82rem;
  margin-top: 0.75rem;
}
.history-run {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
}
.history-run-head {
  align-items: flex-start;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.8rem;
  justify-content: space-between;
  padding: 0.85rem 0.95rem 0.7rem;
}
.history-run-title {
  font-size: 0.95rem;
  font-weight: 700;
  margin: 0;
}
.history-run-sub {
  color: var(--muted);
  font-size: 0.78rem;
}
.history-run-body { padding: 0.85rem 0.95rem 0.95rem; }
.history-prompt {
  color: var(--text);
  font-size: 0.9rem;
  line-height: 1.5;
  margin: 0 0 0.7rem;
  white-space: pre-wrap;
}
.history-negative {
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.45;
  margin: -0.35rem 0 0.7rem;
}
.meta-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem 0.5rem;
  margin-bottom: 0.85rem;
}
.meta-chip {
  background: rgba(148, 163, 184, 0.08);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.78rem;
  line-height: 1.2;
  max-width: 100%;
  overflow: hidden;
  padding: 0.28rem 0.62rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.meta-chip strong {
  color: var(--text);
  font-weight: 700;
  margin-right: 0.2rem;
}
.history-media-grid {
  display: grid;
  gap: 0.65rem;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
}
.history-media-card {
  background: rgba(15, 18, 26, 0.72);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}
.history-media-card img,
.history-media-card video {
  display: block;
  width: 100%;
  height: auto;
  background: #0a0c10;
}
.history-media-name {
  color: var(--muted);
  font-size: 0.72rem;
  overflow: hidden;
  padding: 0.45rem 0.55rem 0.5rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.model-item, .exp-item, .history-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.8rem;
}
.model-item.active {
  border-color: rgba(52, 211, 153, 0.45);
  box-shadow: inset 3px 0 0 var(--success);
}
.model-title { font-size: 0.9rem; font-weight: 700; margin: 0 0 0.25rem; }
.model-meta, .muted { color: var(--muted); font-size: 0.76rem; line-height: 1.4; }
.item-actions { display: flex; flex-wrap: wrap; gap: 0.45rem; margin-top: 0.55rem; }

.progress, .job-status {
  background: rgba(129, 140, 248, 0.08);
  border: 1px solid rgba(129, 140, 248, 0.2);
  border-radius: 12px;
  color: #c7d2fe;
  font-size: 0.84rem;
  margin-top: 0.8rem;
  padding: 0.75rem 0.85rem;
}
.hidden { display: none; }

.result-grid {
  display: grid;
  gap: 0.8rem;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  margin-top: 0.9rem;
}
.result-grid img, .result-grid video {
  border-radius: 12px;
  max-width: 100%;
  width: 100%;
}

.empty {
  color: var(--muted);
  font-size: 0.86rem;
  padding: 0.5rem 0;
}

@media (max-width: 768px) {
  #app { padding: 0.85rem 0.85rem 5.8rem; }
  .desktop-nav { display: none; }
  .mobile-nav {
    backdrop-filter: blur(14px);
    background: rgba(11, 13, 18, 0.88);
    border-top: 1px solid var(--border);
    bottom: 0;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    left: 0;
    padding: 0.45rem 0.5rem calc(0.45rem + env(safe-area-inset-bottom));
    position: fixed;
    right: 0;
    z-index: 20;
  }
  .mobile-nav .nav-btn {
    align-items: center;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 0.55rem 0.35rem;
  }
  .topbar { align-items: flex-start; flex-direction: column; }
  .btn { flex: 1 1 100%; }
}
