:root {
  color-scheme: light;
  --bg: #f8fafc;
  --panel: rgba(255, 255, 255, 0.88);
  --panel-strong: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --faint: #94a3b8;
  --border: rgba(148, 163, 184, 0.28);
  --cyan: #06b6d4;
  --cyan-strong: #0891b2;
  --cyan-soft: rgba(14, 165, 233, 0.12);
  --rose-soft: rgba(236, 72, 153, 0.10);
  --shadow: 0 24px 80px rgba(15, 23, 42, 0.12);
  --radius-xl: 1.5rem;
  --radius-lg: 1.25rem;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #071018;
    --panel: rgba(15, 23, 42, 0.82);
    --panel-strong: #0f172a;
    --text: #f8fafc;
    --muted: #94a3b8;
    --faint: #64748b;
    --border: rgba(255, 255, 255, 0.10);
    --cyan: #67e8f9;
    --cyan-strong: #22d3ee;
    --cyan-soft: rgba(45, 212, 191, 0.18);
    --rose-soft: rgba(244, 114, 182, 0.14);
    --shadow: 0 24px 80px rgba(0, 0, 0, 0.32);
  }
}

* { box-sizing: border-box; min-width: 0; }
html { min-height: 100%; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
}
button, textarea, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.62; }
code { border-radius: 0.45rem; background: rgba(148, 163, 184, 0.16); padding: 0.12rem 0.34rem; }

.studio-shell {
  position: relative;
  width: min(1180px, calc(100vw - 24px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 1rem 0 calc(1rem + env(safe-area-inset-bottom));
}

.ambient { position: fixed; inset: auto; pointer-events: none; z-index: -1; filter: blur(2px); }
.ambient-a {
  left: -12rem;
  top: -9rem;
  width: 42rem;
  height: 42rem;
  background: radial-gradient(circle, var(--cyan-soft), transparent 68%);
}
.ambient-b {
  right: -14rem;
  top: 4rem;
  width: 38rem;
  height: 38rem;
  background: radial-gradient(circle, var(--rose-soft), transparent 70%);
}

.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 1rem;
  padding: 1rem 0 1.25rem;
}

.hero-panel {
  max-width: 46rem;
  padding-top: 0.25rem;
}
.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  border: 1px solid rgba(6, 182, 212, 0.20);
  border-radius: 999px;
  background: var(--cyan-soft);
  color: var(--cyan-strong);
  padding: 0.32rem 0.72rem;
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.spark { color: var(--cyan); }
.hero-panel h1 {
  margin: 1rem 0 0;
  font-size: clamp(2.2rem, 6vw, 4rem);
  line-height: 0.98;
  letter-spacing: -0.06em;
  font-weight: 950;
}
.hero-panel p {
  max-width: 42rem;
  margin: 0.85rem 0 0;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.7;
}

.account-card {
  width: min(25rem, 42vw);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 0.85rem;
  backdrop-filter: blur(18px);
}
.account-summary { display: flex; align-items: center; gap: 0.75rem; }
.avatar {
  display: inline-flex;
  width: 2.5rem;
  height: 2.5rem;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: var(--cyan-soft);
  color: var(--cyan-strong);
  font-weight: 900;
}
.account-name { margin: 0; font-size: 0.95rem; font-weight: 900; }
.account-subtitle { margin: 0.2rem 0 0; color: var(--muted); font-size: 0.82rem; }
.account-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; margin-top: 0.75rem; }

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 420px);
  align-items: start;
  gap: 1rem;
}
.composer-card,
.result-card,
.history-grid,
.footer-note {
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}
.composer-card { padding: clamp(0.85rem, 2vw, 1.5rem); }
.result-card { position: sticky; top: 1rem; padding: clamp(0.85rem, 2vw, 1.25rem); }

.composer-head { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; }
.segmented { display: inline-flex; flex: 0 0 auto; border-radius: 999px; background: rgba(148, 163, 184, 0.14); padding: 0.25rem; }
.segment {
  min-height: 2.5rem;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  padding: 0 1rem;
  font-weight: 850;
  transition: background 160ms ease, color 160ms ease, box-shadow 160ms ease;
}
.segment.is-active { background: var(--text); color: var(--bg); box-shadow: 0 10px 24px rgba(15, 23, 42, 0.16); }
.credit-pill {
  min-height: 2.1rem;
  display: inline-flex;
  align-items: center;
  border: 1px solid rgba(6, 182, 212, 0.18);
  border-radius: 999px;
  background: var(--cyan-soft);
  color: var(--cyan-strong);
  padding: 0 0.8rem;
  font-size: 0.78rem;
  font-weight: 900;
  white-space: nowrap;
}

.edit-callout {
  display: grid;
  grid-template-columns: 5.75rem minmax(0, 1fr);
  gap: 0.85rem;
  margin-top: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: rgba(148, 163, 184, 0.10);
  padding: 0.85rem;
}
.upload-tile {
  display: flex;
  aspect-ratio: 1;
  align-items: center;
  justify-content: center;
  border: 1px dashed var(--border);
  border-radius: 1rem;
  color: var(--cyan-strong);
  font-size: 1.9rem;
  font-weight: 900;
}
.edit-callout h2 { margin: 0; font-size: 1rem; }
.edit-callout p { margin: 0.35rem 0 0; color: var(--muted); font-size: 0.88rem; line-height: 1.6; }

