:root {
  --bg: #ffffff;
  --bg-elev: #ffffff;
  --bg-soft: #f8fafc;
  --bg-card: #f1f5f9;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-dim: #64748b;
  --text-muted: #94a3b8;
  --accent: #0091ff;
  --accent-2: #00c2ff;
  --accent-3: #00d4ff;
  --accent-grad: linear-gradient(135deg, #0091ff 0%, #00c2ff 50%, #00d4ff 100%);
  --warn: #f59e0b;
  --error: #ef4444;
  --success: #10b981;
  --radius: 14px;
  --shadow-xs: 0 1px 2px rgba(15,23,42,0.05);
  --shadow-sm: 0 2px 4px rgba(15,23,42,0.06), 0 1px 2px rgba(15,23,42,0.04);
  --shadow-md: 0 10px 30px rgba(15,23,42,0.08), 0 2px 8px rgba(15,23,42,0.04);
  --shadow-lg: 0 20px 50px rgba(15,23,42,0.12), 0 4px 12px rgba(15,23,42,0.06);
  --shadow-search: 0 4px 16px rgba(15,23,42,0.06), 0 1px 4px rgba(15,23,42,0.04);
  --shadow-search-focus: 0 8px 28px rgba(0,145,255,0.18), 0 2px 6px rgba(15,23,42,0.06);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  background: #ffffff;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Sarabun", "Noto Sans Thai", sans-serif;
  min-height: 100vh;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

body {
  background:
    radial-gradient(800px 500px at 85% -5%, rgba(0,145,255,0.18), transparent 70%),
    radial-gradient(600px 400px at 10% 20%, rgba(0,212,255,0.12), transparent 70%),
    radial-gradient(700px 500px at 50% 100%, rgba(0,145,255,0.10), transparent 70%),
    radial-gradient(400px 300px at 95% 70%, rgba(0,194,255,0.08), transparent 70%),
    #ffffff;
  background-attachment: fixed;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 32px;
  background: rgba(255,255,255,0.75);
  backdrop-filter: blur(16px) saturate(180%);
  -webkit-backdrop-filter: blur(16px) saturate(180%);
  border-bottom: 1px solid rgba(226,232,240,0.6);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-logo {
  width: 38px; height: 38px;
  border-radius: 11px;
  background: var(--accent-grad);
  display: grid;
  place-items: center;
  font-weight: 800;
  color: #fff;
  font-size: 18px;
  box-shadow: 0 6px 20px rgba(0,145,255,0.3);
}
.brand-name {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text);
}
.brand-tag {
  color: var(--text-dim);
  font-size: 12.5px;
}

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

.api-status {
  font-size: 12px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text-dim);
  font-weight: 500;
}
.api-status.ok { color: var(--success); border-color: rgba(16,185,129,0.3); background: rgba(16,185,129,0.06); }
.api-status.warn { color: var(--warn); border-color: rgba(245,158,11,0.3); background: rgba(245,158,11,0.06); }

.icon-btn {
  width: 40px; height: 40px;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  cursor: pointer;
  display: grid; place-items: center;
  transition: all 0.15s;
  box-shadow: var(--shadow-xs);
}
.icon-btn:hover {
  background: var(--bg-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 56px 32px 64px;
}

.hero {
  text-align: center;
  margin-bottom: 36px;
}
.hero h1 {
  font-size: 44px;
  letter-spacing: -0.02em;
  font-weight: 700;
  background: linear-gradient(180deg, #0f172a 0%, #475569 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  margin-bottom: 12px;
  line-height: 1.15;
}
.hero p {
  color: var(--text-dim);
  font-size: 16px;
  max-width: 620px;
  margin: 0 auto;
}

/* === Search bar (Google-style pill) === */
.search-wrap {
  max-width: 920px;
  margin: 0 auto;
}

.search-bar {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 8px 8px 8px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 28px;
  box-shadow: var(--shadow-search);
  transition: box-shadow 0.2s, border-color 0.2s;
}
.search-bar:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--border-strong);
}
.search-bar:focus-within {
  border-color: var(--accent);
  box-shadow: var(--shadow-search-focus);
}

.upload-icon-btn {
  flex-shrink: 0;
  width: 44px; height: 44px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  display: grid; place-items: center;
  transition: all 0.15s;
}
.upload-icon-btn:hover {
  background: var(--bg-soft);
  color: var(--accent);
}
.upload-icon-btn.has-image {
  background: rgba(0,145,255,0.1);
  color: var(--accent);
}
.upload-icon-btn input { display: none; }

.search-input {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  outline: none;
  font-size: 16px;
  font-family: inherit;
  padding: 11px 4px;
  resize: none;
  color: var(--text);
  line-height: 1.5;
  max-height: 200px;
  overflow-y: auto;
}
.search-input::placeholder { color: var(--text-muted); }
.search-input::-webkit-scrollbar { width: 6px; }
.search-input::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.generate-pill {
  flex-shrink: 0;
  height: 44px;
  padding: 0 22px;
  border-radius: 999px;
  border: none;
  background: var(--accent-grad);
  color: #fff;
  font-size: 14.5px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: inherit;
  transition: transform 0.1s, box-shadow 0.15s, opacity 0.15s;
  box-shadow: 0 4px 14px rgba(0,145,255,0.35);
  white-space: nowrap;
}
.generate-pill:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 8px 22px rgba(0,145,255,0.45);
}
.generate-pill:disabled { opacity: 0.55; cursor: not-allowed; }
.generate-pill.loading {
  color: transparent;
  position: relative;
}
.generate-pill.loading::after {
  content: '';
  position: absolute;
  inset: 0;
  margin: auto;
  width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.image-chip {
  display: none;
  align-items: center;
  gap: 10px;
  padding: 8px 14px 8px 8px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 999px;
  margin-top: 12px;
  width: fit-content;
  margin-left: auto;
  margin-right: auto;
  box-shadow: var(--shadow-xs);
  font-size: 13px;
  color: var(--text);
}
.image-chip.visible { display: inline-flex; }
.image-chip img {
  width: 28px; height: 28px;
  border-radius: 50%;
  object-fit: cover;
}
.image-chip-name { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.image-chip-remove {
  width: 22px; height: 22px;
  border-radius: 50%;
  border: none;
  background: var(--bg-card);
  color: var(--text-dim);
  cursor: pointer;
  font-size: 14px;
  display: grid; place-items: center;
  line-height: 1;
  transition: all 0.15s;
}
.image-chip-remove:hover { background: var(--error); color: #fff; }

/* === Gen-image toggle + warning === */
.gen-options {
  max-width: 920px;
  margin: 14px auto 0;
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  justify-content: center;
}
.gen-toggle {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
  font-size: 13.5px;
  color: var(--text);
  font-weight: 500;
}
.gen-toggle input { display: none; }
.gen-toggle-switch {
  width: 38px;
  height: 22px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 999px;
  position: relative;
  transition: background 0.2s, border-color 0.2s;
  flex-shrink: 0;
}
.gen-toggle-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(15,23,42,0.2);
  transition: transform 0.2s;
}
.gen-toggle input:checked + .gen-toggle-switch {
  background: var(--accent);
  border-color: var(--accent);
}
.gen-toggle input:checked + .gen-toggle-switch .gen-toggle-thumb {
  transform: translateX(16px);
}
.gen-image-warning {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: rgba(245,158,11,0.08);
  border: 1px solid rgba(245,158,11,0.3);
  border-radius: 999px;
  font-size: 12.5px;
  color: #92400e;
  line-height: 1.4;
}
.gen-image-warning.visible { display: inline-flex; }
.gen-image-warning svg { flex-shrink: 0; color: var(--warn); }

.status-bar {
  max-width: 920px;
  margin: 16px auto 0;
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 13.5px;
  display: none;
  text-align: center;
}
.status-bar.info { background: rgba(0,145,255,0.06); border: 1px solid rgba(0,145,255,0.2); color: var(--accent); }
.status-bar.success { background: rgba(16,185,129,0.06); border: 1px solid rgba(16,185,129,0.25); color: var(--success); }
.status-bar.error { background: rgba(239,68,68,0.06); border: 1px solid rgba(239,68,68,0.25); color: var(--error); }

/* === Progress widget === */
.progress {
  max-width: 920px;
  margin: 20px auto 0;
  padding: 18px 22px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: #fff;
  box-shadow: var(--shadow-sm);
}
.progress.tone-active {
  border-color: rgba(0,145,255,0.3);
  background: linear-gradient(135deg, rgba(0,145,255,0.04), rgba(0,212,255,0.02));
}
.progress.tone-success { border-color: rgba(16,185,129,0.3); }
.progress.tone-warn { border-color: rgba(245,158,11,0.3); }
.progress.tone-error { border-color: rgba(239,68,68,0.3); }

.progress-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  gap: 12px;
}
.progress-stage {
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
}
.progress-count {
  font-size: 13px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}
.progress-track {
  height: 6px;
  background: var(--bg-card);
  border-radius: 999px;
  overflow: hidden;
  position: relative;
}
.progress-fill {
  height: 100%;
  background: var(--accent-grad);
  border-radius: 999px;
  transition: width 0.4s ease;
  position: relative;
}
.tone-success .progress-fill { background: var(--success); }
.tone-warn .progress-fill { background: var(--warn); }
.tone-error .progress-fill { background: var(--error); }
.progress-fill.indeterminate {
  width: 35% !important;
  animation: indeterminate 1.4s ease-in-out infinite;
}
@keyframes indeterminate {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(350%); }
}
.progress-detail {
  margin-top: 10px;
  font-size: 12.5px;
  color: var(--text-dim);
  line-height: 1.5;
}

