/* =========================================================
   image-edit — magnesium.team aesthetic, dark theme
   ========================================================= */

:root {
  /* Palette */
  --ink:        #050608;
  --ink-2:      #08090F;
  --ink-3:      #0D0F1A;
  --ink-4:      #161A2E;
  --ink-5:      #1F2540;
  --border:     rgba(37, 99, 235, 0.18);
  --border-soft: rgba(148, 163, 184, 0.10);
  --border-strong: rgba(59, 130, 246, 0.40);

  --text:       #F1F5F9;
  --text-mid:   #CBD5E1;
  --text-dim:   #94A3B8;
  --text-faint: #64748B;

  --brand:        #2563EB;
  --brand-bright: #3B82F6;
  --cyan:         #06B6D4;
  --cyan-bright:  #22D3EE;
  --indigo:       #6366F1;
  --violet:       #8B5CF6;
  --green:        #22C55E;
  --amber:        #F59E0B;
  --red:          #EF4444;

  --grad-brand: linear-gradient(135deg, #2563EB 0%, #06B6D4 100%);
  --grad-soft:  linear-gradient(135deg, rgba(37,99,235,0.18) 0%, rgba(6,182,212,0.10) 100%);

  --r-xs: 6px;
  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 20px;
  --r-pill: 999px;

  --font-display: 'Syne', system-ui, sans-serif;
  --font-body:    'DM Sans', system-ui, sans-serif;
  --font-mono:    'JetBrains Mono', ui-monospace, Menlo, monospace;

  --ease-out:    cubic-bezier(0.22, 1, 0.36, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);

  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 24px;
  --sp-6: 32px;
  --sp-7: 48px;
}

*, *::before, *::after { box-sizing: border-box; }
*  { margin: 0; padding: 0; }
html, body { height: 100%; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font-body);
  font-weight: 400;
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
  background:
    radial-gradient(ellipse at 80% -10%, rgba(37, 99, 235, 0.12) 0%, transparent 50%),
    radial-gradient(ellipse at -10% 100%, rgba(6, 182, 212, 0.08) 0%, transparent 55%),
    var(--ink);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100svh;
}
img, svg { display: block; max-width: 100%; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
[hidden] { display: none !important; }

/* ========== TOPBAR ========== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-4) var(--sp-6);
  background: rgba(5, 6, 8, 0.7);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-soft);
}
.brand { display: inline-flex; align-items: center; gap: var(--sp-3); }
.brand-mark {
  width: 40px;
  height: 40px;
  object-fit: contain;
  flex-shrink: 0;
  filter: drop-shadow(0 4px 14px rgba(37, 99, 235, 0.45));
  transition: transform 0.4s var(--ease-spring);
}
.brand:hover .brand-mark { transform: rotate(-6deg) scale(1.06); }
.brand-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: -0.015em;
}
.brand-tag {
  font-size: 0.75rem;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  padding-left: var(--sp-3);
  border-left: 1px solid var(--border-soft);
  margin-left: var(--sp-2);
}
.topbar-meta {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  font-size: 0.78rem;
  color: var(--text-dim);
  font-family: var(--font-mono);
}
.dot {
  width: 8px; height: 8px;
  border-radius: var(--r-pill);
  background: var(--text-faint);
  display: inline-block;
  transition: background 0.2s;
}
.dot[data-state="ok"] {
  background: var(--green);
  box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.6);
  animation: pulse-ok 2s infinite;
}
.dot[data-state="warn"] { background: var(--amber); }
.dot[data-state="error"] { background: var(--red); }
@keyframes pulse-ok {
  0% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.5); }
  70% { box-shadow: 0 0 0 8px rgba(34, 197, 94, 0); }
  100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}

/* ========== TABS ========== */
.tabs {
  display: flex;
  gap: var(--sp-2);
  padding: var(--sp-5) var(--sp-6) 0;
  max-width: 1280px;
  margin: 0 auto;
  width: 100%;
}
.tab {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.92rem;
  padding: var(--sp-3) var(--sp-5);
  color: var(--text-dim);
  border-radius: var(--r-md) var(--r-md) 0 0;
  border-bottom: 2px solid transparent;
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  transition: color 0.2s, background 0.2s, border-color 0.2s;
  letter-spacing: -0.005em;
}
.tab:hover { color: var(--text); background: rgba(255, 255, 255, 0.03); }
.tab[aria-selected="true"] {
  color: var(--text);
  border-bottom-color: var(--brand-bright);
  background: rgba(37, 99, 235, 0.06);
}
.badge {
  display: inline-grid;
  place-items: center;
  min-width: 22px;
  height: 22px;
  padding: 0 var(--sp-2);
  border-radius: var(--r-pill);
  background: rgba(148, 163, 184, 0.12);
  color: var(--text-mid);
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 500;
}
.tab[aria-selected="true"] .badge {
  background: var(--grad-brand);
  color: white;
}

/* ========== SURFACE ========== */
.surface {
  max-width: 1280px;
  margin: 0 auto;
  padding: var(--sp-5) var(--sp-6) var(--sp-7);
  width: 100%;
}
.panel {
  background: linear-gradient(160deg, var(--ink-3) 0%, var(--ink-2) 100%);
  border: 1px solid var(--border-soft);
  border-radius: var(--r-lg);
  padding: var(--sp-6);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45);
}
.panel-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.5rem;
  letter-spacing: -0.018em;
  color: var(--text);
}
.panel-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
  gap: var(--sp-6);
  align-items: start;
}
@media (max-width: 980px) {
  .panel-grid { grid-template-columns: 1fr; }
}

