/* Cutframe — showreel mockup editor.
   Design tokens follow the HorizonX design system: one typeface (Inter),
   near-black ink on white, hierarchy by opacity, rounded containment. */

@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-display: swap;
  font-weight: 100 900;
  src: url('../assets/fonts/inter-latin-wght-normal.woff2') format('woff2-variations');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-display: swap;
  font-weight: 100 900;
  src: url('../assets/fonts/inter-latin-ext-wght-normal.woff2') format('woff2-variations');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
  /* Colour */
  --ink: #171717;
  --ink-soft: #2a2a2a;
  --ink-60: rgba(23, 23, 23, 0.6);   /* 4.69:1 on white: the floor for text */
  --ink-70: rgba(23, 23, 23, 0.7);
  --ink-15: rgba(23, 23, 23, 0.15);
  --ink-10: rgba(23, 23, 23, 0.1);
  --ink-06: rgba(23, 23, 23, 0.06);
  --ink-04: rgba(23, 23, 23, 0.04);
  --white: #ffffff;
  --canvas: #f8f8f8;
  --tertiary: #f3f3f3;
  --error: #d03821;
  --success: #1a8f5c;

  /* Radius */
  --radius-chip: 100px;
  --radius-pill: 48px;
  --radius-card: 30px;
  --radius-lg: 19px;
  --radius-md: 12px;

  /* Shadow */
  --shadow-card: 0 20px 70px rgba(23, 23, 23, 0.07);
  --shadow-card-hover: 0 8px 32px rgba(23, 23, 23, 0.08);
  --shadow-soft: 0 2px 10px rgba(23, 23, 23, 0.06);
  --shadow-lift: 0 12px 28px rgba(23, 23, 23, 0.24);

  /* Motion */
  --duration-fast: 150ms;
  --duration-base: 250ms;
  --duration-slow: 400ms;
  --ease-standard: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);

  /* Type (fluid, same scale as HorizonX) */
  --font: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --fs-xs: clamp(0.75rem, calc(0.715rem + 0.143vw), 0.84375rem);
  --fs-sm: clamp(0.8125rem, calc(0.766rem + 0.19vw), 0.875rem);
  --fs-base: clamp(0.9375rem, calc(0.868rem + 0.286vw), 1.0625rem);
  --fs-lg: clamp(1.0625rem, calc(0.993rem + 0.286vw), 1.1875rem);
  --fs-2xl: clamp(1.25rem, calc(1.16rem + 0.38vw), 1.5rem);

  /* Layout */
  --topbar-h: 68px;
  --rail-w: 340px;
  --inspector-w: 340px;

  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: var(--fs-base);
  font-weight: 500;
  line-height: 1.5;
  color: var(--ink);
  background: var(--white);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
h1, h2, h3, p, ul, dl, dd, fieldset { margin: 0; padding: 0; }
fieldset { border: 0; min-width: 0; }
ul { list-style: none; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; }
img, canvas, svg { display: block; }
[hidden] { display: none !important; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; left: 16px; top: -48px; z-index: 200;
  padding: 10px 16px; border-radius: var(--radius-chip);
  background: var(--ink); color: var(--white); font-size: var(--fs-sm); text-decoration: none;
  transition: top var(--duration-fast) var(--ease-out);
}
.skip-link:focus { top: 12px; }

:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.muted { color: var(--ink-60); }
.mono { font-variant-numeric: tabular-nums; font-feature-settings: 'tnum'; }

/* Icons */
.icon { width: 20px; height: 20px; flex: none; fill: currentColor; }
.icon-xs { width: 14px; height: 14px; }
.icon-lg { width: 24px; height: 24px; }

/* ---------- App shell ---------- */
.app {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  grid-template-columns: var(--rail-w) minmax(0, 1fr) var(--inspector-w);
  grid-template-rows: var(--topbar-h) minmax(0, 1fr);
  grid-template-areas:
    "top top top"
    "templates stage settings";
  height: 100vh;
  height: 100dvh;
}
.topbar { grid-area: top; }
.panel-templates { grid-area: templates; }
.stage-wrap { grid-area: stage; }
.panel-settings { grid-area: settings; }
.panel-switch { display: none; }

