:root,
[data-theme="dark"] {
  --bg: #0a0a0f;
  --bg-elev: #12121a;
  --bg-elev-2: #1a1a24;
  --border: #24242f;
  --border-strong: #34344a;
  --text: #ececf1;
  --text-dim: #a1a1aa;
  --text-mute: #6b6b78;
  --accent: #8b5cf6;
  --accent-2: #06b6d4;
  --accent-grad: linear-gradient(135deg, #8b5cf6 0%, #ec4899 50%, #06b6d4 100%);
  --danger: #ef4444;
  --success: #10b981;
  --topbar-bg: rgba(10, 10, 15, 0.75);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 24px 60px rgba(0, 0, 0, 0.5);
  --grid-line: rgba(139, 92, 246, 0.04);
  --toast-bg: #ececf1;
  --toast-fg: #0a0a0f;
  --btn-primary-bg: #ececf1;
  --btn-primary-fg: #0a0a0f;
  --btn-primary-hover: #ffffff;
}

[data-theme="light"] {
  --bg: #fafafa;
  --bg-elev: #ffffff;
  --bg-elev-2: #f4f4f6;
  --border: #e6e6ec;
  --border-strong: #d0d0da;
  --text: #18181b;
  --text-dim: #52525b;
  --text-mute: #8a8a93;
  --accent: #7c3aed;
  --accent-2: #0891b2;
  --accent-grad: linear-gradient(135deg, #7c3aed 0%, #db2777 50%, #0891b2 100%);
  --danger: #dc2626;
  --success: #059669;
  --topbar-bg: rgba(250, 250, 250, 0.8);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 24px 60px rgba(0, 0, 0, 0.12);
  --grid-line: rgba(124, 58, 237, 0.06);
  --toast-bg: #18181b;
  --toast-fg: #fafafa;
  --btn-primary-bg: #18181b;
  --btn-primary-fg: #fafafa;
  --btn-primary-hover: #000000;
}

:root {
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 16px;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
}

html {
  color-scheme: dark;
}
[data-theme="light"] {
  color-scheme: light;
}

html,
body {
  transition: background-color 0.25s ease, color 0.25s ease;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input,
select,
textarea {
  font-family: inherit;
  color: inherit;
}

/* ───── TOPBAR ───── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px clamp(16px, 5vw, 48px);
  background: var(--topbar-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
}

.brand svg {
  color: var(--accent);
}

.topnav {
  display: flex;
  align-items: center;
  gap: 24px;
  font-size: 14px;
  color: var(--text-dim);
}

.topnav a {
  transition: color 0.2s;
}

.topnav a:hover {
  color: var(--text);
}

.top-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: 4px;
  padding-left: 20px;
  border-left: 1px solid var(--border);
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-dim);
  cursor: pointer;
  transition: all 0.2s;
}

.icon-btn:hover {
  color: var(--text);
  border-color: var(--border-strong);
}

.icon-btn svg {
  width: 16px;
  height: 16px;
}

.lang-btn {
  width: auto;
  padding: 0 12px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-family: var(--mono);
}

.theme-icon-sun { display: none; }
.theme-icon-moon { display: block; }
[data-theme="light"] .theme-icon-sun { display: block; }
[data-theme="light"] .theme-icon-moon { display: none; }

@media (max-width: 600px) {
  .top-tools {
    padding-left: 12px;
    margin-left: 0;
  }
}

/* ───── HERO ───── */
.hero {
  position: relative;
  padding: clamp(64px, 12vw, 140px) clamp(16px, 5vw, 48px) clamp(48px, 8vw, 96px);
  overflow: hidden;
}

.hero-inner {
  max-width: 880px;
  position: relative;
  z-index: 2;
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-dim);
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-elev);
}

.dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 12px var(--accent);
}

h1 {
  font-size: clamp(40px, 7vw, 80px);
  line-height: 1.02;
  letter-spacing: -0.03em;
  font-weight: 700;
  margin: 24px 0 20px;
  font-feature-settings: "kern" 1, "ss01" 1;
  text-rendering: geometricPrecision;
}

.grad {
  background: var(--accent-grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  display: inline-block;
  padding-right: 0.05em;
}

.lede {
  font-size: clamp(16px, 1.6vw, 19px);
  color: var(--text-dim);
  max-width: 580px;
  margin: 0 0 36px;
}

.hero-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.hero-grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 64px 64px;
  mask-image: radial-gradient(ellipse at top right, black 0%, transparent 70%);
  -webkit-mask-image: radial-gradient(ellipse at top right, black 0%, transparent 70%);
  pointer-events: none;
}

