/* ═══════════════ PixelStitch — SwerveMeta family theme ═══════════════
   Shared structure per BRAND_BRIEF section 6: Inter + JetBrains Mono,
   blue-tinted dark surface ramp, radii 6/12/14/999, one motion curve.
   Own identity accent: stitch orange. Teal is reserved for status only. */

/* ── self-hosted fonts (no external requests, ever) ── */
@font-face { font-family: 'Inter'; font-style: normal; font-weight: 400; font-display: swap; src: url('../fonts/inter-latin-400-normal.woff2') format('woff2'); }
@font-face { font-family: 'Inter'; font-style: normal; font-weight: 700; font-display: swap; src: url('../fonts/inter-latin-700-normal.woff2') format('woff2'); }
@font-face { font-family: 'Inter'; font-style: normal; font-weight: 800; font-display: swap; src: url('../fonts/inter-latin-800-normal.woff2') format('woff2'); }
@font-face { font-family: 'JetBrains Mono'; font-style: normal; font-weight: 400; font-display: swap; src: url('../fonts/jetbrains-mono-latin-400-normal.woff2') format('woff2'); }
@font-face { font-family: 'JetBrains Mono'; font-style: normal; font-weight: 500; font-display: swap; src: url('../fonts/jetbrains-mono-latin-500-normal.woff2') format('woff2'); }
@font-face { font-family: 'JetBrains Mono'; font-style: normal; font-weight: 700; font-display: swap; src: url('../fonts/jetbrains-mono-latin-700-normal.woff2') format('woff2'); }

:root {
  color-scheme: dark;
  /* surfaces — blue-tinted dark ramp (family scale) */
  --bg0: #0a0c16;
  --bg1: #0d0f1a;
  --bg2: #151926;
  --bg3: #1d2233;
  --line: rgba(255,255,255,.07);
  --line-hi: rgba(232,69,44,.35);
  /* text */
  --txt: #e8edf4;
  --muted: #93a0b8;
  --dim: #64748b;
  /* identity accent (own palette per family doctrine) */
  --accent: #e8452c;
  --accent2: #ff6a4d;
  --on-accent: #fff;
  /* family gold — selection + focal highlights, used sparingly */
  --gold: #E8B86B;
  --sel: var(--gold);
  /* teal — STATUS ONLY */
  --status: #4dd2c0;
  /* clip colours (functional) */
  --clip-v: #3a6ea5;
  --clip-v2: #2d5580;
  --clip-i: #7a5aa8;
  --clip-i2: #5d4482;
  --clip-a: #3d8f5f;
  --clip-a2: #2e6e49;
  /* type */
  --font-ui: 'Inter', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', 'Consolas', monospace;
  /* motion — one signature curve */
  --ease: cubic-bezier(.2,.7,.2,1);
  --speed: 180ms;
  /* layout */
  --ruler-h: 28px;
  --track-h: 56px;
  --atrack-h: 44px;
  --head-w: 120px;
}
* { box-sizing: border-box; margin: 0; padding: 0; user-select: none; }
html, body { height: 100%; overflow: hidden; }
body {
  background: var(--bg0);
  color: var(--txt);
  font-family: var(--font-ui);
  font-size: 13px;
}
#app { display: flex; flex-direction: column; height: 100vh; }

