/* ═══════════════════════════════════════════════
   CutFlow Mobile  — v3
   Strategy: on phones, we completely replace the
   desktop layout with a purpose-built mobile UI.
   The desktop layout is untouched above 600px.
   ═══════════════════════════════════════════════ */

/* ─── Elements that only exist on mobile ─── */
#m-app        { display: none; }
#m-nav        { display: none; }
#m-player     { display: none; }

/* ════════════════════════════════════════════
   PHONE  ≤ 599px
   We hide the entire desktop app and show a
   completely separate mobile layout.
════════════════════════════════════════════ */
@media (max-width: 599px) {

  /* ── 1. Kill the desktop app ── */
  html, body { overflow: hidden; height: 100%; }
  #app        { display: none !important; }
  #auth-screen { z-index: 1000; }

  /* ── 2. Auth screen mobile fix ── */
  .auth-card {
    width: 100%;
    max-width: 100%;
    border-radius: 0;
    border-left: none;
    border-right: none;
    border-top: none;
    padding: 36px 22px 28px;
    min-height: 100svh;
  }
  .auth-card::before { border-radius: 0; }
  #auth-screen {
    align-items: flex-start;
    padding: 0;
    background-image:
      radial-gradient(ellipse 90% 35% at 50% 5%,
        rgba(124,106,247,0.18) 0%, transparent 70%);
  }

  /* ── 3. Mobile app shell ── */
  #m-app {
    display: flex;
    flex-direction: column;
    position: fixed;
    inset: 0;
    background: var(--bg);
    z-index: 500;
    overflow: hidden;
    height: 100svh;
  }

  /* ── 4. Mobile header ── */
  #m-header {
    height: 50px;
    background: var(--bg2);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 14px;
    gap: 8px;
    flex-shrink: 0;
    z-index: 10;
  }
  #m-logo {
    font-family: var(--sans);
    font-size: 16px;
    font-weight: 800;
    letter-spacing: -.5px;
    color: var(--text);
  }
  #m-logo span { color: var(--accent); }
  #m-project-name {
    font-size: 11px;
    color: var(--text3);
    font-family: var(--mono);
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    cursor: pointer;
  }
  #m-export-btn {
    padding: 7px 16px;
    background: linear-gradient(135deg, var(--accent3), var(--accent));
    border: none;
    border-radius: 8px;
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    font-family: var(--sans);
    cursor: pointer;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
  }
  #m-export-btn:active { opacity: .8; }
  #m-avatar {
    width: 28px; height: 28px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent3), var(--pink));
    display: flex; align-items: center; justify-content: center;
    font-size: 11px; font-weight: 700;
    cursor: pointer; flex-shrink: 0; color: #fff;
  }

  /* ── 5. Video preview area ── */
  #m-player {
    display: flex;
    flex-direction: column;
    background: #000;
    flex-shrink: 0;
    position: relative;
  }
  #m-video-wrap {
    position: relative;
    background: #000;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 36vw;
    min-height: 180px;
    max-height: 220px;
    overflow: hidden;
  }
  #m-video-wrap video {
    width: 100%; height: 100%;
    object-fit: contain;
    display: block;
  }
  #m-drop-hint {
    position: absolute; inset: 0;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    gap: 6px; color: var(--text3);
    cursor: pointer;
  }
  #m-drop-hint .dh-icon { font-size: 32px; opacity: .5; }
  #m-drop-hint p { font-size: 12px; text-align: center; line-height: 1.5; }
  #m-drop-hint strong { color: var(--accent); }

  /* ── 6. Playback controls ── */
  #m-controls {
    background: var(--bg2);
    padding: 8px 14px 6px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
  }
  #m-seekbar-wrap {
    position: relative;
    height: 20px;
    display: flex;
    align-items: center;
    margin-bottom: 6px;
    cursor: pointer;
  }
  #m-seekbar-track {
    position: absolute;
    left: 0; right: 0;
    height: 4px;
    background: var(--surface2);
    border-radius: 2px;
    overflow: visible;
  }
  #m-seekbar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent3), var(--accent));
    border-radius: 2px;
    width: 0%;
    transition: width .1s linear;
  }
  #m-seekbar-thumb {
    position: absolute;
    top: 50%; left: 0%;
    width: 16px; height: 16px;
    background: var(--accent);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    box-shadow: 0 0 0 3px rgba(124,106,247,.3);
    transition: left .1s linear;
    touch-action: none;
  }
  #m-transport {
    display: flex;
    align-items: center;
    gap: 0;
  }
  .m-tbtn {
    width: 40px; height: 36px;
    display: flex; align-items: center; justify-content: center;
    background: none; border: none;
    font-size: 16px; color: var(--text2);
    cursor: pointer; flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
    transition: color .15s;
  }
  .m-tbtn:active { color: var(--text); transform: scale(.9); }
  #m-play-btn {
    width: 48px; height: 44px;
    background: var(--accent);
    border: none; border-radius: 10px;
    font-size: 18px; color: #fff;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; flex-shrink: 0; margin: 0 6px;
    -webkit-tap-highlight-color: transparent;
    transition: all .15s;
  }
  #m-play-btn:active { opacity: .8; transform: scale(.94); }
  #m-time {
    font-family: var(--mono);
    font-size: 11px;
    color: var(--text3);
    flex: 1;
    text-align: right;
  }
  #m-vol-btn {
    width: 36px; height: 36px;
    background: none; border: none;
    font-size: 16px; color: var(--text3);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }

  /* ── 7. Timeline ── */
  #m-timeline {
    flex-shrink: 0;
    background: var(--bg2);
    border-bottom: 1px solid var(--border);
    overflow: hidden;
  }
  #m-tl-header {
    display: flex;
    align-items: center;
    padding: 0 10px;
    height: 28px;
    gap: 5px;
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    scrollbar-width: none;
  }
  #m-tl-header::-webkit-scrollbar { display: none; }
  .m-tl-btn {
    padding: 3px 9px;
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: 5px;
    font-size: 10px; font-weight: 700;
    color: var(--text2);
    cursor: pointer; flex-shrink: 0;
    font-family: var(--sans);
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
  }
  .m-tl-btn:active { background: var(--surface); }
  .m-tl-btn.danger { color: var(--red); border-color: rgba(248,113,113,.3); }
  #m-tl-body {
    height: 80px;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    position: relative;
  }
  #m-tl-body::-webkit-scrollbar { display: none; }
  #m-tl-tracks { position: relative; min-width: 100%; height: 100%; }
  .m-track {
    display: flex;
    align-items: center;
    height: 26px;
    border-bottom: 1px solid rgba(255,255,255,.04);
  }
  .m-track-lbl {
    width: 56px; flex-shrink: 0;
    font-size: 9px; font-weight: 700;
    color: var(--text3); font-family: var(--mono);
    text-transform: uppercase; letter-spacing: .03em;
    padding: 0 5px;
    background: var(--bg2);
    border-right: 1px solid var(--border);
    height: 100%; display: flex; align-items: center;
  }
  .m-track-content { flex: 1; position: relative; height: 100%; }
  .m-clip {
    position: absolute; top: 2px; height: calc(100% - 4px);
    border-radius: 3px; overflow: hidden;
    display: flex; align-items: center; padding: 0 5px;
    font-size: 8px; font-weight: 700; font-family: var(--mono);
    white-space: nowrap; border: 1px solid rgba(255,255,255,.15);
    color: rgba(255,255,255,.8);
    touch-action: none;
  }
  .m-clip-video { background: linear-gradient(135deg,#1a3a5c,#2563eb60); }
  .m-clip-audio { background: linear-gradient(135deg,#1a3a2a,#16a34a60); }
  .m-clip-image { background: linear-gradient(135deg,#3a2a1a,#d9770060); }
  .m-clip.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
  #m-playhead {
    position: absolute; top: 0; bottom: 0; width: 1.5px;
    background: var(--red); pointer-events: none; z-index: 5;
    left: 56px;
  }
  #m-playhead::before {
    content: '';
    position: absolute; top: 0; left: -3px;
    border: 3px solid transparent;
    border-top: 5px solid var(--red);
  }

  /* ── 8. Tab bar (editing modes) ── */
  #m-tabbar {
    display: flex;
    background: var(--bg3);
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    scrollbar-width: none;
    flex-shrink: 0;
  }
  #m-tabbar::-webkit-scrollbar { display: none; }
  .m-tab {
    padding: 10px 14px;
    font-size: 11px; font-weight: 700;
    color: var(--text3);
    white-space: nowrap;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    font-family: var(--sans);
    text-transform: uppercase;
    letter-spacing: .04em;
    flex-shrink: 0;
    transition: color .15s;
    -webkit-tap-highlight-color: transparent;
  }
  .m-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

  /* ── 9. Tab panels ── */
  #m-panels {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 14px;
    background: var(--bg);
    min-height: 0;
  }
  #m-panels::-webkit-scrollbar { display: none; }
  .m-panel { display: none; }
  .m-panel.active { display: block; }

  /* Section label inside panels */
  .m-sec {
    font-size: 10px; font-weight: 700;
    color: var(--text3);
    text-transform: uppercase; letter-spacing: .08em;
    font-family: var(--mono);
    margin: 14px 0 8px;
    display: flex; align-items: center; gap: 8px;
  }
  .m-sec:first-child { margin-top: 0; }
  .m-sec::after { content: ''; flex: 1; height: 1px; background: var(--border); }

  /* ── MEDIA PANEL ── */
  #m-import-grid {
    display: grid;
    grid-template-columns: repeat(3,1fr);
    gap: 8px;
    margin-bottom: 14px;
  }
  .m-import-btn {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px 8px 12px;
    display: flex; flex-direction: column;
    align-items: center; gap: 6px;
    cursor: pointer;
    font-size: 11px; font-weight: 700;
    color: var(--text2); font-family: var(--sans);
    transition: all .15s;
    -webkit-tap-highlight-color: transparent;
  }
  .m-import-btn:active {
    background: var(--surface);
    border-color: var(--accent);
    color: var(--accent);
    transform: scale(.96);
  }
  .m-import-btn .mib-icon { font-size: 28px; }
  #m-media-list {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
  .m-media-thumb {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 8px;
    aspect-ratio: 16/9;
    overflow: hidden;
    cursor: pointer;
    position: relative;
    -webkit-tap-highlight-color: transparent;
  }
  .m-media-thumb video, .m-media-thumb img { width:100%; height:100%; object-fit:cover; }
  .m-media-thumb-lbl {
    position: absolute; bottom: 0; left: 0; right: 0;
    background: linear-gradient(transparent,rgba(0,0,0,.7));
    padding: 8px 5px 4px;
    font-size: 9px; color: #fff; font-family: var(--mono); font-weight: 700;
  }

  /* ── FILTER PANEL ── */
  #m-filter-presets {
    display: grid;
    grid-template-columns: repeat(4,1fr);
    gap: 6px;
    margin-bottom: 14px;
  }
  .m-filter-card {
    background: var(--bg2);
    border: 1.5px solid var(--border);
    border-radius: 8px;
    padding: 4px 4px 6px;
    cursor: pointer; text-align: center;
    font-size: 10px; font-weight: 700; color: var(--text2);
    transition: all .15s;
    -webkit-tap-highlight-color: transparent;
  }
  .m-filter-card:active { transform: scale(.95); }
  .m-filter-card.active { border-color: var(--accent); color: var(--accent); background: rgba(124,106,247,.08); }
  .m-filter-preview {
    height: 36px; border-radius: 5px;
    background: linear-gradient(135deg,#1a2a4a,#4a2a1a);
    margin-bottom: 4px;
  }

  /* ── SHARED SLIDER ROW ── */
  .m-row {
    display: flex; align-items: center; gap: 8px;
    margin-bottom: 10px;
  }
  .m-lbl {
    font-size: 11px; color: var(--text2); font-weight: 600;
    min-width: 72px; flex-shrink: 0;
  }
  .m-val {
    font-family: var(--mono); font-size: 10px;
    color: var(--text3); min-width: 30px; text-align: right;
    flex-shrink: 0;
  }
  .m-slider { flex: 1; accent-color: var(--accent); }

  /* ── TEXT PANEL ── */
  .m-add-btn {
    width: 100%; padding: 12px;
    background: var(--bg2); border: 1px solid var(--border2);
    border-radius: 10px; color: var(--text); font-size: 13px;
    font-weight: 700; font-family: var(--sans);
    cursor: pointer; text-align: center; margin-bottom: 12px;
    -webkit-tap-highlight-color: transparent;
  }
  .m-add-btn:active { background: var(--surface); }
  #m-text-list { margin-bottom: 12px; }
  .m-text-item {
    background: var(--bg2); border: 1px solid var(--border);
    border-radius: 8px; padding: 10px 12px; margin-bottom: 6px;
    cursor: pointer; display: flex; align-items: center;
    justify-content: space-between;
    -webkit-tap-highlight-color: transparent;
  }
  .m-text-item.active { border-color: var(--accent); }
  #m-text-edit { background: var(--bg2); border: 1px solid var(--border); border-radius: 10px; padding: 12px; }

  /* ── BUTTON GRID ── */
  .m-btn-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 8px; }
  .m-btn-grid-4 { display: grid; grid-template-columns: repeat(4,1fr); gap: 6px; margin-bottom: 8px; }
  .m-btn {
    padding: 10px 6px; background: var(--bg2);
    border: 1px solid var(--border); border-radius: 8px;
    font-size: 12px; font-weight: 700; color: var(--text2);
    font-family: var(--sans); cursor: pointer; text-align: center;
    -webkit-tap-highlight-color: transparent; transition: all .15s;
  }
  .m-btn:active { background: var(--surface); border-color: var(--accent); color: var(--accent); transform: scale(.96); }
  .m-btn.danger { color: var(--red); border-color: rgba(248,113,113,.25); }

  /* ── TRANSITIONS PANEL ── */
  #m-trans-grid {
    display: grid;
    grid-template-columns: repeat(4,1fr);
    gap: 6px;
    margin-bottom: 12px;
  }
  .m-trans-card {
    background: var(--bg2); border: 1.5px solid var(--border);
    border-radius: 8px; padding: 8px 4px; cursor: pointer;
    text-align: center; font-size: 10px; font-weight: 700; color: var(--text2);
    -webkit-tap-highlight-color: transparent; transition: all .15s;
  }
  .m-trans-card:active { transform: scale(.95); }
  .m-trans-card.active { border-color: var(--accent); color: var(--accent); background: rgba(124,106,247,.08); }
  .m-trans-icon { font-size: 18px; margin-bottom: 3px; }

  /* ── STICKERS PANEL ── */
  #m-sticker-grid {
    display: grid;
    grid-template-columns: repeat(8,1fr);
    gap: 5px;
    margin-bottom: 12px;
  }
  .m-sticker-btn {
    font-size: 28px; text-align: center;
    padding: 4px 2px; border-radius: 6px;
    cursor: pointer; background: var(--bg2);
    border: 1px solid transparent; transition: all .12s;
    -webkit-tap-highlight-color: transparent;
  }
  .m-sticker-btn:active { background: var(--surface); border-color: var(--accent); transform: scale(1.15); }

  /* ── COLOR GRADE ── */
  #m-lut-grid {
    display: grid;
    grid-template-columns: repeat(3,1fr);
    gap: 7px;
    margin-bottom: 14px;
  }
  .m-lut-card {
    border-radius: 8px; overflow: hidden;
    cursor: pointer; border: 2px solid transparent;
    aspect-ratio: 16/9; position: relative;
    -webkit-tap-highlight-color: transparent;
    transition: border-color .15s;
  }
  .m-lut-card.active { border-color: var(--accent); }
  .m-lut-swatch { width: 100%; height: 100%; }
  .m-lut-lbl {
    position: absolute; bottom: 0; left: 0; right: 0;
    background: rgba(0,0,0,.6);
    font-size: 9px; font-weight: 700; color: #fff;
    text-align: center; padding: 2px; font-family: var(--mono);
  }

  /* ── NUMBER INPUT ── */
  .m-num-input {
    flex: 1; padding: 8px 10px;
    background: var(--bg3); border: 1px solid var(--border);
    border-radius: 7px; color: var(--text);
    font-size: 13px; font-family: var(--mono);
    outline: none; -webkit-appearance: none;
  }
  .m-num-input:focus { border-color: var(--accent); }

  /* ── TEXT INPUT ── */
  .m-text-input {
    width: 100%; padding: 10px 12px;
    background: var(--bg3); border: 1px solid var(--border);
    border-radius: 8px; color: var(--text);
    font-size: 14px; font-family: var(--sans);
    outline: none; margin-bottom: 8px;
  }
  .m-text-input:focus { border-color: var(--accent); }

  /* ── SELECT ── */
  .m-select {
    flex: 1; padding: 8px 10px;
    background: var(--bg3); border: 1px solid var(--border);
    border-radius: 7px; color: var(--text);
    font-size: 12px; font-family: var(--sans); outline: none;
  }

  /* ── COLOR PICK ROW ── */
  .m-color-pick { width: 40px; height: 34px; padding: 3px; background: var(--bg3); border: 1px solid var(--border); border-radius: 7px; cursor: pointer; }

}

