/* Make My Tune -- app-specific styling only.
 *
 * Tokens, reset, buttons, cards, forms, banners, chips, badges, the nav bar and
 * the account panels all come from the shared design system:
 *
 *   <link rel="stylesheet" href="/common-js/ui.css" />
 *
 * What is left here is what is genuinely this app's: the writing editors, the
 * rewrite modal, the interview screens, the admin status grid and the song
 * library. If a rule in this file starts looking generic, it belongs in
 * common/js_ui/esm/components.css instead.
 */

/* --- brand ---------------------------------------------------------------
   The serif headings this app is known for are declared as its DEFAULT for the
   type axis -- `<html data-default-type="editorial">` -- not by overriding
   --font-display here. A bare `:root` override looks equivalent and is not: it
   outranks the axis, so a user who picks "Sans" on the account page keeps
   getting serif headings and the control appears broken.
   ------------------------------------------------------------------------ */

:root {
  /* Text the user will paste elsewhere is shown in mono, so what they see on
     screen is the shape they get. This is not an axis -- it is what a document
     field means in this app, whatever typeface is chosen. */
  --font-doc: var(--font-mono);
}

/* --- page scaffolding ---------------------------------------------------- */

.screen { padding: var(--space-2) 0 var(--space-4); }

.input-row {
  display: flex;
  gap: var(--space-3);
  align-items: flex-start;
}

.input-row textarea { flex: 1; }

.restart-row {
  justify-content: center;
  margin-top: var(--space-6);
  padding-top: var(--space-5);
  border-top: 1px solid var(--border);
}

/* --- dictation ----------------------------------------------------------- */

.mic {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  min-width: 4.25rem;
  padding: var(--space-2) var(--space-3);
  color: var(--fg-muted);
}

.mic:hover { color: var(--fg); }
.mic-icon { font-size: 1.15rem; line-height: 1; }
.mic-label { font-size: var(--text-xs); }

.mic[data-state="recording"] {
  border-color: var(--danger);
  color: var(--danger);
}

.mic[data-state="recording"] .mic-icon {
  animation: mic-pulse 1.1s ease-in-out infinite;
}

.mic[data-state="transcribing"] { color: var(--fg-muted); }

@keyframes mic-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.45; transform: scale(0.9); }
}

/* --- interview ----------------------------------------------------------- */

.progress { margin-bottom: var(--space-5); }

.progress-text {
  margin: var(--space-2) 0 0;
  font-size: var(--text-sm);
  color: var(--fg-muted);
}

.qa-history {
  list-style: none;
  margin: 0 0 var(--space-5);
  padding: 0;
}

.qa-history li {
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--border);
}

.qa-history li + li { margin-top: 0; }
.qa-history .q { margin: 0; color: var(--fg-muted); font-size: var(--text-sm); }
.qa-history .a { margin: var(--space-1) 0 0; }

.question {
  margin: 0 0 var(--space-3);
  font-family: var(--font-display);
  font-size: var(--text-xl);
  line-height: var(--leading-tight);
}

.ready-note {
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-4);
  border-left: 3px solid var(--ok);
  border-radius: var(--radius);
  background: var(--ok-soft);
  font-size: var(--text-sm);
}

/* --- editors ------------------------------------------------------------- */

.editor-card {
  padding: var(--space-4);
  margin-bottom: var(--space-5);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.editor-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin-bottom: var(--space-3);
}

.editor-tools { display: flex; gap: var(--space-2); }

.doc {
  min-height: 22rem;
  background: var(--bg-subtle);
  font-family: var(--font-doc);
  font-size: var(--text-sm);
  line-height: 1.7;
}

.doc.short { min-height: 4.5rem; line-height: 1.5; }

.assist { margin-top: var(--space-3); }

.assist-hint {
  margin: 0 0 var(--space-2);
  font-size: var(--text-sm);
  color: var(--fg-muted);
}

.assist-row { display: flex; gap: var(--space-2); flex-wrap: wrap; }
.assist-row input { flex: 1; min-width: 12rem; }

.selection-preview {
  margin: var(--space-2) 0 0;
  padding: var(--space-1) var(--space-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--fg-muted);
  font-family: var(--font-doc);
  font-size: var(--text-xs);
}

/* --- "Edit with AI", floated above a selection --------------------------- */