button {
  background: var(--bg3); color: var(--txt);
  border: 1px solid var(--line); border-radius: 6px;
  padding: 5px 12px; cursor: pointer;
  font-family: var(--font-mono); font-size: 11px; font-weight: 500;
  letter-spacing: .06em; text-transform: uppercase;
  transition: background var(--speed) var(--ease), border-color var(--speed) var(--ease), transform var(--speed) var(--ease);
}
button:hover { background: #232a3f; border-color: rgba(255,255,255,.14); transform: translateY(-1px); }
button.accent { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 700; }
button.accent:hover { background: var(--accent2); box-shadow: 0 0 18px rgba(232,69,44,.3); }
button:disabled { opacity: .4; cursor: default; transform: none; }
select {
  background: var(--bg3); color: var(--txt); border: 1px solid var(--line);
  border-radius: 6px; padding: 4px 8px; font-size: 12px; font-family: var(--font-ui);
}
select:disabled { opacity: .5; }
.sep { width: 1px; height: 20px; background: var(--line); margin: 0 4px; }
.spacer { flex: 1; }
.dim { color: var(--dim); }

/* ── top bar ── */
#topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 14px; background: var(--bg1); border-bottom: 1px solid var(--line);
  gap: 12px;
}
.topbar-brand { display: flex; align-items: center; gap: 14px; min-width: 0; }
.logo { font-weight: 800; font-size: 16px; letter-spacing: .01em; color: var(--txt); white-space: nowrap; }
.logo span { color: var(--accent); }
.tagline {
  font-family: var(--font-mono); font-size: 10px; font-weight: 500;
  letter-spacing: .16em; text-transform: uppercase; color: var(--muted);
  white-space: nowrap;
}
.status-pill {
  display: flex; align-items: center; gap: 6px;
  font-family: var(--font-mono); font-size: 10px; font-weight: 500;
  letter-spacing: .1em; text-transform: uppercase; color: var(--status);
  border: 1px solid rgba(77,210,192,.3); border-radius: 999px;
  padding: 2px 10px; white-space: nowrap;
}
.status-pill .ping {
  width: 7px; height: 7px; border-radius: 50%; background: var(--status);
  animation: ping 2s var(--ease) infinite;
}
@keyframes ping { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }
.topbar-actions { display: flex; align-items: center; gap: 8px; }

/* ── capability banner ── */
#caps-banner {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 14px; background: rgba(232,184,107,.08);
  border-bottom: 1px solid rgba(232,184,107,.25);
  font-family: var(--font-mono); font-size: 11px; color: var(--gold);
}
#caps-banner button { padding: 1px 7px; font-size: 10px; background: transparent; border-color: transparent; color: var(--gold); }
#caps-banner button:hover { border-color: rgba(232,184,107,.25); transform: none; }
#caps-text { flex: 1; letter-spacing: .02em; }

/* ── restore banner ── */
#restore-banner {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 14px; background: rgba(77,210,192,.06);
  border-bottom: 1px solid rgba(77,210,192,.25);
  font-family: var(--font-mono); font-size: 11px; color: var(--muted);
}
#restore-text { flex: 1; letter-spacing: .02em; }
/* Restore is an ACTION — teal stays on the banner strip (status) only */
#btn-restore-dismiss { padding: 1px 7px; font-size: 10px; background: transparent; border-color: transparent; }

/* ── drag ghost (pool → timeline pointer drag) ── */
.drag-ghost {
  position: fixed; z-index: 300; pointer-events: none;
  display: flex; align-items: center; gap: 8px;
  background: var(--bg3); border: 1px solid var(--line-hi); border-radius: 6px;
  padding: 6px 10px; max-width: 220px;
  box-shadow: 0 8px 24px rgba(0,0,0,.45);
  font-size: 11px; white-space: nowrap;
}
.drag-ghost img { width: 42px; border-radius: 6px; display: block; }
.drag-ghost span { overflow: hidden; text-overflow: ellipsis; }

/* ── main split ── */
#main { display: flex; flex: 1; min-height: 0; }

