/* ═══════════════════════════════════════════════════════
   Obzek.io — Clip Flip
   Tokens mirror ../styles.css so the app reads as part of the site.
   ═══════════════════════════════════════════════════════ */

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

/* Author `display` rules outrank the UA stylesheet's `[hidden] { display:none }`,
   so anything toggled via the `hidden` property needs this to actually hide.
   Without it .stage-empty (display:grid) and .btn (display:inline-flex) stay
   on screen regardless of the attribute. */
[hidden] { display: none !important; }

:root {
  --bg:           #05020F;
  --bg-surface:   #0A0619;
  --bg-card:      #0F0A22;
  --purple-mid:   #4A1D96;
  --purple-vivid: #6D28D9;
  --gold:         #C47B0A;
  --gold-bright:  #F59E0B;
  --gold-light:   #FCD34D;
  --text:         #EDE8FF;
  --text-sub:     #9D8EC4;
  --text-muted:   #4D4068;
  --border:       rgba(109, 40, 217, 0.22);
  --border-gold:  rgba(245, 158, 11, 0.32);
  --danger:       #F87171;
  --ok:           #34D399;

  --font-head: 'Sora', system-ui, sans-serif;
  --font-body: 'DM Sans', system-ui, sans-serif;
  --r: 12px;
}

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* Same purple wash the landing page uses, so the app doesn't feel bolted on. */
body::before {
  content: '';
  position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(60rem 40rem at 12% -10%, rgba(109,40,217,.20), transparent 65%),
    radial-gradient(45rem 35rem at 95% 5%, rgba(245,158,11,.07), transparent 60%);
}

a { color: var(--gold-light); }

/* The topbar and its tool switcher live in ../shared/css/topbar.css. */

/* ─── LAYOUT ────────────────────────────────────────── */
main { max-width: 1400px; margin: 0 auto; padding: 2.5rem 2rem 4rem; }

.page-head { margin-bottom: 2rem; max-width: 60ch; }
.page-head h1 {
  font-family: var(--font-head); font-weight: 800; font-size: clamp(1.9rem, 4vw, 2.6rem);
  letter-spacing: -.035em; line-height: 1.1;
}
.page-head p { color: var(--text-sub); margin-top: .6rem; font-size: .95rem; }

.layout { display: grid; grid-template-columns: minmax(0,1fr) 400px; gap: 1.5rem; align-items: start; }
.col-build { display: flex; flex-direction: column; gap: 1.5rem; min-width: 0; }
.col-preview { display: flex; flex-direction: column; gap: 1.5rem; min-width: 0; }

/* The gift tag sits above the build layout rather than inside it: it only
   appears once a reel exists, and when it does it's the thing to act on. */
#stepGift { margin-bottom: 1.5rem; }

@media (max-width: 1080px) {
  .layout { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  main { padding: 1.5rem 1rem 3rem; }
  /* Beats the unscoped `.controls` rule further down the file. */
  .controls { grid-template-columns: 1fr !important; }
}

/* ─── PANEL ─────────────────────────────────────────── */
.panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 1.25rem;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap;
}
.panel-head h2 {
  font-family: var(--font-head); font-size: .95rem; font-weight: 700;
  letter-spacing: -.01em; display: flex; align-items: center; gap: .6rem;
}
.step {
  display: grid; place-items: center; width: 1.4rem; height: 1.4rem;
  border-radius: 50%; font-size: .7rem; font-weight: 700;
  background: rgba(109,40,217,.28); color: var(--gold-light);
  border: 1px solid var(--border);
}
.panel-actions { display: flex; gap: .5rem; }
.plan { font-size: .74rem; color: var(--text-sub); font-variant-numeric: tabular-nums; }
.plan.warn { color: var(--gold-light); }

/* ─── BUTTONS ───────────────────────────────────────── */
.btn {
  font-family: var(--font-head); font-size: .8rem; font-weight: 600;
  padding: .55rem .95rem; border-radius: 8px; border: 1px solid transparent;
  cursor: pointer; transition: .18s ease; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  background: none; color: var(--text);
}
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-ghost { border-color: var(--border); color: var(--text-sub); }
.btn-ghost:hover:not(:disabled) { border-color: var(--purple-vivid); color: var(--text); background: rgba(109,40,217,.14); }
.btn-ghost.danger:hover:not(:disabled) { border-color: rgba(248,113,113,.5); color: var(--danger); background: rgba(248,113,113,.08); }
.btn-primary {
  background: linear-gradient(135deg, var(--gold-bright), var(--gold));
  color: #1a0d00; font-weight: 700;
}
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); transform: translateY(-1px); }
.btn-block { width: 100%; margin-top: .75rem; padding: .8rem; }
.btn-icon { width: 2.4rem; height: 2.4rem; padding: 0; border: 1px solid var(--border); border-radius: 8px; flex: none; }
.btn-icon:hover:not(:disabled) { border-color: var(--purple-vivid); background: rgba(109,40,217,.16); }