/* Top bar */
.topbar {
  display: flex; align-items: center; gap: 20px;
  padding: 0 20px 0 24px;
  border-bottom: 1px solid var(--ink-06);
  background: var(--white);
  min-width: 0;
}
.brand {
  display: inline-flex; align-items: center; gap: 10px;
  color: var(--ink); text-decoration: none; flex: none;
  min-height: 44px; border-radius: var(--radius-md);
}
.brand-mark {
  display: grid; place-items: center; width: 36px; height: 36px;
  border-radius: var(--radius-md); background: var(--ink); color: var(--white);
}
.brand-mark svg { width: 22px; height: 22px; }
.brand-name { font-size: var(--fs-base); font-weight: 600; letter-spacing: -0.01em; }

.title-group {
  display: flex; align-items: center; gap: 8px; min-width: 0; flex: 1;
  padding-left: 20px; border-left: 1px solid var(--ink-10); height: 28px;
}
.reel-title {
  font-size: var(--fs-sm); font-weight: 500; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; min-width: 0;
}
.rename-form { display: flex; align-items: center; gap: 8px; }
.save-state { font-size: var(--fs-xs); color: var(--ink-60); white-space: nowrap; margin-left: 4px; }
.topbar-actions { display: flex; align-items: center; gap: 8px; flex: none; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 44px; padding: 0 24px; border-radius: var(--radius-chip);
  border: 1px solid transparent; font-size: var(--fs-sm); font-weight: 500;
  white-space: nowrap; text-decoration: none;
  transition: transform var(--duration-fast) var(--ease-out),
              box-shadow var(--duration-fast) var(--ease-out),
              background-color var(--duration-fast) var(--ease-out),
              border-color var(--duration-fast) var(--ease-out),
              color var(--duration-fast) var(--ease-out);
}
.btn .icon { width: 18px; height: 18px; }
.btn-sm { height: 36px; padding: 0 16px; }
.btn-xs { height: 32px; padding: 0 12px; font-size: var(--fs-xs); gap: 6px; }
.btn-primary { background: var(--ink); color: var(--white); }
.btn-primary:hover { transform: translateY(-2px); box-shadow: var(--shadow-lift); }
.btn-primary:active { transform: translateY(0); box-shadow: none; }
.btn-outline { background: transparent; color: var(--ink); border-color: var(--ink-15); }
.btn-outline:hover { border-color: rgba(23, 23, 23, 0.35); box-shadow: 0 6px 18px rgba(23, 23, 23, 0.14); }
.btn-subtle { background: transparent; color: var(--ink-70); }
.btn-subtle:hover { background: var(--ink-06); color: var(--ink); }
.btn:disabled { opacity: 0.45; transform: none; box-shadow: none; }

.icon-btn {
  display: inline-grid; place-items: center; width: 44px; height: 44px; flex: none;
  border-radius: var(--radius-chip); border: 1px solid transparent;
  background: transparent; color: var(--ink);
  transition: background-color var(--duration-fast) var(--ease-out), color var(--duration-fast) var(--ease-out);
}
.icon-btn:hover { background: var(--ink-06); }
.icon-btn-sm { width: 36px; height: 36px; }
.icon-btn-sm .icon { width: 16px; height: 16px; }
.icon-btn-dark { background: var(--ink); color: var(--white); }
.icon-btn-dark:hover { background: var(--ink-soft); }

/* ---------- Panels ---------- */
.panel {
  min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  scrollbar-width: thin; scrollbar-color: var(--ink-15) transparent;
}
.panel-templates { background: var(--canvas); border-right: 1px solid var(--ink-06); padding: 24px 20px 32px; }
.panel-settings { background: var(--white); border-left: 1px solid var(--ink-06); padding: 24px 24px 40px; }
.panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.panel-title { font-size: var(--fs-base); font-weight: 500; }
.panel-sub { font-size: var(--fs-xs); color: var(--ink-60); }