/* ── library ── */
#library {
  width: 260px; min-width: 200px; background: var(--bg1);
  border-right: 1px solid var(--line); display: flex; flex-direction: column;
}
.panel-title {
  padding: 8px 12px; font-family: var(--font-mono); font-size: 10px; font-weight: 500;
  letter-spacing: .16em; text-transform: uppercase; color: var(--dim);
  display: flex; justify-content: space-between; align-items: center;
  border-bottom: 1px solid var(--line);
}
.panel-title button { padding: 2px 8px; font-size: 10px; }
#library-drop { flex: 1; overflow-y: auto; position: relative; padding: 8px; touch-action: pan-y; }
#library-drop.dragover { outline: 2px dashed var(--accent); outline-offset: -6px; }
#library-hint {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; text-align: center;
  color: var(--dim); pointer-events: none; line-height: 1.7;
}
#library-hint .hint-icon { font-size: 32px; opacity: .5; }
#library-hint small { opacity: .6; }
#library-items { display: grid; grid-template-columns: repeat(auto-fill, minmax(105px, 1fr)); gap: 8px; }
.lib-item {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 6px;
  overflow: hidden; cursor: grab; position: relative;
  touch-action: pan-y; /* vertical swipe scrolls the pool; a hold starts a drag */
  transition: border-color var(--speed) var(--ease), background var(--speed) var(--ease);
}
.lib-item:hover { border-color: var(--line-hi); background: var(--bg3); }
.lib-item.missing { border-color: #a33; opacity: .6; }
.lib-thumb {
  width: 100%; aspect-ratio: 16/9; object-fit: cover; display: block;
  background: #000; pointer-events: none;
}
.lib-name {
  font-size: 10px; padding: 4px 6px; white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; color: var(--txt); pointer-events: none;
}
.lib-dur {
  position: absolute; top: 4px; right: 4px; background: rgba(0,0,0,.7);
  font-family: var(--font-mono); font-size: 9px; padding: 1px 5px;
  border-radius: 6px; pointer-events: none;
}
.lib-kind {
  position: absolute; top: 4px; left: 4px; font-size: 9px; padding: 1px 5px;
  border-radius: 6px; pointer-events: none; font-weight: 700; color: #fff;
  font-family: var(--font-mono); text-transform: uppercase;
}
.lib-kind.video { background: var(--clip-v); }
.lib-kind.image { background: var(--clip-i); }
.lib-kind.audio { background: var(--clip-a); }
.lib-del {
  position: absolute; bottom: 22px; right: 4px; background: rgba(0,0,0,.7);
  border: none; font-size: 10px; padding: 2px 6px; border-radius: 6px;
  display: none; color: #f88;
}
.lib-item:hover .lib-del { display: block; }

/* ── viewer ── */
#viewer { flex: 1; display: flex; flex-direction: column; background: var(--bg0); min-width: 0; }
#canvas-wrap {
  flex: 1; display: flex; align-items: center; justify-content: center;
  min-height: 0; padding: 12px; position: relative;
}
#preview-canvas {
  max-width: 100%; max-height: 100%; background: #000;
  box-shadow: 0 8px 24px rgba(0,0,0,.45); border-radius: 6px;
}
#transport {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 16px; background: var(--bg1); border-top: 1px solid var(--line);
}
.transport-btns { display: flex; gap: 6px; }
.transport-btns button { min-width: 40px; font-size: 13px; }
#btn-play { min-width: 52px; }
.timecode { font-family: var(--font-mono); font-size: 14px; letter-spacing: .08em; }

/* ── timeline ── */
#timeline-panel {
  height: 320px; min-height: 160px; background: var(--bg1);
  border-top: 1px solid var(--line); display: flex; flex-direction: column;
}
#timeline-toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 6px 12px;
  border-bottom: 1px solid var(--line);
}
.toggle { display: flex; align-items: center; gap: 5px; font-size: 12px; color: var(--dim); cursor: pointer; }
.toggle input { accent-color: var(--accent); }
.zoom-ctl { display: flex; align-items: center; gap: 6px; }
.zoom-ctl input[type=range] { width: 120px; accent-color: var(--accent); }
.zoom-ctl button { padding: 2px 9px; }

/* touch-action none: pan/pinch are driven manually in timeline.js so clip
   drags, trims and scrubs are never hijacked by native scrolling on touch */
#timeline-scroll { flex: 1; overflow: auto; position: relative; touch-action: none; }
#timeline-inner { position: relative; min-width: 100%; }

#ruler {
  position: sticky; top: 0; z-index: 20; height: var(--ruler-h);
  background: var(--bg2); border-bottom: 1px solid var(--line);
  margin-left: var(--head-w); cursor: pointer;
}
#ruler canvas { display: block; height: var(--ruler-h); }

