/* Marionette — mobile-first palette */

:root {
  --radius: 1rem;
  --radius-sm: calc(var(--radius) - 4px);
  --radius-md: calc(var(--radius) - 2px);
  --radius-lg: var(--radius);
  --radius-xl: calc(var(--radius) + 4px);
  --radius-2xl: calc(var(--radius) + 8px);

  --background: oklch(0.985 0.003 240);
  --foreground: oklch(0.18 0.02 260);
  --surface: oklch(1 0 0);
  --surface-2: oklch(0.965 0.005 250);
  --card: oklch(1 0 0);
  --primary: oklch(0.55 0.18 265);
  --primary-foreground: oklch(0.99 0 0);
  --muted: oklch(0.96 0.005 250);
  --muted-foreground: oklch(0.5 0.015 260);
  --accent: oklch(0.95 0.02 260);
  --destructive: oklch(0.62 0.22 27);
  --border: oklch(0.92 0.005 250);
  --input: oklch(0.94 0.005 250);
  --ring: oklch(0.55 0.18 265);
  --mint: oklch(0.84 0.1 165);
  --coral: oklch(0.78 0.13 30);
  --violet: oklch(0.78 0.1 295);
  --sky: oklch(0.82 0.08 225);

  --shadow-card: 0 1px 2px oklch(0.18 0.02 260 / 0.04),
                 0 8px 24px -8px oklch(0.18 0.02 260 / 0.08);
  --shadow-elev: 0 2px 4px oklch(0.18 0.02 260 / 0.04),
                 0 16px 40px -12px oklch(0.18 0.02 260 / 0.12);
  --shadow-focus: 0 0 0 4px oklch(0.55 0.18 265 / 0.15);

  --font-display: "Plus Jakarta Sans", ui-sans-serif, system-ui, sans-serif;
  --font-sans: "Inter", ui-sans-serif, system-ui, sans-serif;
}

* { box-sizing: border-box; border-color: var(--border); }
html, body {
  margin: 0;
  background: var(--background);
  color: var(--foreground);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
body {
  background-image:
    radial-gradient(1200px 600px at 0% -10%, oklch(0.55 0.18 265 / 0.06), transparent 60%),
    radial-gradient(900px 500px at 100% 0%, oklch(0.78 0.1 295 / 0.08), transparent 60%);
  background-attachment: fixed;
  min-height: 100dvh;
}
h1, h2, h3, h4 { font-family: var(--font-display); letter-spacing: -0.02em; margin: 0; }
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input { font-family: inherit; }

/* ─── Layout shell (mobile-first) ─────────────────────── */

.app-shell {
  max-width: 28rem;
  margin: 0 auto;
  min-height: 100dvh;
  position: relative;
  padding-bottom: env(safe-area-inset-bottom);
}

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px 10px;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  font-family: var(--font-display); font-weight: 800; letter-spacing: -0.01em;
}
.brand-mark {
  width: 32px; height: 32px; border-radius: 10px;
  background: linear-gradient(135deg, var(--primary), var(--violet));
  display: grid; place-items: center; color: white; font-size: 16px;
  box-shadow: var(--shadow-card);
}
.topbar-actions { display: flex; gap: 6px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 999px;
  display: inline-grid; place-items: center;
  transition: background-color .15s ease, transform .15s ease;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn:active { transform: scale(0.96); }

/* ─── Stepper ─────────────────────────────────────────── */

.stepper {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 20px 4px;
}
.stepper .pill {
  height: 4px; flex: 1; border-radius: 999px; background: var(--surface-2);
  overflow: hidden; position: relative;
}
.stepper .pill .fill {
  position: absolute; inset: 0; width: 0%;
  background: linear-gradient(90deg, var(--primary), var(--violet));
  transition: width .35s ease;
}
.stepper-label {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 8px 20px 0; color: var(--muted-foreground); font-size: 13px;
}
.stepper-label strong { color: var(--foreground); font-weight: 700; }

/* ─── Step container ──────────────────────────────────── */

.step {
  padding: 8px 20px 140px;
  animation: slide-up .32s cubic-bezier(.2,.8,.2,1) both;
}
.step h2 {
  font-size: 28px; font-weight: 800; line-height: 1.1; margin-top: 14px;
}
.step p.sub { margin-top: 6px; color: var(--muted-foreground); font-size: 15px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-2xl);
  box-shadow: var(--shadow-card);
}