/* ========== FORM ========== */
.form { display: flex; flex-direction: column; gap: var(--sp-5); }
.form-row { display: flex; flex-direction: column; gap: var(--sp-2); }
.form-row--inline {
  flex-direction: row;
  flex-wrap: wrap;
  gap: var(--sp-4);
  align-items: flex-end;
}
.field { flex: 1 1 160px; min-width: 0; display: flex; flex-direction: column; gap: var(--sp-2); }
.field--small { flex: 0 0 100px; }

.lbl {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.82rem;
  color: var(--text);
  letter-spacing: 0.01em;
}
.lbl-aux { color: var(--text-faint); font-weight: 400; font-size: 0.72rem; margin-left: 4px; }

input[type="text"], input[type="url"], input[type="number"], textarea, select {
  width: 100%;
  padding: 10px 14px;
  background: var(--ink);
  color: var(--text);
  border: 1px solid var(--border-soft);
  border-radius: var(--r-md);
  font-family: var(--font-body);
  font-size: 0.95rem;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}
textarea {
  font-family: var(--font-body);
  resize: vertical;
  min-height: 88px;
  line-height: 1.5;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--brand-bright);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.18);
}
select {
  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 12 12'><path fill='none' stroke='%23CBD5E1' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round' d='M3 4.5l3 3 3-3'/></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}
input::placeholder, textarea::placeholder { color: var(--text-faint); }

.hint {
  font-size: 0.78rem;
  color: var(--text-faint);
  line-height: 1.5;
}
.hint code {
  font-family: var(--font-mono);
  background: rgba(148, 163, 184, 0.1);
  padding: 1px 5px;
  border-radius: var(--r-xs);
  font-size: 0.85em;
}

