/* ----------------------------------------------------
   AVATAR STUDIO — frontend prototype
   Warm minimal aesthetic. Instrument Sans + Instrument Serif.
   ---------------------------------------------------- */

:root {
  --bg:        oklch(0.985 0.005 70);
  --surface:   oklch(0.97 0.006 70);
  --surface-2: oklch(0.945 0.008 70);
  --hover:     oklch(0.93 0.01 70);
  --border:    oklch(0.91 0.008 70);
  --border-2:  oklch(0.86 0.01 70);
  --ink:       oklch(0.17 0.012 60);
  --ink-soft:  oklch(0.32 0.012 60);
  --muted:     oklch(0.52 0.012 70);
  --faint:     oklch(0.72 0.01 70);

  --accent:    oklch(0.58 0.14 38);   /* terracotta */
  --accent-2:  oklch(0.92 0.04 38);   /* tint */
  --good:      oklch(0.62 0.13 150);

  --radius-sm: 6px;
  --radius:    10px;
  --radius-lg: 14px;
  --radius-xl: 20px;

  --shadow-1: 0 1px 0 oklch(0 0 0 / 0.04), 0 1px 2px oklch(0 0 0 / 0.03);
  --shadow-2: 0 6px 24px -8px oklch(0 0 0 / 0.12), 0 2px 6px -2px oklch(0 0 0 / 0.06);
}

* { box-sizing: border-box; }
html, body, #root { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Instrument Sans', ui-sans-serif, sans-serif;
  font-size: 14px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "ss01", "cv11";
}

button { font: inherit; color: inherit; cursor: pointer; background: none; border: 0; padding: 0; }
input, textarea, select { font: inherit; color: inherit; }

/* ---------- App shell ---------- */
.app {
  display: grid;
  grid-template-rows: 56px 1fr;
  height: 100vh;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  z-index: 5;
}
.topbar-left { display: flex; align-items: center; gap: 8px; min-width: 0; flex-shrink: 0; }
.topbar-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.iconbtn {
  width: 32px; height: 32px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--ink-soft);
  transition: background 120ms;
}
.iconbtn:hover { background: var(--surface-2); color: var(--ink); }

.crumb {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  flex-shrink: 0;
}
.crumb:hover { background: var(--surface-2); }
.crumb-name {
  font-family: 'Instrument Serif', serif;
  font-size: 20px;
  letter-spacing: -0.01em;
  font-weight: 400;
}
.crumb-status {
  font-size: 11px;
  color: var(--muted);
  padding: 2px 7px;
  border: 1px solid var(--border);
  border-radius: 999px;
  margin-left: 6px;
  white-space: nowrap;
  flex-shrink: 0;
}
.crumb-status .dot {
  display: inline-block; width: 6px; height: 6px; border-radius: 999px;
  background: var(--good); margin-right: 5px; vertical-align: 1px;
}

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-2);
  background: var(--bg);
  font-size: 13px;
  font-weight: 500;
  transition: background 120ms, border 120ms;
}
.btn:hover { background: var(--surface-2); }
.btn.dark {
  background: var(--ink);
  color: var(--bg);
  border-color: var(--ink);
}
.btn.dark:hover { background: oklch(0.27 0.012 60); }
.btn.ghost { border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.accent {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}
.btn.accent:hover { background: oklch(0.52 0.14 38); }

/* ---------- Main split ---------- */
.main {
  display: grid;
  grid-template-columns: 460px 1fr;
  min-height: 0;
}

/* ---------- Left panel ---------- */
.left {
  display: grid;
  grid-template-rows: auto 1fr auto;
  border-right: 1px solid var(--border);
  min-height: 0;
  background: var(--bg);
}

.tabbar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 14px 18px 0;
  border-bottom: 1px solid var(--border);
}
.tab {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 14px 11px;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 120ms;
}
.tab:hover { color: var(--ink); }
.tab.active { color: var(--ink); border-bottom-color: var(--ink); }
.tab .num {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  color: var(--faint);
  letter-spacing: 0.04em;
}
.tab.active .num { color: var(--accent); }