/* Search */
.search { position: relative; margin-bottom: 12px; }
.search-icon { position: absolute; left: 16px; top: 50%; transform: translateY(-50%); color: var(--ink-60); width: 18px; height: 18px; pointer-events: none; }
.text-input {
  width: 100%; height: 44px; padding: 0 16px;
  border: 1px solid var(--ink-10); border-radius: var(--radius-chip);
  background: var(--white); font-size: var(--fs-sm); font-weight: 500;
  transition: border-color var(--duration-fast) var(--ease-out), box-shadow var(--duration-fast) var(--ease-out);
}
.text-input::placeholder { color: var(--ink-60); }
.text-input:hover { border-color: var(--ink-15); }
.text-input:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px var(--ink-06); }
.text-input-sm { height: 36px; padding: 0 12px; }
.search-input { padding-left: 44px; }
.search-input::-webkit-search-cancel-button { cursor: pointer; }

/* Chips */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 20px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 36px; padding: 0 14px; border-radius: var(--radius-chip);
  border: 1px solid var(--ink-10); background: var(--white);
  font-size: var(--fs-xs); font-weight: 500; color: var(--ink-70);
  transition: background-color var(--duration-fast) var(--ease-out), color var(--duration-fast) var(--ease-out), border-color var(--duration-fast) var(--ease-out);
}
.chip:hover { color: var(--ink); border-color: var(--ink-15); }
.chip[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--white); }

/* Template grid */
.template-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px 12px; }
.tpl { position: relative; }
.tpl-btn {
  display: block; width: 100%; padding: 0; border: 0; background: none; text-align: left;
  border-radius: var(--radius-lg);
}
.tpl-media {
  position: relative; display: block; aspect-ratio: 4 / 3; overflow: hidden;
  border-radius: var(--radius-lg); background: var(--tertiary);
  box-shadow: inset 0 0 0 1px var(--ink-06);
  transition: box-shadow var(--duration-fast) var(--ease-out);
}
.tpl-media canvas { width: 100%; height: 100%; }
.tpl-btn:hover .tpl-media { box-shadow: inset 0 0 0 1px var(--ink-15), var(--shadow-card-hover); }
.tpl-btn[aria-pressed="true"] .tpl-media { box-shadow: inset 0 0 0 2px var(--ink); }
.tpl-btn:focus-visible { outline-offset: 3px; }
.tpl-name { display: block; margin-top: 10px; font-size: var(--fs-sm); font-weight: 500; line-height: 1.3; }
.tpl-desc { display: block; margin-top: 2px; font-size: var(--fs-xs); color: var(--ink-60); line-height: 1.35; text-wrap: pretty; }
.tpl-check {
  position: absolute; left: 8px; top: 8px; display: none; place-items: center;
  width: 24px; height: 24px; border-radius: var(--radius-chip); background: var(--ink); color: var(--white);
}
.tpl-check .icon { width: 14px; height: 14px; }
.tpl-btn[aria-pressed="true"] .tpl-check { display: grid; }
.fav-btn {
  position: absolute; right: 6px; top: 6px; width: 36px; height: 36px;
  display: grid; place-items: center; border: 0; border-radius: var(--radius-chip);
  background: rgba(255, 255, 255, 0.92); color: var(--ink); box-shadow: var(--shadow-soft);
  transition: transform var(--duration-fast) var(--ease-out);
}
.fav-btn:hover { transform: scale(1.06); }
.fav-btn .icon { width: 16px; height: 16px; }
.fav-btn[aria-pressed="true"] { background: var(--ink); color: var(--white); }

.empty { display: grid; justify-items: center; gap: 6px; padding: 40px 12px; text-align: center; }
.empty .icon { color: var(--ink-60); margin-bottom: 6px; }
.empty-title { font-size: var(--fs-base); font-weight: 500; }
.empty-copy { font-size: var(--fs-sm); color: var(--ink-60); margin-bottom: 12px; }

