:root {
  --ink: #17191c;
  --muted: #626a73;
  --line: rgba(23, 25, 28, 0.14);
  --paper: #f7f7f2;
  --panel: #ffffff;
  --carbon: #202327;
  --coral: #ff6b4a;
  --teal: #00a7a0;
  --gold: #f4b740;
  --blue: #2f7fd0;
  --shadow: 0 24px 70px rgba(18, 24, 30, 0.16);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--paper);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
  background:
    linear-gradient(90deg, rgba(23,25,28,0.055) 1px, transparent 1px) 0 0 / 42px 42px,
    linear-gradient(rgba(23,25,28,0.045) 1px, transparent 1px) 0 0 / 42px 42px,
    linear-gradient(140deg, #f7f7f2 0%, #eef4f2 44%, #fff4eb 100%);
}

button,
textarea,
input {
  font: inherit;
}

a {
  color: inherit;
}

.shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 42px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 56px;
  margin-bottom: 28px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 8px;
  color: #fff;
  background: linear-gradient(135deg, var(--carbon), #4b525c);
  box-shadow: 0 10px 24px rgba(23, 25, 28, 0.18);
  font-weight: 800;
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-size: 1rem;
}

.brand small {
  color: var(--muted);
  font-size: 0.78rem;
  margin-top: 1px;
}

.status-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
}

.status-pill,
.credit-pill {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.68);
  color: var(--carbon);
  font-size: 0.85rem;
  font-weight: 700;
}

.status-pill.is-demo {
  border-color: rgba(244, 183, 64, 0.42);
  background: rgba(244, 183, 64, 0.16);
}

.status-pill.is-live {
  border-color: rgba(0, 167, 160, 0.4);
  background: rgba(0, 167, 160, 0.14);
}

.studio {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 18px;
  align-items: stretch;
}

