:root {
  color-scheme: light;
  --bg: #f4f1ea;
  --panel: #fffdf8;
  --panel-strong: #191815;
  --ink: #171613;
  --muted: #6c665d;
  --line: #ded7ca;
  --teal: #0f766e;
  --teal-dark: #115e59;
  --coral: #d95f43;
  --gold: #c58a1e;
  --mint: #dff3e7;
  --shadow: 0 24px 70px rgba(46, 38, 23, 0.13);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(255, 253, 248, 0.82), rgba(244, 241, 234, 0.98)),
    url("data:image/svg+xml,%3Csvg width='160' height='160' viewBox='0 0 160 160' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' stroke='%23d8cfbd' stroke-width='1' opacity='.45'%3E%3Cpath d='M0 40h160M0 80h160M0 120h160M40 0v160M80 0v160M120 0v160'/%3E%3C/g%3E%3C/svg%3E");
}

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

button {
  cursor: pointer;
}

.app-shell {
  width: min(1520px, 100%);
  margin: 0 auto;
  padding: 18px 24px 28px;
}

.workspace {
  display: grid;
  gap: 16px;
}

.login-screen {
  min-height: calc(100vh - 46px);
  display: grid;
  place-items: center;
}

.login-card {
  width: min(620px, 100%);
  display: grid;
  gap: 18px;
  padding: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.94);
  box-shadow: var(--shadow);
}

.login-card h1 {
  margin-bottom: 4px;
}

.login-card h1 {
  font-size: clamp(34px, 6vw, 64px);
}

.login-copy {
  margin-bottom: 2px;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.65;
}

.login-form {
  display: grid;
  gap: 10px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdfa;
}

.entry-grid {
  display: grid;
  gap: 14px;
}

.login-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 150px;
  gap: 10px;
}

.login-state {
  min-height: 22px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.login-state.ok {
  color: var(--teal-dark);
}

.login-state.warn {
  color: var(--coral);
}

.admin-entry {
  background: #f8f4eb;
}

.admin-primary {
  background: var(--coral);
}

.topbar,
.composer,
.results {
  background: rgba(255, 253, 248, 0.92);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 94px;
  padding: 14px 22px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--teal);
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0;
}

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

h1 {
  margin-bottom: 0;
  font-size: clamp(30px, 3.2vw, 52px);
  line-height: 1.06;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 12px;
  font-size: 18px;
}

.title-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

.title-row h1 {
  margin-bottom: 0;
}

.title-row .ghost {
  color: var(--teal-dark);
  background: #edf7f3;
  border-color: #badbd2;
}

.balance-panel,
.key-panel {
  min-width: 220px;
  display: grid;
  align-items: center;
  gap: 6px 12px;
  padding: 12px 14px;
  color: #fffaf0;
  background: var(--panel-strong);
  border-radius: 8px;
}

.balance-panel {
  grid-template-columns: 1fr auto;
}

.key-panel {
  width: min(420px, 46vw);
  grid-template-columns: 1fr;
}

.key-panel label {
  color: #cabfae;
  font-size: 13px;
}

.key-login {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 8px;
}

.key-login input {
  min-height: 38px;
  color: #fffaf0;
  border-color: rgba(255, 255, 255, 0.22);
  background: rgba(255, 255, 255, 0.1);
}

.key-panel strong {
  color: #fffaf0;
  font-size: 15px;
}

.workbench-actions {
  min-width: 500px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  color: #fffaf0;
  background: var(--panel-strong);
  border-radius: 8px;
}

.workbench-actions strong {
  overflow: hidden;
  color: #fffaf0;
  font-size: 15px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header-generate {
  min-height: 48px;
  padding: 0 18px;
  font-size: 16px;
  white-space: nowrap;
}

.balance-panel span {
  color: #cabfae;
  font-size: 13px;
}

.balance-panel strong {
  font-size: 34px;
  line-height: 1;
}

.balance-panel button {
  grid-row: 1 / span 2;
}

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

.form-pane {
  display: grid;
  gap: 18px;
  padding: 24px;
}

.side-pane {
  min-height: 100%;
  display: grid;
  align-content: start;
  gap: 18px;
  padding: 24px;
  border-left: 1px solid var(--line);
  background: rgba(247, 244, 237, 0.72);
}

.grid {
  display: grid;
  gap: 16px;
}

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

.field {
  display: grid;
  gap: 8px;
}

label,
.label-row {
  color: #37332d;
  font-size: 14px;
  font-weight: 750;
}

.label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid #cfc6b8;
  border-radius: 8px;
  color: var(--ink);
  background: #fffdfa;
  outline: none;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

input,
select {
  min-height: 44px;
  padding: 0 12px;
}

textarea {
  min-height: 118px;
  padding: 12px;
  resize: vertical;
  line-height: 1.55;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.15);
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ece5d8;
}

