:root {
  --bg: #f7f5ef;
  --bg-elev: #ffffff;
  --bg-elev-2: #f1efe7;
  --bg-sidebar: #f3f1e8;
  --border: #e6e2d5;
  --border-strong: #d5d0bf;
  --fg: #1a1a1a;
  --fg-dim: #6b6b6b;
  --fg-muted: #9b9b9b;
  --accent: #1f4d3a;
  --accent-hover: #163827;
  --accent-soft: #e8efe9;
  --accent-fg: #ffffff;
  --highlight: #6c5ce7;
  --highlight-soft: rgba(108, 92, 231, 0.08);
  --success: #3fb55a;
  --success-soft: rgba(63, 181, 90, 0.12);
  --danger: #d63a3a;
  --hero-from: #d8eddc;
  --hero-mid: #e8e6f4;
  --hero-to: #d9d2f5;
  --shadow-sm: 0 1px 2px rgba(20, 30, 25, 0.04);
  --shadow-md: 0 2px 6px rgba(20, 30, 25, 0.05);
  --radius: 12px;
  --radius-sm: 8px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- sidebar ---------- */

.sidebar {
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 28px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  color: var(--accent);
  display: flex;
  align-items: center;
  padding: 0 6px;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  color: var(--fg-dim);
  font-size: 14px;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}
.nav-item:hover { color: var(--fg); background: rgba(0,0,0,0.03); text-decoration: none; }
.nav-item.active { color: var(--accent); font-weight: 600; }
.nav-item.active svg { stroke-width: 2.25; }

/* ---------- top bar ---------- */

.app {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 32px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}

.page-title {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

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

.badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 12px;
  color: var(--fg-dim);
}
.badge code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 11px;
  color: var(--fg);
}
.badge-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 0 3px var(--success-soft);
}

/* ---------- main ---------- */

main {
  padding: 28px 32px 48px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  max-width: 1400px;
  width: 100%;
}

/* ---------- hero ---------- */

.hero {
  position: relative;
  background: linear-gradient(115deg, var(--hero-from) 0%, var(--hero-mid) 50%, var(--hero-to) 100%);
  border-radius: var(--radius);
  padding: 36px 40px;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 24px;
  color: var(--accent);
  border: 1px solid rgba(255, 255, 255, 0.5);
  overflow: hidden;
}
.hero::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    radial-gradient(circle at 80% 20%, rgba(255,255,255,0.4) 0%, transparent 40%),
    radial-gradient(circle at 20% 80%, rgba(108,92,231,0.08) 0%, transparent 40%);
  pointer-events: none;
}
.hero > * { position: relative; }

.hero h1 {
  margin: 0 0 10px;
  font-size: 32px;
  letter-spacing: -0.02em;
  font-weight: 600;
  color: var(--fg);
  line-height: 1.15;
}
.hero h1 em {
  font-style: italic;
  color: var(--highlight);
  font-weight: 600;
}
.hero p {
  margin: 0;
  color: var(--fg-dim);
  font-size: 15px;
  max-width: 56ch;
}
.hero-art {
  color: var(--accent);
  opacity: 0.9;
}
.hero-art svg { width: 220px; height: 140px; display: block; }

@media (max-width: 760px) {
  .hero { grid-template-columns: 1fr; padding: 24px; }
  .hero-art { display: none; }
  .hero h1 { font-size: 26px; }
}

/* ---------- layout grid ---------- */

.layout {
  display: grid;
  grid-template-columns: minmax(380px, 460px) minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}
@media (max-width: 1100px) { .layout { grid-template-columns: 1fr; } }

/* ---------- card ---------- */

.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.2s;
}
.card:hover { box-shadow: var(--shadow-md); }

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 0 14px;
}
.card-head h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--fg-dim);
  text-transform: none;
  letter-spacing: 0;
}
.card-head-meta {
  font-size: 12px;
  color: var(--fg-muted);
}

/* ---------- controls ---------- */

.controls { display: flex; flex-direction: column; gap: 14px; }

.dropzone {
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 22px 16px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
  color: var(--fg-dim);
  background: var(--bg);
}
.dropzone:hover { border-color: var(--accent); color: var(--fg); }
.dropzone.drag {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}
.dropzone p { margin: 4px 0; font-size: 13px; }
.dropzone strong { color: var(--fg); }
.dropzone .hint { color: var(--fg-muted); font-size: 11px; }
.dropzone-icon {
  color: var(--accent);
  margin-bottom: 4px;
}

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
  padding: 0;
  font: inherit;
}