/* ---------- Stage ---------- */
.stage-wrap {
  min-width: 0; min-height: 0; display: flex; flex-direction: column; gap: 16px;
  padding: 24px 32px 24px; background: var(--white); outline: none;
}
.stage-meta { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; font-size: var(--fs-sm); }
.stage-template strong { font-weight: 500; margin-left: 4px; }
.stage-size { font-size: var(--fs-xs); font-variant-numeric: tabular-nums; }
.stage {
  position: relative; flex: 1; min-height: 0;
  display: grid; place-items: center;
  border-radius: var(--radius-card); background: var(--canvas);
  box-shadow: inset 0 0 0 1px var(--ink-04);
  padding: 28px; overflow: hidden;
}
.stage canvas {
  max-width: 100%; max-height: 100%; width: auto; height: auto;
  border-radius: 14px; box-shadow: var(--shadow-card);
  background: var(--tertiary);
}
.stage-badge {
  margin-right: auto; padding: 4px 12px; border-radius: var(--radius-chip);
  background: var(--white); box-shadow: inset 0 0 0 1px var(--ink-06);
  font-size: var(--fs-xs); line-height: 1.5; color: var(--ink-70);
}
.stage-badge[hidden] { display: none; }

.transport {
  display: flex; align-items: center; gap: 14px;
  padding: 8px 10px 8px 8px; border-radius: var(--radius-chip);
  border: 1px solid var(--ink-06); background: var(--white); box-shadow: var(--shadow-soft);
}
.time { font-size: var(--fs-xs); font-variant-numeric: tabular-nums; min-width: 48px; }
#time-total { text-align: right; }

/* Range */
.range {
  -webkit-appearance: none; appearance: none; width: 100%; height: 24px;
  background: transparent; margin: 0; cursor: pointer;
  --pct: 50%;
}
.range::-webkit-slider-runnable-track {
  height: 4px; border-radius: 4px;
  background: linear-gradient(to right, var(--ink) var(--pct), var(--ink-10) var(--pct));
}
.range::-moz-range-track { height: 4px; border-radius: 4px; background: var(--ink-10); }
.range::-moz-range-progress { height: 4px; border-radius: 4px; background: var(--ink); }
.range::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; width: 18px; height: 18px; margin-top: -7px;
  border-radius: 50%; background: var(--white); border: 2px solid var(--ink); box-shadow: var(--shadow-soft);
  transition: transform var(--duration-fast) var(--ease-out);
}
.range::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 50%; background: var(--white);
  border: 2px solid var(--ink); box-shadow: var(--shadow-soft);
}
.range:hover::-webkit-slider-thumb { transform: scale(1.1); }
.range:focus-visible { outline: none; }
.range:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 4px var(--ink-15); }
.range:focus-visible::-moz-range-thumb { box-shadow: 0 0 0 4px var(--ink-15); }
.range-scrub { flex: 1; min-width: 80px; }

/* ---------- Settings ---------- */
.group { display: grid; gap: 12px; padding: 20px 0; border-top: 1px solid var(--ink-06); }
.panel-head + .group { border-top: 0; padding-top: 4px; }
.group-title { float: left; width: 100%; font-size: var(--fs-sm); font-weight: 500; margin: 0; padding: 0; }
.group-title + * { clear: both; }
.group-flat { border-top: 0; padding: 0; }
.field-label { display: block; font-size: var(--fs-xs); font-weight: 500; color: var(--ink-70); margin-top: 4px; }
.hint { font-size: var(--fs-xs); color: var(--ink-60); line-height: 1.45; }

/* Drop zone */
.drop { position: relative; }
.drop-label {
  display: grid; justify-items: center; gap: 4px; padding: 20px 16px;
  border: 1.5px dashed var(--ink-15); border-radius: var(--radius-lg);
  background: var(--canvas); text-align: center; cursor: pointer;
  transition: border-color var(--duration-fast) var(--ease-out), background-color var(--duration-fast) var(--ease-out);
}
.drop-label .icon { color: var(--ink-70); margin-bottom: 4px; }
.drop-label:hover, .drop.is-over .drop-label { border-color: var(--ink); background: var(--white); }
.drop input:focus-visible + .drop-label { outline: 2px solid var(--ink); outline-offset: 2px; }
.drop-title { font-size: var(--fs-sm); font-weight: 500; }
.drop-copy { font-size: var(--fs-xs); color: var(--ink-60); }