/* ════════════════════════════════════
   TABLET  600–900px
   Keep desktop layout but adapt it
════════════════════════════════════ */
@media (min-width: 600px) and (max-width: 900px) {
  :root { --timeline-h: 155px; }
  .tools-bar { display: none; }
  .right-panel { display: none; }
  header { padding: 0 12px; gap: 6px; height: 48px; }
  .header-sep { display: none; }
  #rec-badge { display: none !important; }
  #rec-btn { display: none; }
  .hbtn:not(.primary):not(#btn-undo):not(#btn-redo) { display: none; }
  #btn-undo, #btn-redo { padding: 6px 10px; font-size: 11px; }
  .hbtn.primary { padding: 7px 14px; }
  .timeline-header { overflow-x: auto; scrollbar-width: none; }
  .timeline-header::-webkit-scrollbar { display: none; }
}

/* ═══════════════════════════════════════════════
   MOBILE TOOLBAR  (tablet + phone horizontal bar)
   Used on 600–900px tablets where tools-bar is
   hidden and the right panel is hidden too.
═══════════════════════════════════════════════ */

#mobile-toolbar {
  display: none;
  height: 46px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
  flex-shrink: 0;
  -webkit-overflow-scrolling: touch;
}
#mobile-toolbar::-webkit-scrollbar { display: none; }