/* === Results === */
.results-section {
  display: none;
  margin-top: 56px;
}
.results-section h2 {
  font-size: 22px;
  margin-bottom: 16px;
  letter-spacing: -0.01em;
  color: var(--text);
}

.brief-summary {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 22px 26px;
  margin-bottom: 32px;
  font-size: 14px;
  box-shadow: var(--shadow-sm);
}
.brief-row { margin-bottom: 6px; color: var(--text); }
.brief-label {
  color: var(--text-dim);
  font-weight: 600;
  display: inline-block;
  min-width: 100px;
}
.brief-items { margin: 8px 0 0 28px; color: var(--text); }
.brief-items li { margin: 4px 0; }
.brief-items em { color: var(--text-dim); font-size: 12px; }

.grid-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.grid-header h2 { margin: 0; }

.grid-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 6px 6px 14px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: var(--shadow-xs);
}
.toolbar-model {
  display: flex;
  align-items: center;
  gap: 8px;
}
.toolbar-label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-dim);
  white-space: nowrap;
}
.toolbar-select {
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  padding: 6px 8px;
  border-radius: 8px;
  cursor: pointer;
  max-width: 240px;
}
.toolbar-select:hover { background: var(--bg-soft); }
.toolbar-select:focus { outline: none; background: var(--bg-soft); }

