/* Vine Studio — botanical drafting table
   Signature: tempo strip under the stage records draw velocity live.
   Light paper, gold ink, moss utility. Canvas is the product. */

:root {
  --paper: #f2eef4;
  --paper-deep: #e8e2ec;
  --panel: #fffcfa;
  --ink: #2a2630;
  --ink-soft: #5c5566;
  --muted: #8a8294;
  --gold: #d4c4a8;
  --gold-ink: #a8946a;
  --moss: #4a6b52;
  --moss-soft: #6f8f78;
  --danger: #9b4a4a;
  --grid-line: rgba(74, 107, 82, 0.07);
  --line: rgba(42, 38, 48, 0.1);
  --shadow: 0 18px 50px rgba(42, 38, 48, 0.08);
  --radius: 14px;
  --radius-sm: 10px;
  --pad: clamp(0.75rem, 2vw, 1.25rem);
  --dock-h: 4.5rem;
  --topbar-h: 3.4rem;
  --font-display: "Fraunces", Georgia, serif;
  --font-body: "IBM Plex Sans", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;
  --focus: 0 0 0 2px var(--panel), 0 0 0 4px var(--moss);
}

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

html,
body {
  height: 100%;
  margin: 0;
}

body {
  font-family: var(--font-body);
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(168, 148, 106, 0.12), transparent 55%),
    radial-gradient(900px 500px at 100% 0%, rgba(74, 107, 82, 0.08), transparent 50%),
    var(--paper);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  touch-action: none;
}

button,
input {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
}

/* ── App shell ── */
.app {
  height: 100dvh;
  height: 100vh;
  display: grid;
  grid-template-rows: var(--topbar-h) 1fr;
  max-width: 1600px;
  margin: 0 auto;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0
    env(safe-area-inset-left);
}

/* ── Topbar ── */
.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem var(--pad);
  min-height: var(--topbar-h);
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel) 82%, transparent);
  backdrop-filter: blur(12px);
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  min-width: 0;
}

.brand-mark {
  width: 1.65rem;
  height: 1.65rem;
  border-radius: 50%;
  background:
    radial-gradient(circle at 35% 30%, #f7f0e0, var(--gold) 45%, var(--gold-ink));
  box-shadow: inset 0 0 0 1px rgba(42, 38, 48, 0.08);
  flex-shrink: 0;
}

.brand-kicker {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.brand-name {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
  line-height: 1.1;
  font-variation-settings: "opsz" 72, "SOFT" 40;
}

.stage-switch {
  display: inline-flex;
  padding: 0.22rem;
  gap: 0.2rem;
  border-radius: 999px;
  background: var(--paper-deep);
  border: 1px solid var(--line);
}

.chip {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.05rem;
  padding: 0.4rem 0.85rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--ink-soft);
  transition: background 0.15s ease, color 0.15s ease;
}

.chip-meta {
  font-family: var(--font-mono);
  font-size: 0.58rem;
  letter-spacing: 0.04em;
  opacity: 0.7;
}

.chip.is-active {
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(42, 38, 48, 0.08);
}

.chip:focus-visible,
.btn:focus-visible,
.dock-btn:focus-visible,
.check input:focus-visible,
input[type="range"]:focus-visible {
  outline: none;
  box-shadow: var(--focus);
}

.top-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.45rem;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: 2.4rem;
  padding: 0.5rem 1rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  font-size: 0.88rem;
  font-weight: 500;
  transition: transform 0.12s ease, background 0.12s ease, border-color 0.12s ease;
}