.ai-edit-hint {
  position: absolute;
  z-index: 40;
  padding: 0.2rem 0.6rem;
  border: 1px solid var(--accent);
  border-radius: var(--radius-full);
  background: var(--surface);
  color: var(--accent);
  font-size: var(--text-xs);
  font-weight: 600;
  line-height: 1.4;
  white-space: nowrap;
  box-shadow: var(--shadow);
  animation: hint-in var(--duration) var(--ease);
}

.ai-edit-hint:hover,
.ai-edit-hint:focus-visible {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--fg-on-accent);
}

@keyframes hint-in {
  from { opacity: 0; transform: translateY(3px); }
  to { opacity: 1; transform: none; }
}

/* --- rewrite modal ------------------------------------------------------- */

.modal-shell { position: fixed; inset: 0; z-index: 80; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: color-mix(in srgb, var(--grey-950) 45%, transparent);
  backdrop-filter: blur(2px);
}

.modal-panel {
  position: relative;
  z-index: 1;
  width: min(44rem, calc(100vw - 2rem));
  max-height: calc(100vh - 2rem);
  overflow: auto;
  margin: var(--space-5) auto;
  padding: var(--space-5);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  animation: modal-in var(--duration) var(--ease);
}

@keyframes modal-in {
  from { opacity: 0; transform: translateY(8px) scale(0.99); }
  to { opacity: 1; transform: none; }
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

.modal-body { margin-top: var(--space-3); }

.rewrite-markup {
  min-height: 5rem;
  padding: var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-subtle);
  font-family: var(--font-doc);
  font-size: var(--text-sm);
  line-height: 1.55;
  white-space: pre-wrap;
}

.rewrite-markup del {
  background: color-mix(in srgb, var(--danger) 22%, transparent);
  text-decoration: line-through;
}

.rewrite-markup ins {
  background: color-mix(in srgb, var(--ok) 25%, transparent);
  text-decoration: none;
}

.undo-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-2);
  font-size: var(--text-sm);
  color: var(--fg-muted);
}

/* --- Suno handoff -------------------------------------------------------- */

.handoff {
  padding: var(--space-5);
  border: 1px solid var(--accent-border);
  border-radius: var(--radius-lg);
  background: var(--accent-soft);
}

.handoff h3 { margin-bottom: var(--space-2); }
.handoff ol { margin: 0 0 var(--space-4); }

/* --- admin --------------------------------------------------------------- */

.admin-section {
  padding: var(--space-5);
  margin-bottom: var(--space-5);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.status-grid {
  display: grid;
  gap: var(--space-3);
  grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
  margin-top: var(--space-3);
}

.status-card {
  min-width: 0;
  padding: var(--space-3);
  border: 1px solid var(--border);
  border-left: 3px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg-subtle);
}

.status-card.is-ok   { border-left-color: var(--ok); }
.status-card.is-warn { border-left-color: var(--warn); }
.status-card.is-bad  { border-left-color: var(--danger); }

.status-title {
  margin: 0;
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--fg-muted);
}

.status-value {
  margin: var(--space-1) 0 0;
  font-size: var(--text-lg);
  font-weight: 650;
}

/* Paths and error text are long and must not widen the grid. */
.status-hint {
  margin: var(--space-1) 0 0;
  font-family: var(--font-doc);
  font-size: var(--text-xs);
  color: var(--fg-muted);
  overflow-wrap: anywhere;
}

.test-result {
  margin-top: var(--space-3);
  padding: var(--space-3);
  border: 1px solid var(--border);
  border-left: 3px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg-subtle);
  font-family: var(--font-doc);
  font-size: var(--text-sm);
  overflow-wrap: anywhere;
}

.test-result.is-ok  { border-left-color: var(--ok); }
.test-result.is-bad { border-left-color: var(--danger); }

/* settings form ----------------------------------------------------------- */

.field-group { border: 0; padding: 0; margin: var(--space-5) 0 0; }

.field-group legend {
  padding: 0;
  margin-bottom: var(--space-2);
  font-size: var(--text-xs);
  font-weight: 650;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--fg-muted);
}

.field-row {
  display: grid;
  grid-template-columns: minmax(11rem, 15rem) minmax(0, 1fr);
  gap: var(--space-2) var(--space-4);
  align-items: center;
  padding: var(--space-2) 0;
  border-top: 1px solid var(--border);
}

.field-row label {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
  font-size: var(--text-sm);
  font-weight: 550;
}

.field-row.is-locked { opacity: 0.7; }

/* A checkbox must not stretch to the full grid column like a text input. */
.field-row input.field-check {
  width: auto;
  justify-self: start;
  transform: scale(1.2);
}