#tracks { position: relative; }
.track {
  display: flex; border-bottom: 1px solid var(--line); position: relative;
  height: var(--track-h);
}
.track.audio { height: var(--atrack-h); }
.track-head {
  position: sticky; left: 0; z-index: 15; width: var(--head-w); min-width: var(--head-w);
  background: var(--bg2); border-right: 1px solid var(--line);
  display: flex; align-items: center; gap: 6px; padding: 0 8px; font-size: 11px;
}
.track-head .tname { font-family: var(--font-mono); font-weight: 700; font-size: 10px; letter-spacing: .1em; text-transform: uppercase; color: var(--dim); }
.track-head button {
  padding: 1px 6px; font-size: 10px; background: transparent; border-color: transparent;
}
.track-head button:hover { border-color: var(--line); transform: none; }
.track-head button.on { color: var(--accent); }
.track-lane { position: relative; flex: 1; }
.track-lane.drop-target { background: rgba(232,69,44,.07); }

/* ── clips ── */
.clip {
  position: absolute; top: 3px; bottom: 3px; border-radius: 6px;
  overflow: hidden; cursor: grab; border: 1px solid rgba(255,255,255,.15);
  background: linear-gradient(var(--clip-v), var(--clip-v2));
  box-shadow: 0 1px 4px rgba(0,0,0,.4);
}
.clip.image { background: linear-gradient(var(--clip-i), var(--clip-i2)); }
.clip.audio { background: linear-gradient(var(--clip-a), var(--clip-a2)); }
.clip.selected { border: 2px solid var(--sel); box-shadow: 0 0 8px rgba(232,184,107,.35); }
.clip.dragging { opacity: .75; z-index: 30; cursor: grabbing; }
.clip-label {
  position: absolute; top: 2px; left: 6px; right: 6px; font-size: 10px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  color: rgba(255,255,255,.9); text-shadow: 0 1px 2px #000; pointer-events: none; z-index: 3;
}
.clip-thumbs {
  position: absolute; inset: 0; display: flex; overflow: hidden;
  opacity: .55; pointer-events: none;
}
.clip-thumbs img { height: 100%; flex: none; }
.clip-wave {
  position: absolute; inset: 0; pointer-events: none; opacity: .8;
}
.clip-handle {
  position: absolute; top: 0; bottom: 0; width: 8px; cursor: ew-resize; z-index: 4;
}
.clip-handle.left { left: 0; border-left: 3px solid rgba(255,255,255,.35); }
.clip-handle.right { right: 0; border-right: 3px solid rgba(255,255,255,.35); }
.clip-handle:hover { background: rgba(255,255,255,.2); }
.clip-fade {
  position: absolute; top: 0; bottom: 0; pointer-events: none; z-index: 2;
  background: repeating-linear-gradient(45deg, rgba(0,0,0,.25) 0 4px, transparent 4px 8px);
}

/* ── playhead ── */
#playhead {
  position: absolute; top: 0; bottom: 0; width: 1px; background: var(--accent);
  z-index: 25; pointer-events: none; margin-left: var(--head-w);
}
.playhead-cap {
  position: sticky; top: 0; width: 13px; height: 14px; margin-left: -6px;
  background: var(--accent); clip-path: polygon(0 0, 100% 0, 100% 55%, 50% 100%, 0 55%);
}

/* ── snap guide ── */
#snap-guide {
  position: absolute; top: 0; bottom: 0; width: 1px; background: var(--sel);
  z-index: 24; pointer-events: none; display: none;
}

/* ── footer (family provenance strip) ── */
#footer {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 14px; background: var(--bg1); border-top: 1px solid var(--line);
  font-family: var(--font-mono); font-size: 10px; letter-spacing: .04em;
  color: var(--dim); white-space: nowrap; overflow: hidden;
}
#footer a { color: var(--dim); text-decoration: none; transition: color var(--speed) var(--ease); }
#footer a:hover { color: var(--gold); }
.foot-sep { opacity: .5; }
.foot-feedback .arrow { display: inline-block; transition: transform var(--speed) var(--ease); }
.foot-feedback:hover .arrow { transform: translateX(3px); }
.foot-privacy { color: var(--dim); opacity: .8; }