.regen-all-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 36px;
  padding: 0 16px;
  border-radius: 999px;
  border: none;
  background: var(--accent-grad);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: transform 0.1s, box-shadow 0.15s, opacity 0.15s;
  box-shadow: 0 3px 10px rgba(0,145,255,0.3);
  white-space: nowrap;
}
.regen-all-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(0,145,255,0.4);
}
.regen-all-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  background: var(--text-dim);
  box-shadow: none;
}

.results-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: 20px;
}

/* === Image cards === */
.image-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: border-color 0.15s, transform 0.15s, box-shadow 0.15s;
  box-shadow: var(--shadow-xs);
}
.image-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.card-visual {
  position: relative;
  width: 100%;
  aspect-ratio: 16/9;
  background: var(--bg-soft);
  overflow: hidden;
}
.image-card.status-done .card-visual,
.image-card.status-prompt-only .card-visual { cursor: zoom-in; }

.card-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.3s ease;
}
.image-card.status-done:hover .card-image { transform: scale(1.04); }

.card-image-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 6px;
  padding: 12px;
  background: linear-gradient(180deg, transparent 55%, rgba(15,23,42,0.7));
  color: #fff;
  font-size: 12px;
  font-weight: 500;
  opacity: 0;
  transition: opacity 0.2s;
}
.image-card.status-done:hover .card-image-overlay { opacity: 1; }