/* ───── BUTTONS ───── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 11px 20px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  border: 1px solid transparent;
  cursor: pointer;
  transition:
    transform 0.15s ease,
    background 0.2s,
    border-color 0.2s,
    color 0.2s;
  white-space: nowrap;
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: var(--btn-primary-bg);
  color: var(--btn-primary-fg);
  border-color: var(--btn-primary-bg);
}

.btn-primary:hover {
  background: var(--btn-primary-hover);
  border-color: var(--btn-primary-hover);
}

.btn-ghost {
  background: var(--bg-elev);
  border-color: var(--border);
  color: var(--text);
}

.btn-ghost:hover {
  border-color: var(--border-strong);
  background: var(--bg-elev-2);
}

/* ───── BUILDER ───── */
.builder,
.library,
.about {
  padding: clamp(48px, 8vw, 96px) clamp(16px, 5vw, 48px);
  border-top: 1px solid var(--border);
}

.builder-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 32px;
}

h2 {
  font-size: clamp(24px, 3vw, 32px);
  font-weight: 600;
  letter-spacing: -0.02em;
  margin: 0;
}

.model-switch {
  display: inline-flex;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px;
  gap: 2px;
  flex-wrap: wrap;
}

.model {
  background: transparent;
  border: none;
  padding: 7px 14px;
  font-size: 13px;
  color: var(--text-dim);
  cursor: pointer;
  border-radius: 7px;
  transition: all 0.2s;
}

.model:hover {
  color: var(--text);
}

.model.active {
  background: var(--bg-elev-2);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.builder-grid {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 24px;
}

@media (max-width: 900px) {
  .builder-grid {
    grid-template-columns: 1fr;
  }
}

.panel {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
}

.field {
  display: block;
  margin-bottom: 20px;
}

.field-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  margin-bottom: 10px;
  font-weight: 500;
}

input[type="text"],
input[type="search"] {
  width: 100%;
  padding: 11px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  transition: border-color 0.2s;
}

input[type="text"]:focus,
input[type="search"]:focus {
  outline: none;
  border-color: var(--accent);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  padding: 7px 13px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 13px;
  color: var(--text-dim);
  cursor: pointer;
  transition: all 0.15s;
  user-select: none;
}

.chip:hover {
  color: var(--text);
  border-color: var(--border-strong);
}

.chip.active {
  background: color-mix(in oklab, var(--accent) 14%, transparent);
  border-color: var(--accent);
  color: var(--accent);
}

/* ratios */
.ratios {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.ratio {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  cursor: pointer;
  color: var(--text-dim);
  transition: all 0.15s;
}

.ratio:hover {
  color: var(--text);
}

.ratio.active {
  border-color: var(--accent);
  color: var(--text);
  background: color-mix(in oklab, var(--accent) 10%, transparent);
}

.r-box {
  display: block;
  border: 1.5px solid currentColor;
  border-radius: 2px;
}

.r-1-1 { width: 14px; height: 14px; }
.r-16-9 { width: 20px; height: 11px; }
.r-9-16 { width: 11px; height: 20px; }
.r-4-5 { width: 12px; height: 15px; }
.r-3-2 { width: 18px; height: 12px; }

/* sliders */
.sliders {
  display: grid;
  gap: 14px;
  margin-bottom: 20px;
}

.slider {
  display: block;
}

.slider span {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  margin-bottom: 6px;
  font-weight: 500;
}

.slider em {
  font-family: var(--mono);
  font-style: normal;
  color: var(--accent);
  text-transform: none;
  letter-spacing: 0;
}

input[type="range"] {
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  background: var(--bg);
  border-radius: 2px;
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 0 0 4px color-mix(in oklab, var(--accent) 18%, transparent);
}

input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
  border: none;
}

/* toggle */
.toggle {
  position: relative;
  display: inline-block;
  width: 32px;
  height: 18px;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle span {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 999px;
  cursor: pointer;
  transition: 0.2s;
}

.toggle span::before {
  content: "";
  position: absolute;
  width: 14px;
  height: 14px;
  left: 2px;
  top: 2px;
  background: var(--text);
  border-radius: 50%;
  transition: 0.2s;
}

.toggle input:checked + span {
  background: var(--accent);
}

.toggle input:checked + span::before {
  transform: translateX(14px);
}

.row-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

/* output panel */
.output {
  position: sticky;
  top: 88px;
  align-self: start;
}

.output-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.counter {
  font-size: 12px;
  color: var(--text-mute);
  font-family: var(--mono);
}

.counter em {
  font-style: normal;
  color: var(--accent);
}

.prompt-out {
  min-height: 160px;
  padding: 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--mono);
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  margin: 0 0 16px;
}

.prompt-out:focus {
  outline: none;
  border-color: var(--accent);
}

.output-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}