.btn:hover:not(:disabled) {
  border-color: color-mix(in srgb, var(--gold-ink) 45%, var(--line));
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn.primary {
  background: var(--moss);
  border-color: var(--moss);
  color: #f7faf7;
}

.btn.primary:hover:not(:disabled) {
  background: color-mix(in srgb, var(--moss) 88%, #000);
  border-color: transparent;
}

.btn.ghost {
  background: transparent;
}

.btn.full {
  width: 100%;
}

/* ── Workspace ── */
.workspace {
  display: grid;
  grid-template-columns: 1fr min(19.5rem, 30vw);
  min-height: 0;
  height: 100%;
}

.stage-wrap {
  min-width: 0;
  min-height: 0;
  padding: var(--pad);
  display: flex;
  flex-direction: column;
}

.stage-frame {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 4px);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.stage-chrome {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.4rem 0.75rem;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
  min-height: 0;
  flex-wrap: nowrap;
}

/* Inline switch lives in stage chrome (mobile); topbar keeps the big one on desktop */
.stage-switch-inline {
  display: none;
  flex-shrink: 0;
}

/* Prompt lives in this bar — not a second header */
.chrome-prompt {
  margin: 0;
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: baseline;
  gap: 0.35rem;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.chrome-prompt.is-hidden {
  display: none;
}

.chrome-prompt-title {
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--ink);
  letter-spacing: -0.02em;
  font-variation-settings: "opsz" 72, "SOFT" 45;
  flex-shrink: 0;
}

.chrome-prompt-body {
  font-size: 0.78rem;
  color: var(--ink-soft);
  overflow: hidden;
  text-overflow: ellipsis;
}

.stage-label {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  flex-shrink: 0;
  margin-left: auto;
}

.stage-stat {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--moss);
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
  min-width: 0;
}

.stage-stat:empty {
  display: none;
}

.btn-original {
  min-height: 1.75rem;
  padding: 0.25rem 0.65rem;
  font-size: 0.75rem;
  flex-shrink: 0;
}

.btn-original.is-on {
  background: color-mix(in srgb, var(--moss) 12%, var(--panel));
  border-color: color-mix(in srgb, var(--moss) 35%, var(--line));
  color: var(--moss);
}

.canvas-shell {
  position: relative;
  flex: 1;
  min-height: 0;
  background:
    radial-gradient(ellipse 80% 60% at 50% 45%, rgba(255, 252, 250, 0.55), transparent 70%),
    linear-gradient(180deg, #e4dde8 0%, #d9d2df 100%);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

/* Centers artboard; sizes from container */
.workbench {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 0.5rem 0.65rem 0.35rem;
  min-height: 0;
  container-type: size;
  container-name: workbench;
}

.artboard-stack {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  min-width: 0;
  min-height: 0;
  max-width: 100%;
  max-height: 100%;
}

/* Clean frame — no fake phone chrome */
.artboard {
  min-width: 0;
  min-height: 0;
  border-radius: 12px;
  overflow: hidden;
  background: #fcfaf5;
  box-shadow:
    0 0 0 1px rgba(42, 38, 48, 0.1),
    0 16px 40px rgba(42, 38, 48, 0.12);
}

/* Desktop: as wide as fits, 16:9 */
.artboard[data-preset="desktop"] {
  width: min(100cqw, calc((100cqh - 1.25rem) * 16 / 9));
  height: min(calc(100cqh - 1.25rem), calc(100cqw * 9 / 16));
  aspect-ratio: 16 / 9;
}

/* Mobile: portrait container only — max size that fits the workbench */
.artboard[data-preset="mobile"] {
  width: min(100cqw, calc((100cqh - 1.25rem) * 390 / 844));
  height: min(calc(100cqh - 1.25rem), calc(100cqw * 844 / 390));
  aspect-ratio: 390 / 844;
}

.artboard-screen {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #fcfaf5;
  touch-action: none;
  cursor: crosshair;
}

.artboard-caption {
  margin: 0;
  flex-shrink: 0;
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ink-soft);
  text-align: center;
  line-height: 1.35;
  opacity: 0.85;
}

.canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.canvas-paper {
  pointer-events: none;
}

.artboard-screen.is-drawing,
.canvas.is-drawing {
  cursor: none;
}

.live-path {
  stroke-width: var(--live-w, 3.8);
  pointer-events: none;
  filter: drop-shadow(0 0 0.5px rgba(168, 148, 106, 0.35));
}

.stroke-layer path,
.replay-layer path {
  pointer-events: none;
}

.safe-zones,
.safe-zones * {
  pointer-events: none;
}

.ref-vines {
  pointer-events: none;
}



/* ── Tempo strip (signature) ── */
.tempo {
  flex-shrink: 0;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.65rem;
  align-items: center;
  padding: 0.4rem 0.75rem;
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--paper) 55%, var(--panel));
}