.history-wrap { position: relative; }
.iconbtn.on { background: var(--surface-2); color: var(--ink); }

.history-pop {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  width: 260px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-2);
  padding: 6px;
  z-index: 20;
  animation: pop-in 140ms ease-out;
}
@keyframes pop-in {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}
.history-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 8px 8px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
  font-size: 12px;
  font-weight: 500;
}
.history-item {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%;
  padding: 8px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 120ms;
  text-align: left;
}
.history-item:hover { background: var(--surface-2); }
.history-item.current { background: var(--surface); }
.history-item .hi-id { font-size: 11.5px; color: var(--ink); letter-spacing: 0.04em; }
.history-item .hi-meta { display: flex; align-items: center; gap: 8px; font-size: 11px; color: var(--muted); }
.history-item .hi-current {
  font-family: 'JetBrains Mono', monospace;
  font-size: 9.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
  border: 1px solid var(--accent);
  padding: 1px 5px;
  border-radius: 999px;
}

.panel-body {
  overflow-y: auto;
  padding: 18px;
  min-height: 0;
}

.section-head {
  display: flex; align-items: center; justify-content: space-between;
  margin: 4px 2px 12px;
}
.section-head h3 {
  margin: 0;
  font-family: 'Instrument Serif', serif;
  font-weight: 400;
  font-size: 18px;
  letter-spacing: -0.01em;
}
.section-head .sub {
  font-size: 11px;
  color: var(--muted);
  font-family: 'JetBrains Mono', monospace;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* search field */
.field {
  display: flex; align-items: center; gap: 8px;
  height: 38px;
  padding: 0 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border 120ms, background 120ms;
}
.field:focus-within { border-color: var(--ink-soft); background: var(--bg); }
.field input {
  flex: 1; min-width: 0;
  border: 0; outline: 0; background: transparent;
  font-size: 13px;
}
.field input::placeholder { color: var(--faint); }
.field .left-icon { color: var(--muted); display: inline-flex; }
.field .right-tools { display: inline-flex; gap: 4px; color: var(--muted); }
.field .right-tools button { padding: 4px; border-radius: 4px; }
.field .right-tools button:hover { background: var(--hover); color: var(--ink); }

/* ---------- Avatar grid ---------- */
.avatars {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 14px;
}
.avatar {
  position: relative;
  aspect-ratio: 4 / 5;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: transform 160ms, box-shadow 160ms;
}
.avatar:hover { transform: translateY(-1px); box-shadow: var(--shadow-2); }
.avatar.selected {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
  border-color: transparent;
}
.avatar .swatch {
  position: absolute; inset: 0;
  display: grid; place-items: center;
}
.avatar .swatch::after {
  content: "";
  position: absolute; inset: 0;
  background-image: repeating-linear-gradient(135deg,
    oklch(1 0 0 / 0) 0 9px,
    oklch(1 0 0 / 0.06) 9px 10px);
}
.avatar .head {
  width: 38%;
  aspect-ratio: 1;
  border-radius: 999px;
  background: oklch(1 0 0 / 0.32);
  border: 1px solid oklch(1 0 0 / 0.18);
  margin-top: -8%;
  z-index: 1;
}
.avatar .shoulders {
  position: absolute;
  bottom: -22%;
  left: 50%;
  transform: translateX(-50%);
  width: 95%;
  aspect-ratio: 1.5;
  border-radius: 999px 999px 0 0;
  background: oklch(1 0 0 / 0.28);
  border: 1px solid oklch(1 0 0 / 0.16);
  border-bottom: 0;
  z-index: 1;
}
.avatar .meta {
  position: absolute;
  left: 8px; bottom: 8px; right: 8px;
  display: flex; justify-content: space-between; align-items: flex-end;
  z-index: 2;
  font-family: 'JetBrains Mono', monospace;
  font-size: 9.5px;
  letter-spacing: 0.04em;
  color: oklch(1 0 0 / 0.92);
  text-transform: uppercase;
  text-shadow: 0 1px 2px oklch(0 0 0 / 0.25);
}
.avatar .id-tag {
  background: oklch(0 0 0 / 0.32);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  padding: 2px 5px;
  border-radius: 4px;
}
.avatar .selected-mark {
  position: absolute; top: 8px; right: 8px;
  width: 22px; height: 22px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--bg);
  display: none;
  align-items: center; justify-content: center;
  z-index: 3;
}
.avatar.selected .selected-mark { display: inline-flex; }