/* ========== SEGMENTED CONTROL (model toggle) ========== */
.seg {
  display: inline-flex;
  padding: 3px;
  background: var(--ink);
  border: 1px solid var(--border-soft);
  border-radius: var(--r-pill);
  gap: 2px;
}
.seg-btn {
  padding: 7px 16px;
  border-radius: var(--r-pill);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.82rem;
  color: var(--text-dim);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: color 0.2s, background 0.2s;
}
.seg-btn:hover { color: var(--text); }
.seg-btn[data-active="true"] {
  background: var(--grad-brand);
  color: white;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.4);
}
.seg-tag {
  font-size: 0.62rem;
  padding: 1px 5px;
  border-radius: var(--r-xs);
  background: rgba(255, 255, 255, 0.18);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.seg-btn:not([data-active="true"]) .seg-tag { background: var(--cyan); color: white; }

/* ========== BUTTONS ========== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: 11px 22px;
  border-radius: var(--r-pill);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.92rem;
  letter-spacing: -0.005em;
  transition: transform 0.15s, box-shadow 0.15s, background 0.15s, border-color 0.15s, color 0.15s;
  white-space: nowrap;
}
.btn--primary {
  background: var(--grad-brand);
  color: white;
  box-shadow: 0 8px 20px rgba(37, 99, 235, 0.4);
}
.btn--primary:hover { transform: translateY(-1px); box-shadow: 0 12px 28px rgba(37, 99, 235, 0.55); }
.btn--primary:disabled, .btn[aria-busy="true"] { opacity: 0.6; pointer-events: none; transform: none; }
.btn--ghost {
  background: transparent;
  color: var(--text-mid);
  border: 1px solid var(--border-soft);
}
.btn--ghost:hover { color: var(--text); border-color: var(--border); background: rgba(255,255,255,0.03); }
.btn--small { padding: 6px 12px; font-size: 0.78rem; }
.btn--danger { color: var(--red); border-color: rgba(239, 68, 68, 0.3); }
.btn--danger:hover { background: rgba(239, 68, 68, 0.08); border-color: var(--red); color: var(--red); }
.form-actions { display: flex; gap: var(--sp-3); align-items: center; padding-top: var(--sp-2); }

/* spinner */
.btn[aria-busy="true"] .btn-label::after {
  content: '';
  display: inline-block;
  width: 12px; height: 12px;
  margin-left: 8px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ========== SOURCE GROUP (Edit tab) ========== */
.source-group { display: flex; flex-direction: column; gap: var(--sp-3); }
.source-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  padding: 4px;
  background: var(--ink);
  border: 1px solid var(--border-soft);
  border-radius: var(--r-md);
}
.source-tab {
  flex: 1 1 120px;
  padding: 8px 12px;
  border-radius: var(--r-sm);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.78rem;
  color: var(--text-dim);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: color 0.2s, background 0.2s;
}
.source-tab:hover { color: var(--text); }
.source-tab[data-active="true"] {
  background: var(--ink-4);
  color: var(--text);
  box-shadow: inset 0 0 0 1px var(--border);
}
.source-pane { padding: var(--sp-3) 0; }

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: var(--sp-7) var(--sp-5);
  border: 1.5px dashed var(--border-soft);
  border-radius: var(--r-md);
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  text-align: center;
  color: var(--text-dim);
}
.dropzone:hover, .dropzone.is-dragover {
  border-color: var(--brand-bright);
  background: rgba(37, 99, 235, 0.05);
  color: var(--text);
}
.dropzone-icon { font-size: 1.6rem; }
.dropzone-text { font-size: 0.92rem; }

.thumb-preview {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3);
  background: var(--ink-4);
  border: 1px solid var(--border-soft);
  border-radius: var(--r-md);
}
.thumb-preview img { width: 80px; height: 80px; object-fit: contain; border-radius: var(--r-sm); background: var(--ink); }
.thumb-meta { flex: 1; display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); }
.thumb-name { font-family: var(--font-mono); font-size: 0.82rem; color: var(--text-mid); word-break: break-all; }
.thumb-remove {
  width: 28px; height: 28px;
  border-radius: var(--r-pill);
  color: var(--text-dim);
  display: grid; place-items: center;
}
.thumb-remove:hover { background: rgba(239, 68, 68, 0.12); color: var(--red); }

.library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: var(--sp-3);
}
.library-empty { grid-column: 1 / -1; color: var(--text-faint); font-size: 0.88rem; padding: var(--sp-5); text-align: center; }
.library-item {
  position: relative;
  aspect-ratio: 1;
  border-radius: var(--r-md);
  overflow: hidden;
  background: var(--ink);
  border: 1px solid var(--border-soft);
  cursor: pointer;
  transition: border-color 0.2s, transform 0.2s;
}
.library-item:hover { border-color: var(--brand-bright); transform: translateY(-2px); }
.library-item[data-selected="true"] {
  border-color: var(--brand-bright);
  box-shadow: 0 0 0 2px var(--brand-bright);
}
.library-item img { width: 100%; height: 100%; object-fit: cover; }
.library-item-overlay {
  position: absolute;
  inset: auto 0 0 0;
  padding: var(--sp-2);
  background: linear-gradient(180deg, transparent, rgba(0, 0, 0, 0.7));
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: white;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}

/* ========== RESULT PANE ========== */
.result {
  background: var(--ink);
  border: 1px solid var(--border-soft);
  border-radius: var(--r-md);
  padding: var(--sp-5);
  min-height: 320px;
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
  position: sticky;
  top: 96px;
}
.result-empty {
  text-align: center;
  margin: auto;
  color: var(--text-faint);
}
.result-empty-headline {
  font-family: var(--font-display);
  font-size: 1.05rem;
  color: var(--text-dim);
  margin-bottom: var(--sp-2);
}
.result-empty-sub { font-size: 0.88rem; }