.tempo-replay {
  min-height: 2rem;
  padding: 0.3rem 0.85rem;
  font-size: 0.82rem;
}

.tempo-track {
  position: relative;
  height: 0.4rem;
  border-radius: 999px;
  background: var(--paper-deep);
  overflow: hidden;
  border: 1px solid var(--line);
}

.tempo-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0%;
  background: linear-gradient(
    90deg,
    color-mix(in srgb, var(--moss) 40%, var(--paper)),
    var(--gold),
    var(--gold-ink)
  );
  border-radius: inherit;
  /* no transition while drawing — avoids lag; replay sets width per frame */
}

.tempo.is-drawing .tempo-track {
  /* recording: soft pulse, not a fake 0→100% */
  background: color-mix(in srgb, var(--moss) 12%, var(--paper-deep));
}

.tempo.is-drawing .tempo-fill {
  width: 100% !important;
  opacity: 0.35;
  background: linear-gradient(
    90deg,
    transparent,
    color-mix(in srgb, var(--gold-ink) 50%, transparent),
    transparent
  );
  background-size: 40% 100%;
  animation: tempo-record 1.1s linear infinite;
}

@keyframes tempo-record {
  from {
    background-position: -40% 0;
  }
  to {
    background-position: 140% 0;
  }
}

.tempo-readout {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  min-width: 3.25rem;
  text-align: right;
  color: var(--moss);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0;
}

/* ── Rail ── */
.rail {
  display: flex;
  flex-direction: column;
  gap: 0;
  min-height: 0;
  border-left: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel) 70%, var(--paper));
  overflow: hidden;
}

.rail-block {
  padding: 1rem var(--pad);
  border-bottom: 1px solid var(--line);
}

.rail-block.flex-1 {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.rail-block.actions {
  border-bottom: none;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding-bottom: calc(1rem + env(safe-area-inset-bottom));
}

.rail-title {
  margin: 0 0 0.75rem;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.rail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}

.rail-head .rail-title {
  margin: 0;
}

.count {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  min-width: 1.5rem;
  height: 1.5rem;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: var(--paper-deep);
  color: var(--ink-soft);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 0.85rem;
  font-size: 0.85rem;
  color: var(--ink-soft);
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 2.5rem;
  gap: 0.5rem;
  align-items: center;
}

.field-row output {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  text-align: right;
  color: var(--moss);
}

input[type="range"] {
  width: 100%;
  accent-color: var(--moss);
}

.check {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  margin-bottom: 0.55rem;
  font-size: 0.88rem;
  color: var(--ink-soft);
  cursor: pointer;
}

.check input {
  width: 1rem;
  height: 1rem;
  accent-color: var(--moss);
}

.stroke-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.stroke-empty {
  margin: 0.25rem 0 0;
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.4;
}

.stroke-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.55rem;
  align-items: center;
  padding: 0.55rem 0.65rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--panel);
  font-size: 0.82rem;
}

.stroke-item.is-active {
  border-color: color-mix(in srgb, var(--gold-ink) 50%, var(--line));
  background: color-mix(in srgb, var(--gold) 18%, var(--panel));
}

.stroke-swatch {
  width: 1.4rem;
  height: 1.4rem;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--paper);
  display: grid;
  place-items: center;
}

.stroke-swatch svg {
  width: 1rem;
  height: 1rem;
  overflow: visible;
}

.stroke-meta {
  min-width: 0;
}

