:root {
  color-scheme: light;
  --bg: #f3f5f2;
  --surface: #ffffff;
  --surface-2: #eef1ed;
  --surface-3: #e6eae5;
  --ink: #17201c;
  --muted: #69736e;
  --line: #d8ddd8;
  --line-strong: #bec7c1;
  --accent: #ef5a3c;
  --accent-dark: #c9412a;
  --teal: #087f74;
  --yellow: #e4bd4f;
  --dark-panel: #15211d;
  --shadow: 0 16px 42px rgba(28, 42, 35, 0.08);
  --radius: 6px;
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--ink);
  background: var(--bg);
  letter-spacing: 0;
}

button,
input,
textarea,
select {
  font: inherit;
  letter-spacing: 0;
}

button,
label,
select {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
a:focus-visible,
summary:focus-visible {
  outline: 3px solid rgba(8, 127, 116, 0.25);
  outline-offset: 2px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.app-shell {
  display: grid;
  grid-template: 64px minmax(0, 1fr) / 208px minmax(0, 1fr);
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
  padding: 0 24px;
  background: rgba(247, 248, 245, 0.96);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(16px);
}

.brand {
  display: flex;
  align-items: center;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  position: relative;
  display: grid;
  grid-template-columns: repeat(3, 5px);
  align-items: end;
  gap: 3px;
  width: 29px;
  height: 29px;
  margin-right: 10px;
  padding: 6px;
  background: var(--ink);
  border-radius: 5px;
}

.brand-mark i {
  display: block;
  width: 5px;
  background: #fff;
}

.brand-mark i:nth-child(1) { height: 8px; }
.brand-mark i:nth-child(2) { height: 16px; background: var(--accent); }
.brand-mark i:nth-child(3) { height: 11px; }

.brand-name {
  font-size: 16px;
  font-weight: 800;
}

.brand-suffix {
  margin-left: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.topbar-actions,
.preview-actions,
.preview-toolbar > div,
.head-meta {
  display: flex;
  align-items: center;
}

.topbar-actions {
  gap: 10px;
}

.provider-status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 32px;
  padding: 0 11px;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 5px;
  font-size: 12px;
  font-weight: 650;
  font-family: inherit;
  cursor: pointer;
}

.provider-status:hover { border-color: var(--line-strong); background: var(--surface-2); }

.status-dot,
.preview-state i {
  width: 7px;
  height: 7px;
  background: var(--yellow);
  border-radius: 50%;
}

.provider-status.connected .status-dot { background: var(--teal); }
.provider-status.demo .status-dot { background: var(--accent); }

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 5px;
  cursor: pointer;
  transition: border-color 150ms ease, background 150ms ease, transform 150ms ease;
}

.icon-button:hover:not(:disabled) {
  background: var(--surface-2);
  border-color: var(--line-strong);
}

.icon-button:active:not(:disabled) { transform: translateY(1px); }
.icon-button.small { width: 30px; height: 30px; }

.sidebar {
  position: sticky;
  top: 64px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  height: calc(100vh - 64px);
  padding: 20px 14px;
  background: #f8f9f7;
  border-right: 1px solid var(--line);
}

.sidebar nav {
  display: grid;
  gap: 5px;
}

.nav-item {
  display: grid;
  grid-template-columns: 24px 1fr auto;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 11px;
  color: var(--muted);
  border-radius: 5px;
  font-size: 13px;
  font-weight: 650;
  text-decoration: none;
}

.nav-item:hover { color: var(--ink); background: var(--surface-2); }
.nav-item.active { color: var(--ink); background: var(--surface-3); }

.nav-icon {
  display: grid;
  place-items: center;
  width: 24px;
  color: var(--teal);
  font-size: 17px;
}

.grid-icon { font-size: 18px; }

.nav-count {
  display: grid;
  place-items: center;
  min-width: 21px;
  height: 21px;
  padding: 0 5px;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 4px;
  font-size: 10px;
}

.sidebar-foot {
  display: grid;
  gap: 16px;
}

.quota-block {
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.quota-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 9px;
  color: var(--muted);
  font-size: 11px;
}

.quota-row strong { color: var(--ink); }

.quota-track,
.progress-track {
  overflow: hidden;
  height: 4px;
  background: var(--surface-3);
  border-radius: 2px;
}

.quota-track span,
.progress-track span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--teal);
  transition: width 300ms ease;
}