.source-tag {
  padding: 0.05rem 0.45rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  color: var(--fg-muted);
  font-size: 0.66rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.source-env  { border-color: var(--accent); color: var(--accent); }
.source-file { border-color: var(--ok); color: var(--ok); }

.field-help,
.field-error {
  grid-column: 2;
  margin: var(--space-1) 0 0;
  font-size: var(--text-xs);
}

.field-help  { color: var(--fg-muted); }
.field-error { color: var(--danger); }

/* Not position:sticky -- with `bottom: 0` inside the form's containing block it
   resolved ABOVE the field list rather than pinning to the viewport, putting
   Save before the fields it saves. Normal flow is correct and boring. */
.sticky-actions {
  margin-top: var(--space-5);
  padding-top: var(--space-4);
  border-top: 1px solid var(--border);
}

.dirty-note {
  font-size: var(--text-sm);
  font-weight: 550;
  color: var(--accent);
}

/* --- auth ---------------------------------------------------------------- */

.auth-bar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
  padding: var(--space-2) var(--space-4);
  margin-bottom: var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: var(--text-sm);
}

.auth-bar a { margin-left: auto; }

.auth-warning {
  flex-basis: 100%;
  margin: var(--space-1) 0 0;
  color: var(--danger);
  font-size: var(--text-sm);
}

.signin-gate {
  max-width: 26rem;
  margin: 10vh auto;
  padding: var(--space-6) var(--space-5);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  background: var(--surface);
  box-shadow: var(--shadow);
  text-align: center;
}

.signin-gate h2 { margin-bottom: var(--space-2); }
.signin-gate .link-button { margin-top: var(--space-3); }

/* --- My Songs ------------------------------------------------------------ */

.songs-list {
  display: grid;
  gap: var(--space-4);
  grid-template-columns: repeat(auto-fill, minmax(17rem, 1fr));
}

.song-card {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--duration) var(--ease),
              transform var(--duration) var(--ease),
              border-color var(--duration) var(--ease);
}

.song-card:hover {
  border-color: var(--accent-border);
  box-shadow: var(--shadow);
  transform: translateY(-2px);
}

/* The whole card is the control, so the hit target matches what looks
   clickable rather than being a small link inside a large box. */
.song-open {
  display: block;
  width: 100%;
  padding: var(--space-4);
  border: 0;
  border-radius: 0;
  background: none;
  text-align: left;
  white-space: normal;
  cursor: pointer;
}

.song-open:hover {
  background: var(--surface-2);
  border-color: transparent;
}

.song-title-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.song-title {
  margin: 0 0 var(--space-2);
  font-family: var(--font-display);
  font-size: var(--text-lg);
}

.song-excerpt {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin: 0 0 var(--space-3);
  color: var(--fg-muted);
  font-size: var(--text-sm);
}

.song-meta { margin: 0; font-size: var(--text-xs); color: var(--fg-subtle); }

.song-detail {
  position: fixed;
  inset: 0;
  z-index: 50;
  overflow-y: auto;
  padding: var(--space-5) var(--space-4);
  background: color-mix(in srgb, var(--grey-950) 45%, transparent);
  backdrop-filter: blur(2px);
}

.song-detail-inner {
  max-width: 46rem;
  margin: 0 auto;
  padding: var(--space-5);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  animation: modal-in var(--duration) var(--ease);
}

.song-textarea {
  margin-bottom: var(--space-4);
  font-family: var(--font-doc);
  font-size: var(--text-sm);
  line-height: 1.6;
}

/* --- small screens (NFR-6, NFR-7) ---------------------------------------- */

@media (max-width: 34rem) {
  .input-row { flex-direction: column; }
  .mic { flex-direction: row; width: 100%; justify-content: center; }
  .actions button,
  .actions .link-button { flex: 1 1 auto; }
  .doc { min-height: 16rem; }
  .editor-card,
  .admin-section { padding: var(--space-4); }
  .field-row { grid-template-columns: 1fr; }
  .field-help, .field-error { grid-column: 1; }
}

/* --- rewrite alternatives ------------------------------------------------ */

.rewrite-choices { margin-bottom: var(--space-4); }