.stroke-name {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stroke-time {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--muted);
  margin-top: 0.1rem;
}

.stroke-del {
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 50%;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1;
}

.stroke-del:hover {
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  color: var(--danger);
}

/* ── Mobile dock / sheet ── */
.dock {
  display: none;
}

.sheet-backdrop,
.sheet {
  display: none;
}

/* ── Modal system (never native alert/confirm) ── */
.modal {
  border: none;
  padding: 0;
  background: transparent;
  max-width: calc(100vw - 1.5rem);
  width: 26rem;
  color: var(--ink);
}

.modal::backdrop {
  background:
    radial-gradient(600px 300px at 50% 40%, rgba(168, 148, 106, 0.12), transparent 70%),
    rgba(42, 38, 48, 0.42);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.modal[open] {
  animation: modal-in 0.22s cubic-bezier(0.2, 0.85, 0.25, 1);
}

.modal[open]::backdrop {
  animation: backdrop-in 0.2s ease;
}

@keyframes modal-in {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes backdrop-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.modal-card {
  position: relative;
  background:
    linear-gradient(165deg, color-mix(in srgb, var(--panel) 92%, var(--gold) 8%) 0%, var(--panel) 42%),
    var(--panel);
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 6px);
  box-shadow:
    0 1px 0 rgba(255, 252, 250, 0.8) inset,
    0 24px 60px rgba(42, 38, 48, 0.16);
  padding: 1.35rem 1.3rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.modal-x {
  position: absolute;
  top: 0.85rem;
  right: 0.85rem;
  width: 2rem;
  height: 2rem;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: var(--muted);
  border: 1px solid transparent;
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}

.modal-x:hover {
  background: var(--paper);
  color: var(--ink);
  border-color: var(--line);
}

.modal-kicker {
  margin: 0 0 0.25rem;
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--moss);
}

.modal-head h2 {
  margin: 0 0 0.4rem;
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 1.45rem;
  letter-spacing: -0.02em;
  line-height: 1.15;
  font-variation-settings: "opsz" 72, "SOFT" 40;
  padding-right: 1.5rem;
}

.modal-head p {
  margin: 0;
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--ink-soft);
}

.modal-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.55rem;
  padding: 0.85rem;
  border-radius: var(--radius-sm);
  background: var(--paper);
  border: 1px solid var(--line);
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.modal-stats strong {
  display: block;
  color: var(--ink);
  font-size: 0.98rem;
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
  margin-top: 0.2rem;
  font-variant-numeric: tabular-nums;
}

/* Export rows — primary actions as list, not stack of generic buttons */
.export-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.export-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.75rem;
  align-items: center;
  width: 100%;
  text-align: left;
  padding: 0.7rem 0.8rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel) 88%, var(--paper));
  transition: border-color 0.12s ease, background 0.12s ease, transform 0.12s ease;
}

.export-row:hover {
  border-color: color-mix(in srgb, var(--gold-ink) 40%, var(--line));
  background: var(--panel);
}

.export-row:active {
  transform: translateY(1px);
}

.export-row-primary {
  border-color: color-mix(in srgb, var(--moss) 35%, var(--line));
  background: color-mix(in srgb, var(--moss) 8%, var(--panel));
}

.export-row-primary:hover {
  border-color: var(--moss);
  background: color-mix(in srgb, var(--moss) 12%, var(--panel));
}

.export-ico {
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 0.65rem;
  display: grid;
  place-items: center;
  background: var(--paper);
  color: var(--gold-ink);
  border: 1px solid var(--line);
  flex-shrink: 0;
}

.export-row-primary .export-ico {
  background: color-mix(in srgb, var(--moss) 14%, var(--panel));
  color: var(--moss);
  border-color: color-mix(in srgb, var(--moss) 25%, var(--line));
}

.export-copy {
  display: flex;
  flex-direction: column;
  gap: 0.12rem;
  min-width: 0;
}

.export-copy strong {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--ink);
}

.export-copy span {
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.3;
}