.privacy-note {
  color: var(--muted);
  font-size: 10px;
  text-align: center;
}

.privacy-note span { color: var(--teal); }

.main-content {
  min-width: 0;
  padding: 36px clamp(22px, 3.4vw, 54px) 80px;
}

.page-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  max-width: 1400px;
  margin: 0 auto 24px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--teal);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p { margin-top: 0; }

h1 {
  margin-bottom: 0;
  font-size: clamp(26px, 3vw, 38px);
  line-height: 1.1;
}

h2 {
  margin-bottom: 0;
  font-size: 22px;
}

.head-meta {
  gap: 10px;
  color: var(--muted);
  font-size: 11px;
}

.meta-separator {
  width: 3px;
  height: 3px;
  background: var(--line-strong);
  border-radius: 50%;
}

.studio-layout {
  display: grid;
  grid-template-columns: minmax(350px, 430px) minmax(0, 1fr);
  gap: clamp(18px, 2.4vw, 32px);
  align-items: start;
  max-width: 1400px;
  margin: auto;
}

.composer {
  display: grid;
  gap: 20px;
  padding: 22px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.mode-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  background: var(--surface-2);
  border-radius: 5px;
}

.mode-button {
  height: 38px;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
}

.mode-button.active {
  color: var(--ink);
  background: var(--surface);
  box-shadow: 0 1px 3px rgba(20, 32, 27, 0.1);
}

.mode-button.unavailable {
  opacity: 0.42;
  cursor: not-allowed;
}

.mode-symbol { margin-right: 6px; color: var(--accent); font-size: 10px; }
.image-symbol { color: var(--teal); font-size: 14px; }

.field-block {
  display: grid;
  gap: 9px;
  min-width: 0;
}

.inline-fields {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.85fr);
  gap: 10px;
}

.field-block > label,
.field-heading label,
.option-group legend,
.negative-prompt summary,
.legend-row legend {
  color: var(--ink);
  font-size: 12px;
  font-weight: 750;
}

.field-heading,
.legend-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.field-heading > span,
.field-heading output,
.legend-row > span {
  color: var(--muted);
  font-size: 10px;
}

textarea,
input[type="number"],
input[type="text"],
input[type="url"],
input[type="password"],
select {
  width: 100%;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 5px;
}

input[type="text"],
input[type="url"],
input[type="password"] {
  height: 42px;
  padding: 0 11px;
  font-size: 12px;
}

textarea:hover,
input:hover,
select:hover { border-color: var(--line-strong); }

textarea:focus,
input:focus,
select:focus {
  border-color: var(--teal);
  outline: 0;
}

select {
  height: 40px;
  padding: 0 38px 0 11px;
  appearance: none;
  cursor: pointer;
  font-size: 12px;
}

.select-wrap { position: relative; }

.select-wrap::after {
  content: "⌄";
  position: absolute;
  top: 8px;
  right: 12px;
  color: var(--muted);
  pointer-events: none;
}

.prompt-field { position: relative; }

.prompt-field textarea {
  min-height: 126px;
  padding: 13px 13px 40px;
  resize: vertical;
  font-size: 13px;
  line-height: 1.7;
}

