:root {
  color-scheme: dark;
  --bg: #090b14;
  --bg-soft: #121827;
  --surface: rgba(17, 21, 34, 0.97);
  --surface-strong: rgba(22, 28, 44, 0.98);
  --ink: #f8fbff;
  --muted: #bbcaea;
  --line: rgba(155, 171, 222, 0.18);
  --field-bg: rgba(255, 255, 255, 0.045);
  --chip-bg: rgba(255, 255, 255, 0.055);
  --chip-hover: rgba(255, 255, 255, 0.085);
  --accent: #6f8dff;
  --accent-2: #28c7a4;
  --ok: #5fe3b2;
  --warn: #ffbc75;
  --danger: #ff7676;
  --shadow: 0 24px 80px rgba(5, 8, 18, 0.45);
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f5f7fb;
  --bg-soft: #e9eef7;
  --surface: rgba(255, 255, 255, 0.98);
  --surface-strong: rgba(248, 250, 255, 0.98);
  --ink: #101522;
  --muted: #526179;
  --line: rgba(65, 82, 120, 0.18);
  --field-bg: rgba(20, 31, 52, 0.035);
  --chip-bg: rgba(31, 63, 107, 0.055);
  --chip-hover: rgba(31, 63, 107, 0.085);
  --accent: #315eea;
  --accent-2: #0f9f83;
  --ok: #078d67;
  --warn: #b76c1d;
  --danger: #c93248;
  --shadow: 0 20px 60px rgba(52, 70, 104, 0.16);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: -webkit-fill-available;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    linear-gradient(145deg, rgba(111, 141, 255, 0.13), transparent 34%),
    linear-gradient(35deg, rgba(40, 199, 164, 0.12), transparent 32%),
    var(--bg);
}

button, input, textarea, select {
  font: inherit;
  white-space: pre-wrap;
}

button {
  border: 0;
  cursor: pointer;
}

.app-shell {
  width: min(920px, calc(100% - 1.25rem));
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 0 max(40px, env(safe-area-inset-bottom));
}

.prefill-banner {
  margin-bottom: 0.85rem;
  padding: 0.9rem 1rem;
  border-radius: 18px;
  border: 1px solid rgba(111, 141, 255, 0.28);
  background: rgba(111, 141, 255, 0.12);
  color: #eef2ff;
  line-height: 1.45;
}

.studio-card {
  display: grid;
  gap: 1rem;
  padding: 1.15rem;
  border-radius: 22px;
  background: linear-gradient(180deg, var(--surface), var(--surface-strong));
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.hero-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.9rem;
  align-items: start;
}

.eyebrow {
  margin: 0 0 0.45rem;
  color: #dbe4ff;
  font-size: 0.74rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

h1 {
  margin: 0;
  font-size: clamp(1.65rem, 3vw, 2.45rem);
  line-height: 1.08;
}

.subcopy {
  margin: 0.7rem 0 0;
  color: var(--muted);
  line-height: 1.55;
}

.theme-button {
  display: inline-grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--field-bg);
  color: var(--ink);
  transition: transform 140ms ease, background 140ms ease, border-color 140ms ease;
}

.theme-button:hover {
  transform: translateY(-1px);
  background: var(--chip-hover);
  border-color: color-mix(in srgb, var(--accent) 45%, var(--line));
}

.theme-icon {
  position: relative;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: currentColor;
}

:root[data-theme="dark"] .theme-icon::after,
:root:not([data-theme="light"]) .theme-icon::after {
  content: "";
  position: absolute;
  inset: -2px -2px auto auto;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--surface-strong);
}

:root[data-theme="light"] .theme-icon {
  box-shadow:
    0 -9px 0 -6px currentColor,
    0 9px 0 -6px currentColor,
    9px 0 0 -6px currentColor,
    -9px 0 0 -6px currentColor,
    6px 6px 0 -6px currentColor,
    -6px 6px 0 -6px currentColor,
    6px -6px 0 -6px currentColor,
    -6px -6px 0 -6px currentColor;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr minmax(180px, 0.75fr);
  gap: 0.85rem;
}

.title-duration-row {
  display: grid;
  grid-template-columns: 1fr minmax(100px, 0.4fr);
  gap: 0.85rem;
}

.field {
  display: grid;
  gap: 0.5rem;
  font-weight: 700;
}

.field input,
.field textarea,
.field select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--field-bg);
  color: var(--ink);
  outline: 0;
}

.field input,
.field select {
  height: 48px;
  padding: 0 0.95rem;
}

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