.state-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 24px;
  text-align: center;
}
.state-overlay.prompt-only {
  background: linear-gradient(135deg, rgba(0,145,255,0.05), rgba(0,212,255,0.03));
  color: var(--accent);
}
.state-overlay.prompt-only .state-text { color: var(--text); }
.state-overlay.queued {
  background: repeating-linear-gradient(45deg, var(--bg-soft) 0 8px, #fff 8px 16px);
}
.state-overlay.generating {
  background: radial-gradient(circle at center, rgba(0,145,255,0.10), #fff 70%);
}
.state-overlay.error { background: rgba(239,68,68,0.04); }
.state-overlay.no-key { background: rgba(245,158,11,0.05); color: var(--warn); }

.queue-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 12px;
  color: var(--text-dim);
  font-weight: 500;
  box-shadow: var(--shadow-xs);
}
.queue-dot {
  width: 6px; height: 6px;
  background: var(--text-dim);
  border-radius: 50%;
  animation: queue-pulse 1.5s ease-in-out infinite;
}
@keyframes queue-pulse {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 1; }
}
.spinner-lg {
  width: 44px; height: 44px;
  border: 3px solid rgba(0,145,255,0.15);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
.state-text { font-size: 13px; font-weight: 600; color: var(--text); }
.state-sub { font-size: 11.5px; color: var(--text-dim); max-width: 240px; word-break: break-word; }
.error-mark {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--error);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 22px;
}
.retry-btn, .settings-shortcut {
  background: #fff;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 12px;
  font-family: inherit;
  margin-top: 4px;
  transition: all 0.15s;
  box-shadow: var(--shadow-xs);
}
.retry-btn:hover, .settings-shortcut:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.card-meta {
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-top: 1px solid var(--border);
  background: #fff;
}
.card-badge {
  width: 28px; height: 28px;
  border-radius: 8px;
  background: var(--accent-grad);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 13px;
  flex-shrink: 0;
}
.card-meta-text { flex: 1; min-width: 0; }
.card-title {
  font-size: 14.5px;
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.01em;
  color: var(--text);
}
.card-sub {
  font-size: 11.5px;
  color: var(--text-dim);
  margin: 2px 0 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* === Action button (used in lightbox) === */
.action-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #fff;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.15s;
  text-decoration: none;
  font-family: inherit;
  box-shadow: var(--shadow-xs);
}
.action-btn:hover { background: var(--accent); border-color: var(--accent); color: #fff; }
.action-btn:disabled { opacity: 0.55; cursor: not-allowed; }
.action-btn.copied { background: var(--success); border-color: var(--success); color: #fff; }

/* === Lightbox === */
.lightbox {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,0.85);
  backdrop-filter: blur(16px);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 32px;
}
.lightbox.open { display: flex; }
.lightbox-close {
  position: absolute;
  top: 20px;
  right: 24px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.18);
  color: #fff;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: all 0.15s;
  z-index: 2;
}
.lightbox-close:hover { background: rgba(255,255,255,0.2); }
.lightbox-content {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 420px;
  gap: 20px;
  max-width: 1600px;
  width: 100%;
  height: 100%;
  max-height: calc(100vh - 64px);
}
.lightbox-image-side {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.08);
}
.lightbox-image-side img {
  max-width: 100%;
  max-height: 100%;
  display: block;
  object-fit: contain;
}
.lightbox-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 40px;
  color: var(--text-dim);
  text-align: center;
  max-width: 460px;
}
.lightbox-placeholder svg { color: var(--text-muted); }
.placeholder-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}
.placeholder-sub {
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.55;
}
.lightbox-prompt-side {
  background: #fff;
  border-radius: 16px;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow: hidden;
}
.lightbox-header {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.lightbox-header h2 { font-size: 18px; margin: 0; letter-spacing: -0.01em; color: var(--text); }
.lightbox-header p { font-size: 12.5px; color: var(--text-dim); margin: 4px 0 0; }
.lightbox-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.lightbox-section-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
}
.lightbox-prompt {
  flex: 1;
  font-family: ui-monospace, "SF Mono", Menlo, Monaco, Consolas, monospace;
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-wrap: break-word;
  margin: 0;
}
.lightbox-prompt::-webkit-scrollbar { width: 8px; }
.lightbox-prompt::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

