:root {
  /* Warm Editorial Atelier Palette */
  --bg-canvas: hsl(38, 26%, 96%);
  --bg-surface: hsl(0, 0%, 100%);
  --bg-subtle: hsl(36, 22%, 93%);
  --bg-elevated: hsl(38, 30%, 98%);
  --bg-ink: hsl(24, 14%, 11%);

  --text-primary: hsl(24, 15%, 12%);
  --text-secondary: hsl(26, 9%, 38%);
  --text-muted: hsl(28, 7%, 54%);
  --text-on-accent: hsl(0, 0%, 100%);

  /* Cloudflare R2 Terracotta & Status Accents */
  --accent: hsl(20, 84%, 50%);
  --accent-hover: hsl(20, 86%, 44%);
  --accent-soft: hsl(22, 85%, 95%);
  --accent-ink: hsl(19, 80%, 34%);

  --ok-bg: hsl(150, 44%, 93%);
  --ok-text: hsl(152, 64%, 24%);
  --warn-bg: hsl(38, 86%, 93%);
  --warn-text: hsl(30, 78%, 28%);
  --danger-bg: hsl(4, 76%, 95%);
  --danger-text: hsl(4, 68%, 38%);

  --border-hairline: hsl(34, 16%, 87%);
  --border-strong: hsl(32, 14%, 76%);

  --shadow-card:
    0 1px 2px hsla(24, 20%, 12%, 0.04),
    0 8px 24px -6px hsla(24, 20%, 12%, 0.06);
  --shadow-float:
    0 4px 12px hsla(24, 20%, 12%, 0.08),
    0 24px 48px -12px hsla(24, 20%, 12%, 0.16);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;

  --font-sans: "Plus Jakarta Sans", "Noto Sans SC", -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

  --container-max: 1180px;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

body {
  margin: 0;
  min-height: 100vh;
  background-color: var(--bg-canvas);
  background-image: radial-gradient(
    ellipse 90% 50% at 50% -10%,
    hsla(24, 70%, 88%, 0.38),
    transparent 70%
  );
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.6;
}

/* Top Header */
.site-header {
  position: sticky;
  top: 0;
  z-index: 30;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  background: hsla(38, 26%, 96%, 0.84);
  border-bottom: 1px solid var(--border-hairline);
}

.header-inner {
  max-width: var(--container-max);
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

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

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: var(--bg-ink);
  color: var(--text-on-accent);
  display: grid;
  place-items: center;
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 13px;
  letter-spacing: -0.03em;
  box-shadow: inset 0 1px 0 hsla(0, 0%, 100%, 0.18);
}

.brand-mark span {
  color: hsl(22, 92%, 62%);
}

.brand-copy {
  display: flex;
  flex-direction: column;
}

.brand-title {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.25;
}

.brand-subtitle {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.2;
}

.header-status {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 11px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  background: var(--bg-surface);
  border: 1px solid var(--border-hairline);
  color: var(--text-secondary);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
}

.status-chip.is-ready {
  background: var(--ok-bg);
  color: var(--ok-text);
  border-color: hsla(152, 48%, 35%, 0.18);
}

.status-chip.is-ready .status-dot {
  background: hsl(152, 68%, 34%);
}

.status-chip.is-pending {
  background: var(--warn-bg);
  color: var(--warn-text);
  border-color: hsla(32, 70%, 40%, 0.2);
}

.status-chip.is-pending .status-dot {
  background: hsl(32, 88%, 44%);
}

.btn-ghost {
  appearance: none;
  border: 1px solid var(--border-hairline);
  background: var(--bg-surface);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 500;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.18s var(--ease-out), border-color 0.18s var(--ease-out), color 0.18s var(--ease-out);
}

.btn-ghost:hover {
  background: var(--bg-elevated);
  border-color: var(--border-strong);
  color: var(--text-primary);
}

/* Main Workspace */
.workspace {
  max-width: var(--container-max);
  margin: 0 auto;
  padding: 28px 24px 72px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

/* R2 Connection Notice (only visible if R2 not yet configured) */
.r2-banner {
  background: var(--bg-surface);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-md);
  padding: 16px 20px;
  box-shadow: var(--shadow-card);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.r2-banner[hidden] {
  display: none;
}

.r2-banner-title {
  margin: 0 0 4px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.r2-banner-desc {
  margin: 0;
  font-size: 13px;
  color: var(--text-secondary);
}

.r2-banner-desc code {
  font-family: var(--font-mono);
  font-size: 12px;
  background: var(--bg-subtle);
  padding: 2px 6px;
  border-radius: 4px;
}

/* Composer Studio Panel */
.composer-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.composer-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.composer-heading {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.composer-hint {
  font-size: 12.5px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.prompt-box {
  position: relative;
}

.prompt-textarea {
  width: 100%;
  min-height: 104px;
  resize: vertical;
  padding: 14px 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-hairline);
  background: var(--bg-elevated);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 15px;
  line-height: 1.6;
  transition: border-color 0.2s var(--ease-out), background 0.2s var(--ease-out), box-shadow 0.2s var(--ease-out);
}

.prompt-textarea:focus {
  outline: none;
  background: var(--bg-surface);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px hsla(20, 84%, 50%, 0.12);
}

.prompt-presets {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.preset-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-right: 2px;
}

.preset-chip {
  appearance: none;
  border: 1px solid var(--border-hairline);
  background: var(--bg-canvas);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.16s var(--ease-out);
}

.preset-chip:hover {
  background: var(--accent-soft);
  border-color: hsla(20, 84%, 50%, 0.35);
  color: var(--accent-ink);
}

.composer-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding-top: 6px;
  border-top: 1px solid var(--border-hairline);
}

.control-Cluster {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.field-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.field-label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-secondary);
}

.ratio-segmented {
  display: inline-flex;
  background: var(--bg-subtle);
  padding: 3px;
  border-radius: var(--radius-sm);
  gap: 2px;
}

.ratio-btn {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  padding: 5px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.16s var(--ease-out);
}

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

.ratio-btn.is-active {
  background: var(--bg-surface);
  color: var(--text-primary);
  box-shadow: 0 1px 3px hsla(24, 20%, 12%, 0.08);
}

.model-select {
  appearance: none;
  padding: 7px 30px 7px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-hairline);
  background-color: var(--bg-surface);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23635c55' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  font-family: inherit;
  font-size: 13px;
  color: var(--text-primary);
  cursor: pointer;
}

.model-select:focus {
  outline: none;
  border-color: var(--accent);
}

.btn-primary {
  appearance: none;
  border: none;
  background: var(--accent);
  color: var(--text-on-accent);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 10px 22px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  box-shadow: 0 2px 6px hsla(20, 84%, 40%, 0.24);
  transition: background 0.18s var(--ease-out), transform 0.15s var(--ease-out), box-shadow 0.18s var(--ease-out);
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px hsla(20, 84%, 40%, 0.3);
}

.btn-primary:active:not(:disabled) {
  transform: translateY(0);
}

.btn-primary:disabled {
  opacity: 0.65;
  cursor: wait;
}

.spinner {
  width: 15px;
  height: 15px;
  border: 2px solid hsla(0, 0%, 100%, 0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

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

.feedback-bar {
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.feedback-bar[hidden] {
  display: none;
}

.feedback-bar.is-error {
  background: var(--danger-bg);
  color: var(--danger-text);
  border: 1px solid hsla(4, 68%, 45%, 0.2);
}

.feedback-bar.is-progress {
  background: var(--accent-soft);
  color: var(--accent-ink);
  border: 1px solid hsla(20, 84%, 50%, 0.2);
}

/* Latest Spotlight Result */
.spotlight-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  overflow: hidden;
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(300px, 0.85fr);
}

.spotlight-card[hidden] {
  display: none;
}

.spotlight-stage {
  background: hsl(34, 18%, 92%);
  display: grid;
  place-items: center;
  padding: 24px;
  min-height: 320px;
}

.spotlight-stage img {
  max-width: 100%;
  max-height: 460px;
  border-radius: var(--radius-sm);
  box-shadow: 0 10px 30px hsla(24, 20%, 10%, 0.14);
  object-fit: contain;
}

.spotlight-meta {
  padding: 24px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 18px;
  border-left: 1px solid var(--border-hairline);
}

.meta-eyebrow {
  font-family: var(--font-mono);
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent-ink);
  margin-bottom: 6px;
}

.spotlight-prompt {
  margin: 0 0 14px;
  font-size: 15px;
  font-weight: 500;
  color: var(--text-primary);
}

.url-field-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.url-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
}

.url-copy-row {
  display: flex;
  gap: 8px;
}

.url-input {
  flex: 1;
  min-width: 0;
  padding: 8px 11px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-hairline);
  background: var(--bg-canvas);
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-primary);
}