.field input:focus,
.field textarea:focus,
.field select:focus {
  border-color: rgba(111, 141, 255, 0.65);
  box-shadow: 0 0 0 4px rgba(111, 141, 255, 0.15);
}

.style-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.65rem;
  margin-bottom: 1.15rem;
}

.style-field {
  margin: 0.85rem 0;
  padding: 0.9rem 0 1rem;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.style-manual-input {
  min-height: 180px;
  padding: 0.95rem !important;
  border-color: color-mix(in srgb, var(--line) 72%, var(--accent)) !important;
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--surface) 72%, transparent), transparent),
    var(--field-bg) !important;
  box-shadow: 0 -1px 0 var(--line);
  resize: vertical;
  line-height: 1.5;
}

.style-manual-input::placeholder {
  color: color-mix(in srgb, var(--muted) 78%, transparent);
}

.style-chip {
  display: grid;
  align-content: start;
  gap: 0.25rem;
  min-height: 84px;
  padding: 0.8rem 0.85rem;
  border-radius: 14px;
  text-align: left;
  background: var(--chip-bg);
  border: 1px solid var(--line);
  color: var(--ink);
  font-weight: 800;
  overflow: hidden;
  transition: transform 140ms ease, background 140ms ease, border-color 140ms ease;
}

.style-chip:hover {
  transform: translateY(-1px);
  background: var(--chip-hover);
  border-color: color-mix(in srgb, var(--accent) 48%, var(--line));
}

.style-chip.active {
  background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 18%, transparent), color-mix(in srgb, var(--accent-2) 16%, transparent));
  border-color: color-mix(in srgb, var(--accent) 56%, var(--line));
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 24%, transparent);
}

.style-chip-name,
.style-chip-description {
  display: block;
  min-width: 0;
}

.style-chip-name {
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.style-chip-description {
  color: var(--muted);
  font-size: 0.79rem;
  font-weight: 650;
  line-height: 1.25;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  line-clamp: 2;
  -webkit-line-clamp: 2;
  overflow: hidden;
}

.options-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-height: 42px;
}

.advanced-grid {
  margin-top: 0.15rem;
}

.field-hint {
  color: var(--muted);
  font-weight: 650;
  font-size: 0.88rem;
}

.field-caption {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 550;
  line-height: 1.35;
}

.photo-field {
  padding: 0.65rem 0;
}

.photo-upload {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  align-items: center;
}

.secondary-button {
  border: 1px solid var(--line);
  background: var(--chip-bg);
  color: var(--ink);
  min-height: 42px;
  border-radius: 12px;
  padding: 0 0.85rem;
  font-weight: 750;
  transition: background 140ms ease, border-color 140ms ease;
}

.secondary-button:hover {
  background: var(--chip-hover);
  border-color: color-mix(in srgb, var(--accent) 45%, var(--line));
}

.ghost-button {
  min-height: 42px;
  border-radius: 12px;
  padding: 0 0.85rem;
  font-weight: 750;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  transition: color 140ms ease;
}

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

.photo-preview {
  display: none;
  gap: 0.45rem;
  margin-top: 0.15rem;
}

.photo-preview.visible {
  display: grid;
}

.photo-preview img {
  width: min(100%, 220px);
  max-height: 140px;
  object-fit: cover;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--field-bg);
}

.photo-meta {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
}

.switch {
  display: inline-flex;
  align-items: center;
  gap: 0.7rem;
  font-weight: 800;
}

.switch input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.switch span {
  position: relative;
  width: 42px;
  height: 25px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--muted) 20%, transparent);
}

.switch span::after {
  content: "";
  position: absolute;
  inset: 3px auto auto 3px;
  width: 19px;
  height: 19px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 4px 12px rgba(8, 10, 18, 0.3);
  transition: transform 140ms ease;
}

.switch input:checked + span {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}

.switch input:checked + span::after {
  transform: translateX(17px);
}

.text-field {
  margin-top: 0.15rem;
}

.text-field-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.text-field-header span {
  font-weight: 700;
}

.instrumental-row {
  display: flex;
  align-items: center;
  min-height: 42px;
  margin-bottom: 0.5rem;
}

.info-button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  min-width: 20px;
  padding: 0;
  background: none;
  border: none;
  color: var(--muted);
  cursor: help;
  transition: color 140ms ease;
  position: relative;
}

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

.info-button svg {
  width: 100%;
  height: 100%;
  stroke: currentColor;
}