.list { display: flex; flex-direction: column; gap: 10px; margin-top: 18px; }
.row {
  display: flex; align-items: center; gap: 12px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-card);
  transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
  text-align: left;
  width: 100%;
}
.row:active { transform: scale(0.99); }
.row.selected { border-color: var(--primary); box-shadow: var(--shadow-focus); }
.row .emoji {
  width: 44px; height: 44px; border-radius: 12px;
  display: grid; place-items: center; font-size: 22px;
  background: linear-gradient(135deg, oklch(0.95 0.02 260), oklch(0.97 0.02 285));
  flex-shrink: 0;
}
.row .grow { flex: 1; min-width: 0; }
.row .title { font-weight: 600; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .meta { color: var(--muted-foreground); font-size: 12px; margin-top: 2px; }
.row .chev { color: var(--muted-foreground); flex-shrink: 0; }

.row.new {
  background: linear-gradient(135deg, oklch(0.97 0.02 270), oklch(0.96 0.04 290));
  border: 1px dashed oklch(0.55 0.18 265 / 0.4);
}
.row.new .emoji {
  background: linear-gradient(135deg, var(--primary), var(--violet));
  color: white;
}

.segmented {
  display: inline-flex; padding: 4px;
  background: var(--surface-2); border-radius: 999px; gap: 4px;
  border: 1px solid var(--border);
}
.segmented button {
  padding: 8px 14px; border-radius: 999px; font-size: 13px; font-weight: 600;
  color: var(--muted-foreground);
}
.segmented button.active {
  background: var(--surface); color: var(--foreground); box-shadow: var(--shadow-card);
}

/* ─── Forms ───────────────────────────────────────────── */

.field { display: flex; flex-direction: column; gap: 6px; margin-top: 14px; }
.field label { font-size: 13px; color: var(--muted-foreground); font-weight: 600; }
.input, .textarea {
  width: 100%; padding: 12px 14px;
  background: var(--surface); color: var(--foreground);
  border: 1px solid var(--border); border-radius: 14px;
  font-size: 15px; outline: none; transition: box-shadow .15s ease, border-color .15s ease;
}
.input:focus { border-color: var(--primary); box-shadow: var(--shadow-focus); }

/* ─── Buttons ─────────────────────────────────────────── */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 14px 18px; border-radius: 14px; font-weight: 700; font-size: 15px;
  background: var(--surface); color: var(--foreground);
  border: 1px solid var(--border); box-shadow: var(--shadow-card);
  transition: transform .15s ease, box-shadow .15s ease, background-color .15s ease;
}
.btn:active { transform: scale(0.98); }
.btn.primary {
  background: linear-gradient(135deg, var(--primary), oklch(0.6 0.18 280));
  color: white; border-color: transparent;
  box-shadow: 0 10px 24px -10px oklch(0.55 0.18 265 / 0.55);
}
.btn.danger { color: white; background: var(--destructive); border-color: transparent; }
.btn.ghost { background: transparent; box-shadow: none; }
.btn[disabled] { opacity: 0.5; pointer-events: none; }
.btn-block { width: 100%; }

/* ─── Sticky footer ───────────────────────────────────── */