textarea::placeholder,
input::placeholder { color: #949d98; }

.prompt-actions {
  position: absolute;
  right: 8px;
  bottom: 7px;
  left: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  pointer-events: none;
}

.prompt-actions button { pointer-events: auto; }

.text-button {
  padding: 6px;
  color: var(--teal);
  background: transparent;
  border: 0;
  border-radius: 4px;
  cursor: pointer;
  font-size: 11px;
  font-weight: 700;
}

.text-button:hover { background: rgba(8, 127, 116, 0.08); }
.text-button.danger { color: var(--accent-dark); }

.negative-prompt {
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.negative-prompt summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0;
  cursor: pointer;
  list-style: none;
}

.negative-prompt summary::-webkit-details-marker { display: none; }
.negative-prompt[open] summary span { transform: rotate(45deg); }
.negative-prompt textarea { min-height: 78px; margin-bottom: 14px; padding: 10px; resize: vertical; font-size: 12px; }

.upload-zone {
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto;
  align-items: center;
  gap: 1px 10px;
  min-height: 72px;
  padding: 12px;
  overflow: hidden;
  background: var(--bg);
  border: 1px dashed var(--line-strong);
  border-radius: 5px;
  cursor: pointer;
}

.upload-zone:hover,
.upload-zone.dragover { border-color: var(--teal); background: rgba(8, 127, 116, 0.05); }

.upload-icon {
  grid-row: 1 / 3;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  color: var(--teal);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 5px;
  font-size: 18px;
}

.upload-primary { align-self: end; font-size: 11px; font-weight: 750; }
.upload-secondary { align-self: start; color: var(--muted); font-size: 10px; }

#referencePreview {
  display: none;
  grid-row: 1 / 3;
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: 4px;
}

.upload-zone.has-image #referencePreview { display: block; }
.upload-zone.has-image .upload-icon { display: none; }

.remove-reference {
  position: absolute;
  top: 8px;
  right: 8px;
  display: none;
  width: 26px;
  height: 26px;
  padding: 0;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 4px;
  cursor: pointer;
}

.upload-zone.has-image .remove-reference { display: block; }

.option-group {
  margin: 0;
  padding: 0;
  border: 0;
}

.ratio-options {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 7px;
}

.ratio-options label,
.resolution-options label { min-width: 0; }
.ratio-options input,
.resolution-options input { position: absolute; opacity: 0; pointer-events: none; }

.ratio-options label > span {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 38px;
  color: var(--muted);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 4px;
  cursor: pointer;
  font-size: 10px;
  font-weight: 700;
}

.ratio-options input:checked + span,
.resolution-options input:checked + span {
  color: var(--teal);
  background: rgba(8, 127, 116, 0.07);
  border-color: var(--teal);
}

.ratio-shape {
  display: inline-block;
  border: 1px solid currentColor;
  border-radius: 1px;
}

.ratio-shape.landscape { width: 16px; height: 9px; }
.ratio-shape.portrait { width: 8px; height: 14px; }
.ratio-shape.square { width: 11px; height: 11px; }
.ratio-shape.classic { width: 14px; height: 10px; }

.resolution-options {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
}

.resolution-options label > span {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 43px;
  padding: 0 10px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 4px;
  cursor: pointer;
}

.resolution-options strong { font-size: 11px; }
.resolution-options small { color: var(--muted); font-size: 9px; }
.resolution-options input:checked + span small { color: var(--teal); }

input[type="range"] {
  width: 100%;
  height: 4px;
  margin: 8px 0 2px;
  accent-color: var(--teal);
}

.range-scale {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 9px;
}

.input-with-action { position: relative; }
.input-with-action input { height: 40px; padding: 0 46px 0 11px; font-size: 12px; }
.input-with-action button { position: absolute; top: 5px; right: 5px; }

.generate-button {
  display: grid;
  grid-template-columns: 28px 1fr 28px;
  align-items: center;
  min-height: 50px;
  padding: 0 12px;
  color: #fff;
  background: var(--ink);
  border: 0;
  border-radius: 5px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 800;
  box-shadow: 0 10px 22px rgba(23, 32, 28, 0.16);
  transition: background 150ms ease, transform 150ms ease;
}

.generate-button:hover:not(:disabled) { background: var(--teal); }
.generate-button:active:not(:disabled) { transform: translateY(1px); }
.generate-icon { color: var(--yellow); font-size: 18px; }
.button-arrow { font-size: 18px; }

.preview-panel {
  position: sticky;
  top: 88px;
  min-width: 0;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.preview-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 58px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
}

