:root {
  --paper: #f2eee4;
  --card: #fbf9f3;
  --ink: #181820;
  --mute: #6d6960;
  --rule: #d6d0c2;
  --rule-2: #b8b3a5;
  --navy: #12224f;
  --brass: #b5852b;
  --exclude: #8b2a1e;
  --display: "Iowan Old Style", ui-serif, Palatino, "Times New Roman", serif;
  --sans: ui-sans-serif, -apple-system, "Helvetica Neue", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--paper); color: var(--ink);
  font-family: var(--sans); font-size: 15px; line-height: 1.5;
  -webkit-font-smoothing: antialiased; }

/* Washed-out analog-console backdrop: a heavy cream overlay (more opaque up top
   so the masthead stays clean) over the console photo, full-bleed. */
body {
  min-height: 100vh;
  background-color: var(--paper);
  background-image:
    linear-gradient(180deg, rgba(242,238,228,0.93) 0%, rgba(242,238,228,0.85) 30%, rgba(242,238,228,0.80) 100%),
    url("/bg-console.jpg");
  background-repeat: no-repeat;
  background-position: center top, center;
  background-size: cover;
  background-attachment: scroll;   /* 'fixed' is janky on iOS; scroll is safe */
}


main { max-width: 640px; margin: 0 auto; padding: clamp(24px,5vw,48px) clamp(16px,4vw,32px) 64px;
  display: flex; flex-direction: column; gap: clamp(20px,4vw,32px); }

.masthead { text-align: center; display: flex; flex-direction: column; gap: 6px; }
.brand { font-size: 13px; letter-spacing: 0.3em; text-transform: uppercase;
  color: var(--navy); font-weight: 600; }
.brand .dot { color: var(--brass); }
.tagline { font-family: var(--display); font-style: italic; font-size: 22px; margin: 0;
  color: var(--ink); text-wrap: balance; }

.card { background: var(--card); border: 1px solid var(--rule); border-radius: 3px;
  padding: clamp(20px,5vw,40px); box-shadow: 0 28px 60px -26px rgba(18,34,79,0.35); }

/* state machine */
.processing, .ready, .errorbox { display: none; }
#app[data-state="empty"] .dropzone { display: flex; }
#app[data-state="processing"] .dropzone { display: none; }
#app[data-state="processing"] .processing { display: flex; }
#app[data-state="ready"] .dropzone { display: none; }
#app[data-state="ready"] .ready { display: flex; }
#app[data-state="error"] .dropzone { display: none; }
#app[data-state="error"] .errorbox { display: flex; }

/* dropzone */
.dropzone { flex-direction: column; align-items: center; gap: 8px; text-align: center;
  border: 1px dashed var(--rule-2); border-radius: 3px; padding: clamp(28px,6vw,48px);
  cursor: pointer; outline: none; transition: border-color .15s, background .15s; }
.dropzone:hover, .dropzone:focus-visible, .dropzone.drag {
  border-color: var(--navy); background: rgba(18,34,79,0.03); }
.dz-headline { font-family: var(--display); font-style: italic; font-size: 26px;
  color: var(--navy); margin: 0; text-wrap: balance; }
.dz-sub { color: var(--mute); margin: 0; max-width: 34ch; }
.dz-badge { font-size: 12px; letter-spacing: 0.16em; text-transform: uppercase;
  color: var(--mute); margin: 6px 0 0; }

/* processing */
.processing { flex-direction: column; align-items: center; gap: 14px; text-align: center; }
.proc-headline { font-family: var(--display); font-style: italic; font-size: 26px;
  color: var(--navy); margin: 0; }
.proc-file { color: var(--mute); margin: 0; }
.bar { width: 100%; max-width: 340px; height: 3px; background: var(--rule); overflow: hidden; }
.bar-fill { height: 100%; width: 100%; background: var(--navy);
  transform: scaleX(0); transform-origin: left; transition: transform .3s linear; }
.proc-eta { font-size: 13px; color: var(--mute); font-style: italic; margin: 0; }
.proc-eta:empty { display: none; }
.proc-stage { font-size: 12px; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--mute); font-variant-numeric: tabular-nums; margin: 0; }
/* indeterminate bar — unknown-duration waits (payment finalize + full-mix render) */
.bar-fill.indeterminate { width: 40%; transform: none; transition: none;
  animation: op-indeterminate 1.1s ease-in-out infinite; }
@keyframes op-indeterminate { 0% { margin-left: -45%; } 100% { margin-left: 100%; } }

/* ready */
.ready { flex-direction: column; gap: 24px; }
.track { display: flex; align-items: baseline; justify-content: space-between; gap: 16px;
  padding-bottom: 16px; border-bottom: 1px solid var(--rule); }
.track-title { font-family: var(--display); font-style: italic; font-size: clamp(28px,6vw,40px);
  margin: 0; line-height: 1.05; overflow-wrap: anywhere; }
.track-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex-shrink: 0; }
.track-duration { color: var(--navy); font-variant-numeric: tabular-nums; }
.linkbtn { background: none; border: none; padding: 2px 0; cursor: pointer; font-family: inherit;
  font-size: 12px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--mute);
  border-bottom: 1px solid transparent; }