/* ── modal ── */
.modal {
  position: fixed; inset: 0; background: rgba(4,6,13,.72); z-index: 100;
  display: flex; align-items: center; justify-content: center;
}
.modal.hidden, .hidden { display: none !important; }
.modal-card {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 14px;
  padding: 24px; width: 380px; max-width: calc(100vw - 24px);
  box-shadow: 0 10px 60px rgba(0,0,0,.7);
}
.modal-card h2 { font-size: 15px; margin-bottom: 18px; font-weight: 700; letter-spacing: .02em; }
#export-options { display: flex; flex-direction: column; gap: 12px; }
#export-options label { display: flex; justify-content: space-between; align-items: center; font-size: 12px; color: var(--muted); }
#export-options select { width: 210px; }
#engine-note {
  font-family: var(--font-mono); font-size: 10px; line-height: 1.5;
  color: var(--gold); background: rgba(232,184,107,.07);
  border: 1px solid rgba(232,184,107,.2); border-radius: 6px; padding: 8px 10px;
}
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }
.progress-bar {
  height: 8px; background: var(--bg0); border-radius: 6px; overflow: hidden; margin: 16px 0 8px;
}
#export-bar { height: 100%; width: 0%; background: var(--accent); transition: width var(--speed) var(--ease); }
#export-status { font-family: var(--font-mono); font-size: 11px; color: var(--muted); text-align: center; }

/* ── toast ── */
#toast {
  position: fixed; bottom: 40px; left: 50%; transform: translateX(-50%);
  background: var(--bg3); border: 1px solid var(--line); color: var(--txt);
  padding: 10px 20px; border-radius: 6px; font-size: 13px; z-index: 200;
  opacity: 0; pointer-events: none; transition: opacity var(--speed) var(--ease);
  box-shadow: 0 8px 24px rgba(0,0,0,.45);
}
#toast.show { opacity: 1; }

/* scrollbars */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg1); }
::-webkit-scrollbar-thumb { background: var(--bg3); border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: #262e45; }

/* ── touch ergonomics ── */
.mobile-only { display: none; }
@media (pointer: coarse) {
  .clip-handle { width: 16px; }
  .lib-del { display: block; }         /* no hover on touch — keep delete reachable */
  .track-head button { padding: 4px 8px; }
  .transport-btns button { min-width: 46px; padding: 8px 10px; }
}

/* ── narrow screens ── */
@media (max-width: 900px) {
  .tagline, .foot-privacy { display: none; }
}

/* ── phone layout: stacked panels, media pool as a slide-in drawer ── */
@media (max-width: 760px) {
  :root { --head-w: 68px; }
  .mobile-only { display: inline-block; }
  .status-pill { display: none; }
  #topbar { flex-wrap: wrap; padding: 6px 10px; gap: 8px; }
  #main { position: relative; }
  #library {
    position: absolute; top: 0; bottom: 0; left: 0; z-index: 40;
    width: min(78vw, 320px);
    border-right: 1px solid var(--line);
    box-shadow: 0 8px 24px rgba(0,0,0,.45);
    transform: translateX(-105%);
    visibility: hidden; /* keep the closed drawer out of tab order / AT */
    transition: transform var(--speed) var(--ease), visibility 0s var(--speed);
  }
  #library.open { transform: translateX(0); visibility: visible; transition: transform var(--speed) var(--ease), visibility 0s 0s; }
  #timeline-panel { height: 38vh; min-height: 150px; }
  #timeline-toolbar { flex-wrap: wrap; gap: 6px; padding: 6px 8px; }
  .zoom-ctl input[type=range] { width: 72px; }
  .track-head { font-size: 10px; padding: 0 4px; }
  .timecode { font-size: 12px; }
  #transport { padding: 6px 10px; }
  #tc-duration { display: none; }        /* duration readout doesn't fit beside 5 transport buttons */
  .transport-btns { gap: 4px; }
  #canvas-wrap { padding: 6px; }
  #footer { padding: 4px 10px; }
  /* phone footer: version + feedback link only (full provenance on desktop) */
  #footer a:not(.foot-feedback), .foot-sep { display: none; }
}
/* reduced motion: the brand guard */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