.preview-toolbar > div:first-child { gap: 12px; }
.panel-label { font-size: 12px; font-weight: 800; }

.preview-state {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 10px;
}

.preview-state.processing i { background: var(--yellow); animation: pulse 1.1s infinite; }
.preview-state.success i { background: var(--teal); }
.preview-state.error i { background: var(--accent); }

@keyframes pulse {
  50% { opacity: 0.35; transform: scale(0.75); }
}

.preview-actions { gap: 7px; }

.download-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 78px;
  height: 34px;
  padding: 0 11px;
  color: var(--surface);
  background: var(--ink);
  border: 0;
  border-radius: 5px;
  cursor: pointer;
  font-size: 11px;
  font-weight: 700;
}

.preview-stage {
  position: relative;
  display: grid;
  place-items: center;
  min-height: clamp(390px, 56vw, 650px);
  overflow: hidden;
  background: var(--dark-panel);
  isolation: isolate;
}

#idleCanvas,
.media-mount,
.media-mount img,
.media-mount video,
.media-mount canvas {
  width: 100%;
  height: 100%;
}

#idleCanvas {
  position: absolute;
  inset: 0;
  opacity: 0.72;
}

.empty-preview {
  position: relative;
  z-index: 2;
  display: grid;
  justify-items: center;
  color: #f5f6f2;
  text-align: center;
  text-shadow: 0 2px 18px rgba(0, 0, 0, 0.32);
}

.empty-kicker {
  margin-bottom: 10px;
  padding: 4px 7px;
  color: #13201c;
  background: var(--yellow);
  font-size: 9px;
  font-weight: 900;
}

.empty-title { font-size: clamp(24px, 4vw, 48px); font-weight: 800; }
.empty-format { margin-top: 9px; color: rgba(255, 255, 255, 0.66); font-size: 10px; }

.media-mount {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: grid;
  place-items: center;
}

.media-mount img,
.media-mount video,
.media-mount canvas {
  display: block;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  background: #0f1714;
}

.media-mount canvas {
  width: auto;
  height: auto;
}

.progress-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: auto 1fr;
  align-content: center;
  gap: 16px 18px;
  padding: clamp(24px, 6vw, 72px);
  color: #f7f8f5;
  background: rgba(15, 23, 20, 0.88);
  backdrop-filter: blur(10px);
}

.progress-overlay[hidden] { display: none; }

.progress-number {
  display: flex;
  align-items: start;
  min-width: 78px;
}

.progress-number strong { font-size: 48px; line-height: 0.9; }
.progress-number span { margin-left: 3px; color: var(--yellow); font-size: 14px; }
.progress-copy { display: grid; align-content: center; gap: 6px; }
.progress-copy strong { font-size: 15px; }
.progress-copy span { color: rgba(255,255,255,0.6); font-size: 11px; }
.progress-overlay .progress-track { grid-column: 1 / -1; height: 5px; background: rgba(255,255,255,0.14); }
.progress-overlay .progress-track span {
  position: relative;
  overflow: hidden;
  background: linear-gradient(90deg, var(--yellow), #fff1a8, var(--yellow));
  background-size: 180% 100%;
  box-shadow: 0 0 14px rgba(238, 195, 73, 0.42);
  animation: progress-shine 1.15s linear infinite;
}

@keyframes progress-shine {
  from { background-position: 180% 0; }
  to { background-position: 0 0; }
}

.preview-footer {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  min-height: 60px;
  border-top: 1px solid var(--line);
}

.preview-spec {
  display: grid;
  align-content: center;
  gap: 3px;
  padding: 0 16px;
  border-right: 1px solid var(--line);
}

.preview-spec:last-child { border: 0; }
.preview-spec span { color: var(--muted); font-size: 9px; }
.preview-spec strong { overflow: hidden; font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }

.library-section {
  max-width: 1400px;
  margin: 70px auto 0;
  padding-top: 32px;
  border-top: 1px solid var(--line);
  scroll-margin-top: 80px;
}

.section-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  margin-bottom: 20px;
}