.field-block { margin-top: 1rem; }
.field-line { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 0.65rem; }
.field-line label { font-size: 0.92rem; font-weight: 900; }
.counter { color: var(--faint); font-size: 0.78rem; font-weight: 750; }
textarea {
  width: 100%;
  min-height: 12rem;
  resize: vertical;
  border: 1px solid var(--border);
  border-radius: 1.15rem;
  background: var(--panel-strong);
  color: var(--text);
  box-shadow: 0 1px 0 rgba(148, 163, 184, 0.12) inset;
  padding: 1rem;
  font-size: 1rem;
  line-height: 1.75;
  outline: none;
  transition: border 160ms ease, box-shadow 160ms ease;
}
textarea::placeholder { color: var(--faint); }
textarea:focus { border-color: var(--cyan); box-shadow: 0 0 0 4px rgba(6, 182, 212, 0.14); }

.prompt-chips {
  display: flex;
  gap: 0.5rem;
  margin: 0.8rem -0.15rem 0;
  overflow-x: auto;
  padding: 0.15rem 0.15rem 0.35rem;
  scrollbar-width: none;
}
.prompt-chips::-webkit-scrollbar { display: none; }
.prompt-chips button {
  flex: 0 0 14rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel-strong);
  color: var(--muted);
  padding: 0.58rem 0.78rem;
  text-align: left;
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1.5;
  transition: transform 160ms ease, background 160ms ease, color 160ms ease;
}
.prompt-chips button:hover { transform: translateY(-1px); color: var(--text); }

.advanced-panel { margin-top: 0.85rem; border: 1px solid var(--border); border-radius: var(--radius-lg); background: rgba(148, 163, 184, 0.10); padding: 0.75rem; }
.advanced-toggle {
  display: flex;
  min-height: 2.4rem;
  width: 100%;
  align-items: center;
  justify-content: space-between;
  border: 0;
  background: transparent;
  color: var(--text);
  padding: 0;
  font-weight: 900;
}
.chevron { color: var(--muted); transition: transform 160ms ease; }
.advanced-toggle[aria-expanded="false"] .chevron { transform: rotate(-90deg); }
.advanced-body { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-top: 0.85rem; }
fieldset { min-width: 0; margin: 0; border: 0; padding: 0; }
legend { margin-bottom: 0.5rem; color: var(--faint); font-size: 0.78rem; font-weight: 900; }
.option-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.5rem; }
.option-card {
  display: flex;
  min-height: 3rem;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 0.85rem;
  background: var(--panel-strong);
  color: var(--muted);
  padding: 0.55rem;
  text-align: center;
  font-size: 0.84rem;
  font-weight: 850;
  transition: background 160ms ease, color 160ms ease, border 160ms ease;
}
.option-card input { position: absolute; opacity: 0; pointer-events: none; }
.option-card.is-selected { border-color: var(--text); background: var(--text); color: var(--bg); }

