:root {
  --bg: #0b0c09;
  --desk: #10120d;
  --panel: #161913;
  --line: #2a2e24;
  --text: #f3f0e6;
  --muted: #8d8e7d;
  --accent: #dff25a;
  --ink: #17190f;
  --danger: #ff6d5c;
  --ok: #9adf8a;
  --warn: #f0b45a;
  --sans: "Segoe UI", "Helvetica Neue", sans-serif;
  --mono: Consolas, "Cascadia Mono", monospace;
}

* { box-sizing: border-box; }
/* Several blocks set display explicitly, which beats the browser's own [hidden]
   rule. The studio hides panels per tool, so hidden has to win everywhere. */
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  font: 13px/1.45 var(--sans);
  color: var(--text);
  background: var(--bg);
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.app { height: 100%; display: flex; flex-direction: column; }

header {
  height: 56px;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  background: var(--desk);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 180px; }
.brand strong { display: block; font-size: 15px; letter-spacing: -0.03em; }
.brand span { color: var(--muted); font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; }
.mark {
  width: 28px; height: 28px; border-radius: 7px;
  background:
    linear-gradient(var(--accent), var(--accent)) 5px 18px / 18px 5px no-repeat,
    #1c2016;
  box-shadow: inset 0 0 0 1px #343828;
}
.pill {
  margin-right: auto;
  border: 1px solid var(--line);
  border-radius: 99px;
  padding: 5px 10px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.pill[data-state="work"] { color: var(--ink); background: var(--accent); border-color: transparent; }
.pill[data-state="ok"] { color: var(--ok); }
.pill[data-state="bad"] { color: var(--danger); }
.header-actions { display: flex; align-items: center; gap: 8px; }
#who { color: var(--accent); font-size: 12px; max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 324px minmax(0, 1fr) 320px;
}