.slots { display: grid; gap: 8px; }
.slot {
  display: flex; align-items: center; gap: 12px; padding: 8px 8px 8px 8px;
  border-radius: var(--radius-md); border: 1px solid var(--ink-06); background: var(--white);
}
.slot-thumb { width: 56px; height: 40px; flex: none; border-radius: 8px; object-fit: cover; background: var(--tertiary); }
.slot-text { min-width: 0; flex: 1; display: grid; }
.slot-name { font-size: var(--fs-xs); font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.slot-meta { font-size: var(--fs-xs); color: var(--ink-60); }
.slot .icon-btn { width: 36px; height: 36px; }
.slot .icon-btn .icon { width: 16px; height: 16px; }

/* Segmented radio */
.seg-radio {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; padding: 4px;
  border-radius: var(--radius-md); background: var(--tertiary);
}
.seg-radio-text { grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); grid-template-columns: none; }
.seg-radio input { position: absolute; opacity: 0; pointer-events: none; }
.seg-radio label {
  display: grid; justify-items: center; align-content: center; gap: 4px; min-height: 44px; padding: 6px 4px;
  border-radius: 9px; font-size: var(--fs-xs); font-weight: 500; color: var(--ink-70); text-align: center; cursor: pointer;
  transition: background-color var(--duration-fast) var(--ease-out), color var(--duration-fast) var(--ease-out), box-shadow var(--duration-fast) var(--ease-out);
}
.seg-radio-text label { min-height: 36px; }
.seg-radio label .icon { width: 18px; height: 18px; }
.seg-radio label:hover { color: var(--ink); }
.seg-radio input:checked + label { background: var(--white); color: var(--ink); box-shadow: var(--shadow-soft), inset 0 0 0 1px var(--ink-06); }
.seg-radio input:focus-visible + label { outline: 2px solid var(--ink); outline-offset: 1px; }

/* Swatches */
.swatches { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 8px; }
.swatch { position: relative; aspect-ratio: 1; }
.swatch input { position: absolute; opacity: 0; pointer-events: none; }
.swatch label {
  display: block; width: 100%; height: 100%; min-height: 32px; border-radius: var(--radius-chip); cursor: pointer;
  box-shadow: inset 0 0 0 1px var(--ink-10);
  transition: transform var(--duration-fast) var(--ease-out);
}
.swatch label:hover { transform: scale(1.06); }
.swatch input:checked + label { box-shadow: inset 0 0 0 1px var(--ink-10), 0 0 0 2px var(--white), 0 0 0 4px var(--ink); }
.swatch input:focus-visible + label { outline: 2px solid var(--ink); outline-offset: 4px; }

.color-row { display: flex; align-items: center; gap: 8px; }
.color-chip {
  position: relative; width: 36px; height: 36px; flex: none; border-radius: var(--radius-chip);
  overflow: hidden; box-shadow: inset 0 0 0 1px var(--ink-10); cursor: pointer;
}
.color-chip input { position: absolute; inset: -8px; width: calc(100% + 16px); height: calc(100% + 16px); border: 0; padding: 0; cursor: pointer; }
.color-chip:focus-within { outline: 2px solid var(--ink); outline-offset: 2px; }
#bg-hex { width: 108px; text-transform: uppercase; }

/* Switch */
.switch { position: relative; display: inline-flex; align-items: center; gap: 10px; font-size: var(--fs-sm); cursor: pointer; min-height: 36px; margin-left: auto; }
.group > .switch { margin-left: 0; }
.switch input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; pointer-events: none; }
.switch-track {
  position: relative; width: 40px; height: 24px; flex: none; border-radius: var(--radius-chip);
  background: var(--ink-15); transition: background-color var(--duration-base) var(--ease-out);
}
.switch-thumb {
  position: absolute; left: 3px; top: 3px; width: 18px; height: 18px; border-radius: 50%;
  background: var(--white); box-shadow: 0 1px 3px rgba(23, 23, 23, 0.25);
  transition: transform var(--duration-base) var(--ease-out);
}
.switch input:checked + .switch-track { background: var(--ink); }
.switch input:checked + .switch-track .switch-thumb { transform: translateX(16px); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--ink); outline-offset: 2px; }