.mobile-toolbar-inner {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 0 12px;
  height: 100%;
  min-width: max-content;
}

.mtool-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 12px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text2);
  cursor: pointer;
  font-family: var(--sans);
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
  transition: all .15s;
  flex-shrink: 0;
  height: 32px;
}
.mtool-btn:hover { background: var(--surface); color: var(--text); border-color: var(--border2); }
.mtool-btn:active { transform: scale(.95); }
.mtool-btn.active {
  background: linear-gradient(135deg, var(--accent3), var(--accent));
  border-color: transparent;
  color: #fff;
}
.mtool-btn.primary {
  background: linear-gradient(135deg, var(--accent3), var(--accent));
  border-color: transparent;
  color: #fff;
  box-shadow: 0 2px 10px rgba(124,106,247,.3);
}
.mtool-btn.primary:hover { opacity: .9; }
.mtool-sep {
  width: 1px;
  height: 20px;
  background: var(--border2);
  margin: 0 3px;
  flex-shrink: 0;
}

/* Show mobile toolbar on tablet */
@media (min-width: 600px) and (max-width: 900px) {
  #mobile-toolbar { display: flex; }
}

/* Show mobile toolbar on phone too (v3 mobile app hides desktop toolbar anyway) */
@media (max-width: 599px) {
  #mobile-toolbar { display: none; } /* phone uses #m-app instead */
}

/* ── MOBILE FREE BADGE ── */
#m-free-badge {
  font-size: 9px;
  font-weight: 700;
  font-family: var(--mono);
  padding: 2px 7px;
  background: rgba(52,211,153,.12);
  border: 1px solid rgba(52,211,153,.3);
  border-radius: 20px;
  color: var(--green);
  letter-spacing: .04em;
  text-transform: uppercase;
  flex-shrink: 0;
  white-space: nowrap;
}

/* ── MOBILE FOOTER ── */
#m-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px 10px;
  background: var(--bg2);
  border-top: 1px solid var(--border);
  font-size: 10px;
  color: var(--text3);
  font-family: var(--mono);
  flex-shrink: 0;
}
#m-footer strong { color: var(--accent2); font-weight: 700; }
#m-footer a { color: var(--text3); text-decoration: none; }
#m-footer a:hover { color: var(--accent); }
.m-footer-dot { color: var(--text3); opacity: .5; }
.m-footer-free { color: var(--green); font-weight: 700; }
.m-heart {
  color: var(--red);
  display: inline-block;
  animation: hb .9s ease-in-out infinite;
}
@keyframes hb { 0%,100%{transform:scale(1);} 50%{transform:scale(1.3);} }