.result-card {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}
.result-meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  font-size: 0.78rem;
  color: var(--text-dim);
  font-family: var(--font-mono);
}
.result-meta .pill {
  background: var(--ink-4);
  border: 1px solid var(--border-soft);
  padding: 3px 10px;
  border-radius: var(--r-pill);
}
.pill--brand { background: var(--grad-soft); color: var(--cyan-bright); border-color: var(--border); }
.pill--warn  { background: rgba(245, 158, 11, 0.10); color: var(--amber); border-color: rgba(245, 158, 11, 0.3); }
.pill--ok    { background: rgba(34, 197, 94, 0.10); color: var(--green); border-color: rgba(34, 197, 94, 0.3); }
.pill--err   { background: rgba(239, 68, 68, 0.10); color: var(--red); border-color: rgba(239, 68, 68, 0.3); }

.result-images {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: var(--sp-3);
}
.result-image {
  position: relative;
  aspect-ratio: 1;
  background: var(--ink-2);
  border-radius: var(--r-md);
  overflow: hidden;
  border: 1px solid var(--border-soft);
}
.result-image img { width: 100%; height: 100%; object-fit: contain; }
.result-image-actions {
  position: absolute;
  inset: auto 0 0 0;
  padding: var(--sp-2);
  display: flex;
  gap: 4px;
  background: linear-gradient(180deg, transparent, rgba(0, 0, 0, 0.7));
  opacity: 0;
  transition: opacity 0.2s;
}
.result-image:hover .result-image-actions { opacity: 1; }
.icon-btn {
  width: 28px; height: 28px;
  border-radius: var(--r-sm);
  background: rgba(13, 15, 26, 0.85);
  color: var(--text);
  display: grid; place-items: center;
  font-size: 0.7rem;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.icon-btn:hover { background: var(--brand); color: white; }

.result-prompt {
  background: var(--ink-2);
  border: 1px solid var(--border-soft);
  border-radius: var(--r-md);
  padding: var(--sp-3);
  font-size: 0.84rem;
  color: var(--text-mid);
  font-family: var(--font-body);
  line-height: 1.55;
  white-space: pre-wrap;
  max-height: 140px;
  overflow-y: auto;
}
.result-actions { display: flex; gap: var(--sp-2); flex-wrap: wrap; }

/* ========== HISTORY ========== */
.history-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--sp-3);
  margin-bottom: var(--sp-5);
  flex-wrap: wrap;
}
.history-tools { display: flex; gap: var(--sp-3); align-items: center; }
.history-tools select { width: auto; min-width: 160px; }
.history-list { display: flex; flex-direction: column; gap: var(--sp-3); }
.empty {
  color: var(--text-faint);
  text-align: center;
  padding: var(--sp-7) var(--sp-5);
  font-size: 0.92rem;
  border: 1px dashed var(--border-soft);
  border-radius: var(--r-md);
}