.footer {
  position: sticky; bottom: 0; left: 0; right: 0;
  padding: 12px 20px max(16px, env(safe-area-inset-bottom));
  background: color-mix(in oklab, var(--background) 85%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
}

/* ─── Step 2: sound tiles ─────────────────────────────── */

.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; }
.tile {
  display: flex; flex-direction: column; align-items: flex-start; gap: 8px;
  padding: 14px; border-radius: var(--radius-xl);
  background: var(--surface); border: 1px solid var(--border);
  box-shadow: var(--shadow-card);
  text-align: left;
  transition: border-color .15s ease, box-shadow .15s ease, transform .15s ease;
}
.tile:active { transform: scale(0.98); }
.tile.active { border-color: var(--primary); box-shadow: var(--shadow-focus); }
.tile .ico {
  width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--surface-2));
  font-size: 18px;
}
.tile .ttl { font-weight: 700; font-size: 14px; }
.tile .desc { font-size: 12px; color: var(--muted-foreground); }

/* Mic sub-selector (inside "Record now") */
.mic-sub {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
  margin-top: 12px;
}
.mic-sub .opt {
  padding: 12px; border-radius: 14px;
  background: var(--surface); border: 1px solid var(--border);
  text-align: center; font-size: 13px; font-weight: 600;
  color: var(--muted-foreground);
  transition: border-color .15s, box-shadow .15s, color .15s;
}
.mic-sub .opt.active {
  border-color: var(--primary); color: var(--foreground);
  box-shadow: var(--shadow-focus);
}
.mic-sub .opt[disabled] { opacity: 0.45; pointer-events: none; }

/* ─── Step 3: recording stage ─────────────────────────── */

.stage {
  margin-top: 18px;
  border-radius: var(--radius-2xl);
  background:
    radial-gradient(60% 60% at 50% 30%, oklch(0.55 0.18 265 / 0.12), transparent 60%),
    linear-gradient(180deg, var(--surface), var(--surface-2));
  border: 1px solid var(--border);
  padding: 28px 20px;
  text-align: center;
  box-shadow: var(--shadow-card);
}
.stage .robot {
  width: 120px; height: 120px; margin: 0 auto;
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 35%, white 0 22%, transparent 23%),
    radial-gradient(circle at 38% 38%, var(--foreground) 0 4%, transparent 5%),
    radial-gradient(circle at 62% 38%, var(--foreground) 0 4%, transparent 5%),
    linear-gradient(180deg, oklch(0.92 0.02 260), oklch(0.85 0.04 265));
  box-shadow: var(--shadow-elev);
  animation: float-y 4s ease-in-out infinite;
}
.stage .countdown {
  font-family: var(--font-display); font-size: 96px; font-weight: 800; line-height: 1;
  background: linear-gradient(135deg, var(--primary), var(--violet));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.rec-badge {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 12px; border-radius: 999px;
  background: oklch(0.62 0.22 27 / 0.1); color: var(--destructive);
  font-weight: 700; font-size: 12px; margin-top: 14px;
}
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--destructive); animation: pulse-ring 1.6s ease-out infinite; }

.progress {
  height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin-top: 18px;
}
.progress > span {
  display: block; height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--primary), var(--violet));
  transition: width .15s linear;
}
.time {
  display: flex; justify-content: space-between; color: var(--muted-foreground);
  font-size: 12px; margin-top: 6px;
}

/* ─── Folder view ─────────────────────────────────────── */