.avatar.add {
  display: grid; place-items: center;
  background: var(--surface);
  color: var(--muted);
  border: 1px dashed var(--border-2);
}
.avatar.add:hover { border-color: var(--ink-soft); color: var(--ink); }
.avatar.add .plus { font-size: 22px; line-height: 1; }
.avatar.add .lbl {
  font-size: 10px; margin-top: 6px;
  font-family: 'JetBrains Mono', monospace;
  letter-spacing: 0.08em; text-transform: uppercase;
}

/* ---------- Voice list ---------- */
.voices { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.voice {
  display: grid;
  grid-template-columns: 36px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  cursor: pointer;
  transition: background 120ms, border 120ms;
}
.voice:hover { background: var(--surface); }
.voice.selected { border-color: var(--ink); background: var(--surface); }
.voice .play {
  width: 32px; height: 32px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--bg);
  display: grid; place-items: center;
}
.voice.playing .play { background: var(--accent); }
.voice .info { display: flex; flex-direction: column; min-width: 0; }
.voice .name { font-weight: 500; font-size: 13.5px; }
.voice .descr {
  font-size: 11px; color: var(--muted);
  display: flex; gap: 6px; align-items: center;
  margin-top: 1px;
}
.voice .descr .sep { color: var(--faint); }
.voice .descr .tag {
  font-family: 'JetBrains Mono', monospace;
  font-size: 9.5px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ink-soft);
  background: var(--surface-2);
  padding: 1px 5px;
  border-radius: 3px;
}
.voice .wave { display: flex; gap: 2px; align-items: center; height: 22px; }
.voice .wave span {
  display: inline-block;
  width: 2px;
  border-radius: 1px;
  background: var(--border-2);
}
.voice.playing .wave span { background: var(--accent); animation: wave 1.2s ease-in-out infinite; }
.voice.playing .wave span:nth-child(2n) { animation-delay: -0.4s; }
.voice.playing .wave span:nth-child(3n) { animation-delay: -0.8s; }
@keyframes wave {
  0%, 100% { transform: scaleY(0.4); }
  50%      { transform: scaleY(1); }
}

.voice.add-voice {
  border-style: dashed;
  border-color: var(--border-2);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
}
.voice.add-voice:hover {
  border-color: var(--ink-soft);
  color: var(--ink);
  background: var(--surface-2);
}
.voice .play-add {
  width: 32px; height: 32px;
  border-radius: 999px;
  border: 1px dashed var(--border-2);
  display: grid; place-items: center;
  color: var(--muted);
}
.voice.add-voice:hover .play-add {
  border-color: var(--ink-soft);
  color: var(--ink);
}

.voice.add-voice .name { color: var(--ink-soft); font-weight: 500; }
.voice.add-voice .descr { color: var(--muted); }

/* keep voice grid layout when add-voice has no waveform */
.voice.add-voice { grid-template-columns: 36px 1fr; }