.segmented button,
.chips button,
.plans button,
.ghost,
.primary,
.download {
  min-height: 40px;
  border: 0;
  border-radius: 8px;
  text-decoration: none;
  transition: transform 150ms ease, background 150ms ease, border-color 150ms ease;
}

.segmented button {
  color: var(--muted);
  background: transparent;
  font-weight: 800;
}

.segmented button.active {
  color: #fffaf0;
  background: var(--teal);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chips button {
  min-height: 34px;
  padding: 0 12px;
  color: #49443d;
  border: 1px solid #cfc6b8;
  background: #fffdfa;
}

.chips button.active {
  color: #083b36;
  border-color: #7fc7bd;
  background: var(--mint);
}

.studio {
  grid-template-columns: minmax(500px, 0.92fr) minmax(540px, 1.08fr);
  grid-template-rows: auto minmax(0, 1fr);
  height: calc(100vh - 158px);
  min-height: calc(100vh - 158px);
  background: rgba(255, 253, 248, 0.92);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.studio-title {
  grid-column: 1 / -1;
  padding: 14px 18px 0;
}

.studio-title h2 {
  margin-bottom: 0;
}

.chat-pane,
.preview-pane {
  min-width: 0;
  min-height: 0;
  align-self: stretch;
}

.chat-pane {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto auto;
  gap: 14px;
  height: auto;
  margin: 18px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdfa;
}

.preview-pane {
  display: grid;
  grid-template-rows: minmax(0, 1fr);
  gap: 14px;
  height: auto;
  padding: 18px;
  border-left: 1px solid var(--line);
  background: transparent;
}

.mode-row {
  display: grid;
  grid-template-columns: auto minmax(260px, 1fr);
  align-items: center;
  gap: 14px;
}

.mode-row span {
  color: #37332d;
  font-size: 14px;
  font-weight: 850;
}

.segmented.compact {
  min-height: 44px;
}

.conversation {
  min-height: 280px;
  height: 100%;
  min-width: 0;
  overflow: auto;
  display: grid;
  align-content: start;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdfa;
}

.message {
  width: min(88%, 720px);
  padding: 12px 14px;
  border: 1px solid #d9d0c2;
  border-radius: 8px;
  background: #f8f4eb;
}

.message.user {
  justify-self: end;
  color: #fffaf0;
  border-color: #0f766e;
  background: var(--teal);
}

.message span {
  display: block;
  margin-bottom: 5px;
  font-size: 12px;
  font-weight: 850;
  color: var(--teal-dark);
}

.message.user span {
  color: #bfe9df;
}

.message p {
  margin-bottom: 0;
  white-space: pre-wrap;
  line-height: 1.55;
}

.quick-prompts {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 7px;
}

.prompt-list {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 5px;
  min-width: 0;
}

.quick-prompts button,
.prompt-list button {
  min-height: 34px;
  min-width: 0;
  padding: 0 7px;
  color: #4e463b;
  border: 1px solid #d0c4b2;
  border-radius: 8px;
  background: #fffdfa;
  font-size: 15px;
  font-weight: 750;
  line-height: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.prompt-list button.prompt-long {
  padding: 0 5px;
  font-size: 13px;
}

.prompt-list button.prompt-xl {
  padding: 0 4px;
  font-size: 12px;
}

.quick-prompts .prompt-refresh {
  padding: 0 10px;
  color: var(--teal-dark);
  background: #edf7f3;
  border-color: #badbd2;
  white-space: nowrap;
}

.chat-input {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 210px;
  align-items: stretch;
  gap: 10px;
}

.chat-input textarea {
  min-height: 86px;
  max-height: 150px;
  font-size: 16px;
}

.preview-card,
.action-card,
.advanced {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdfa;
}

.preview-card {
  min-height: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: auto;
}

.preview-status {
  margin: -4px 0 12px;
}

.action-card {
  display: grid;
  grid-template-columns: minmax(180px, 0.72fr) minmax(240px, 1fr);
  align-items: center;
  gap: 12px;
}

.advanced summary {
  cursor: pointer;
  color: #37332d;
  font-size: 15px;
  font-weight: 850;
}

.advanced .settings {
  margin-top: 14px;
  padding: 0;
  border: 0;
}

.primary.big {
  min-height: 50px;
  font-size: 18px;
}

.action-stack {
  display: grid;
  gap: 8px;
}

.plan h3 {
  margin-bottom: 12px;
  font-size: clamp(24px, 2.2vw, 34px);
  line-height: 1.15;
}

.plan {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.edit-field {
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.edit-field label {
  white-space: nowrap;
}

.chips.readonly span {
  display: inline-flex;
  min-height: 32px;
  align-items: center;
  padding: 0 10px;
  color: #083b36;
  border: 1px solid #7fc7bd;
  border-radius: 8px;
  background: var(--mint);
  font-size: 14px;
  font-weight: 800;
}

.style-preview {
  margin: 14px 0;
  color: #4b453c;
  line-height: 1.6;
}

.preview-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.sources {
  padding: 12px;
  border: 1px solid #d8eadf;
  border-radius: 8px;
  background: #f3fbf6;
}

#sourceList {
  max-height: 178px;
  overflow: auto;
  padding-right: 4px;
}

.sources h2 {
  margin-bottom: 10px;
  color: var(--teal-dark);
  font-size: 15px;
}

.sources article + article {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid #d8eadf;
}

.sources a {
  color: var(--teal-dark);
  font-weight: 850;
  text-decoration: none;
}

.sources p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.lyrics-box {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  margin: 12px 0 0;
}

.section-head.tight h2 {
  margin-bottom: 0;
}

.lyrics-box pre,
.lyrics-box textarea {
  max-height: 260px;
  overflow: auto;
  margin: 12px 0 0;
  padding: 14px;
  color: #2b2822;
  white-space: pre-wrap;
  line-height: 1.65;
  border: 1px solid #e1d7c8;
  border-radius: 8px;
  background: #fbf8f1;
}

.lyrics-box textarea {
  width: 100%;
  flex: 1;
  min-height: 360px;
  max-height: none;
  resize: vertical;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(23, 22, 19, 0.42);
}

.modal-panel {
  position: relative;
  z-index: 1;
  width: min(720px, 100%);
  max-height: min(680px, calc(100vh - 48px));
  overflow: auto;
  padding: 18px;
  box-shadow: var(--shadow);
}

.modal-panel #sourceList {
  max-height: none;
}

.guide-panel {
  background: #fffdfa;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.guide-list {
  display: grid;
  gap: 12px;
  margin: 0;
  padding-left: 24px;
  color: #37332d;
  line-height: 1.65;
}

.meter,
.settings,
.plans {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdfa;
}

.action-card .meter {
  padding: 0;
  border: 0;
  background: transparent;
}

.meter div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.meter span {
  color: var(--muted);
  font-size: 14px;
  font-weight: 750;
}

.meter strong {
  color: var(--coral);
  font-size: 40px;
  line-height: 1;
}

.meter p,
.status {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.settings {
  display: grid;
  gap: 14px;
}

.check-row {
  display: grid;
  grid-template-columns: 18px 1fr;
  align-items: start;
  gap: 10px;
  color: var(--muted);
  font-weight: 650;
  line-height: 1.4;
}

.check-row input {
  width: 18px;
  min-height: 18px;
  margin-top: 1px;
  accent-color: var(--teal);
}

.primary {
  min-height: 52px;
  color: #fffaf0;
  background: var(--teal);
  font-weight: 900;
  font-size: 17px;
}

.primary:hover,
.segmented button:hover,
.chips button:hover,
.plans button:hover,
.ghost:hover,
.download:hover {
  transform: translateY(-1px);
}

.primary:disabled,
.ghost:disabled {
  cursor: not-allowed;
  opacity: 0.58;
  transform: none;
}

.ghost {
  padding: 0 14px;
  color: #fffaf0;
  background: rgba(255, 255, 255, 0.16);
  border: 1px solid rgba(255, 255, 255, 0.22);
}

.ghost.tiny,
.ghost.small {
  min-height: 32px;
  font-size: 13px;
}

.label-row .ghost,
.section-head .ghost {
  color: var(--teal-dark);
  background: #edf7f3;
  border-color: #badbd2;
}

.plans {
  display: grid;
  gap: 8px;
}

.assist-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(220px, 0.9fr);
  gap: 12px;
  align-items: start;
}

.plans summary {
  cursor: pointer;
  color: #37332d;
  font-size: 15px;
  font-weight: 850;
  list-style-position: inside;
}

.plans button {
  min-height: 42px;
  color: #58340a;
  background: #fff4cf;
  border: 1px solid #e5c676;
  font-weight: 800;
}

.results {
  padding: 18px 20px 20px;
}

.admin-shell {
  display: grid;
  gap: 16px;
  min-width: 0;
}

.admin-topbar {
  margin-bottom: 0;
}

.admin-login {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 100px;
  gap: 10px;
}

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

.admin-card {
  min-width: 0;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.92);
  box-shadow: var(--shadow);
}

.admin-ops {
  min-width: 0;
  display: grid;
  gap: 14px;
}

.admin-ops-head {
  display: grid;
  grid-template-columns: minmax(180px, 0.5fr) minmax(420px, 0.82fr);
  align-items: center;
  gap: 18px;
}

.admin-ops-head h2 {
  margin-bottom: 6px;
}

.admin-form {
  display: grid;
  grid-template-columns: auto 120px auto minmax(0, 1fr) 160px;
  gap: 12px;
  align-items: center;
}

.admin-form label {
  display: contents;
}

.generated-box {
  grid-column: 1 / -1;
  margin-top: 16px;
}

.generated-box textarea {
  width: 100%;
  min-height: 116px;
  resize: vertical;
}

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

.stats div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 58px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdfa;
}

.stats span {
  color: var(--muted);
  font-weight: 800;
}

.stats strong {
  font-size: 28px;
  color: var(--teal-dark);
}

.table-wrap {
  min-width: 0;
  max-width: 100%;
  overflow: auto;
}

.key-table {
  width: 100%;
  min-width: 920px;
  border-collapse: collapse;
}

.key-table th,
.key-table td {
  padding: 12px;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--line);
}