.export-arrow {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--muted);
}

.modal-note {
  margin: 0;
  text-align: center;
  font-size: 0.82rem;
  color: var(--moss);
  font-weight: 500;
}

/* Confirm dialog */
.modal-confirm {
  width: 22.5rem;
}

.confirm-card {
  text-align: center;
  align-items: center;
  padding-top: 1.5rem;
  gap: 1.1rem;
}

.confirm-icon {
  width: 3.25rem;
  height: 3.25rem;
  color: var(--danger);
  display: grid;
  place-items: center;
}

.confirm-icon svg {
  width: 100%;
  height: 100%;
}

.confirm-icon.is-warn {
  color: var(--gold-ink);
}

.confirm-icon.is-info {
  color: var(--moss);
}

.confirm-head {
  max-width: 18rem;
}

.confirm-head h2 {
  padding-right: 0;
  font-size: 1.35rem;
}

.confirm-head p {
  font-size: 0.9rem;
}

.confirm-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  width: 100%;
  margin-top: 0.15rem;
}

.btn.danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fdf8f8;
}

.btn.danger:hover:not(:disabled) {
  background: color-mix(in srgb, var(--danger) 88%, #000);
  border-color: transparent;
}

@media (max-width: 420px) {
  .confirm-actions {
    grid-template-columns: 1fr;
  }

  .confirm-actions .btn:first-child {
    order: 2;
  }
}

/* ── Toast ── */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(1.25rem + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 80;
  padding: 0.7rem 1.2rem;
  border-radius: 999px;
  background: color-mix(in srgb, var(--ink) 94%, var(--moss));
  color: var(--panel);
  font-size: 0.88rem;
  font-weight: 500;
  letter-spacing: -0.01em;
  box-shadow: 0 12px 32px rgba(42, 38, 48, 0.2);
  max-width: min(90vw, 22rem);
  text-align: center;
  border: 1px solid rgba(255, 252, 250, 0.08);
  animation: toast-in 0.25s cubic-bezier(0.2, 0.85, 0.25, 1);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%);
  }
}

.toast[hidden] {
  display: none;
}