/* ---------- Coming soon (Conversation tab) ---------- */
.coming-soon {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding: 36px 10px 24px;
  gap: 14px;
}
.cs-badge {
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent);
  background: var(--accent-2);
  border: 1px solid color-mix(in oklch, var(--accent) 30%, transparent);
  padding: 4px 10px;
  border-radius: 999px;
}
.cs-title {
  font-family: 'Instrument Serif', serif;
  font-weight: 400;
  font-size: 28px;
  letter-spacing: -0.01em;
  margin: 0;
  line-height: 1.1;
}
.cs-body {
  font-size: 13.5px;
  line-height: 1.55;
  color: var(--ink-soft);
  margin: 0;
  max-width: 360px;
  text-wrap: pretty;
}
.cs-actions { display: flex; gap: 8px; margin-top: 2px; }

.cs-preview {
  margin-top: 18px;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 16px;
  border: 1px dashed var(--border-2);
  border-radius: var(--radius);
  background: var(--surface);
  position: relative;
}
.cs-preview::after {
  content: 'PREVIEW · NON-FUNCTIONAL';
  position: absolute;
  top: 8px; right: 12px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 9px;
  letter-spacing: 0.1em;
  color: var(--faint);
}
.cs-bubble {
  max-width: 78%;
  padding: 9px 12px;
  border-radius: 14px;
  font-size: 13px;
  line-height: 1.4;
}
.cs-them {
  align-self: flex-start;
  background: var(--bg);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
  color: var(--ink);
}
.cs-you {
  align-self: flex-end;
  background: var(--ink);
  color: var(--bg);
  border-bottom-right-radius: 4px;
}
.cs-typing { display: flex; gap: 4px; padding: 12px 14px; }
.cs-typing span {
  width: 6px; height: 6px;
  border-radius: 999px;
  background: var(--faint);
  animation: dot 1.2s ease-in-out infinite;
}
.cs-typing span:nth-child(2) { animation-delay: 0.15s; }
.cs-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes dot {
  0%, 80%, 100% { opacity: 0.3; transform: translateY(0); }
  40%           { opacity: 1;   transform: translateY(-2px); }
}

/* ---------- Script tab ---------- */
.script-wrap {
  margin-top: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  display: flex; flex-direction: column;
  transition: border 120ms;
}
.script-wrap:focus-within { border-color: var(--ink-soft); }
.script-wrap textarea {
  width: 100%;
  border: 0; outline: 0;
  resize: none;
  padding: 14px 14px 8px;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.55;
  background: transparent;
  min-height: 220px;
}
.script-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 10px 8px 12px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 11.5px;
  font-family: 'JetBrains Mono', monospace;
  letter-spacing: 0.03em;
}
.script-toolbar .tools { display: flex; gap: 2px; }
.script-toolbar .tool {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 7px;
  border-radius: 5px;
  color: var(--ink-soft);
}
.script-toolbar .tool:hover { background: var(--surface-2); color: var(--ink); }

.script-presets { margin-top: 14px; }
.script-presets-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 8px;
  font-size: 11px;
  font-family: 'JetBrains Mono', monospace;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.preset-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}
.preset {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-align: left;
  background: var(--bg);
  transition: background 120ms, border 120ms;
}
.preset:hover { background: var(--surface); border-color: var(--border-2); }
.preset .ptitle { font-size: 12.5px; font-weight: 500; }
.preset .pdesc { font-size: 11px; color: var(--muted); margin-top: 2px; line-clamp: 2; overflow: hidden; }