.info-tooltip {
  position: absolute;
  bottom: 100%;
  left: 0;
  margin-bottom: 0.4rem;
  padding: 0.6rem 0.75rem;
  background: color-mix(in srgb, var(--ink) 86%, transparent);
  border-radius: 8px;
  font-size: 0.8rem;
  color: var(--bg);
  white-space: normal;
  max-width: 220px;
  z-index: 10;
  pointer-events: none;
  font-weight: 400;
  line-height: 1.3;
}

.info-tooltip::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 8px;
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 4px solid color-mix(in srgb, var(--ink) 86%, transparent);
}

.meter-panel {
  display: grid;
  gap: 0.55rem;
  padding: 0.75rem 0.85rem;
  border-radius: 14px;
  border: 1px solid rgba(255, 188, 117, 0.24);
  background: color-mix(in srgb, var(--warn) 9%, transparent);
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.4;
}

.meter-hint {
  font-size: 0.82rem;
  color: var(--muted);
}

.meter-panel strong {
  color: var(--ink);
}

.meter-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.meter-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 0.65rem;
  border-radius: 999px;
  background: var(--chip-bg);
  color: var(--ink);
  font-weight: 800;
}

.meter-issues {
  display: grid;
  gap: 0.4rem;
}

.meter-issue {
  padding: 0.55rem 0.65rem;
  border-left: 3px solid var(--warn);
  border-radius: 8px;
  background: var(--field-bg);
}

.meter-issue-info {
  border-left-color: color-mix(in srgb, var(--muted) 70%, transparent);
}

.meter-issue-action {
  cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease, transform 140ms ease;
}

.meter-issue-action:hover,
.meter-issue-action:focus-visible {
  background: color-mix(in srgb, var(--warn) 14%, var(--field-bg));
  border-left-color: var(--accent);
  outline: none;
}

.meter-issue-action:active {
  transform: translateY(1px);
}

.meter-line {
  color: var(--ink);
}

.actions-row {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.primary-button,
.secondary-button {
  min-height: 46px;
  border-radius: 14px;
  padding: 0 1rem;
  font-weight: 800;
}

.primary-button {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #ffffff;
  box-shadow: 0 14px 30px color-mix(in srgb, var(--accent) 22%, transparent);
}

.primary-button:disabled {
  cursor: wait;
  opacity: 0.8;
}

.balance-info {
  margin: 0.85rem 0 0.65rem;
  padding: 0.7rem 0.85rem;
  border-radius: 12px;
  background: rgba(255, 180, 117, 0.08);
  border: 1px solid rgba(255, 180, 117, 0.25);
  color: rgba(255, 178, 117, 0.95);
  font-size: 0.88rem;
  line-height: 1.5;
}

.balance-info.low {
  background: color-mix(in srgb, var(--danger) 9%, transparent);
  border-color: color-mix(in srgb, var(--danger) 32%, transparent);
  color: var(--danger);
}

.balance-info strong {
  font-weight: 900;
  color: var(--warn);
}

.balance-info.low strong {
  color: var(--danger);
}

.status {
  min-height: 20px;
  color: var(--muted);
  line-height: 1.4;
  word-break: break-word;
  white-space: pre-wrap;
}

.status.ok { color: var(--ok); }
.status.warn { color: var(--warn); }

.prefill-highlight {
  border-color: rgba(111, 141, 255, 0.65) !important;
  box-shadow: 0 0 0 4px rgba(111, 141, 255, 0.16) !important;
}

@media (max-width: 720px) {
  .form-grid {
    display: grid;
    grid-template-columns: 1fr;
  }

  .actions-row {
    display: grid;
    grid-template-columns: 1fr;
  }

  .actions-row {
    gap: 0.65rem;
  }

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

  .text-field-header {
    position: relative;
  }

  .info-tooltip {
    bottom: auto;
    top: 100%;
    margin-bottom: 0;
    margin-top: 0.4rem;
  }

  .info-tooltip::after {
    top: auto;
    bottom: 100%;
    border-top: none;
    border-bottom: 4px solid color-mix(in srgb, var(--ink) 86%, transparent);
  }
}

@media (max-width: 420px) {
  .app-shell {
    width: min(100% - 0.75rem, 920px);
    padding-top: max(10px, env(safe-area-inset-top));
  }

  .studio-card {
    gap: 0.85rem;
    padding: 0.85rem;
    border-radius: 18px;
  }

  .hero-row {
    gap: 0.65rem;
  }

  .theme-button {
    width: 38px;
    height: 38px;
    border-radius: 12px;
  }

  .style-grid {
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 136px), 1fr));
    gap: 0.5rem;
    margin-bottom: 0.95rem;
  }

  .style-chip {
    min-height: 76px;
    padding: 0.7rem;
  }

  .style-manual-input {
    min-height: 60px;
  }

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