/* Mobile: dock visible, rail → sheet — compress chrome, canvas is king */
@media (max-width: 860px) {
  :root {
    --dock-h: 3.85rem;
    --topbar-h: auto;
    --pad: 0.55rem;
  }

  .app {
    grid-template-rows: auto 1fr var(--dock-h);
    max-width: none;
    padding-bottom: 0;
  }

  .topbar {
    grid-template-columns: 1fr auto;
    grid-template-areas: "brand actions";
    padding: 0.4rem 0.55rem;
    gap: 0.4rem;
    min-height: unset;
  }

  .brand {
    grid-area: brand;
    gap: 0.45rem;
  }

  .brand-mark {
    width: 1.25rem;
    height: 1.25rem;
  }

  .brand-kicker {
    display: none;
  }

  .brand-name {
    font-size: 0.98rem;
  }

  .top-actions {
    grid-area: actions;
  }

  .top-actions .btn {
    min-height: 2.05rem;
    padding: 0.35rem 0.85rem;
    font-size: 0.8rem;
  }

  .top-actions .btn:not(.primary) {
    display: none;
  }

  /* Topbar stage switch hidden; compact inline switch in stage chrome */
  .topbar .stage-switch {
    display: none;
  }

  .stage-switch-inline {
    display: inline-flex;
    padding: 0.12rem;
    gap: 0.12rem;
  }

  .stage-switch-inline .chip {
    padding: 0.28rem 0.55rem;
    font-size: 0.72rem;
    flex-direction: row;
  }

  .workspace {
    grid-template-columns: 1fr;
    min-height: 0;
  }

  .rail {
    display: none;
  }

  .stage-wrap {
    padding: 0;
    min-height: 0;
  }

  .stage-frame {
    border-radius: 0;
    border: none;
    box-shadow: none;
    background: transparent;
  }

  .stage-chrome {
    padding: 0.28rem 0.45rem;
    border-bottom: 1px solid var(--line);
    background: color-mix(in srgb, var(--panel) 92%, transparent);
    gap: 0.35rem;
  }

  .stage-label {
    display: none;
  }

  .chrome-prompt-title {
    font-size: 0.85rem;
  }

  .chrome-prompt-body {
    font-size: 0.68rem;
  }

  .stage-stat {
    font-size: 0.58rem;
  }

  .btn-original {
    min-height: 1.55rem;
    padding: 0.2rem 0.45rem;
    font-size: 0.65rem;
  }

  .tempo {
    padding: 0.32rem 0.5rem;
    gap: 0.45rem;
  }

  .tempo-replay {
    min-height: 1.85rem;
    padding: 0.25rem 0.65rem;
    font-size: 0.75rem;
  }

  .tempo-track {
    height: 0.35rem;
  }

  .tempo-readout {
    font-size: 0.72rem;
    min-width: 2.75rem;
  }

  .artboard-caption {
    font-size: 0.55rem;
  }

  .artboard {
    border-radius: 10px;
  }

  .artboard[data-preset="mobile"] {
    width: min(100cqw - 0.3rem, calc((100cqh - 1rem) * 390 / 844));
    height: min(calc(100cqh - 1rem), calc((100cqw - 0.3rem) * 844 / 390));
  }

  .artboard[data-preset="desktop"] {
    width: min(100cqw - 0.3rem, calc((100cqh - 1rem) * 16 / 9));
    height: min(calc(100cqh - 1rem), calc((100cqw - 0.3rem) * 9 / 16));
  }

  .workbench {
    padding: 0.25rem 0.3rem 0.15rem;
  }

  .dock {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    align-items: stretch;
    gap: 0.15rem;
    height: var(--dock-h);
    padding: 0.25rem 0.35rem calc(0.25rem + env(safe-area-inset-bottom));
    border-top: 1px solid var(--line);
    background: color-mix(in srgb, var(--panel) 94%, transparent);
    backdrop-filter: blur(12px);
    z-index: 30;
  }

  .dock-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.08rem;
    border-radius: 0.65rem;
    font-size: 0.62rem;
    font-weight: 500;
    color: var(--ink-soft);
    min-height: 100%;
  }

  .dock-btn:disabled {
    opacity: 0.35;
  }

  .dock-btn.primary {
    background: color-mix(in srgb, var(--moss) 14%, transparent);
    color: var(--moss);
  }

  .dock-ico {
    font-size: 0.95rem;
    line-height: 1;
  }

  .sheet-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(42, 38, 48, 0.28);
    z-index: 40;
  }

  .sheet-backdrop[hidden] {
    display: none;
  }

  .sheet {
    display: block;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 50;
    max-height: min(72dvh, 34rem);
    background: var(--panel);
    border-radius: 1.1rem 1.1rem 0 0;
    border: 1px solid var(--line);
    border-bottom: none;
    box-shadow: 0 -12px 40px rgba(42, 38, 48, 0.12);
    padding: 0.4rem 0 calc(0.75rem + env(safe-area-inset-bottom));
    overflow: auto;
  }

  .sheet[hidden] {
    display: none;
  }

  .sheet-handle {
    width: 2.5rem;
    height: 0.28rem;
    border-radius: 999px;
    background: var(--paper-deep);
    margin: 0.35rem auto 0.5rem;
  }

  .sheet .rail-block {
    border-bottom: 1px solid var(--line);
  }

  .sheet .rail-block.actions {
    border-bottom: none;
  }

  .toast {
    bottom: calc(var(--dock-h) + 0.75rem + env(safe-area-inset-bottom));
  }
}

@media (max-width: 420px) {
  .brand-name {
    font-size: 0.95rem;
  }

  .chip-meta {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }

  .tempo.is-drawing .tempo-fill {
    animation: none !important;
    opacity: 0.5;
  }
}