.prompt-label, .chips-label {
  font-weight: 600;
  font-size: 12px;
  color: var(--fg-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-top: 4px;
}

textarea {
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font: inherit;
  font-size: 13px;
  resize: vertical;
  transition: border-color 0.15s, box-shadow 0.15s;
}
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.chips {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.chip {
  background: var(--bg);
  color: var(--fg-dim);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  text-align: left;
  line-height: 1.4;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.chip:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-soft);
}

.actions {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 4px;
}
.primary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--accent);
  color: var(--accent-fg);
  border: none;
  border-radius: var(--radius-sm);
  padding: 9px 18px;
  font: inherit;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s;
}
.primary:disabled {
  background: var(--border-strong);
  color: var(--fg-muted);
  cursor: not-allowed;
}
.primary:not(:disabled):hover { background: var(--accent-hover); }
.primary:not(:disabled):active { transform: translateY(0.5px); }

.secondary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-elev-2);
  color: var(--fg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font: inherit;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.secondary:disabled { color: var(--fg-muted); cursor: not-allowed; opacity: 0.6; }
.secondary:not(:disabled):hover {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

select#model-select {
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%231f4d3a' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}
select#model-select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.kbd-hint {
  font-size: 11px;
  color: var(--fg-muted);
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.kbd-hint kbd {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  font-family: inherit;
  font-size: 10px;
  color: var(--fg-dim);
}

.ghost-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 10px;
  font: inherit;
  font-size: 11px;
  color: var(--fg-dim);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.ghost-btn:hover { color: var(--accent); border-color: var(--accent); }

.status {
  color: var(--fg-dim);
  font-size: 12px;
  min-height: 18px;
}
.status.error { color: var(--danger); }
.status.ok { color: var(--success); }

/* ---------- results ---------- */

.results { display: flex; flex-direction: column; gap: 20px; min-width: 0; }

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  animation: fade-up 0.3s ease-out;
}
@keyframes fade-up {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
@media (max-width: 700px) { .stats { grid-template-columns: 1fr; } }

.stat-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.stat-icon {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-soft);
  color: var(--accent);
  flex-shrink: 0;
}
.stat-body { min-width: 0; }
.stat-label {
  font-size: 11px;
  color: var(--fg-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 2px;
}
.stat-value {
  font-size: 18px;
  font-weight: 600;
  color: var(--fg);
}

/* ---------- canvas card ---------- */

.canvas-wrap {
  position: relative;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  min-height: 320px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.canvas-wrap::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(
    100deg,
    transparent 0%,
    transparent 35%,
    rgba(108, 92, 231, 0.08) 50%,
    transparent 65%,
    transparent 100%
  );
  background-size: 200% 100%;
  background-position: 100% 0;
  opacity: 0;
  transition: opacity 0.2s;
}
.canvas-wrap.loading::after {
  opacity: 1;
  animation: shimmer 1.4s ease-in-out infinite;
}
@keyframes shimmer {
  0%   { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}
.canvas-wrap canvas {
  max-width: 100%;
  height: auto;
  display: block;
  background: #fff;
}
.canvas-empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--fg-muted);
  pointer-events: none;
}
.canvas-empty p { margin: 0; font-size: 13px; }
.canvas-wrap.has-image .canvas-empty { display: none; }

/* ---------- json card ---------- */

/* ---------- compare view ---------- */

.compare-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  align-items: start;
}
@media (max-width: 1300px) { .compare-grid { grid-template-columns: 1fr; } }

.compare-card .canvas-wrap { min-height: 240px; }

.mini-stats {
  display: flex;
  gap: 14px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  font-size: 12px;
}
.mini-stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.mini-stat-label {
  color: var(--fg-muted);
  text-transform: uppercase;
  font-size: 10px;
  letter-spacing: 0.04em;
}
.mini-stat b { font-weight: 600; font-size: 14px; }
.mini-pending { color: var(--fg-muted); font-style: italic; }
.mini-error { color: var(--danger); font-size: 12px; }

.json-card pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  max-height: 50vh;
  overflow: auto;
}

/* ---------- responsive ---------- */

@media (max-width: 760px) {
  body { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    gap: 16px;
    padding: 12px 16px;
  }
  .sidebar-nav { flex-direction: row; gap: 4px; }
  .nav-item { padding: 6px 10px; font-size: 13px; }
  .topbar { padding: 14px 20px; }
  .page-title { font-size: 18px; }
  main { padding: 20px 16px 40px; gap: 18px; }
}
