/* ==========================================================================
   Infinite v0.1 — design tokens + components
   ========================================================================== */

:root {
  --bg: #1A1715;
  --surface: #221F1C;
  --surface-2: #2B2723;
  --surface-3: #35302B;
  --text: #EAE3DA;
  --text-dim: #9A928A;
  --text-faint: #6A6158;
  --accent: #ff6a3d;
  --accent-dim: #c44a22;
  --accent-glow: rgba(255,106,61,.18);
  --ok: #7dd48f;
  --warn: #f0c14b;
  --danger: #e86564;
  --line: rgba(255,255,255,.06);
  --line-strong: rgba(255,255,255,.12);
  --radius: 12px;
  --radius-sm: 6px;
  --radius-lg: 18px;
  --touch: 48px;
  --ease: cubic-bezier(.2,.8,.2,1);
  --mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;
  --display: 'Space Grotesk', 'Inter', system-ui, sans-serif;
  --sans: 'Inter', -apple-system, system-ui, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg); color: var(--text);
  font-family: var(--sans);
  overflow-x: hidden;
}
html { scroll-behavior: smooth; }
body {
  font-size: 15px; line-height: 1.5;
  min-height: 100vh; min-height: 100dvh;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  -webkit-font-smoothing: antialiased;
}

button {
  font-family: inherit; color: inherit;
  background: none; border: 0; cursor: pointer;
  padding: 0; margin: 0;
  position: relative;
}
button > span { pointer-events: none; }
button:disabled { opacity: .4; cursor: not-allowed; }

input, select, textarea {
  font-family: inherit; color: inherit;
  background: none; border: 0;
}

a { color: var(--accent); text-decoration: none; }
code {
  font-family: var(--mono);
  font-size: 0.88em;
  background: rgba(255,255,255,.06);
  padding: 1px 6px; border-radius: 4px;
}

.hidden { display: none !important; }

/* ==========================================================================
   Splash
   ========================================================================== */

.splash {
  position: fixed; inset: 0; z-index: 500;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  padding-top: max(20px, env(safe-area-inset-top));
  padding-bottom: max(20px, env(safe-area-inset-bottom));
  transition: opacity 400ms var(--ease);
}
.splash.hiding {
  opacity: 0; pointer-events: none;
}
.splash-inner {
  text-align: center;
  max-width: 420px;
  width: 100%;
}
.logo-big {
  font-family: var(--display);
  font-weight: 700;
  font-size: 48px;
  letter-spacing: -0.04em;
  margin-bottom: 8px;
}
.logo-big .dot { color: var(--accent); }
.splash-tag {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-dim);
  text-transform: lowercase;
  letter-spacing: 0.2em;
  margin-bottom: 60px;
}
.splash-btn {
  width: 100%;
  padding: 24px;
  background: var(--accent);
  color: white;
  border-radius: var(--radius-lg);
  min-height: 100px;
  transition: transform 120ms var(--ease), background 120ms var(--ease);
  box-shadow: 0 8px 24px rgba(255,106,61,.25);
}
.splash-btn:active { transform: scale(.97); background: var(--accent-dim); }
.splash-btn-inner {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  pointer-events: none;
}
.splash-btn-icon {
  font-size: 32px;
}
.splash-btn-label {
  font-family: var(--display);
  font-weight: 600;
  font-size: 20px;
  letter-spacing: -0.01em;
}
.splash-hint {
  margin-top: 20px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

/* ==========================================================================
   App shell
   ========================================================================== */

.app {
  min-height: 100vh;
  min-height: 100dvh;
}
.topnav {
  position: sticky; top: 0; z-index: 100;
  background: rgba(26,23,21,.85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--line);
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
}
.logo {
  font-family: var(--display);
  font-weight: 700;
  font-size: 18px;
  letter-spacing: -0.02em;
}
.logo .dot { color: var(--accent); }
.nav-right {
  display: flex; align-items: center; gap: 8px;
}
.ctx-chip {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-dim);
  padding: 6px 10px;
  background: var(--surface);
  border-radius: 100px;
  border: 1px solid var(--line);
}
.icon-btn {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
  transition: background 120ms;
}
.icon-btn:active { background: var(--surface-2); }

.main {
  max-width: 780px;
  margin: 0 auto;
  padding: 20px;
  padding-bottom: 100px;
}

/* ==========================================================================
   Stage (step) layout
   ========================================================================== */