.folder-head {
  display: flex; align-items: center; gap: 12px; padding: 8px 20px 4px;
}
.folder-head .emoji {
  width: 52px; height: 52px; border-radius: 14px; display: grid; place-items: center; font-size: 26px;
  background: linear-gradient(135deg, oklch(0.95 0.02 260), oklch(0.97 0.02 285));
  flex-shrink: 0;
}
.folder-head .grow { flex: 1; min-width: 0; }
.folder-head .title {
  font-weight: 800; font-size: 20px; font-family: var(--font-display);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.folder-head .meta { color: var(--muted-foreground); font-size: 13px; }
.folder-head .btn { padding: 10px 14px; font-size: 14px; }

.move-row {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px;
  border-radius: var(--radius-xl); border: 1px solid var(--border); background: var(--surface);
  box-shadow: var(--shadow-card);
}
.move-row.highlight {
  border-color: var(--primary); box-shadow: var(--shadow-focus);
  animation: pop .6s ease;
}
.move-row .play {
  width: 40px; height: 40px; border-radius: 12px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--primary), var(--violet));
  color: white; font-size: 15px;
  flex-shrink: 0;
}
.move-row .grow { flex: 1; min-width: 0; }
.move-row .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.move-row .meta { color: var(--muted-foreground); font-size: 12px; }
.move-row .actions { display: flex; gap: 6px; flex-shrink: 0; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 10px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: var(--surface-2); color: var(--muted-foreground);
  border: 1px solid var(--border);
}
.chip.shared { background: oklch(0.84 0.1 165 / 0.2); color: oklch(0.4 0.12 165); border-color: transparent; }

/* ─── Empty, toast ────────────────────────────────────── */

.empty {
  text-align: center; padding: 40px 20px; color: var(--muted-foreground);
}

.toast {
  position: fixed; left: 50%; bottom: 100px; transform: translateX(-50%);
  background: var(--foreground); color: var(--background);
  padding: 10px 14px; border-radius: 999px; font-size: 13px; font-weight: 600;
  box-shadow: var(--shadow-elev); z-index: 80;
  animation: slide-up .3s ease both;
  max-width: calc(100vw - 40px);
}
.toast.error { background: var(--destructive); color: white; }
.toast.success { background: oklch(0.4 0.12 165); color: white; }

/* ─── Connection gate ─────────────────────────────────── */

.gate {
  display: grid; place-items: center;
  min-height: 100dvh;
  padding: 20px;
}
.gate-card {
  max-width: 26rem;
  width: 100%;
  padding: 32px 24px;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-2xl);
  box-shadow: var(--shadow-elev);
}
.gate-card .big-emoji { font-size: 64px; }
.gate-card h1 {
  font-family: var(--font-display); font-weight: 800; font-size: 28px;
  margin-top: 6px;
}
.gate-card p { color: var(--muted-foreground); font-size: 15px; margin-top: 6px; }
.gate-card .btn { margin-top: 18px; }
.gate-card .divider {
  margin: 22px 0 6px;
  color: var(--muted-foreground);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
  position: relative;
}
.gate-card .divider::before,
.gate-card .divider::after {
  content: "";
  position: absolute; top: 50%;
  width: calc(50% - 30px);
  height: 1px; background: var(--border);
}
.gate-card .divider::before { left: 0; }
.gate-card .divider::after { right: 0; }

.robot-list { display: grid; gap: 8px; margin-top: 14px; text-align: left; }

/* ─── Settings sheet ──────────────────────────────────── */

.sheet-backdrop {
  position: fixed; inset: 0; background: oklch(0.18 0.02 260 / 0.4);
  z-index: 60; animation: fade-in .2s ease both;
}
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0;
  background: var(--surface);
  border-top-left-radius: var(--radius-2xl);
  border-top-right-radius: var(--radius-2xl);
  box-shadow: var(--shadow-elev);
  padding: 20px 20px max(24px, env(safe-area-inset-bottom));
  z-index: 70;
  animation: slide-up .25s ease both;
  max-width: 28rem; margin: 0 auto;
}
.sheet h3 {
  font-family: var(--font-display); font-weight: 800; font-size: 20px;
  margin-bottom: 14px;
}
.sheet .row-setting {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}
.sheet .row-setting:last-child { border-bottom: none; }
.sheet .row-setting .label { font-weight: 600; font-size: 14px; }
.sheet .row-setting .sublabel { color: var(--muted-foreground); font-size: 12px; margin-top: 2px; }

.segmented.small button { padding: 6px 10px; font-size: 12px; }

/* ─── Animations ──────────────────────────────────────── */