.workspace,
.output {
  border: 1px solid rgba(23, 25, 28, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.workspace {
  display: grid;
  grid-template-columns: 0.82fr 1.18fr;
  gap: 28px;
  padding: clamp(22px, 3vw, 36px);
}

.studio-copy {
  align-self: center;
}

.eyebrow {
  margin: 0 0 14px;
  color: var(--teal);
  font-size: 0.78rem;
  font-weight: 850;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

h1 {
  max-width: 10ch;
  margin-bottom: 16px;
  font-size: clamp(2.65rem, 5vw, 5.5rem);
  line-height: 0.94;
}

.lead {
  max-width: 34ch;
  color: var(--muted);
  font-size: 1.03rem;
  line-height: 1.6;
}

.composer {
  display: grid;
  gap: 18px;
}

.field,
.style-field {
  display: grid;
  gap: 9px;
  margin: 0;
  padding: 0;
  border: 0;
}

.field span,
.style-field legend {
  color: var(--carbon);
  font-size: 0.88rem;
  font-weight: 800;
}

textarea {
  width: 100%;
  resize: vertical;
  min-height: 118px;
  padding: 14px 15px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
  outline: none;
  line-height: 1.45;
  transition: border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

textarea:focus {
  border-color: rgba(0, 167, 160, 0.62);
  box-shadow: 0 0 0 4px rgba(0, 167, 160, 0.12);
}

.styles-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.style-toggle {
  position: relative;
  min-height: 42px;
  cursor: pointer;
}

.style-toggle input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.style-toggle span {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 42px;
  width: 100%;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--carbon);
  font-size: 0.86rem;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: border-color 140ms ease, color 140ms ease, background 140ms ease, transform 140ms ease;
}

.style-toggle input:checked + span {
  border-color: color-mix(in srgb, var(--style-color) 68%, #17191c);
  color: #fff;
  background: var(--style-color);
  transform: translateY(-1px);
}

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

.primary-btn,
.secondary-btn,
.download-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  padding: 0 18px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-weight: 850;
  text-decoration: none;
  cursor: pointer;
  transition: transform 150ms ease, box-shadow 150ms ease, opacity 150ms ease;
}

.primary-btn {
  min-width: 146px;
  color: #fff;
  background: var(--carbon);
  box-shadow: 0 14px 28px rgba(23, 25, 28, 0.2);
}

.secondary-btn {
  color: var(--carbon);
  border-color: var(--line);
  background: #fff;
}

.primary-btn:hover,
.secondary-btn:hover,
.download-link:hover {
  transform: translateY(-1px);
}

.primary-btn:disabled {
  cursor: wait;
  opacity: 0.62;
  transform: none;
}

.output {
  display: flex;
  min-height: 100%;
  flex-direction: column;
  justify-content: space-between;
  padding: 24px;
  color: #fff;
  background:
    linear-gradient(135deg, rgba(255,255,255,0.08), transparent 44%),
    linear-gradient(160deg, #202327 0%, #30373b 50%, #1a1c1f 100%);
}

.meter {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  align-items: end;
  gap: 8px;
  height: 150px;
  margin-bottom: 34px;
}

.meter span {
  display: block;
  height: var(--h, 42%);
  border-radius: 8px 8px 0 0;
  background: linear-gradient(180deg, var(--coral), var(--gold));
  transform-origin: bottom;
  animation: pulse 1.4s ease-in-out infinite;
  animation-play-state: paused;
}

.meter span:nth-child(1) { --h: 38%; animation-delay: 0ms; }
.meter span:nth-child(2) { --h: 66%; animation-delay: 80ms; background: linear-gradient(180deg, var(--teal), #7adbc8); }
.meter span:nth-child(3) { --h: 48%; animation-delay: 160ms; }
.meter span:nth-child(4) { --h: 88%; animation-delay: 240ms; background: linear-gradient(180deg, var(--blue), #74c2ff); }
.meter span:nth-child(5) { --h: 72%; animation-delay: 320ms; }
.meter span:nth-child(6) { --h: 44%; animation-delay: 400ms; background: linear-gradient(180deg, var(--teal), #7adbc8); }
.meter span:nth-child(7) { --h: 78%; animation-delay: 480ms; }
.meter span:nth-child(8) { --h: 54%; animation-delay: 560ms; background: linear-gradient(180deg, var(--blue), #74c2ff); }

.is-generating .meter span {
  animation-play-state: running;
}

.output-label {
  margin-bottom: 12px;
  color: rgba(255, 255, 255, 0.62);
  font-size: 0.78rem;
  font-weight: 850;
  text-transform: uppercase;
}

.result-state h2 {
  margin-bottom: 9px;
  font-size: 2rem;
}

.result-state p:last-child {
  margin-bottom: 0;
  color: rgba(255, 255, 255, 0.76);
  line-height: 1.55;
}

.result-state[data-state="error"] h2 {
  color: #ff9b86;
}

.result-state[data-state="done"] h2 {
  color: #80e3d2;
}

.progress-wrap {
  display: grid;
  gap: 12px;
  margin-top: 24px;
}

.progress-track {
  position: relative;
  height: 10px;
  overflow: hidden;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.14);
}

.progress-track span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--teal), var(--gold), var(--coral));
  transition: width 420ms ease;
}

.progress-steps {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.progress-steps span {
  display: flex;
  min-height: 32px;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  color: rgba(255, 255, 255, 0.62);
  font-size: 0.76rem;
  font-weight: 850;
}

.progress-steps span.is-active {
  border-color: rgba(128, 227, 210, 0.74);
  color: #fff;
  background: rgba(128, 227, 210, 0.14);
}

.progress-steps span.is-done {
  color: rgba(255, 255, 255, 0.86);
  background: rgba(255, 255, 255, 0.1);
}

.player-wrap {
  display: grid;
  gap: 12px;
  margin-top: 26px;
}

audio {
  width: 100%;
  min-height: 44px;
}

.download-link {
  width: 100%;
  color: #101214;
  background: #fff;
}

.history-band {
  margin-top: 18px;
  padding: 20px 0 0;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.section-heading h2 {
  margin: 0;
  font-size: 1.05rem;
}

.section-heading span {
  display: grid;
  min-width: 30px;
  height: 30px;
  place-items: center;
  border-radius: 8px;
  color: #fff;
  background: var(--carbon);
  font-size: 0.82rem;
  font-weight: 850;
}

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

.history-item {
  display: flex;
  min-height: 92px;
  flex-direction: column;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.78);
}

.history-item strong,
.history-item span {
  display: block;
}

.history-item strong {
  font-size: 0.9rem;
  line-height: 1.35;
}

.history-item span {
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.78rem;
}

.history-item a {
  color: var(--teal);
  font-size: 0.86rem;
  font-weight: 850;
  text-decoration: none;
}

.empty-history {
  grid-column: 1 / -1;
  margin: 0;
  color: var(--muted);
}

@keyframes pulse {
  0%, 100% { transform: scaleY(0.45); }
  45% { transform: scaleY(1); }
}

@media (max-width: 980px) {
  .studio,
  .workspace {
    grid-template-columns: 1fr;
  }

  .studio-copy {
    align-self: start;
  }

  h1 {
    max-width: 12ch;
  }

  .history-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .shell {
    width: min(100% - 20px, 1180px);
    padding-top: 14px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
    margin-bottom: 14px;
  }

  .workspace,
  .output {
    padding: 18px;
  }

  h1 {
    max-width: 100%;
    font-size: 2.65rem;
  }

  .styles-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

  .history-list {
    grid-template-columns: 1fr;
  }
}

input,
select {
  width: 100%;
  min-height: 44px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
  outline: none;
}

input:focus,
select:focus {
  border-color: rgba(0, 167, 160, 0.62);
  box-shadow: 0 0 0 4px rgba(0, 167, 160, 0.12);
}

.auth-screen {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 420px;
  gap: 22px;
  align-items: stretch;
  min-height: calc(100vh - 150px);
}

.auth-copy,
.auth-panel,
.admin-login,
.admin-panel,
.admin-stats article {
  border: 1px solid rgba(23, 25, 28, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.auth-copy {
  display: flex;
  min-height: 560px;
  flex-direction: column;
  justify-content: center;
  padding: clamp(24px, 4vw, 48px);
}

.auth-panel {
  align-self: center;
  padding: 22px;
}

.auth-tabs {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
  margin-bottom: 18px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(23, 25, 28, 0.04);
}

.auth-tab {
  min-height: 38px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-weight: 850;
  cursor: pointer;
}

.auth-tab.is-active {
  color: var(--ink);
  background: #fff;
  box-shadow: 0 5px 18px rgba(23, 25, 28, 0.08);
}

.auth-form {
  display: none;
  gap: 14px;
}

.auth-form.is-active {
  display: grid;
}

.form-message {
  min-height: 22px;
  margin: 14px 0 0;
  color: #ba3f1d;
  font-size: 0.9rem;
  font-weight: 800;
}

.link-button,
.admin-link {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 4px;
  border: 0;
  background: transparent;
  color: var(--carbon);
  font-weight: 850;
  text-decoration: none;
  cursor: pointer;
}

.quick-settings {
  display: grid;
  grid-template-columns: 1fr 120px auto;
  gap: 10px;
  align-items: end;
}

.field.compact {
  gap: 7px;
}

.settings-btn {
  min-height: 44px;
}

.settings-modal {
  width: min(860px, calc(100% - 28px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  color: var(--ink);
  background: transparent;
}

.settings-modal::backdrop {
  background: rgba(17, 19, 21, 0.58);
}

.modal-shell {
  display: grid;
  gap: 18px;
  padding: 22px;
  border: 1px solid rgba(23, 25, 28, 0.12);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 28px 90px rgba(0, 0, 0, 0.26);
}

.modal-header,
.modal-footer,
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.modal-header h2,
.panel-header h2 {
  margin: 0;
  font-size: 1.1rem;
}

.icon-btn {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-size: 1.45rem;
  line-height: 1;
  cursor: pointer;
}

.modal-grid,
.admin-form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.span-2 {
  grid-column: span 2;
}

.admin-shell {
  width: min(1320px, calc(100% - 32px));
}

.admin-login {
  display: grid;
  width: min(420px, 100%);
  gap: 22px;
  margin: 12vh auto 0;
  padding: 24px;
}

.flash {
  margin: 0 0 16px;
  padding: 12px 14px;
  border-radius: 8px;
  font-weight: 850;
}

.flash.success {
  color: #125a48;
  background: rgba(0, 167, 160, 0.14);
}

.flash.error {
  color: #8c2f19;
  background: rgba(255, 107, 74, 0.15);
}

.admin-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}

.admin-stats article {
  padding: 18px;
}

.admin-stats strong,
.admin-stats span {
  display: block;
}

.admin-stats strong {
  font-size: 2rem;
}

.admin-stats span,
.admin-note {
  color: var(--muted);
  font-size: 0.9rem;
}

.admin-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.admin-panel {
  display: grid;
  gap: 16px;
  padding: 18px;
}

.admin-panel.wide {
  grid-column: 1 / -1;
}

.admin-panel h3 {
  margin: 4px 0 -4px;
  font-size: 1rem;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  color: var(--carbon);
  font-weight: 800;
}

.check-row input {
  width: 18px;
  min-height: 18px;
}

.small {
  min-height: 38px;
  padding: 0 13px;
  font-size: 0.84rem;
}

.tiny {
  min-height: 30px;
  padding: 0 10px;
  font-size: 0.78rem;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

th,
td {
  padding: 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
}

td form {
  margin: 0;
}

@media (max-width: 980px) {
  .auth-screen,
  .admin-grid,
  .admin-stats {
    grid-template-columns: 1fr;
  }

  .auth-copy {
    min-height: auto;
  }

  .modal-grid,
  .admin-form-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .quick-settings,
  .modal-grid,
  .admin-form-grid {
    grid-template-columns: 1fr;
  }

  .span-2 {
    grid-column: auto;
  }

  .modal-footer {
    align-items: stretch;
    flex-direction: column;
  }
}