/* ---------- Left panel footer ---------- */
.panel-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  background: var(--bg);
  gap: 12px;
}
.model-picker {
  display: inline-flex; align-items: center; gap: 8px;
}
.model-picker .lbl {
  font-size: 11px;
  font-family: 'JetBrains Mono', monospace;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.select {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 10px;
  border: 1px solid var(--border-2);
  border-radius: 7px;
  font-size: 12.5px;
  background: var(--bg);
}
.select:hover { background: var(--surface-2); }

/* ---------- Right panel (preview) ---------- */
.right {
  position: relative;
  min-width: 0;
  display: grid;
  grid-template-rows: 1fr auto;
  background:
    radial-gradient(circle at 1px 1px, oklch(0.78 0.01 70) 1px, transparent 1px),
    var(--bg);
  background-size: 18px 18px, auto;
  background-position: 0 0;
}
.right::before {
  /* soft vignette */
  content: "";
  position: absolute; inset: 0;
  background: radial-gradient(ellipse at center, transparent 30%, var(--bg) 95%);
  pointer-events: none;
}

.canvas {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
}

.preview-frame {
  position: relative;
  aspect-ratio: 4 / 5;
  height: min(100%, 760px);
  max-width: 100%;
  border-radius: var(--radius-lg);
  background: oklch(0.94 0.012 70);
  overflow: hidden;
  box-shadow: var(--shadow-2);
  border: 1px solid var(--border);
  transition: width 220ms ease, height 220ms ease;
}

.preview-bg {
  position: absolute; inset: 0;
  background-image: repeating-linear-gradient(135deg,
    oklch(0.92 0.012 70) 0 18px,
    oklch(0.89 0.013 70) 18px 19px);
}
.preview-portrait {
  position: absolute; inset: 0;
  display: grid; place-items: end center;
}
.preview-portrait .head {
  width: 28%;
  aspect-ratio: 1;
  border-radius: 999px;
  background: oklch(0.84 0.018 60);
  border: 1px solid oklch(0.78 0.018 60);
  margin-bottom: 22%;
  transform-origin: center 80%;
}
.preview-portrait .head.talking { animation: nod 0.45s ease-in-out infinite alternate; }
.preview-portrait .shoulders {
  position: absolute;
  bottom: 0;
  width: 78%;
  aspect-ratio: 2;
  border-radius: 50% 50% 0 0;
  background: oklch(0.8 0.018 60);
  border: 1px solid oklch(0.74 0.018 60);
  border-bottom: 0;
}
@keyframes nod {
  from { transform: translateY(0) rotate(-0.6deg); }
  to   { transform: translateY(-3px) rotate(0.6deg); }
}

.preview-tag {
  position: absolute;
  top: 16px; left: 16px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
  background: oklch(1 0 0 / 0.7);
  border: 1px solid var(--border);
  padding: 4px 8px;
  border-radius: 999px;
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}
.preview-tag .dot {
  display: inline-block; width: 6px; height: 6px; border-radius: 999px;
  background: var(--accent); margin-right: 6px; vertical-align: 1px;
}
.preview-tag.live .dot { background: var(--good); animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.4; } }

.preview-corner {
  position: absolute;
  bottom: 14px; right: 14px;
  display: flex; gap: 8px;
}
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px;
  font-size: 11px;
  background: oklch(1 0 0 / 0.7);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--ink-soft);
  font-family: 'JetBrains Mono', monospace;
  letter-spacing: 0.04em;
}

.preview-caption {
  position: absolute;
  left: 50%; transform: translateX(-50%);
  bottom: 76px;
  max-width: 78%;
  text-align: center;
  font-family: 'Instrument Serif', serif;
  font-size: 20px;
  letter-spacing: -0.01em;
  color: oklch(0.16 0.01 60);
  line-height: 1.25;
  text-wrap: pretty;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.preview-frame.portrait .preview-caption { font-size: 18px; bottom: 110px; }

.scrubbar {
  position: absolute;
  bottom: 14px; left: 16px; right: 16px;
  display: flex; align-items: center; gap: 12px;
  padding: 8px 14px;
  background: oklch(1 0 0 / 0.78);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: 999px;
  min-width: 0;
}
.scrubbar .playbtn {
  width: 24px; height: 24px;
  border-radius: 999px;
  background: var(--ink); color: var(--bg);
  display: grid; place-items: center;
  flex-shrink: 0;
}
.scrubbar .time {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--ink-soft);
  letter-spacing: 0.04em;
  flex-shrink: 0;
}
.scrubbar .progress {
  flex: 1;
  height: 4px;
  border-radius: 2px;
  background: var(--surface-2);
  overflow: hidden;
}
.scrubbar .progress .fill {
  height: 100%;
  background: var(--ink);
  border-radius: 2px;
  transition: width 80ms linear;
}