.meta-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 18px;
  padding-top: 14px;
  border-top: 1px solid var(--border-hairline);
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
}

/* Gallery Section */
.gallery-section {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.section-title {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.015em;
}

.section-count {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 18px;
}

.gallery-empty {
  grid-column: 1 / -1;
  background: var(--bg-surface);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-md);
  padding: 48px 24px;
  text-align: center;
  color: var(--text-muted);
}

.asset-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  transition: transform 0.2s var(--ease-out), box-shadow 0.2s var(--ease-out), border-color 0.2s var(--ease-out);
}

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

.asset-thumb-wrap {
  position: relative;
  aspect-ratio: 4 / 3;
  background: var(--bg-subtle);
  overflow: hidden;
  cursor: pointer;
}

.asset-thumb-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.35s var(--ease-out);
}

.asset-card:hover .asset-thumb-wrap img {
  transform: scale(1.03);
}

.storage-badge {
  position: absolute;
  top: 10px;
  left: 10px;
  padding: 3px 8px;
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  backdrop-filter: blur(8px);
  background: hsla(24, 16%, 12%, 0.74);
  color: #fff;
}

.storage-badge.is-r2 {
  background: hsla(20, 86%, 44%, 0.9);
}

.asset-body {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1;
}

.asset-prompt {
  margin: 0;
  font-size: 13.5px;
  line-height: 1.45;
  color: var(--text-primary);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  flex: 1;
}