@keyframes float-y { 0%,100%{transform:translateY(0)} 50%{transform:translateY(-8px)} }
@keyframes pulse-ring {
  0% { box-shadow: 0 0 0 0 oklch(0.62 0.22 27 / 0.4); }
  70% { box-shadow: 0 0 0 16px oklch(0.62 0.22 27 / 0); }
  100% { box-shadow: 0 0 0 0 oklch(0.62 0.22 27 / 0); }
}
@keyframes slide-up { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { 0% { transform: scale(.97); } 50% { transform: scale(1.02); } 100% { transform: scale(1); } }

/* Trim controls — playhead overlay.
   The trim field has two range sliders (start/end). When the user hits
   Preview, this red vertical line moves across the slider tracks to
   show the current playback position. Pointer-events:none ONLY on the
   playhead itself — keeping it off the wrapper would also block the
   sliders inside. */
.trim-playhead-track {
  position: relative;
}
.trim-playhead {
  position: absolute;
  top: 0; bottom: 0;
  width: 2px;
  background: var(--destructive);
  border-radius: 1px;
  pointer-events: none;
  display: none;
  box-shadow: 0 0 6px var(--destructive);
}
.trim-playhead.on { display: block; }

/* Robot speaker volume control — shown at the top of HomeView and
   FolderView so it's always within reach when playing moves. */
.volume-row {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-card);
  margin: 14px 20px 0;
}
.volume-row .ico {
  width: 28px; height: 28px;
  display: grid; place-items: center;
  font-size: 16px; flex-shrink: 0;
}
.volume-row input[type="range"] {
  flex: 1;
  -webkit-appearance: none;
  height: 4px;
  background: var(--surface-2);
  border-radius: 999px;
  outline: none;
}
.volume-row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--violet));
  cursor: pointer;
  box-shadow: var(--shadow-card);
  border: none;
}
.volume-row input[type="range"]::-moz-range-thumb {
  width: 22px; height: 22px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--violet));
  cursor: pointer;
  border: none;
  box-shadow: var(--shadow-card);
}
.volume-row .pct {
  min-width: 40px; text-align: right;
  font-variant-numeric: tabular-nums;
  font-size: 13px; font-weight: 600;
  color: var(--muted-foreground);
}

/* In-app dialogs (confirm / prompt) — themed alternative to the
   native browser pop-ups, which look out-of-place. */
.dialog-backdrop {
  position: fixed; inset: 0; background: oklch(0.18 0.02 260 / 0.5);
  z-index: 100; animation: fade-in .18s ease both;
}
.dialog {
  position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-2xl);
  box-shadow: var(--shadow-elev);
  z-index: 110;
  width: min(420px, calc(100vw - 32px));
  padding: 22px 22px 18px;
  animation: dialog-pop .2s ease both;
}
.dialog h3 {
  font-family: var(--font-display); font-weight: 800; font-size: 18px;
  margin-bottom: 8px;
}
.dialog p {
  margin: 0; color: var(--muted-foreground); font-size: 14px;
  line-height: 1.45;
}
.dialog .input {
  margin-top: 14px;
}
.dialog-actions {
  display: flex; gap: 8px; margin-top: 18px;
}
.dialog-actions .btn { flex: 1; padding: 12px 14px; }

@keyframes dialog-pop {
  from { opacity: 0; transform: translate(-50%, calc(-50% + 8px)) scale(.97); }
  to   { opacity: 1; transform: translate(-50%, -50%)              scale(1); }
}

/* Tiny debug HUD (toggled from settings) */
.debug-hud {
  position: fixed;
  right: 8px; bottom: 8px;
  background: rgba(0,0,0,0.72);
  color: #fff;
  font-family: ui-monospace, monospace;
  font-size: 11px;
  padding: 6px 10px;
  border-radius: 8px;
  z-index: 90;
  pointer-events: none;
  line-height: 1.4;
}