.library-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.library-card {
  min-width: 0;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
  transition: transform 150ms ease, border-color 150ms ease, box-shadow 150ms ease;
}

.library-card:hover {
  transform: translateY(-2px);
  border-color: var(--line-strong);
  box-shadow: var(--shadow);
}

.card-media {
  position: relative;
  aspect-ratio: 16 / 10;
  overflow: hidden;
  background: var(--dark-panel);
}

.card-media img,
.card-media video,
.card-media canvas { width: 100%; height: 100%; object-fit: cover; }

.card-kind {
  position: absolute;
  top: 8px;
  left: 8px;
  padding: 4px 6px;
  color: #fff;
  background: rgba(15, 23, 20, 0.76);
  border-radius: 3px;
  font-size: 9px;
  font-weight: 800;
}

.card-info { padding: 11px; }
.card-prompt { margin: 0 0 8px; overflow: hidden; font-size: 11px; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.card-meta { display: flex; justify-content: space-between; color: var(--muted); font-size: 9px; }

.library-empty {
  display: grid;
  justify-items: center;
  gap: 7px;
  padding: 54px 20px;
  color: var(--muted);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  text-align: center;
}

.library-empty-mark { color: var(--teal); font-size: 26px; }
.library-empty strong { color: var(--ink); font-size: 13px; }
.library-empty span:last-child { font-size: 10px; }

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 100;
  max-width: min(360px, calc(100vw - 32px));
  padding: 11px 14px;
  color: #fff;
  background: var(--ink);
  border-left: 4px solid var(--teal);
  border-radius: 4px;
  box-shadow: var(--shadow);
  font-size: 11px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.visible { opacity: 1; transform: translateY(0); }
.toast.error { border-left-color: var(--accent); }

.key-dialog {
  width: min(500px, calc(100vw - 28px));
  min-width: 0;
  max-width: none;
  max-height: calc(100vh - 28px);
  padding: 0;
  overflow: auto;
  color: var(--ink);
  background: transparent;
  border: 0;
  border-radius: var(--radius);
}

.key-dialog::backdrop {
  background: rgba(10, 16, 13, 0.72);
  backdrop-filter: blur(8px);
}

.key-panel {
  display: grid;
  gap: 18px;
  min-width: 0;
  padding: 28px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  box-shadow: 0 28px 70px rgba(0, 0, 0, 0.3);
}

.key-panel > * { min-width: 0; }

.key-panel-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.key-panel-head .brand-mark { flex: 0 0 auto; margin-right: 0; }
.key-panel-head .eyebrow { margin-bottom: 4px; }
.key-panel-head h2 { font-size: 20px; }

.key-provider-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 38px;
  padding: 0 11px;
  background: var(--surface-2);
  border-left: 3px solid var(--teal);
  border-radius: 3px;
  font-size: 11px;
  overflow: hidden;
}

.key-provider-row span { color: var(--muted); }
.key-provider-row strong {
  flex: 1 1 0;
  max-width: none;
  min-width: 0;
  overflow: hidden;
  font-size: 11px;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.key-input-wrap { position: relative; }
.key-input-wrap input { padding-right: 48px; }
.key-input-wrap button { position: absolute; top: 6px; right: 6px; }
.key-model-fields { grid-template-columns: 1fr 1fr; }

.model-discovery-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 48px;
  padding: 7px 8px 7px 11px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 4px;
  overflow: hidden;
}

.model-discovery-row > div { display: grid; gap: 2px; min-width: 0; }
.model-discovery-row strong { font-size: 11px; }
.model-discovery-row span { color: var(--muted); font-size: 9px; }

.model-fetch-button {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 32px;
  padding: 0 10px;
  color: var(--teal);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  cursor: pointer;
  font-size: 10px;
  font-weight: 800;
}

.model-fetch-button:hover:not(:disabled) { border-color: var(--teal); }
.model-fetch-button:disabled { cursor: wait; opacity: 0.55; }

.key-status {
  min-height: 17px;
  margin: -5px 0;
  color: var(--muted);
  font-size: 10px;
}