.rewrite-choice {
  display: flex;
  gap: var(--space-3);
  align-items: flex-start;
  padding: var(--space-3);
  margin-bottom: var(--space-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
}

.rewrite-choice:hover { border-color: var(--border-strong); }

/* :has() so the whole card reads as chosen, not just the dot. */
.rewrite-choice:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.rewrite-choice input { flex: none; margin-top: 0.25rem; }

.rewrite-choice-text {
  font-family: var(--font-doc);
  font-size: var(--text-sm);
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* --- stage navigation ----------------------------------------------------- */

.stage-nav {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: center;
  padding-top: 0;
  padding-bottom: var(--space-3);
}

.stage {
  padding: 0.25rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  background: var(--surface);
  color: var(--fg-muted);
  font-size: var(--text-xs);
  font-weight: 600;
  cursor: pointer;
}

.stage:hover { border-color: var(--accent-border); color: var(--fg); }

.stage.is-current {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

/* --- editable past answers ------------------------------------------------ */

.qa-answer-edit {
  width: 100%;
  margin-top: var(--space-1);
  padding: var(--space-2);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
  font: inherit;
  resize: vertical;
}

/* Editable, but not shouting about it until you go near it. */
.qa-answer-edit:hover { border-color: var(--border); }
.qa-answer-edit:focus {
  border-color: var(--accent);
  background: var(--surface);
  outline: none;
  box-shadow: var(--ring);
}

.qa-history li.is-focused {
  border-radius: var(--radius);
  background: var(--accent-soft);
  padding-left: var(--space-3);
  padding-right: var(--space-3);
}

/* --- stale lyrics --------------------------------------------------------- */

.stale-note {
  padding: var(--space-4);
  margin-bottom: var(--space-5);
  border: 1px solid var(--warn);
  border-left-width: 3px;
  border-radius: var(--radius);
  background: var(--warn-soft);
}

.stale-note p { margin: 0; font-size: var(--text-sm); }
.stale-note .actions { margin-top: var(--space-3); }

/* --- navigation within the Questions stage -------------------------------- */

.qa-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-2) 0 var(--space-3);
  margin-bottom: var(--space-3);
  border-bottom: 1px solid var(--border);
}

.qa-position {
  font-size: var(--text-sm);
  font-weight: 550;
  color: var(--fg-muted);
}

/* --- lyric style chooser -------------------------------------------------- */

.lyric-group {
  border: 0;
  padding: 0;
  margin: 0 0 var(--space-5);
}

.lyric-group legend {
  padding: 0;
  margin-bottom: var(--space-1);
  font-size: var(--text-xs);
  font-weight: 650;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--fg-muted);
}

.lyric-group .hint { margin-bottom: var(--space-2); }
.lyric-group .chips + .hint { margin: var(--space-2) 0 0; }

.lyric-chip {
  padding: 0.35rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  background: var(--surface);
  font-size: var(--text-sm);
  cursor: pointer;
}

.lyric-chip:hover { border-color: var(--border-strong); }

.lyric-chip.is-chosen {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--fg-on-accent);
  font-weight: 550;
}

/* --- Structure stage ---------------------------------------------------- */

.section-count {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin-bottom: var(--space-4);
}

.section-count .field-label { margin: 0; }
.section-count input { width: 6rem; }

.structure-list {
  list-style: none;
  margin: 0 0 var(--space-4);
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.section-card {
  padding: var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
}

.section-head {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
  margin-bottom: var(--space-2);
}

.section-number {
  min-width: 1.5rem;
  color: var(--fg-muted);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.section-desc { width: 100%; }

/* Wraps rather than scrolls: six kinds on a phone will not fit one line, and
   a horizontally scrolling row hides the choices at the end. */
.kind-radios {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
}

/* The radio itself is hidden rather than removed: it is what carries the
   keyboard behaviour and the group semantics, so the label just draws it. */
.kind-option {
  /* Positioned so the hidden radio inside stays inside: without this the
     absolutely-placed input escapes to the nearest positioned ancestor and
     ends up somewhere else on the page entirely. */
  position: relative;
  display: inline-flex;
  align-items: center;
  padding: 0.3rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  background: var(--surface);
  font-size: var(--text-sm);
  cursor: pointer;
}

/* The radio is what carries the keyboard behaviour and the group semantics,
   so it stays in the DOM and covers the label -- the label just draws it. */
.kind-option input {
  position: absolute;
  inset: 0;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}
.kind-option:hover { border-color: var(--border-strong); }
.kind-option:has(input:focus-visible) { outline: 2px solid var(--accent); }

.kind-option.is-chosen {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--fg-on-accent);
  font-weight: 550;
}