.key-table th {
  color: #37332d;
  font-size: 13px;
  background: #f6f0e6;
}

.key-table td span {
  color: var(--muted);
  font-size: 13px;
}

.pill {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  padding: 0 10px;
  border-radius: 8px;
  font-weight: 850;
}

.pill.available {
  color: #0b5c43;
  background: #dff3e7;
}

.pill.used {
  color: #7d341f;
  background: #ffe1d5;
}

.empty-cell {
  color: var(--muted);
  text-align: center;
}

#adminStatus.ok {
  color: var(--teal-dark);
}

#adminStatus.warn {
  color: var(--coral);
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.tracks {
  display: grid;
  gap: 12px;
}

.track {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 160px;
  gap: 16px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdfa;
}

.track h3 {
  margin-bottom: 6px;
  font-size: 17px;
}

.track p {
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

audio {
  width: 100%;
}

.track-actions {
  display: grid;
  align-content: space-between;
  justify-items: end;
  gap: 10px;
}

.track-actions span {
  color: var(--gold);
  font-size: 13px;
  font-weight: 850;
}

.download {
  display: inline-grid;
  min-width: 104px;
  place-items: center;
  padding: 0 14px;
  color: #fffaf0;
  background: var(--coral);
  font-weight: 850;
}

.empty {
  padding: 22px;
  color: var(--muted);
  text-align: center;
  border: 1px dashed #cfc6b8;
  border-radius: 8px;
}

.hidden {
  display: none;
}

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

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

@media (max-width: 1180px) {
  .composer,
  .studio {
    grid-template-columns: 1fr;
    height: auto;
    min-height: auto;
  }

  .side-pane,
  .preview-pane {
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .chat-pane,
  .preview-pane {
    min-height: auto;
  }

  .conversation {
    height: 420px;
  }

  .admin-ops {
    grid-template-columns: 1fr;
  }

  .admin-ops-head {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .app-shell {
    padding: 14px;
  }

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

  .login-card {
    padding: 22px;
  }

  .login-row,
  .workbench-actions,
  .key-panel {
    min-width: 0;
    grid-template-columns: 1fr;
    width: 100%;
  }

  .key-login,
  .admin-login,
  .admin-grid,
  .admin-form {
    grid-template-columns: 1fr;
  }

  .grid.two,
  .track {
    grid-template-columns: 1fr;
  }

  .chat-pane,
  .preview-pane {
    padding: 16px;
  }

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

  .chat-input,
  .action-card,
  .assist-row,
  .quick-prompts,
  .stats {
    grid-template-columns: 1fr;
  }

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

  .conversation {
    height: 360px;
  }

  .message {
    width: 100%;
  }

  .track-actions {
    justify-items: stretch;
  }

  .download {
    width: 100%;
  }
}