.history-item {
  background: var(--ink-2);
  border: 1px solid var(--border-soft);
  border-radius: var(--r-md);
  padding: var(--sp-4);
  display: grid;
  grid-template-columns: auto 1fr;
  gap: var(--sp-4);
  transition: border-color 0.2s;
}
.history-item:hover { border-color: var(--border); }
.history-item--error { border-color: rgba(239, 68, 68, 0.3); }
.history-thumbs {
  display: flex;
  gap: 4px;
  align-items: flex-start;
}
.history-thumb {
  width: 80px; height: 80px;
  border-radius: var(--r-sm);
  overflow: hidden;
  background: var(--ink);
  border: 1px solid var(--border-soft);
  flex-shrink: 0;
}
.history-thumb img { width: 100%; height: 100%; object-fit: cover; }
.history-thumb--more {
  display: grid;
  place-items: center;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--text-dim);
}
.history-body {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  min-width: 0;
}
.history-meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  font-size: 0.74rem;
  color: var(--text-dim);
  font-family: var(--font-mono);
}
.history-prompt {
  font-size: 0.92rem;
  color: var(--text);
  line-height: 1.5;
  word-break: break-word;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.history-actions { display: flex; gap: var(--sp-2); flex-wrap: wrap; margin-top: var(--sp-2); }

/* ========== FILES ========== */
.files-section { margin-bottom: var(--sp-7); }
.files-heading {
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: var(--sp-4);
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  letter-spacing: -0.01em;
}
.files-sub {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--text-faint);
  font-weight: 400;
}
.files-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: var(--sp-3);
}
.file-card {
  background: var(--ink-2);
  border: 1px solid var(--border-soft);
  border-radius: var(--r-md);
  overflow: hidden;
  transition: border-color 0.2s, transform 0.2s;
}
.file-card:hover { border-color: var(--border); transform: translateY(-2px); }
.file-card-thumb {
  aspect-ratio: 1;
  background: var(--ink);
  display: grid;
  place-items: center;
  overflow: hidden;
}
.file-card-thumb img { width: 100%; height: 100%; object-fit: cover; }
.file-card-meta {
  padding: var(--sp-3);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-dim);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.file-card-name {
  color: var(--text);
  word-break: break-all;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-weight: 500;
}
.file-card-actions {
  display: flex;
  gap: 4px;
  padding: 0 var(--sp-3) var(--sp-3);
}

/* ========== MODAL (Refine) ========== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: var(--sp-4);
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(5, 6, 8, 0.65);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  animation: fade 0.2s ease;
}
.modal-panel {
  position: relative;
  background: linear-gradient(160deg, var(--ink-3) 0%, var(--ink-2) 100%);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  width: min(640px, 100%);
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 50px 100px rgba(0, 0, 0, 0.7);
  animation: pop 0.25s var(--ease-spring);
}
@keyframes fade { from { opacity: 0; } }
@keyframes pop {
  from { opacity: 0; transform: translateY(20px) scale(0.96); }
  to { opacity: 1; transform: none; }
}
.modal-header {
  padding: var(--sp-4) var(--sp-5);
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-soft);
}
.modal-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: -0.015em;
}
.modal-close {
  width: 32px; height: 32px;
  border-radius: var(--r-pill);
  color: var(--text-dim);
  display: grid; place-items: center;
}
.modal-close:hover { background: rgba(148, 163, 184, 0.1); color: var(--text); }
.modal-body {
  padding: var(--sp-5);
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
  overflow-y: auto;
}
.modal-actions {
  padding: var(--sp-4) var(--sp-5);
  display: flex;
  justify-content: flex-end;
  gap: var(--sp-3);
  border-top: 1px solid var(--border-soft);
  background: var(--ink-2);
}
.refine-source {
  display: flex;
  gap: var(--sp-3);
  padding: var(--sp-3);
  background: var(--ink);
  border: 1px solid var(--border-soft);
  border-radius: var(--r-md);
}
.refine-source img { width: 96px; height: 96px; object-fit: contain; border-radius: var(--r-sm); background: var(--ink-2); flex-shrink: 0; }
.refine-meta { display: flex; flex-direction: column; gap: var(--sp-2); min-width: 0; }
.refine-meta-line { font-size: 0.72rem; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.1em; }
.refine-original {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--text-mid);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 80px;
  overflow-y: auto;
  line-height: 1.5;
}

/* ========== TOAST ========== */
.toast-wrap {
  position: fixed;
  bottom: var(--sp-5);
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  align-items: center;
  pointer-events: none;
}
.toast {
  background: var(--ink-3);
  border: 1px solid var(--border);
  color: var(--text);
  padding: var(--sp-3) var(--sp-5);
  border-radius: var(--r-pill);
  font-size: 0.88rem;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  pointer-events: auto;
  animation: slide-up 0.25s var(--ease-out);
}
.toast--ok { border-color: rgba(34, 197, 94, 0.4); }
.toast--err { border-color: rgba(239, 68, 68, 0.4); color: var(--red); }
@keyframes slide-up { from { opacity: 0; transform: translateY(12px); } }

/* ========== RESPONSIVE ========== */
@media (max-width: 720px) {
  .topbar { padding: var(--sp-3) var(--sp-4); }
  .brand-tag { display: none; }
  .tabs { padding: var(--sp-4) var(--sp-4) 0; flex-wrap: wrap; }
  .surface { padding: var(--sp-4); }
  .panel { padding: var(--sp-4); }
  .result { position: static; }
}