.linkbtn:hover { color: var(--navy); border-bottom-color: var(--navy); }

.section-label { font-size: 12px; letter-spacing: 0.3em; text-transform: uppercase;
  color: var(--mute); margin: 0 0 -8px; }

.stems { list-style: none; margin: 0; padding: 0; }
.stem { display: flex; align-items: center; gap: 12px; padding: 12px 0;
  border-top: 1px solid transparent; cursor: pointer; user-select: none; }
.stem + .stem { border-top: 1px solid var(--rule); }
.stem-icon { font-size: 20px; line-height: 1; width: 1.4em; text-align: center; flex-shrink: 0; }
.stem.drop .stem-icon { opacity: 0.4; }
.stem input { appearance: none; -webkit-appearance: none; width: 20px; height: 20px; margin: 0;
  border: 1px solid var(--rule-2); border-radius: 3px; cursor: pointer; flex-shrink: 0;
  display: grid; place-content: center; transition: background .15s, border-color .15s; }
.stem input::before { content: "✓"; color: var(--card); font-size: 13px; line-height: 1;
  transform: scale(0); transition: transform .12s; }
.stem input:checked { background: var(--navy); border-color: var(--navy); }
.stem input:checked::before { transform: scale(1); }
.stem input:focus-visible { outline: 2px solid var(--navy); outline-offset: 2px; }
.stem-name { font-family: var(--display); font-size: 22px; text-transform: capitalize; flex: 1; }
.stem-tag { font-size: 11px; letter-spacing: 0.16em; text-transform: uppercase; }
.stem.keep .stem-tag { color: var(--navy); }
.stem.drop .stem-name { color: var(--mute); text-decoration: line-through;
  text-decoration-color: var(--exclude); }
.stem.drop .stem-tag { color: var(--exclude); }

/* Ensure the hidden attribute wins over .btn's display. */
[hidden] { display: none !important; }

.transport { display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding-top: 20px; border-top: 1px solid var(--rule); }
.pv-icon { font-size: 12px; line-height: 1; display: inline-block; min-width: 1em; text-align: center; }
/* Fixed label width so Preview↔Pause doesn't reflow the transport row. */
.pv-label { display: inline-block; min-width: 3.75em; text-align: left; }
.dl-hint { color: var(--mute); font-size: 13px; font-style: italic; }

/* Stems locked while a preview is playing (can't change the mix mid-listen). */
.stems.locked { opacity: 0.5; }
.stems.locked .stem { cursor: not-allowed; }
.stems.locked .stem input { cursor: not-allowed; }

/* Preview scrubber — full-track timeline; click to audition any 20s window. */
.pv-scrub { display: flex; flex-direction: column; gap: 6px; margin: -6px 0 2px; }
.pv-timeline { position: relative; height: 22px; border-radius: 6px;
  background: var(--card-2); border: 1px solid var(--rule);
  cursor: pointer; overflow: hidden; outline: none; user-select: none; touch-action: none; }
.pv-timeline:hover, .pv-timeline:focus-visible { border-color: var(--navy); }
.pv-window { position: absolute; top: 0; bottom: 0; left: 0; width: 0;
  background: rgba(18,34,79,0.12);
  border-left: 2px solid var(--navy); border-right: 2px solid var(--navy);
  pointer-events: none; }
.pv-head { position: absolute; top: 0; bottom: 0; left: 0; width: 2px;
  background: var(--brass); pointer-events: none; transform: translateX(-1px);
  box-shadow: 0 0 0 1px rgba(181,133,43,0.3); }
.pv-meta { display: flex; justify-content: space-between; gap: 12px; }
.pv-hint { color: var(--mute); font-size: 12px; font-style: italic; }
.pv-time { color: var(--mute); font-size: 12px; font-variant-numeric: tabular-nums; letter-spacing: 0.04em; }
.transport .spacer { flex: 1; }
.btn { font-family: inherit; font-size: 14px; padding: 12px 18px; min-height: 44px;
  border: 1px solid var(--navy); background: transparent; color: var(--navy);
  border-radius: 3px; cursor: pointer; display: inline-flex; align-items: center; gap: 8px;
  transition: background .15s, color .15s; }
.btn:hover:not(:disabled) { background: var(--navy); color: var(--card); }
.btn:disabled { opacity: 0.5; cursor: default; }
/* Secondary "start over" — centered, muted, so it reads as a reset not a CTA. */
.restart-btn { align-self: center; justify-content: center; border-color: var(--rule-2);
  color: var(--mute); }
.restart-btn:hover:not(:disabled) { background: transparent; border-color: var(--navy);
  color: var(--navy); }
