:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-strong: #f1f5f9;
  --text: #0f172a;
  --muted: #64748b;
  --line: #d9e1ea;
  --accent: #16a34a;
  --accent-strong: #15803d;
  --danger: #b42318;
  --shadow: 0 18px 60px rgba(15, 23, 42, 0.1);
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #090d14;
  --surface: #111827;
  --surface-strong: #172033;
  --text: #f8fafc;
  --muted: #9aa8ba;
  --line: #263244;
  --accent: #22c55e;
  --accent-strong: #4ade80;
  --danger: #f97066;
  --shadow: 0 18px 60px rgba(0, 0, 0, 0.34);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  overflow-x: hidden;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
textarea,
select {
  font: inherit;
}

button,
a,
label[for] {
  cursor: pointer;
}

svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

.skip-link {
  position: absolute;
  left: 16px;
  top: -48px;
  z-index: 10;
  padding: 10px 12px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.skip-link:focus {
  top: 16px;
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  max-width: 1320px;
  margin: 0 auto;
  padding: 28px 24px 18px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 30px;
  line-height: 1.15;
  letter-spacing: 0;
}

h2 {
  font-size: 18px;
  line-height: 1.25;
  letter-spacing: 0;
}

.eyebrow {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

.icon-button {
  display: inline-grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  transition: border-color 180ms ease, background 180ms ease;
}

.icon-button:hover {
  border-color: var(--accent);
}

.studio {
  display: grid;
  grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
  gap: 18px;
  max-width: 1320px;
  margin: 0 auto;
  padding: 0 24px 28px;
}

.control-panel,
.preview-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.control-panel {
  padding: 20px;
}

.preview-panel {
  min-height: 720px;
  padding: 20px;
}

.panel-title-row,
.preview-header,
.dialog-header,
.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.mode-pill {
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.form-stack {
  display: grid;
  gap: 16px;
  margin-top: 20px;
}

.field {
  display: grid;
  gap: 8px;
  color: var(--text);
  font-size: 13px;
  font-weight: 650;
}

.field input,
.field textarea,
.field select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--text);
  outline: none;
  padding: 11px 12px;
  transition: border-color 180ms ease, box-shadow 180ms ease;
}

.api-key-field {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--accent) 7%, var(--surface));
}

.field textarea {
  min-height: 180px;
  resize: vertical;
  line-height: 1.5;
}

.field input:focus,
.field textarea:focus,
.field select:focus,
.icon-button:focus-visible,
.primary-button:focus-visible,
.secondary-button:focus-visible,
.text-button:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 24%, transparent);
}

.upload-zone {
  display: grid;
  gap: 5px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  padding: 16px;
  transition: border-color 180ms ease, background 180ms ease;
}

.upload-zone:hover {
  border-color: var(--accent);
}

.upload-zone input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.upload-title {
  font-weight: 700;
}

.upload-copy {
  color: var(--muted);
  font-size: 13px;
}

.uploaded-preview {
  display: grid;
  grid-template-columns: 84px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.uploaded-preview img {
  width: 84px;
  height: 64px;
  border-radius: 6px;
  object-fit: cover;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.primary-button,
.secondary-button,
.text-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  border-radius: 8px;
  border: 1px solid transparent;
  text-decoration: none;
  transition: background 180ms ease, border-color 180ms ease, opacity 180ms ease;
}

.primary-button {
  width: 100%;
  background: var(--accent);
  color: #052e16;
  font-weight: 800;
}

.primary-button:hover {
  background: var(--accent-strong);
}

.primary-button:disabled {
  cursor: not-allowed;
  opacity: .55;
}

.primary-button.compact {
  width: auto;
  padding: 0 18px;
}

.secondary-button {
  padding: 0 14px;
  border-color: var(--line);
  background: var(--surface-strong);
  color: var(--text);
}

.text-button {
  width: max-content;
  border: 0;
  background: transparent;
  color: var(--accent-strong);
  font-weight: 750;
}

.button-spinner {
  display: none;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(5, 46, 22, .35);
  border-top-color: #052e16;
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}

.is-loading .button-spinner {
  display: block;
}

.status {
  min-height: 22px;
  margin-top: 16px;
  color: var(--muted);
  font-size: 13px;
}

.status.error {
  color: var(--danger);
}

.preview-stage {
  display: grid;
  min-height: 560px;
  margin-top: 20px;
  place-items: center;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(45deg, color-mix(in srgb, var(--surface-strong) 75%, transparent) 25%, transparent 25%),
    linear-gradient(-45deg, color-mix(in srgb, var(--surface-strong) 75%, transparent) 25%, transparent 25%);
  background-size: 26px 26px;
}

.preview-stage img {
  max-width: 100%;
  max-height: 76vh;
  object-fit: contain;
}

.empty-state {
  display: grid;
  justify-items: center;
  gap: 14px;
  color: var(--muted);
}

.empty-mark {
  width: 96px;
  height: 96px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 18%, transparent), transparent);
}

.metadata {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 12px;
  margin: 16px 0 0;
}

.metadata div {
  display: contents;
}

.metadata dt,
.metadata dd {
  margin: 0;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  font-size: 13px;
}

.metadata dt {
  color: var(--muted);
}

.metadata dd {
  min-width: 0;
  word-break: break-word;
}

[hidden] {
  display: none !important;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 900px) {
  .app-header {
    padding: 20px 16px 14px;
  }

  .studio {
    grid-template-columns: 1fr;
    padding: 0 16px 20px;
  }

  .preview-panel {
    min-height: auto;
  }

  .preview-stage {
    min-height: 360px;
  }
}

@media (max-width: 560px) {
  .app-header {
    gap: 12px;
  }

  h1 {
    font-size: 24px;
    overflow-wrap: anywhere;
  }

  .control-panel,
  .preview-panel {
    padding: 16px;
  }

  .field-grid,
  .metadata {
    grid-template-columns: 1fr;
  }

  .panel-title-row,
  .preview-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .field textarea {
    min-height: 150px;
  }

  .upload-zone {
    padding: 14px;
  }

  .uploaded-preview {
    grid-template-columns: 72px minmax(0, 1fr);
  }

  .uploaded-preview img {
    width: 72px;
    height: 56px;
  }

  .preview-stage {
    min-height: 280px;
  }

  .secondary-button,
  .text-button {
    width: 100%;
  }

  .metadata dt,
  .metadata dd {
    padding-top: 10px;
  }
}

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