/* Slider rows: label above the track, never under the thumb */
.slider { display: grid; gap: 6px; }
.slider-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; font-size: var(--fs-xs); color: var(--ink-70); }
.slider-head label { font-weight: 500; }
.slider-head output { font-variant-numeric: tabular-nums; color: var(--ink); }

/* Select */
.select-wrap { position: relative; }
.select {
  -webkit-appearance: none; appearance: none; width: 100%; height: 44px; padding: 0 40px 0 16px;
  border: 1px solid var(--ink-10); border-radius: var(--radius-chip); background: var(--white);
  font-size: var(--fs-sm); font-weight: 500; cursor: pointer;
}
.select:hover { border-color: var(--ink-15); }
.select:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px var(--ink-06); }
.select-caret { position: absolute; right: 16px; top: 50%; transform: translateY(-50%); pointer-events: none; color: var(--ink-70); }

.caption-fields { display: grid; gap: 8px; }
.caption-fields.is-off { opacity: 0.5; }

/* ---------- Dialogs ---------- */
.modal {
  width: min(520px, calc(100vw - 32px)); max-height: calc(100dvh - 32px);
  padding: 0; border: 0; border-radius: var(--radius-card);
  background: var(--white); color: var(--ink); box-shadow: 0 30px 90px rgba(23, 23, 23, 0.18);
}
.modal-sm { width: min(420px, calc(100vw - 32px)); }
.modal::backdrop { background: rgba(23, 23, 23, 0.4); }
.modal[open] { animation: modal-in var(--duration-slow) var(--ease-standard); }
@keyframes modal-in { from { opacity: 0; transform: translateY(12px) scale(0.98); } }
.modal-body { display: grid; gap: 20px; padding: 28px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin: -6px -10px -6px 0; }
.modal-title { font-size: var(--fs-lg); font-weight: 600; }
.modal-copy { font-size: var(--fs-sm); color: var(--ink-60); margin-top: -12px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }

.export-preview { border-radius: var(--radius-lg); overflow: hidden; background: var(--tertiary); display: grid; place-items: center; aspect-ratio: 16 / 9; }
.export-preview canvas { max-width: 100%; max-height: 100%; }

.estimate { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.estimate > div { padding: 12px 14px; border-radius: var(--radius-md); background: var(--canvas); }
.estimate dt { font-size: var(--fs-xs); color: var(--ink-60); }
.estimate dd { font-size: var(--fs-sm); font-weight: 600; font-variant-numeric: tabular-nums; }

.progress { display: grid; gap: 8px; }
.progress-row { display: flex; justify-content: space-between; font-size: var(--fs-xs); color: var(--ink-70); font-variant-numeric: tabular-nums; }
.progress-track { height: 6px; border-radius: 6px; background: var(--ink-10); overflow: hidden; }
.progress-fill { display: block; height: 100%; width: 100%; background: var(--ink); transform-origin: left; transform: scaleX(0); transition: transform var(--duration-fast) linear; }

.alert { padding: 12px 16px; border-radius: var(--radius-md); background: rgba(208, 56, 33, 0.08); color: #a32b19; font-size: var(--fs-sm); }

.keys { display: grid; gap: 4px; }
.keys > div { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 10px 0; border-bottom: 1px solid var(--ink-06); }
.keys > div:last-child { border-bottom: 0; }
.keys dd { font-size: var(--fs-sm); color: var(--ink-70); }
kbd {
  display: inline-grid; place-items: center; min-width: 28px; height: 28px; padding: 0 8px;
  border-radius: 8px; background: var(--canvas); box-shadow: inset 0 0 0 1px var(--ink-10), 0 1px 0 var(--ink-10);
  font: 500 var(--fs-xs) var(--font);
}

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 120; transform: translateX(-50%);
  display: flex; align-items: center; gap: 10px; max-width: calc(100vw - 32px);
  padding: 12px 20px; border-radius: var(--radius-chip);
  background: var(--ink); color: var(--white); font-size: var(--fs-sm);
  box-shadow: 0 12px 28px rgba(23, 23, 23, 0.24);
  animation: toast-in var(--duration-base) var(--ease-out);
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } }

/* ---------- Tablet: one side column with tabs (no squeezed 3 columns) ---------- */
@media (max-width: 1199px) {
  :root { --rail-w: 360px; }
  .app {
    grid-template-columns: var(--rail-w) minmax(0, 1fr);
    grid-template-rows: var(--topbar-h) auto minmax(0, 1fr);
    grid-template-areas:
      "top top"
      "switch stage"
      "side stage";
  }
  .panel-switch { display: block; grid-area: switch; padding: 16px 20px 0; background: var(--canvas); border-right: 1px solid var(--ink-06); }
  .panel-templates, .panel-settings { grid-area: side; background: var(--canvas); border-left: 0; border-right: 1px solid var(--ink-06); }
  .panel-settings { padding: 20px 20px 40px; }
  .app[data-panel="templates"] .panel-settings { display: none; }
  .app[data-panel="settings"] .panel-templates { display: none; }
  .panel-settings .text-input, .panel-settings .select, .panel-settings .drop-label { background: var(--white); }
  .panel-settings .seg-radio { background: rgba(23, 23, 23, 0.05); }
  .stage-wrap { padding: 20px 24px; }
}

.segmented {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px;
  border-radius: var(--radius-chip); background: rgba(23, 23, 23, 0.05);
}
.segmented button {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 40px;
  border: 0; border-radius: var(--radius-chip); background: transparent;
  font-size: var(--fs-sm); font-weight: 500; color: var(--ink-70);
  transition: background-color var(--duration-base) var(--ease-out), color var(--duration-base) var(--ease-out);
}
.segmented button .icon { width: 18px; height: 18px; }
.segmented button[aria-selected="true"] { background: var(--white); color: var(--ink); box-shadow: var(--shadow-soft); }

/* ---------- Phone: stage first, then the active panel ---------- */
@media (max-width: 899px) {
  :root { --topbar-h: 60px; }
  html, body { height: auto; }
  .app {
    display: flex; flex-direction: column; height: auto; min-height: 100dvh;
  }
  .topbar { position: sticky; top: 0; z-index: 20; height: var(--topbar-h); padding: 0 12px 0 16px; gap: 12px; }
  .brand-name, .save-state, .hide-sm { display: none; }
  .title-group { padding-left: 12px; }
  .topbar .btn-primary { height: 40px; padding: 0 16px; }
  .stage-wrap { order: 1; padding: 16px 16px 8px; gap: 12px; }
  .stage { flex: none; padding: 16px; border-radius: 24px; aspect-ratio: auto; }
  .stage canvas { border-radius: 10px; }
  .stage-badge { order: 3; }
  .stage { display: flex; flex-direction: column; align-items: center; }
  .transport { gap: 8px; }
  .time { min-width: 40px; }
  #restart-btn { display: none; }
  .panel-switch {
    order: 2; position: sticky; top: var(--topbar-h); z-index: 15;
    padding: 8px 16px; background: rgba(255, 255, 255, 0.96); border: 0; border-bottom: 1px solid var(--ink-06);
  }
  .panel-templates, .panel-settings { order: 3; overflow: visible; border: 0; padding: 16px 16px 48px; background: var(--white); }
  .panel-templates { background: var(--white); }
  .panel-settings .seg-radio { background: var(--tertiary); }
  .template-grid { gap: 16px 12px; grid-template-columns: repeat(auto-fill, minmax(156px, 1fr)); }
  .estimate { grid-template-columns: 1fr 1fr 1fr; }
  .modal-body { padding: 22px; }
  .modal-actions .btn { flex: 1; }
}

@media (min-width: 1600px) {
  :root { --rail-w: 380px; --inspector-w: 360px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; transition-duration: 1ms !important; }
  .btn-primary:hover { transform: none; }
}