.btn.primary { background: var(--navy); color: var(--card); }
.btn.primary:hover:not(:disabled) { background: var(--ink); border-color: var(--ink); }
.btn .note { font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; opacity: 0.7; }
.btn .price { font-family: var(--display); font-size: 18px; color: var(--brass); }
.btn.primary .price { color: #d8b25c; }

.fineprint { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  color: var(--mute); font-size: 12px; margin: 0; }

.paused-notice { text-align: center; }
.paused-headline { font-family: var(--display); font-style: italic; font-size: 26px;
  color: var(--exclude); margin: 0 0 6px; }
.paused-sub { color: var(--mute); margin: 0; }

.errorbox { flex-direction: column; gap: 12px; text-align: center; align-items: center; }
.err-headline { font-family: var(--display); font-style: italic; font-size: 24px;
  color: var(--exclude); margin: 0; }
.err-text { color: var(--mute); margin: 0; }
.err-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }

footer { text-align: center; color: var(--mute); font-size: 12px; letter-spacing: 0.06em;
  display: flex; flex-direction: column; gap: 6px; }
.footer-links a { color: var(--navy); text-decoration: none; }
.footer-links a:hover { text-decoration: underline; }

/* Clickwrap consent — only shown in the empty/upload state, gates upload. */
.consent { display: none; align-items: flex-start; gap: 10px; margin-top: 16px;
  font-size: 13px; color: var(--ink); line-height: 1.4; cursor: pointer; }
#app[data-state="empty"] .consent { display: flex; }
.consent input { width: 18px; height: 18px; margin: 1px 0 0; flex-shrink: 0;
  accent-color: var(--navy); cursor: pointer; }
.consent a { color: var(--navy); }
.consent.nudge { animation: consent-shake 0.4s; }
.consent.nudge span { color: var(--exclude); }
@keyframes consent-shake {
  0%,100% { transform: translateX(0); }
  25% { transform: translateX(-4px); } 75% { transform: translateX(4px); }
}

/* Cookie banner */
.cookie-banner { position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%);
  width: calc(100% - 32px); max-width: 620px; z-index: 50;
  background: var(--card); border: 1px solid var(--rule-2); border-radius: 10px;
  box-shadow: 0 18px 40px -18px rgba(18,34,79,0.4);
  padding: 16px 18px; display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.cookie-text { margin: 0; font-size: 13px; color: var(--ink); flex: 1 1 260px; line-height: 1.45; }
.cookie-text a { color: var(--navy); }
.cookie-actions { display: flex; gap: 8px; flex-shrink: 0; }
.cookie-actions .btn { min-height: 38px; padding: 8px 14px; font-size: 13px; }

/* Legal pages (terms / privacy) */
.legal { max-width: 720px; margin: 0 auto; padding: clamp(24px,5vw,56px) clamp(16px,4vw,32px) 80px;
  line-height: 1.65; }
.legal h1 { font-family: var(--display); font-size: clamp(28px,6vw,40px); margin: 0 0 4px; }
.legal h2 { font-family: var(--display); font-size: 20px; margin: 28px 0 6px; color: var(--navy); }
.legal p, .legal li { color: var(--ink); font-size: 15px; }
.legal ul { padding-left: 20px; }
.legal li { margin: 4px 0; }
.legal a { color: var(--navy); }
.legal-meta { color: var(--mute); font-size: 13px; margin: 0 0 20px; }
.legal-back { font-size: 13px; }
.legal-back a { color: var(--navy); text-decoration: none; }

/* Legal modal — displays the terms/privacy page content inline */
.modal-overlay { position: fixed; inset: 0; z-index: 100; background: rgba(14,15,19,0.55);
  display: flex; align-items: flex-start; justify-content: center;
  padding: clamp(16px,5vh,64px) 16px; overflow-y: auto; }
.modal { position: relative; background: var(--card); border: 1px solid var(--rule);
  border-radius: 12px; width: 100%; max-width: 720px;
  box-shadow: 0 30px 60px -20px rgba(18,34,79,0.5);
  padding: clamp(24px,4vw,44px); }
.modal-close { position: absolute; top: 10px; right: 12px; width: 34px; height: 34px;
  border: none; background: none; color: var(--mute); font-size: 26px; line-height: 1;
  cursor: pointer; border-radius: 6px; }
.modal-close:hover { color: var(--ink); background: var(--card-2); }
.modal .legal { padding: 0; margin: 0; max-width: none; }
.modal .legal h1 { font-size: clamp(24px,5vw,32px); }
.modal .legal .legal-back { display: none; }  /* back-links belong to the full page */

/* payment return banner (shown after coming back from Polar's hosted checkout) */
.pay-return-note {
  margin: 0 0 18px; padding: 12px 16px; border-radius: 8px;
  background: rgba(181, 133, 43, 0.12); border: 1px solid var(--brass);
  color: var(--navy); font-family: var(--display); font-size: 16px; text-align: center;
}
.dl-spinner { margin-right: 8px; }
.spinner { width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent;
  border-radius: 50%; display: inline-block; vertical-align: -2px; animation: op-spin .6s linear infinite; }
@keyframes op-spin { to { transform: rotate(360deg); } }

@media (max-width: 520px) {
  .track { flex-direction: column; align-items: flex-start; gap: 6px; }
  .track-meta { flex-direction: row; align-items: center; gap: 14px; }
  .transport { flex-direction: column; align-items: stretch; }
  .transport .spacer { display: none; }
  .btn { justify-content: center; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