.left, .right {
  background: var(--panel);
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.left { border-right: 1px solid var(--line); overflow: hidden; }
.right { border-left: 1px solid var(--line); overflow: auto; }
/* The intake can grow past the viewport, so it scrolls on its own and the
   transcript keeps a share of the column instead of falling off the screen. */
.left-top { flex: 1 1 0; min-height: 0; overflow-y: auto; }
.rail { padding: 16px 16px 4px; }
.intake { padding: 4px 16px 16px; }
.inspector { padding: 16px 16px 28px; }
.kicker {
  margin: 16px 0 8px;
  color: var(--accent);
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}
.intake .kicker, .words-head .kicker { margin-top: 0; }

.hint.warn { color: #ffb4a8; }
/* Always visible between the scrolling intake and the transcript panel. */
.action-strip {
  flex: 0 0 auto;
  padding: 8px 16px 12px;
  border-top: 1px solid var(--line);
  background: #12150f;
}
.action-strip .wide { margin-top: 6px; }
.action-strip .hint { margin: 4px 0 0; }
.action-strip .row { margin: 0; }
#speechRow .hint {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Two columns keeps all nine tools visible without pushing the upload box
   off the screen. The long description lives in the right-hand panel. */
.tool-rail { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
.rail-group {
  grid-column: 1 / -1;
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
.rail-group:first-child { margin-top: 0; }
.tool-card {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 5px;
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #10120d;
  padding: 6px 8px;
}
.tool-card b { font-size: 12px; font-weight: 620; }
.tool-card span { color: var(--muted); font-size: 10px; white-space: nowrap; }
.tool-card:hover { border-color: #47503a; }
.tool-card.on { border-color: var(--accent); background: #1c2016; }
.tool-card.on b { color: var(--accent); }
.tool-card.locked b { opacity: 0.6; }
.tool-card.locked span { color: var(--warn); }

.tool-panel { border-bottom: 1px solid var(--line); padding-bottom: 12px; margin-bottom: 4px; }
.tool-panel h2 { margin: 2px 0 4px; font-size: 17px; letter-spacing: -0.02em; }
.tool-blurb { margin: 0 0 10px; color: var(--muted); font-size: 12px; }
.tool-facts { display: grid; grid-template-columns: 62px 1fr; gap: 4px 10px; margin: 0; }
.tool-facts dt { color: var(--muted); font-size: 11px; }
.tool-facts dd { margin: 0; font-size: 12px; }
.upgrade { display: block; margin-top: 12px; text-align: center; text-decoration: none; }

.next-up {
  width: min(640px, 100%);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
}
#nextChips { display: flex; gap: 6px; flex-wrap: wrap; }
#nextChips button {
  border: 1px solid var(--line);
  background: #14170f;
  color: var(--text);
  border-radius: 999px;
  padding: 4px 11px;
  font-size: 11px;
}
#nextChips button:hover { border-color: var(--accent); color: var(--accent); }
#nextChips button:disabled { opacity: 0.5; }
.brand-mark {
  position: absolute;
  z-index: 3;
  left: 8%;
  bottom: 6%;
  color: #fff;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-shadow: 0 1px 2px #000;
  pointer-events: none;
}
.drop {
  position: relative;
  display: block;
  border: 1px dashed #3c4232;
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 8px;
  background: #10120d;
  cursor: pointer;
}
.drop input {
  display: block;
  width: 100%;
  margin-top: 8px;
  color: var(--text);
  font-size: 12px;
}
.drop.hot { border-color: var(--accent); }
.drop b { display: block; font-size: 12px; }
.drop span { color: var(--muted); font-size: 12px; }

label { display: block; color: var(--muted); font-size: 11px; }
label select, label input[type="number"], label input[type="text"] {
  display: block;
  width: 100%;
  margin-top: 4px;
  background: #0d0f0b;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 8px;
  color: var(--text);
}
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 8px 0; }
.row.three { grid-template-columns: 1fr 1fr 1fr; }
.row.tight { display: flex; gap: 16px; margin: 8px 0 4px; }

.primary, .ghost, .text {
  border-radius: 8px;
  border: 0;
  padding: 8px 12px;
  font-weight: 700;
}
.primary { background: var(--accent); color: var(--ink); }
.primary:disabled, .ghost:disabled { opacity: 0.4; cursor: not-allowed; }
.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
.wide { width: 100%; margin-top: 8px; }
.text { background: transparent; color: var(--muted); padding: 0; }
.file-inline {
  display: inline-block;
  margin: -2px 0 8px;
  color: var(--accent);
  cursor: pointer;
  font-size: 12px;
}

.words-wrap {
  flex: 0 0 210px;
  min-height: 210px;
  display: flex;
  flex-direction: column;
  border-top: 1px solid var(--line);
  background: #13160f;
}
.words-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px 4px;
}
.words { flex: 1; min-height: 0; overflow: auto; padding: 0 10px 16px; }
.word {
  display: grid;
  grid-template-columns: 58px 1fr 22px;
  gap: 6px;
  align-items: center;
  margin-bottom: 4px;
}
.word time { color: var(--muted); font: 10px var(--mono); }
.word input {
  width: 100%;
  background: transparent;
  border: 0;
  border-bottom: 1px solid transparent;
  padding: 4px 2px;
}
.word input:focus { outline: 0; border-bottom-color: var(--accent); }
.word button {
  border: 0; background: transparent; color: var(--muted); padding: 0;
}
.word.break { margin-top: 8px; }
.recent { margin-top: 12px; display: flex; flex-wrap: wrap; gap: 6px; }
.recent button, .recent a {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 11px;
  text-decoration: none;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stage-col {
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 18px 18px 10px;
  background:
    radial-gradient(circle at 50% 38%, rgba(223, 242, 90, 0.07), transparent 42%),
    var(--bg);
}
.stage {
  flex: 1;
  width: 100%;
  min-height: 0;
  display: grid;
  place-items: center;
}
.fit {
  position: relative;
  height: min(100%, 820px);
  aspect-ratio: 9 / 16;
  max-width: 100%;
  background: #050505;
  border-radius: 18px;
  overflow: hidden;
  box-shadow: 0 0 0 1px #2c3126, 0 28px 70px rgba(0, 0, 0, 0.45);
}
.fit video {
  width: 100%;
  height: 100%;
  object-fit: fill;
  background: #111;
  display: block;
}
.placeholder {
  position: absolute;
  inset: 18% 12% auto;
  color: var(--muted);
  text-align: center;
  pointer-events: none;
}
.caption {
  position: absolute;
  z-index: 2;
  left: 50%;
  top: 72%;
  transform: translate(-50%, -50%);
  max-width: 88%;
  text-align: center;
  line-height: 1.05;
  white-space: nowrap;
  cursor: grab;
  user-select: none;
  touch-action: none;
}
.caption span { display: inline-block; margin: 0 0.14em; }
.guides {
  position: absolute;
  inset: 8%;
  border: 1px dashed rgba(223, 242, 90, 0.55);
  pointer-events: none;
}
.veil {
  position: absolute;
  inset: 0;
  display: grid;
  align-content: end;
  gap: 8px;
  padding: 18px;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.72));
}
.bar { height: 4px; background: #2a2e24; border-radius: 99px; overflow: hidden; }
.bar span { display: block; height: 100%; width: 0; background: var(--accent); }
.veil p { margin: 0; color: #ddd; }

.transport {
  width: min(640px, 100%);
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
}
.transport input[type="range"] { flex: 1; }
#time { font: 12px var(--mono); color: var(--muted); min-width: 42px; }
.check { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.seg { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: transparent; color: var(--muted); padding: 6px 10px; }
.seg button.on { background: #24281d; color: var(--text); }
.hint { color: var(--muted); font-size: 12px; margin: 8px 0 0; }

.slider { margin: 8px 0; }
.slider > span, .swatches label { display: flex; justify-content: space-between; }
.slider b { color: var(--text); font-weight: 650; }
.swatches { display: flex; gap: 8px; margin: 8px 0; }
.swatches input { width: 36px; height: 28px; padding: 0; border: 0; background: transparent; }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 2px;
  margin: 8px 0 0;
  background: #3a3f32;
  border-radius: 99px;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
}

.toast {
  position: fixed;
  left: 16px;
  bottom: 16px;
  max-width: 420px;
  background: #2a1614;
  color: #ffd2cb;
  border: 1px solid #6a322c;
  border-radius: 10px;
  padding: 10px 12px;
  z-index: 40;
}

.mobile-dock { display: none; }
.download-fab { display: none; }

@media (max-width: 1100px) {
  /* App-shell: one viewport, dock fixed, sheets slide under a live preview */
  html, body {
    height: 100%;
    max-height: 100dvh;
    overflow: hidden;
    overscroll-behavior: none;
    -webkit-tap-highlight-color: transparent;
  }
  body { background: #050605; }
  .app {
    height: 100%;
    max-height: 100dvh;
    overflow: hidden;
    padding-bottom: calc(56px + env(safe-area-inset-bottom, 0));
  }

  header {
    height: 48px;
    gap: 8px;
    padding: 0 10px;
    flex-shrink: 0;
    z-index: 5;
  }
  .brand { min-width: 0; }
  .brand span { display: none; }
  .brand strong { font-size: 14px; }
  .pill {
    margin-right: auto;
    font-size: 11px;
    padding: 4px 8px;
    max-width: 32vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  #who { display: none; }
  .header-actions .ghost[href="/account"] { display: none; }
  #downloadBtn { display: none; } /* FAB handles download on phone */
  .header-actions .ghost,
  .header-actions .primary {
    padding: 8px 12px;
    font-size: 12px;
    min-height: 36px;
    border-radius: 10px;
  }

  .workspace {
    display: flex;
    flex-direction: column;
    grid-template-columns: none;
    min-height: 0;
    flex: 1;
    overflow: hidden;
  }

  /* Preview always mounted — never swapped away while styling */
  .stage-col {
    display: flex !important;
    flex: 0 0 auto;
    height: min(38dvh, 320px);
    max-height: 40dvh;
    min-height: 200px;
    padding: 4px 10px 0;
    border: 0;
    order: 0;
    background: #050605;
    z-index: 2;
  }
  .stage {
    flex: 1;
    min-height: 0;
    width: 100%;
    place-items: center;
  }
  .fit {
    height: 100%;
    width: auto;
    max-width: 100%;
    max-height: 100%;
    border-radius: 12px;
    box-shadow: none;
  }
  .transport {
    width: 100%;
    gap: 6px;
    margin-top: 4px;
    padding: 0 0 2px;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .transport::-webkit-scrollbar { display: none; }
  .transport .check span,
  .hint, .next-up { display: none; }
  .transport .check { font-size: 11px; white-space: nowrap; }
  .seg button { padding: 6px 10px; font-size: 11px; }
  #play { flex-shrink: 0; min-height: 34px; padding: 6px 12px; border-radius: 10px; }
  #scrub { flex: 1; min-width: 80px; }
  #time { font-size: 11px; font-variant-numeric: tabular-nums; flex-shrink: 0; }

  .left, .right {
    display: none;
    flex: 1 1 0;
    min-height: 0;
    border: 0;
    order: 1;
    overflow: hidden;
    background: var(--panel);
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -10px 32px rgba(0, 0, 0, 0.4);
    z-index: 3;
  }

  /* Media sheet */
  body[data-mobile-panel="tools"] .left { display: flex; flex-direction: column; }
  body[data-mobile-panel="tools"] .words-wrap { display: none !important; }
  body[data-mobile-panel="tools"] .left-top {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 8px;
  }
  body[data-mobile-panel="tools"] .action-strip {
    display: block;
    padding: 10px 12px calc(12px + env(safe-area-inset-bottom, 0));
  }

  /* Style sheet — live preview stays above so every slider paints on the video */
  body[data-mobile-panel="style"] .right {
    display: flex;
    flex-direction: column;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
  }
  body[data-mobile-panel="style"] .inspector {
    padding: 10px 14px calc(20px + env(safe-area-inset-bottom, 0));
  }
  body[data-mobile-panel="style"] .tool-panel h2 { font-size: 16px; }
  body[data-mobile-panel="style"] .kicker { margin-top: 14px; }

  /* Words sheet */
  body[data-mobile-panel="words"] .left { display: flex; flex-direction: column; }
  body[data-mobile-panel="words"] .left-top,
  body[data-mobile-panel="words"] .action-strip { display: none !important; }
  body[data-mobile-panel="words"] .words-wrap {
    display: flex !important;
    flex: 1;
    min-height: 0;
    border-top: 0;
    border-radius: 20px 20px 0 0;
  }
  body[data-mobile-panel="words"] .words {
    max-height: none;
    padding-bottom: calc(16px + env(safe-area-inset-bottom, 0));
  }
  body[data-mobile-panel="words"] .word {
    grid-template-columns: 52px 1fr 28px;
    min-height: 44px;
  }
  body[data-mobile-panel="words"] .word input { font-size: 16px; padding: 8px 2px; }

  /* Full preview mode */
  body[data-mobile-panel="stage"] .stage-col {
    flex: 1;
    height: auto;
    max-height: none;
    min-height: 0;
    padding: 8px 12px 6px;
  }
  body[data-mobile-panel="stage"] .left,
  body[data-mobile-panel="stage"] .right { display: none !important; }
  body[data-mobile-panel="stage"] .hint,
  body[data-mobile-panel="stage"] .next-up {
    display: block;
    width: 100%;
    font-size: 11px;
    margin-top: 6px;
  }
  body[data-mobile-panel="stage"] .transport .check { display: flex; }

  .rail { padding: 12px 12px 4px; }
  .intake { padding: 4px 12px 16px; }
  .tool-rail { grid-template-columns: 1fr 1fr; gap: 8px; }
  .tool-card {
    min-height: 48px;
    padding: 12px;
    border-radius: 14px;
    transition: transform 0.12s ease, border-color 0.12s ease, background 0.12s ease;
  }
  .tool-card:active { transform: scale(0.97); }
  .tool-card b { font-size: 13px; }
  .drop { padding: 14px; border-radius: 14px; }
  .drop input { font-size: 16px; }
  label select,
  label input[type="number"],
  label input[type="text"],
  label input[type="color"] {
    font-size: 16px;
    min-height: 46px;
    border-radius: 12px;
  }
  .primary, .ghost { min-height: 48px; border-radius: 14px; font-size: 14px; }
  .action-strip {
    position: sticky;
    bottom: 0;
    z-index: 2;
    background: #12150f;
    border-top: 1px solid var(--line);
  }
  .slider { margin: 10px 0; }
  .slider input[type="range"] {
    height: 28px;
    margin-top: 4px;
  }
  .slider input[type="range"]::-webkit-slider-runnable-track {
    height: 4px;
    border-radius: 99px;
    background: #2a2e24;
  }
  .slider input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 24px;
    height: 24px;
    margin-top: -10px;
    border-radius: 50%;
    background: var(--accent);
    border: 0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
  }

  .mobile-dock {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 2px;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 40;
    padding: 4px 6px calc(4px + env(safe-area-inset-bottom, 0));
    background: rgba(10, 12, 8, 0.96);
    border-top: 1px solid var(--line);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
  }
  .mobile-dock button {
    border: 0;
    background: transparent;
    color: var(--muted);
    border-radius: 14px;
    padding: 6px 4px 5px;
    font-size: 10px;
    font-weight: 650;
    letter-spacing: 0.02em;
    min-height: 50px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    transition: color 0.15s ease, background 0.15s ease;
  }
  .mobile-dock button i {
    width: 22px;
    height: 3px;
    border-radius: 99px;
    background: currentColor;
    opacity: 0.4;
    display: block;
    transition: width 0.15s ease, opacity 0.15s ease;
  }
  .mobile-dock button.on {
    color: var(--accent);
    background: #1a1e14;
  }
  .mobile-dock button.on i { opacity: 1; width: 16px; }

  .download-fab {
    display: none;
    position: fixed;
    right: 14px;
    bottom: calc(68px + env(safe-area-inset-bottom, 0));
    z-index: 45;
    border: 0;
    border-radius: 999px;
    padding: 14px 20px;
    background: var(--accent);
    color: var(--ink);
    font-weight: 800;
    font-size: 14px;
    letter-spacing: -0.01em;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
  }
  body.has-output .download-fab { display: inline-flex; align-items: center; gap: 6px; }
  .download-fab.pulse { animation: fabPulse 0.9s ease 2; }
  @keyframes fabPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.06); }
  }

  .toast {
    bottom: calc(72px + env(safe-area-inset-bottom, 0));
    left: 12px;
    right: 12px;
    max-width: none;
    z-index: 50;
  }
  .veil { border-radius: 12px; }
  .caption { touch-action: none; }
}

@media (max-width: 520px) {
  .seg { margin-left: auto; }
  .transport .check { display: none; }
  body[data-mobile-panel="stage"] .transport .check { display: flex; }
  body[data-mobile-panel="tools"] .stage-col,
  body[data-mobile-panel="style"] .stage-col,
  body[data-mobile-panel="words"] .stage-col {
    height: min(34dvh, 280px);
    min-height: 180px;
  }
}