.key-status.error { color: var(--accent-dark); }
.key-status.success { color: var(--teal); }
.key-status.checking { color: var(--muted); }
.key-connect-button { width: 100%; }

.disconnect-button {
  min-height: 36px;
  color: var(--accent-dark);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 4px;
  cursor: pointer;
  font-size: 11px;
  font-weight: 700;
}

.disconnect-button:hover { background: rgba(239, 90, 60, 0.07); border-color: var(--accent); }

.key-security {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  color: var(--muted);
  font-size: 9px;
  text-align: center;
}

.key-security > span:first-child { color: var(--teal); }

.preview-stage:fullscreen {
  width: 100vw;
  height: 100vh;
  min-height: 100vh;
  background: #0b120f;
}

body.dark {
  color-scheme: dark;
  --bg: #151b18;
  --surface: #1d2521;
  --surface-2: #242d28;
  --surface-3: #2b3530;
  --ink: #eef2ee;
  --muted: #9da8a2;
  --line: #354039;
  --line-strong: #4a5750;
  --dark-panel: #0a100d;
  --shadow: 0 16px 42px rgba(0, 0, 0, 0.24);
}

body.dark .topbar,
body.dark .sidebar { background: rgba(21, 27, 24, 0.97); }
body.dark .generate-button { color: #14201b; background: #eef2ee; }
body.dark .download-button { color: #14201b; background: #eef2ee; }

@media (max-width: 1100px) {
  .app-shell { grid-template-columns: 72px minmax(0, 1fr); }
  .sidebar { padding-inline: 9px; }
  .nav-item { grid-template-columns: 1fr; justify-items: center; gap: 0; padding: 7px 3px; font-size: 9px; }
  .nav-count,
  .sidebar-foot { display: none; }
  .studio-layout { grid-template-columns: minmax(320px, 390px) minmax(0, 1fr); }
  .library-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 840px) {
  .app-shell { display: block; }
  .topbar { padding-inline: 16px; }
  .sidebar {
    position: fixed;
    top: auto;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 30;
    display: block;
    width: auto;
    height: 62px;
    padding: 6px 18px;
    border-top: 1px solid var(--line);
    border-right: 0;
  }
  .sidebar nav { grid-template-columns: 1fr 1fr; max-width: 360px; margin: auto; }
  .nav-item { min-height: 48px; }
  .main-content { padding: 28px 16px 100px; }
  .studio-layout { grid-template-columns: 1fr; }
  .preview-panel { position: relative; top: auto; grid-row: 1; }
  .composer { grid-row: 2; }
  .preview-stage { min-height: min(65vh, 520px); }
  .library-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 540px) {
  .brand-suffix { display: none; }
  .topbar-actions { min-width: 0; gap: 6px; }
  .provider-status { min-width: 0; max-width: 112px; padding-inline: 8px; }
  #providerLabel { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .page-head { align-items: start; }
  .head-meta { display: none; }
  .composer { padding: 16px; }
  .inline-fields,
  .key-model-fields { grid-template-columns: 1fr; }
  .key-panel { gap: 15px; padding: 20px; }
  .preview-toolbar { padding-inline: 12px; }
  .preview-toolbar > div:first-child { display: grid; gap: 2px; }
  .preview-stage { min-height: 360px; }
  .progress-overlay { grid-template-columns: 1fr; gap: 10px; padding: 28px; }
  .progress-overlay .progress-track { grid-column: 1; }
  .preview-footer { min-height: 56px; }
  .preview-spec { padding-inline: 10px; }
  .ratio-options { grid-template-columns: repeat(2, 1fr); }
  .resolution-options label > span { display: grid; justify-content: center; gap: 2px; padding: 7px 3px; text-align: center; }
  .library-grid { grid-template-columns: 1fr; }
  .toast { right: 16px; bottom: 78px; }
}

@media (max-width: 380px) {
  .topbar { padding-inline: 12px; }
  .brand-name { font-size: 14px; }
  .provider-status { max-width: 88px; }
  .topbar-actions .icon-button { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