.asset-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border-hairline);
}

.asset-meta-tag {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
}

.asset-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn-mini {
  appearance: none;
  border: 1px solid var(--border-hairline);
  background: var(--bg-canvas);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 11.5px;
  font-weight: 500;
  padding: 4px 9px;
  border-radius: 6px;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.15s var(--ease-out);
}

.btn-mini:hover {
  background: var(--accent-soft);
  border-color: hsla(20, 84%, 50%, 0.35);
  color: var(--accent-ink);
}

.btn-mini.is-danger:hover {
  background: var(--danger-bg);
  border-color: hsla(4, 68%, 45%, 0.3);
  color: var(--danger-text);
}

/* Modal Dialogs */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: hsla(24, 18%, 10%, 0.56);
  backdrop-filter: blur(6px);
  display: grid;
  place-items: center;
  padding: 20px;
}

.modal-backdrop[hidden] {
  display: none;
}

.modal-panel {
  width: 100%;
  max-width: 440px;
  background: var(--bg-surface);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-float);
  padding: 24px;
}

.modal-panel.is-wide {
  max-width: 860px;
  padding: 0;
  overflow: hidden;
}

.modal-title {
  margin: 0 0 6px;
  font-size: 17px;
  font-weight: 700;
}

.modal-desc {
  margin: 0 0 16px;
  font-size: 13.5px;
  color: var(--text-secondary);
}

.modal-input {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-hairline);
  font-family: var(--font-mono);
  font-size: 14px;
  margin-bottom: 16px;
}

.modal-input:focus {
  outline: none;
  border-color: var(--accent);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 80;
  background: var(--bg-ink);
  color: #fff;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  box-shadow: var(--shadow-float);
  transition: opacity 0.2s var(--ease-out), transform 0.2s var(--ease-out);
}

.toast[hidden] {
  display: none;
}

/* Responsive */
@media (max-width: 820px) {
  .spotlight-card {
    grid-template-columns: 1fr;
  }

  .spotlight-meta {
    border-left: none;
    border-top: 1px solid var(--border-hairline);
  }

  .composer-controls {
    flex-direction: column;
    align-items: stretch;
  }

  .btn-primary {
    justify-content: center;
    width: 100%;
  }
}