.notice-row {
  margin-top: 0.85rem;
  border: 1px solid rgba(245, 158, 11, 0.22);
  border-radius: 1rem;
  background: rgba(245, 158, 11, 0.12);
  color: #92400e;
  padding: 0.75rem 0.9rem;
  font-size: 0.88rem;
  font-weight: 750;
  line-height: 1.55;
}
@media (prefers-color-scheme: dark) { .notice-row { color: #fde68a; } }

.submit-dock { margin-top: 0.9rem; }
.primary-button,
.dark-button,
.cyan-button,
.ghost-button {
  display: inline-flex;
  min-height: 2.75rem;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  border-radius: 0.95rem;
  padding: 0 1rem;
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 900;
  transition: transform 160ms ease, filter 160ms ease, background 160ms ease;
}
.primary-button { width: 100%; min-height: 3.15rem; border: 0; background: #06b6d4; color: white; box-shadow: 0 18px 36px rgba(6, 182, 212, 0.26); font-size: 1rem; }
.dark-button { border: 0; background: var(--text); color: var(--bg); }
.cyan-button { border: 0; background: #06b6d4; color: white; }
.ghost-button { border: 1px solid var(--border); background: var(--panel-strong); color: var(--text); }
.wide { width: 100%; }
.primary-button:not(:disabled):hover,
.dark-button:hover,
.cyan-button:hover,
.ghost-button:hover { transform: translateY(-1px); filter: brightness(1.02); }
.button-icon { font-size: 1.08rem; }

.result-head { display: flex; align-items: start; justify-content: space-between; gap: 1rem; }
.small-label { margin: 0; color: var(--faint); font-size: 0.72rem; font-weight: 950; letter-spacing: 0.12em; text-transform: uppercase; }
.result-head h2,
.history-grid h2 { margin: 0.2rem 0 0; font-size: 1.2rem; }
.status-badge {
  display: inline-flex;
  flex: 0 0 auto;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.12);
  color: var(--muted);
  padding: 0.32rem 0.64rem;
  font-size: 0.75rem;
  font-weight: 900;
}
.status-badge.good { border-color: rgba(16, 185, 129, 0.22); background: rgba(16, 185, 129, 0.12); color: #059669; }
.status-badge.busy { border-color: rgba(6, 182, 212, 0.22); background: var(--cyan-soft); color: var(--cyan-strong); }
.status-badge.bad { border-color: rgba(244, 63, 94, 0.24); background: rgba(244, 63, 94, 0.12); color: #e11d48; }

.preview-frame {
  display: flex;
  aspect-ratio: 1 / 1;
  align-items: center;
  justify-content: center;
  margin-top: 0.85rem;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: linear-gradient(135deg, rgba(148, 163, 184, 0.18), rgba(148, 163, 184, 0.08));
}
.empty-preview { max-width: 17rem; padding: 1.25rem; text-align: center; }
.preview-icon { margin: 0 auto 0.75rem; color: var(--faint); font-size: 3rem; font-weight: 200; }
.empty-preview p { margin: 0; color: var(--muted); font-size: 0.92rem; line-height: 1.65; }
.preview-frame img { width: 100%; height: 100%; object-fit: contain; }
.result-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 0.55rem; margin-top: 0.75rem; }
.result-actions .wide { grid-column: 1 / -1; }
.task-json {
  max-height: 15rem;
  margin: 0.75rem 0 0;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 1rem;
  background: rgba(15, 23, 42, 0.06);
  color: var(--muted);
  padding: 0.8rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 0.78rem;
  line-height: 1.55;
}
@media (prefers-color-scheme: dark) { .task-json { background: rgba(2, 6, 23, 0.42); } }

.history-grid {
  display: grid;
  grid-template-columns: minmax(0, 0.82fr) minmax(0, 1.18fr);
  gap: 1rem;
  margin-top: 1rem;
  padding: clamp(0.9rem, 2vw, 1.25rem);
}
.history-grid p { margin: 0.45rem 0 0; color: var(--muted); line-height: 1.6; }
.history-list { display: grid; gap: 0.55rem; }
.history-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.65rem;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 1rem;
  background: var(--panel-strong);
  padding: 0.72rem;
}
.history-item strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.86rem; }
.history-item span { display: block; margin-top: 0.18rem; color: var(--muted); font-size: 0.74rem; }
.history-item button { min-height: 2.35rem; border-radius: 0.8rem; padding: 0 0.75rem; }
.empty-history { color: var(--muted); font-size: 0.9rem; }
.footer-note {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 1rem;
  padding: 0.85rem 1rem;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.55;
}

.is-spinning .button-icon { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (min-width: 720px) {
  .prompt-chips { flex-wrap: wrap; overflow: visible; }
  .prompt-chips button { flex: 1 1 12rem; }
}

@media (max-width: 860px) {
  .studio-shell { width: min(100vw - 1rem, 46rem); padding-top: 0.75rem; }
  .topbar { grid-template-columns: 1fr; gap: 0.75rem; padding-bottom: 0.75rem; }
  .hero-panel h1 { font-size: clamp(1.9rem, 12vw, 3.1rem); }
  .hero-panel p { display: none; }
  .account-card { width: 100%; border-radius: 1.25rem; padding: 0.7rem; }
  .account-actions { grid-template-columns: 1fr 1fr; }
  .workspace-grid { grid-template-columns: 1fr; gap: 0.75rem; }
  .result-card { position: static; }
  .advanced-body { grid-template-columns: 1fr; }
  .submit-dock {
    position: sticky;
    bottom: calc(0.65rem + env(safe-area-inset-bottom));
    z-index: 20;
    margin: 0.85rem -0.2rem -0.2rem;
    border: 1px solid rgba(255, 255, 255, 0.66);
    border-radius: 1.25rem;
    background: rgba(255, 255, 255, 0.88);
    padding: 0.45rem;
    box-shadow: 0 18px 48px rgba(15, 23, 42, 0.18);
    backdrop-filter: blur(18px);
  }
  @media (prefers-color-scheme: dark) { .submit-dock { border-color: rgba(255,255,255,0.10); background: rgba(15,23,42,0.90); } }
  .history-grid { grid-template-columns: 1fr; }
  .footer-note { flex-direction: column; }
}

@media (max-width: 460px) {
  .studio-shell { width: min(100vw - 0.75rem, 46rem); }
  .eyebrow { font-size: 0.68rem; max-width: 100%; }
  .composer-head { align-items: stretch; flex-direction: column; }
  .segmented, .credit-pill { width: 100%; justify-content: center; }
  .segment { flex: 1 1 0; }
  textarea { min-height: 9.5rem; }
  .option-grid { grid-template-columns: 1fr; }
  .result-actions { grid-template-columns: 1fr; }
  .history-item { grid-template-columns: 1fr; }
}