/* ---------- Right rail (small) ---------- */
.right-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px 18px;
  border-top: 1px solid var(--border);
  background: var(--bg);
  font-size: 12px;
  color: var(--muted);
  gap: 16px;
  position: relative;
  z-index: 2;
}
.right-bottom .left-cluster, .right-bottom .right-cluster { display: flex; align-items: center; gap: 12px; }
.specchip {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 10.5px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.specchip .k { color: var(--faint); }

/* aspect toggle */
.aspect-toggle { display: inline-flex; gap: 2px; background: var(--surface); border: 1px solid var(--border); padding: 2px; border-radius: 8px; }
.aspect-toggle button {
  padding: 4px 8px; border-radius: 6px; font-size: 11px; color: var(--muted);
  font-family: 'JetBrains Mono', monospace; letter-spacing: 0.04em;
}
.aspect-toggle button.on { background: var(--bg); color: var(--ink); box-shadow: var(--shadow-1); }

/* timeline / takes strip (overlaid on right canvas) */
.takes {
  position: absolute;
  top: 18px; right: 18px;
  display: flex; flex-direction: column; gap: 6px;
  z-index: 2;
}
.takes .take {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px;
  font-size: 11px;
  background: oklch(1 0 0 / 0.78);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-family: 'JetBrains Mono', monospace;
  letter-spacing: 0.04em;
  color: var(--ink-soft);
  white-space: nowrap;
}
.takes .take .dot { width: 6px; height: 6px; border-radius: 999px; background: var(--faint); }
.takes .take.current .dot { background: var(--accent); }
.takes .take.current { color: var(--ink); }

/* ---------- misc bits ---------- */
.kbd {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  padding: 1px 4px;
  border-radius: 3px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
}
.divider { height: 1px; background: var(--border); margin: 18px 0; }
.muted { color: var(--muted); }
.ink-soft { color: var(--ink-soft); }
.mono { font-family: 'JetBrains Mono', monospace; }

/* ===========================================================
   Fullscreen / expand-preview toggle.
   Hidden on desktop; shown on mobile via the media query below.
   =========================================================== */
.expand-toggle { display: none; }
@media (max-width: 860px) {
  .expand-toggle { display: inline-flex; }
}

/* ===========================================================
   MOBILE — < 860px stacks preview on top, panel below.
   =========================================================== */
@media (max-width: 860px) {
  .app {
    grid-template-rows: 52px 1fr;
    height: 100vh;     /* fallback for iOS Safari < 15.4 */
    height: 100dvh;    /* dynamic viewport — accounts for the URL bar */
  }
  .topbar { padding: 0 12px; }

  .main {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    transition: grid-template-rows 280ms cubic-bezier(0.4, 0, 0.2, 1);
  }

  /* Expanded preview: preview frame grows downward, panel shrinks */
  .app.preview-expanded .main {
    grid-template-rows: 1fr 0fr;
  }
  .app.preview-expanded .left {
    visibility: hidden;
    opacity: 0;
    pointer-events: none;
    transition: opacity 180ms ease-out;
  }
  .app.preview-expanded .right {
    border-bottom: 0;
  }
  .app.preview-expanded .preview-frame {
    height: auto;
    max-height: none;
    width: 100%;
    max-width: 480px;
  }
  .app.preview-expanded .canvas {
    padding: 18px 14px;
  }

  /* Expand toggle button — mobile shows just the icon, no label */
  .expand-toggle .expand-label { display: none; }
  .expand-toggle {
    width: 36px; height: 36px;
    padding: 0 !important;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px !important;
    border: 1px solid var(--border-2) !important;
  }
  .app.preview-expanded .expand-toggle {
    background: var(--ink) !important;
    color: var(--bg);
    border-color: var(--ink) !important;
  }

  /* Preview moves to top */
  .right {
    order: 0;
    border-right: 0;
    border-bottom: 1px solid var(--border);
    grid-template-rows: 1fr auto;
    background-size: 14px 14px, auto;
  }
  .canvas { padding: 14px; }
  .preview-frame {
    /* Set BOTH width and height explicitly (don't rely on aspect-ratio for
       sizing). aspect-ratio works on iOS Safari 15.4+ and Chrome 88+, but
       earlier mobile browsers compute `width: auto` as 0 when combined with
       `aspect-ratio` + a fixed height, collapsing the preview to nothing. */
    width: min(44.8vw, 288px);   /* 4/5 of height */
    height: min(56vw, 360px);
    aspect-ratio: 4 / 5;          /* keep the hint for modern browsers */
  }
  .preview-caption {
    font-size: 15px;
    bottom: 62px;
    max-width: 86%;
  }
  .scrubbar { padding: 6px 10px; gap: 8px; bottom: 10px; left: 10px; right: 10px; }
  .scrubbar .time { font-size: 10px; }
  .preview-tag { top: 10px; left: 10px; font-size: 9.5px; padding: 3px 7px; }

  .right-bottom {
    padding: 10px 14px;
    flex-wrap: wrap;
    gap: 8px;
  }
  .right-bottom .left-cluster { flex-wrap: wrap; gap: 8px; }
  .right-bottom .right-cluster { gap: 6px; }
  .right-bottom .right-cluster .btn { padding: 6px 10px; font-size: 12px; }

  /* Left panel becomes the scrollable body */
  .left {
    order: 1;
    border-right: 0;
    min-height: 0;
  }
  .tabbar {
    padding: 6px 12px 0;
    overflow-x: auto;
    white-space: nowrap;
    scrollbar-width: none;
  }
  .tabbar::-webkit-scrollbar { display: none; }
  .tab { padding: 8px 10px 10px; font-size: 12.5px; }
  .tab .num { display: none; }

  .panel-body { padding: 14px; }

  .section-head { margin: 2px 2px 10px; }
  .section-head h3 { font-size: 16px; }

  .avatars { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .voice { grid-template-columns: 32px 1fr auto; padding: 9px 10px; gap: 10px; }
  .voice .play { width: 28px; height: 28px; }
  .voice .name { font-size: 13px; }
  .voice .descr { font-size: 10.5px; flex-wrap: wrap; }
  .voice .wave { display: none; }

  .preset-grid { grid-template-columns: 1fr; }

  .panel-foot {
    padding: 10px 12px;
    gap: 8px;
    flex-wrap: wrap;
  }
  .panel-foot .model-picker { flex: 1; min-width: 0; }
  .panel-foot .select { width: 100%; justify-content: space-between; }
  .panel-foot .btn.accent {
    flex: 0 0 auto;
    padding: 9px 14px;
  }

  /* History popover full-width-ish on mobile */
  .history-pop {
    right: -6px;
    width: min(280px, calc(100vw - 24px));
  }

  /* Coming-soon section trims a bit */
  .coming-soon { padding: 18px 4px 8px; gap: 12px; }
  .cs-title { font-size: 24px; }
  .cs-body { font-size: 13px; }
}

@media (max-width: 480px) {
  .preview-frame { height: 60vw; max-height: 320px; }
  .avatars { grid-template-columns: repeat(2, 1fr); }
  .right-bottom .right-cluster .btn span,
  .right-bottom .right-cluster .btn { font-size: 12px; }
  .right-bottom .specchip { font-size: 9.5px; }
  .topbar .btn { padding: 6px 10px; font-size: 12px; }
}