/* ─── DROPZONE ──────────────────────────────────────── */
.dropzone {
  display: flex; flex-direction: column; align-items: center; gap: .4rem;
  padding: 2rem 1rem; text-align: center; cursor: pointer;
  border: 1.5px dashed var(--border); border-radius: var(--r);
  color: var(--text-sub); transition: .2s ease;
}
.dropzone:hover, .dropzone:focus-visible, .dropzone.over {
  border-color: var(--gold-bright); background: rgba(245,158,11,.06); color: var(--text);
  outline: none;
}
.dropzone.over { transform: scale(1.005); }
.dropzone strong { font-family: var(--font-head); font-size: .95rem; color: var(--text); }
.dropzone span { font-size: .76rem; max-width: 46ch; }

.ingest-status { margin-top: .8rem; font-size: .78rem; color: var(--text-sub); }
.ingest-status .err { color: var(--danger); display: block; }

/* ─── STORYBOARD ────────────────────────────────────── */
.storyboard {
  list-style: none; display: grid; gap: .6rem; margin-top: 1rem;
  grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
}
.storyboard:empty { display: none; }
.tile {
  position: relative; aspect-ratio: 1; border-radius: 9px; overflow: hidden;
  border: 1px solid var(--border); background: var(--bg-surface);
  cursor: grab; transition: .15s ease;
}
.tile:hover { border-color: var(--purple-vivid); }
.tile.dragging { opacity: .35; cursor: grabbing; }
.tile.drop-target { border-color: var(--gold-bright); box-shadow: 0 0 0 2px var(--gold-glow, rgba(245,158,11,.3)); }
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; }
.tile .idx {
  position: absolute; top: 4px; left: 4px; z-index: 2;
  font-family: var(--font-head); font-size: .62rem; font-weight: 700;
  padding: .1rem .35rem; border-radius: 4px;
  background: rgba(5,2,15,.8); color: var(--gold-light);
}
.tile .kind {
  position: absolute; bottom: 4px; left: 4px; z-index: 2;
  font-size: .58rem; letter-spacing: .05em; text-transform: uppercase;
  padding: .1rem .3rem; border-radius: 4px;
  background: rgba(5,2,15,.8); color: var(--text-sub);
}
.tile .rm {
  position: absolute; top: 3px; right: 3px; z-index: 3;
  width: 1.15rem; height: 1.15rem; border-radius: 50%; border: none;
  background: rgba(5,2,15,.85); color: var(--text-sub);
  cursor: pointer; font-size: .8rem; line-height: 1; display: grid; place-items: center;
  opacity: 0; transition: .15s;
}
.tile:hover .rm { opacity: 1; }
.tile .rm:hover { background: var(--danger); color: #fff; }
.hint { font-size: .74rem; color: var(--text-muted); margin-top: .7rem; }

/* ─── TRACKS ────────────────────────────────────────── */
.track-list { display: grid; gap: .45rem; }
.track {
  display: flex; align-items: center; gap: .75rem; width: 100%;
  padding: .6rem .75rem; border-radius: 9px; cursor: pointer;
  border: 1px solid var(--border); background: var(--bg-surface);
  color: var(--text); text-align: left; transition: .15s ease;
  font-family: var(--font-body);
}
.track:hover { border-color: var(--purple-vivid); background: rgba(109,40,217,.12); }
.track.active { border-color: var(--gold-bright); background: rgba(245,158,11,.08); }
.track .t-play {
  flex: none; width: 1.9rem; height: 1.9rem; border-radius: 50%;
  display: grid; place-items: center; background: rgba(109,40,217,.25); color: var(--gold-light);
  border: 1px solid var(--border);
}
.track.active .t-play { background: rgba(245,158,11,.18); }
.t-body { min-width: 0; flex: 1; }
.t-title { font-size: .84rem; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.t-sub { font-size: .7rem; color: var(--text-sub); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.t-bpm {
  flex: none; font-family: var(--font-head); font-size: .66rem; font-weight: 700;
  color: var(--text-sub); font-variant-numeric: tabular-nums;
}
.track.active .t-bpm { color: var(--gold-light); }

.analysis { margin-top: .9rem; }
#waveform { width: 100%; height: 72px; display: block; border-radius: 8px; background: var(--bg-surface); border: 1px solid var(--border); }
.analysis-meta {
  display: flex; justify-content: space-between; gap: 1rem; align-items: baseline;
  margin-top: .5rem; font-size: .74rem; color: var(--text-sub);
}
.analysis-meta #bpmOut { font-family: var(--font-head); font-weight: 700; color: var(--gold-light); white-space: nowrap; }
.credit { text-align: right; min-width: 0; overflow: hidden; text-overflow: ellipsis; }

/* ─── CONTROLS ──────────────────────────────────────── */
.controls { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
.ctrl { display: flex; flex-direction: column; gap: .35rem; min-width: 0; }
.ctrl-wide { grid-column: 1 / -1; }
.ctrl > span { font-size: .74rem; color: var(--text-sub); display: flex; justify-content: space-between; }
.ctrl > span b { color: var(--gold-light); font-family: var(--font-head); font-variant-numeric: tabular-nums; }
select, input[type="range"] { width: 100%; font-family: var(--font-body); }
select {
  padding: .5rem .6rem; border-radius: 8px; font-size: .8rem;
  background: var(--bg-surface); color: var(--text); border: 1px solid var(--border);
  cursor: pointer;
}
select:focus-visible, input:focus-visible { outline: 2px solid var(--purple-vivid); outline-offset: 1px; }
input[type="range"] {
  -webkit-appearance: none; appearance: none; height: 4px; border-radius: 2px;
  background: rgba(109,40,217,.35); cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 14px; height: 14px; border-radius: 50%;
  background: var(--gold-bright); border: none; cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--gold-bright); border: none; cursor: pointer;
}
input[type="range"]:disabled { opacity: .4; cursor: not-allowed; }
.toggle-row > span { align-items: center; }

/* ─── PREVIEW ───────────────────────────────────────── */
.stage {
  position: relative; border-radius: var(--r); overflow: hidden;
  background: #000; border: 1px solid var(--border);
  display: grid; place-items: center; min-height: 240px;
  max-height: min(58vh, 520px);
}
#preview { display: block; max-width: 100%; max-height: min(58vh, 520px); object-fit: contain; }
.stage-empty {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-size: .82rem; color: var(--text-muted); pointer-events: none; text-align: center; padding: 1rem;
}

.transport { display: flex; align-items: center; gap: .7rem; margin-top: .8rem; }
.transport input[type="range"] { flex: 1; }
.time { font-size: .72rem; color: var(--text-sub); font-variant-numeric: tabular-nums; white-space: nowrap; }

.progress-wrap { margin-top: .8rem; }
.progress { height: 5px; border-radius: 3px; background: rgba(109,40,217,.28); overflow: hidden; }
.progress > div { height: 100%; width: 0; border-radius: 3px; background: linear-gradient(90deg, var(--gold), var(--gold-light)); transition: width .2s ease; }
#progressText { display: block; margin-top: .45rem; font-size: .74rem; color: var(--text-sub); }

/* The finished reel gets its own card below the stage, so the
   download, the share row and the gift tag aren't competing with the
   controls that are no longer relevant once the render is done. */
.result { border-color: var(--border-gold); }
.result .panel-head h2 { color: var(--gold-light); }
.result-meta { margin-top: .6rem; font-size: .74rem; color: var(--text-sub); }
.result-meta code {
  display: block; margin-top: .4rem; padding: .5rem .6rem; border-radius: 6px;
  background: var(--bg-surface); border: 1px solid var(--border);
  font-size: .7rem; color: var(--gold-light); word-break: break-word; font-family: ui-monospace, monospace;
}

.share-row { margin-top: .75rem; }
.share-row-label { display: block; font-size: .72rem; color: var(--text-sub); margin-bottom: .4rem; }
.share-row-buttons { display: flex; flex-wrap: wrap; gap: .4rem; }
.share-row-buttons .btn { flex: 1 1 calc(50% - .2rem); padding: .5rem .3rem; font-size: .72rem; }

.footnote { margin-top: 2rem; font-size: .76rem; color: var(--text-muted); text-align: center; }

/* ─── TOAST ─────────────────────────────────────────── */
.toast {
  position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%);
  z-index: 200; padding: .7rem 1.1rem; border-radius: 9px;
  background: var(--bg-card); border: 1px solid var(--border-gold);
  font-size: .8rem; box-shadow: 0 12px 40px rgba(0,0,0,.5); max-width: 90vw;
}
.toast.err { border-color: rgba(248,113,113,.5); color: var(--danger); }

/* ─── AAC CONSENT MODAL ─────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 300;
  display: flex; align-items: center; justify-content: center;
  padding: 1.25rem; background: rgba(2, 1, 8, 0.72); backdrop-filter: blur(2px);
}
.modal-card {
  width: 100%; max-width: 30rem; padding: 1.4rem 1.5rem;
  background: var(--bg-card); border: 1px solid var(--border-gold); border-radius: var(--r);
  box-shadow: 0 24px 70px rgba(0,0,0,.55);
}
.modal-card h3 {
  display: flex; align-items: center; gap: .5rem;
  font-family: var(--font-head); font-size: 1rem; color: var(--gold-light);
  margin-bottom: .7rem;
}
.modal-card p { font-size: .84rem; color: var(--text-sub); margin-bottom: .7rem; }
.modal-card p:last-of-type { margin-bottom: 1.1rem; }
.modal-card strong { color: var(--text); }
.modal-actions { display: flex; flex-wrap: wrap; gap: .5rem; justify-content: flex-end; }
.modal-actions .btn { flex: 1 1 auto; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