@media (max-width: 900px) {
  .lightbox { padding: 16px; }
  .lightbox-content {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 50%) minmax(0, 50%);
    gap: 12px;
  }
}

/* === Settings modal === */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,0.4);
  backdrop-filter: blur(8px);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal.open { display: flex; }

.modal-content {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 28px;
  width: 100%;
  max-width: 520px;
  box-shadow: var(--shadow-lg);
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}
.modal-header h2 { font-size: 20px; letter-spacing: -0.01em; color: var(--text); }
.modal-close {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 24px;
  cursor: pointer;
  line-height: 1;
  width: 32px; height: 32px;
  display: grid; place-items: center;
  border-radius: 8px;
}
.modal-close:hover { color: var(--text); background: var(--bg-soft); }

.api-link-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 20px;
}
.api-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: #fff;
  border: 1.5px solid var(--border);
  border-radius: 14px;
  text-decoration: none;
  color: var(--text);
  transition: all 0.15s;
  position: relative;
  overflow: hidden;
}
.api-link::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(0,145,255,0.06), rgba(0,212,255,0.03));
  opacity: 0;
  transition: opacity 0.15s;
}
.api-link:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}
.api-link:hover::before { opacity: 1; }
.api-link > * { position: relative; }
.api-link-icon {
  width: 38px; height: 38px;
  border-radius: 10px;
  background: var(--accent-grad);
  color: #fff;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.api-link.gemini-link .api-link-icon {
  background: linear-gradient(135deg, #4285f4 0%, #ea4335 50%, #fbbc04 100%);
}
.api-link-text { flex: 1; min-width: 0; }
.api-link-title {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.005em;
}
.api-link-sub {
  font-size: 11.5px;
  color: var(--text-dim);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.api-link-arrow {
  color: var(--text-dim);
  flex-shrink: 0;
  transition: transform 0.15s, color 0.15s;
}
.api-link:hover .api-link-arrow {
  color: var(--accent);
  transform: translate(2px, -2px);
}

@media (max-width: 520px) {
  .api-link-row { grid-template-columns: 1fr; }
}

.form-group { margin-bottom: 18px; }
.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text);
}
.form-group input, .form-group select {
  width: 100%;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  padding: 11px 14px;
  font-size: 14px;
  font-family: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.form-group input:focus, .form-group select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0,145,255,0.12);
}
.form-hint {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 6px;
  line-height: 1.55;
}
.form-hint a { color: var(--accent); text-decoration: none; }
.form-hint a:hover { text-decoration: underline; }

.save-btn {
  width: 100%;
  height: 46px;
  border-radius: 12px;
  border: none;
  background: var(--accent-grad);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  box-shadow: 0 4px 14px rgba(0,145,255,0.3);
  transition: transform 0.1s, box-shadow 0.15s;
}
.save-btn:hover { transform: translateY(-1px); box-shadow: 0 8px 22px rgba(0,145,255,0.4); }

@media (max-width: 720px) {
  .container { padding: 32px 16px 48px; }
  .hero h1 { font-size: 30px; }
  .hero p { font-size: 14.5px; }
  .app-header { padding: 14px 16px; }
  .api-status { display: none; }
  .results-grid { grid-template-columns: 1fr; }
  .search-bar {
    flex-wrap: wrap;
    border-radius: 22px;
    padding: 6px 6px 6px 6px;
  }
  .generate-pill {
    width: 100%;
    justify-content: center;
    order: 99;
  }
  .search-input { font-size: 15px; }
}