.stage {
  animation: stageIn 400ms var(--ease);
}
@keyframes stageIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.stage-head {
  margin-bottom: 24px;
  padding-top: 20px;
}
.stage-step {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.15em;
  margin-bottom: 8px;
}
.stage-title {
  font-family: var(--display);
  font-size: 32px;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.02em;
  margin: 0 0 8px;
}
@media (min-width: 640px) {
  .stage-title { font-size: 40px; }
}
.stage-sub {
  color: var(--text-dim);
  font-size: 16px;
  margin: 0;
  max-width: 520px;
}

/* ==========================================================================
   Record box
   ========================================================================== */

.record-box {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 16px;
}
.rec-btn {
  width: 100%;
  padding: 20px;
  background: var(--surface-2);
  border: 2px solid var(--line-strong);
  border-radius: var(--radius);
  min-height: 80px;
  transition: all 120ms var(--ease);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
.rec-btn:active { transform: scale(.98); }
.rec-btn.recording {
  background: rgba(232,101,100,.1);
  border-color: var(--danger);
}
.rec-btn.recording .rec-icon {
  color: var(--danger);
  animation: recPulse 1s ease-in-out infinite;
}
@keyframes recPulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.9); }
}
.rec-inner {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.rec-icon {
  font-size: 32px;
  color: var(--text-dim);
}
.rec-label {
  font-family: var(--display);
  font-weight: 600;
  font-size: 16px;
}
.rec-waveform {
  height: 60px;
  margin: 16px 0;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.rec-waveform canvas {
  width: 100%; height: 100%; display: block;
}
.rec-status {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  text-align: center;
}

/* ==========================================================================
   Detected info chips
   ========================================================================== */

.rec-result {
  animation: stageIn 300ms var(--ease);
}
.rec-chips {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}
.info-chip {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  text-align: center;
}
.info-chip-label {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  margin-bottom: 4px;
}
.info-chip-value {
  font-family: var(--display);
  font-weight: 600;
  font-size: 18px;
}

/* ==========================================================================
   Buttons
   ========================================================================== */

.primary-btn {
  width: 100%;
  padding: 16px;
  background: var(--accent);
  color: white;
  border-radius: var(--radius);
  min-height: var(--touch);
  font-family: var(--display);
  font-weight: 600;
  font-size: 16px;
  transition: all 120ms var(--ease);
  margin-bottom: 8px;
}
.primary-btn:active { transform: scale(.97); background: var(--accent-dim); }

.ghost-btn {
  width: 100%;
  padding: 12px;
  background: transparent;
  color: var(--text-dim);
  border-radius: var(--radius);
  min-height: 44px;
  font-size: 14px;
  transition: color 120ms;
}
.ghost-btn:active { color: var(--text); }

.danger-btn {
  width: 100%;
  padding: 12px;
  background: var(--surface);
  color: var(--danger);
  border: 1px solid rgba(232,101,100,.2);
  border-radius: var(--radius);
  min-height: 44px;
  font-size: 14px;
}

/* ==========================================================================
   Vibe cards
   ========================================================================== */

.vibe-cards {
  display: grid;
  gap: 12px;
  margin-bottom: 20px;
}
.vibe-card {
  background: var(--surface);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  text-align: left;
  transition: all 150ms var(--ease);
  width: 100%;
}
.vibe-card:active { transform: scale(.99); }
.vibe-card.playing {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent-glow);
}
.vibe-card.chosen {
  border-color: var(--ok);
  background: rgba(125,212,143,.04);
}
.vibe-name {
  font-family: var(--display);
  font-weight: 600;
  font-size: 18px;
  margin-bottom: 4px;
}
.vibe-desc {
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 10px;
}
.vibe-waveform {
  height: 40px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  overflow: hidden;
  position: relative;
}
.vibe-waveform canvas {
  width: 100%; height: 100%; display: block;
}
.vibe-status {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-top: 8px;
}
.vibe-card.playing .vibe-status { color: var(--accent); }
.vibe-card.chosen .vibe-status { color: var(--ok); }

.vibe-prompt {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
}
.vibe-input {
  flex: 1;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 15px;
  min-height: var(--touch);
}
.vibe-input:focus {
  outline: 2px solid var(--accent);
  border-color: var(--accent);
}

/* ==========================================================================
   Transport
   ========================================================================== */

.transport {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 16px;
}
.transport-play {
  width: 48px; height: 48px;
  background: var(--accent);
  color: white;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
  transition: background 120ms;
}
.transport-play:active { background: var(--accent-dim); }
.transport-info {
  flex: 1;
  min-width: 0;
}
.transport-title {
  font-family: var(--display);
  font-weight: 600;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.transport-meta {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-top: 2px;
}

/* ==========================================================================
   Stems list
   ========================================================================== */

.stems {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 24px;
  overflow: hidden;
}
.stem {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}
.stem:last-child { border-bottom: 0; }
.stem-icon {
  width: 32px; height: 32px;
  background: var(--surface-2);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}
.stem-info {
  flex: 1;
  min-width: 0;
}
.stem-name {
  font-family: var(--display);
  font-weight: 600;
  font-size: 14px;
}
.stem-meta {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 2px;
}
.stem-btn {
  width: 28px; height: 28px;
  background: var(--surface-2);
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px;
  color: var(--text-dim);
}
.stem-btn.muted { opacity: 0.5; }

/* ==========================================================================
   Magic buttons
   ========================================================================== */

.magic-section {
  margin-bottom: 24px;
}
.section-label {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  margin-bottom: 10px;
}
.magic-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
@media (min-width: 520px) {
  .magic-grid { grid-template-columns: 1fr 1fr 1fr; }
}
.magic-btn {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 12px;
  min-height: 68px;
  text-align: center;
  transition: all 120ms var(--ease);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
}
.magic-btn:active {
  transform: scale(.96);
  background: var(--surface-2);
}
.magic-btn.processing {
  border-color: var(--accent);
  background: rgba(255,106,61,.05);
}
.magic-btn-icon {
  font-size: 20px;
  margin-bottom: 2px;
}
.magic-btn-label {
  font-family: var(--display);
  font-weight: 600;
  font-size: 13px;
  line-height: 1.2;
}

/* ==========================================================================
   Prompt box
   ========================================================================== */

.prompt-box {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
.prompt-input-big {
  flex: 1;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 15px;
  min-height: var(--touch);
}
.prompt-input-big:focus {
  outline: 2px solid var(--accent);
  border-color: var(--accent);
}
.prompt-box .primary-btn {
  width: auto;
  padding: 0 20px;
  margin-bottom: 0;
  white-space: nowrap;
}
.director-log {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  font-size: 13px;
  color: var(--text-dim);
  min-height: 40px;
  max-height: 160px;
  overflow-y: auto;
}
.director-log:empty { display: none; }
.log-entry {
  padding: 6px 0;
  border-bottom: 1px solid var(--line);
}
.log-entry:last-child { border-bottom: 0; }
.log-entry-time {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-faint);
  margin-right: 8px;
}

/* ==========================================================================
   Sheets (settings, share)
   ========================================================================== */

.sheet-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 150;
  opacity: 0; pointer-events: none;
  transition: opacity 300ms;
}
.sheet-backdrop.open {
  opacity: 1; pointer-events: auto;
}
.sheet {
  position: fixed; inset: auto 0 0 0;
  z-index: 200;
  background: var(--surface);
  border-top: 1px solid var(--line-strong);
  border-radius: 20px 20px 0 0;
  padding: 12px 20px 20px;
  padding-bottom: max(20px, env(safe-area-inset-bottom));
  transform: translateY(100%);
  transition: transform 300ms var(--ease);
  max-height: 92vh;
  overflow-y: auto;
  box-shadow: 0 -8px 32px rgba(0,0,0,.4);
}
.sheet.open { transform: translateY(0); }
.sheet-handle {
  width: 40px; height: 4px;
  background: var(--surface-3);
  border-radius: 2px;
  margin: 0 auto 16px;
  cursor: pointer;
}
.sheet-title {
  font-family: var(--display);
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 20px;
}
.settings-group {
  margin-bottom: 20px;
}
.settings-label {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 8px;
}
.settings-input {
  width: 100%;
  padding: 12px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-family: var(--mono);
  font-size: 12px;
  min-height: var(--touch);
}
.settings-hint {
  font-size: 12px;
  color: var(--text-faint);
  margin-top: 8px;
  line-height: 1.5;
}
.settings-credits {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  text-align: center;
  line-height: 2;
}
.mode-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  background: var(--bg);
  padding: 4px;
  border-radius: var(--radius-sm);
}
.mode-option {
  padding: 10px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-dim);
  border-radius: calc(var(--radius-sm) - 2px);
  min-height: 40px;
}
.mode-option.active {
  background: var(--surface);
  color: var(--text);
}

.share-preview {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  height: 200px;
  margin-bottom: 16px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-faint);
  font-size: 12px;
}