.tips {
  padding: 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  border-left: 2px solid var(--accent);
}

.tips h3 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--accent);
  margin: 0 0 8px;
  font-weight: 600;
}

.tips p {
  margin: 0;
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.55;
}

/* ───── LIBRARY ───── */
.lib-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.lib-actions input {
  width: 220px;
}

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

.lib-card {
  padding: 18px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color 0.2s;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.lib-card:hover {
  border-color: var(--border-strong);
}

.lib-card .lib-title {
  font-weight: 500;
  font-size: 14px;
}

.lib-card .lib-meta {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-mute);
  font-family: var(--mono);
}

.lib-card .lib-body {
  font-family: var(--mono);
  font-size: 12.5px;
  color: var(--text-dim);
  line-height: 1.5;
  max-height: 80px;
  overflow: hidden;
  position: relative;
}

.lib-card .lib-body::after {
  content: "";
  position: absolute;
  inset: auto 0 0 0;
  height: 30px;
  background: linear-gradient(transparent, var(--bg-elev));
}

.lib-card-actions {
  display: flex;
  gap: 6px;
}

.lib-card-actions button {
  flex: 1;
  padding: 7px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: var(--text-dim);
  cursor: pointer;
  transition: all 0.15s;
}

.lib-card-actions button:hover {
  color: var(--text);
  border-color: var(--border-strong);
}

.lib-card-actions .del:hover {
  color: var(--danger);
  border-color: var(--danger);
}

.lib-empty {
  color: var(--text-mute);
  font-size: 14px;
  margin: 0;
}

/* ───── ABOUT ───── */
.about-inner {
  max-width: 1100px;
}

.about-grid {
  margin-top: 32px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 32px;
}

.about-grid h3 {
  font-size: 15px;
  font-weight: 600;
  margin: 0 0 8px;
  letter-spacing: -0.01em;
}

.about-grid p {
  color: var(--text-dim);
  font-size: 14px;
  margin: 0;
  line-height: 1.6;
}

/* ───── FOOT ───── */
.foot {
  display: flex;
  justify-content: space-between;
  padding: 32px clamp(16px, 5vw, 48px);
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-mute);
  flex-wrap: wrap;
  gap: 12px;
}

/* ───── TOAST ───── */
.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  padding: 11px 20px;
  background: var(--toast-bg);
  color: var(--toast-fg);
  border-radius: var(--radius);
  font-size: 13.5px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 100;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ───── MOBILE ───── */
@media (max-width: 600px) {
  .topnav {
    gap: 18px;
  }
  .output {
    position: static;
  }
  .model-switch {
    width: 100%;
    justify-content: stretch;
  }
  .model {
    flex: 1;
    text-align: center;
  }
}

/* ───── LAUNCH BUTTON ───── */
.btn-launch {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}
.launch-icon {
  display: inline-block;
  transform: translateX(0);
  transition: transform 0.2s ease;
}
.btn-launch:hover .launch-icon {
  transform: translateX(3px);
}

/* ───── MODAL ───── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  z-index: 1000;
  animation: fadeIn 0.18s ease;
}
[data-theme="light"] .modal-backdrop {
  background: rgba(20, 20, 30, 0.35);
}
.modal-backdrop[hidden] {
  display: none;
}
.modal {
  width: min(640px, 100%);
  max-height: 88vh;
  overflow: auto;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  padding: 1.5rem;
  animation: slideUp 0.22s ease;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.25rem;
}
.modal-head h2 {
  font-size: 1.25rem;
  margin: 0;
  font-weight: 600;
}
.modal-sub {
  color: var(--text-dim);
  font-size: 0.9rem;
  margin: 0 0 1.25rem;
}
.modal-foot {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}
.checkbox-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.88rem;
  color: var(--text-dim);
  cursor: pointer;
}
.checkbox-row input {
  accent-color: var(--accent);
}

/* ───── AI GRID ───── */
.ai-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.65rem;
}
.ai-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.35rem;
  padding: 0.85rem 1rem;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  text-align: left;
  transition: all 0.18s ease;
  font: inherit;
  color: var(--text);
}
.ai-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  background: color-mix(in oklab, var(--accent) 8%, var(--input-bg));
}
.ai-card-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
}
.ai-card-name {
  font-weight: 600;
  font-size: 0.98rem;
}
.ai-card-badge {
  margin-left: auto;
  font-size: 0.68rem;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  background: color-mix(in oklab, var(--accent) 18%, transparent);
  color: var(--accent);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.ai-card-desc {
  font-size: 0.78rem;
  color: var(--text-dim);
  line-height: 1.4;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes slideUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 600px) {
  .ai-grid { grid-template-columns: 1fr; }
  .modal { padding: 1.15rem; }
}
