:root {
  --bg: #0b0e14;
  --panel: #141925;
  --panel-2: #1c2230;
  --line: #262d3d;
  --text: #e6e9ef;
  --muted: #8a93a6;
  --accent: #4f8cff;
  --danger: #ff5d6c;
  --radius: 14px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  height: 100%;
  overscroll-behavior: none;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1.2em; margin: 8px 0 0; font-size: 14px; }

/* ===================== Disguise: fake video editor ("MotionSnap") ===================== */
.editor {
  --eink:#f2f2f5; --emuted:#8b8b96; --eline:#26262e; --epanel:#17171d;
  --eaccent:#22e0c8; --eaccent2:#7c5cff;
  position: fixed; inset: 0; background: #0e0e12; color: var(--eink);
  display: flex; flex-direction: column; z-index: 30; overflow: hidden;
}
.ed-screen { position: absolute; inset: 0; display: flex; flex-direction: column; background: #0e0e12; }
.ed-topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: max(env(safe-area-inset-top), 16px) 18px 14px;
}
.ed-brand { font-size: 20px; font-weight: 800; letter-spacing: -0.3px;
  background: linear-gradient(90deg, var(--eaccent), var(--eaccent2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.ed-avatar { width: 34px; height: 34px; border-radius: 50%; background: linear-gradient(135deg, var(--eaccent2), var(--eaccent));
  display: flex; align-items: center; justify-content: center; font-weight: 700; color: #0e0e12; font-size: 15px; }
.ed-icon-btn { background: none; border: none; color: var(--eink); font-size: 28px; width: 34px; height: 34px; cursor: pointer; }
.ed-export-btn { background: linear-gradient(90deg, var(--eaccent2), var(--eaccent)); color: #0e0e12;
  border: none; font-weight: 700; font-size: 14px; padding: 8px 18px; border-radius: 20px; cursor: pointer; }

.ed-new-project { margin: 8px 18px 4px; padding: 18px; border-radius: 16px; border: none; cursor: pointer;
  background: linear-gradient(120deg, var(--eaccent2), var(--eaccent)); color: #0e0e12; font-size: 17px; font-weight: 800;
  display: flex; align-items: center; justify-content: center; gap: 10px; }
.ed-new-project .plus { font-size: 22px; }
.ed-section-title { color: var(--emuted); font-size: 13px; font-weight: 600; padding: 20px 18px 10px; text-transform: uppercase; letter-spacing: 0.5px; }
.ed-projects { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; padding: 0 18px 30px; overflow-y: auto; }
.ed-proj { cursor: default; }
.ed-thumb { width: 100%; aspect-ratio: 4/5; border-radius: 12px; margin-bottom: 7px; }
.ed-thumb.g1 { background: linear-gradient(135deg,#3a2a5c,#22354d); }
.ed-thumb.g2 { background: linear-gradient(135deg,#4d3320,#5c2a3a); }
.ed-thumb.g3 { background: linear-gradient(135deg,#204d3a,#22354d); }
.ed-thumb.g4 { background: linear-gradient(135deg,#4d4620,#2a3a5c); }
.ed-proj-name { font-size: 13px; color: var(--eink); }

.ed-ratio-title { color: var(--emuted); font-size: 14px; text-align: center; padding: 20px 0 24px; }
.ed-ratios { display: flex; justify-content: center; gap: 20px; padding: 10px 18px; }
.ed-ratio { display: flex; flex-direction: column; align-items: center; gap: 10px; cursor: pointer; opacity: 0.6; }
.ed-ratio.active { opacity: 1; }
.ed-ratio-box { border: 2px solid var(--emuted); border-radius: 6px; background: var(--epanel); }
.ed-ratio.active .ed-ratio-box { border-color: var(--eaccent); }
.ed-ratio-box.tall { width: 54px; height: 96px; }
.ed-ratio-box.square { width: 80px; height: 80px; }
.ed-ratio-box.wide { width: 96px; height: 54px; }
.ed-ratio span { font-size: 13px; color: var(--eink); }
.ed-continue-btn { margin: 34px 18px 0; padding: 16px; border-radius: 14px; border: none; cursor: pointer;
  background: linear-gradient(90deg, var(--eaccent2), var(--eaccent)); color: #0e0e12; font-size: 16px; font-weight: 800; }

.ed-preview { flex: 1; margin: 6px 14px; border-radius: 14px; background: #000;
  display: flex; align-items: center; justify-content: center; min-height: 200px;
  background-image: radial-gradient(circle at 50% 40%, #1a1a24, #000); }
.ed-preview-hint { color: var(--emuted); font-size: 13px; }
.ed-timeline { display: flex; gap: 6px; padding: 8px 14px; align-items: center; overflow-x: auto; }
.ed-clip { flex: 0 0 auto; width: 96px; height: 42px; border-radius: 6px;
  background: linear-gradient(120deg,#2a2a38,#33333f); border: 1px solid var(--eline); }
.ed-clip.short { width: 48px; }
.ed-toolbar { display: flex; justify-content: space-around; padding: 12px 8px max(env(safe-area-inset-bottom),16px);
  border-top: 1px solid var(--eline); background: var(--epanel); }
.ed-tool { display: flex; flex-direction: column; align-items: center; gap: 5px; color: var(--emuted);
  font-size: 11px; cursor: pointer; flex: 1; }
.ed-tool.active { color: var(--eaccent); }
.ed-ic { font-size: 20px; width: 34px; height: 34px; border-radius: 9px; background: #23232c;
  display: flex; align-items: center; justify-content: center; }
.ed-tool.active .ed-ic { background: rgba(34,224,200,0.15); }

/* inline SVG icon sizing per context */
.ic-svg { width: 20px; height: 20px; display: block; }
.ed-ic .ic-svg { width: 19px; height: 19px; }
.ed-quick-ic .ic-svg { width: 24px; height: 24px; }
.ed-nav-ic .ic-svg { width: 20px; height: 20px; }
.ed-nav-plus .ic-svg { width: 22px; height: 22px; }
.ed-mini-btn .ic-svg { width: 17px; height: 17px; margin: auto; }
.ed-play-btn .ic-svg { width: 15px; height: 15px; margin: auto; }
.ed-icon-btn .ic-svg { width: 20px; height: 20px; margin: auto; }
.ed-pro-ic { display: inline-flex; vertical-align: -3px; margin-right: 4px; }
.ed-pro-ic .ic-svg { width: 15px; height: 15px; }
.ed-menu-ic { display: inline-flex; width: 24px; }
.ed-menu-ic .ic-svg { width: 21px; height: 21px; }
.ed-list-play .ic-svg { width: 14px; height: 14px; margin: auto; }
.ed-subtool .ed-ic .ic-svg { width: 20px; height: 20px; }

.ed-sheet { position: absolute; left: 0; right: 0; bottom: 0; z-index: 6; background: var(--epanel);
  border-top: 1px solid var(--eline); border-radius: 18px 18px 0 0; padding: 10px 16px max(env(safe-area-inset-bottom),20px);
  box-shadow: 0 -10px 30px rgba(0,0,0,0.4); }
.ed-sheet-handle { width: 40px; height: 4px; border-radius: 2px; background: #3a3a46; margin: 4px auto 12px; }
.ed-sheet-title { font-size: 15px; font-weight: 700; margin-bottom: 14px; }
.ed-filters-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; max-height: 44vh; overflow-y: auto; }
.ed-filter { text-align: center; cursor: pointer; }
.ed-filter-sw { width: 100%; aspect-ratio: 1; border-radius: 12px; margin-bottom: 6px; border: 2px solid transparent; }
.ed-filter.active .ed-filter-sw { border-color: var(--eaccent); }
.ed-filter-name { font-size: 11px; color: var(--emuted); }
.ed-code-input { width: 100%; padding: 14px; font-size: 16px; border-radius: 12px; border: 1px solid var(--eline);
  background: #0e0e12; color: var(--eink); outline: none; margin-bottom: 4px; }
.ed-code-input:focus { border-color: var(--eaccent); }

/* --- browse screens: scroll area + bottom nav spacing --- */
.ed-browse .ed-scroll { position: absolute; inset: 0 0 64px 0; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.ed-top-actions { display: flex; align-items: center; gap: 10px; }
.ed-pro-chip { background: linear-gradient(90deg,#ffd166,#ff8f5e); color: #1a1a1e; border: none; font-weight: 800;
  font-size: 12px; padding: 6px 12px; border-radius: 20px; cursor: pointer; }

.ed-quick-row { display: flex; gap: 14px; overflow-x: auto; padding: 16px 18px 6px; }
.ed-quick { flex: 0 0 auto; display: flex; flex-direction: column; align-items: center; gap: 6px; cursor: pointer; }
.ed-quick-ic { width: 54px; height: 54px; border-radius: 16px; background: var(--epanel); border: 1px solid var(--eline);
  display: flex; align-items: center; justify-content: center; font-size: 24px; }
.ed-quick span { font-size: 11px; color: var(--emuted); }
.ed-thumb { position: relative; }
.ed-thumb-dur { position: absolute; right: 6px; bottom: 6px; background: rgba(0,0,0,0.6); color: #fff;
  font-size: 10px; padding: 1px 5px; border-radius: 4px; }
.ed-ratio-box.portrait { width: 62px; height: 78px; }

/* --- chips --- */
.ed-chips { display: flex; gap: 8px; overflow-x: auto; padding: 10px 18px; }
.ed-chip { flex: 0 0 auto; padding: 7px 15px; border-radius: 18px; background: var(--epanel); border: 1px solid var(--eline);
  color: var(--emuted); font-size: 13px; cursor: pointer; }
.ed-chip.active { background: rgba(34,224,200,0.15); color: var(--eaccent); border-color: var(--eaccent); }

/* --- templates grid --- */
.ed-templates-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; padding: 8px 18px 24px; }
.ed-tpl { cursor: pointer; }
.ed-tpl-thumb { width: 100%; aspect-ratio: 9/16; border-radius: 12px; position: relative; overflow: hidden; }
.ed-tpl-uses { position: absolute; left: 6px; bottom: 6px; color: #fff; font-size: 11px; text-shadow: 0 1px 3px rgba(0,0,0,.6); }
.ed-tpl-name { font-size: 12px; color: var(--eink); margin-top: 6px; }

/* --- profile --- */
.ed-profile { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 16px; }
.ed-avatar.big { width: 76px; height: 76px; font-size: 32px; }
.ed-profile-name { font-size: 18px; font-weight: 700; }
.ed-profile-handle { font-size: 13px; color: var(--emuted); }
.ed-stats { display: flex; gap: 30px; margin-top: 14px; }
.ed-stats div { display: flex; flex-direction: column; align-items: center; }
.ed-stats b { font-size: 18px; } .ed-stats span { font-size: 12px; color: var(--emuted); }
.ed-menu { padding: 10px 16px 30px; display: flex; flex-direction: column; gap: 2px; }
.ed-menu-item { display: flex; align-items: center; gap: 12px; padding: 15px 12px; border-radius: 12px; cursor: pointer; font-size: 15px; }
.ed-menu-item:active { background: var(--epanel); }
.ed-menu-item span { flex: 1; } .ed-menu-item i { color: var(--emuted); font-style: normal; font-size: 20px; }

/* --- editor top / playbar / timeline extras --- */
.ed-editor-top .ed-top-mid { display: flex; align-items: center; gap: 10px; }
.ed-mini-btn { background: var(--epanel); border: 1px solid var(--eline); color: var(--eink); width: 32px; height: 32px;
  border-radius: 9px; font-size: 16px; cursor: pointer; }
.ed-res-badge { font-size: 11px; color: var(--emuted); border: 1px solid var(--eline); border-radius: 6px; padding: 3px 7px; }
.ed-stage { flex: 1; display: flex; min-height: 0; }
.ed-preview { position: relative; flex: 1; margin: 6px 14px; border-radius: 14px; background: #000; overflow: hidden;
  display: flex; align-items: center; justify-content: center; min-height: 180px; }
.ed-preview-media { position: absolute; inset: 0; background-image: radial-gradient(circle at 50% 40%, #1a1a24, #000);
  transition: filter .12s, background .2s; }
.ed-overlay-layer { position: absolute; inset: 0; pointer-events: none; }
.ed-ov-text { position: absolute; left: 50%; top: 50%; transform: translate(-50%,-50%); color: #fff; font-weight: 700;
  font-size: 26px; text-shadow: 0 2px 8px rgba(0,0,0,.5); white-space: nowrap; }
.ed-ov-sticker { position: absolute; font-size: 40px; }
.ed-preview-hint { position: relative; color: var(--emuted); font-size: 13px; pointer-events: none; }

.ed-playbar { display: flex; align-items: center; gap: 10px; padding: 6px 16px; }
.ed-play-btn { width: 34px; height: 34px; border-radius: 50%; border: none; background: var(--eink); color: #0e0e12;
  font-size: 14px; cursor: pointer; }
.ed-time { font-size: 11px; color: var(--emuted); font-variant-numeric: tabular-nums; }
.ed-scrub { flex: 1; height: 4px; border-radius: 2px; background: #2a2a34; overflow: hidden; }
.ed-scrub-fill { height: 100%; width: 0%; background: var(--eaccent); }
.ed-clip { position: relative; }
.ed-clip span { position: absolute; left: 6px; bottom: 4px; font-size: 10px; color: var(--emuted); }
.ed-add-clip { flex: 0 0 auto; width: 42px; height: 42px; border-radius: 8px; border: 1px dashed var(--emuted);
  background: transparent; color: var(--emuted); font-size: 20px; cursor: pointer; }

/* --- toolbar scrolls now --- */
.ed-toolbar { overflow-x: auto; justify-content: flex-start; gap: 6px; }
.ed-tool { flex: 0 0 auto; min-width: 58px; }

/* --- sheet head + generic body --- */
.ed-sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.ed-sheet-head .ed-sheet-title { margin-bottom: 0; }
.ed-sheet-close { width: 30px; height: 30px; border-radius: 50%; border: none; background: var(--eaccent); color: #0e0e12;
  font-size: 15px; font-weight: 800; cursor: pointer; }
.ed-sheet-body { max-height: 46vh; overflow-y: auto; }

/* sub-tool button grid (Edit) */
.ed-subtools { display: grid; grid-template-columns: repeat(4,1fr); gap: 14px; }
.ed-subtool { display: flex; flex-direction: column; align-items: center; gap: 6px; color: var(--emuted); font-size: 11px; cursor: pointer; }
.ed-subtool .ed-ic { font-size: 18px; }

/* sliders (Adjust / Speed) */
.ed-slider-row { margin: 14px 0; }
.ed-slider-row label { display: flex; justify-content: space-between; font-size: 13px; color: var(--emuted); margin-bottom: 8px; }
.ed-slider-row input[type=range] { width: 100%; accent-color: var(--eaccent); }

/* list rows (Audio) */
.ed-list-row { display: flex; align-items: center; gap: 12px; padding: 12px 4px; border-bottom: 1px solid var(--eline); }
.ed-list-play { width: 34px; height: 34px; border-radius: 50%; background: var(--epanel); border: 1px solid var(--eline);
  color: var(--eaccent); font-size: 14px; cursor: pointer; }
.ed-list-meta { flex: 1; } .ed-list-meta b { display: block; font-size: 14px; } .ed-list-meta span { font-size: 12px; color: var(--emuted); }
.ed-list-add { background: none; border: 1px solid var(--eaccent); color: var(--eaccent); border-radius: 16px; padding: 5px 12px; font-size: 12px; cursor: pointer; }

/* text tool */
.ed-text-input { width: 100%; padding: 13px; font-size: 15px; border-radius: 12px; border: 1px solid var(--eline);
  background: #0e0e12; color: var(--eink); outline: none; margin-bottom: 12px; }
.ed-swatches { display: flex; gap: 10px; flex-wrap: wrap; }
.ed-swatch { width: 34px; height: 34px; border-radius: 50%; cursor: pointer; border: 2px solid transparent; }
.ed-swatch.active { border-color: var(--eaccent); }

/* sticker/emoji grid */
.ed-emoji-grid { display: grid; grid-template-columns: repeat(6,1fr); gap: 8px; }
.ed-emoji { font-size: 28px; text-align: center; cursor: pointer; padding: 4px 0; }

/* format ratio row inside sheet */
.ed-ratio-row { display: flex; gap: 16px; justify-content: center; flex-wrap: wrap; }

/* --- bottom nav --- */
.ed-bottomnav { position: absolute; left: 0; right: 0; bottom: 0; height: calc(56px + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom); background: var(--epanel); border-top: 1px solid var(--eline);
  display: flex; align-items: center; justify-content: space-around; z-index: 8; }
.ed-nav-item { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 10px; color: var(--emuted); cursor: pointer; flex: 1; }
.ed-nav-item.active { color: var(--eink); }
.ed-nav-ic { font-size: 18px; }
.ed-nav-plus { width: 46px; height: 32px; border-radius: 10px; background: linear-gradient(90deg,var(--eaccent2),var(--eaccent));
  color: #0e0e12; display: flex; align-items: center; justify-content: center; font-size: 22px; font-weight: 800; cursor: pointer; }

/* --- toast --- */
.ed-toast { position: absolute; left: 50%; bottom: 90px; transform: translateX(-50%); background: rgba(20,20,26,0.96);
  color: var(--eink); border: 1px solid var(--eline); padding: 11px 18px; border-radius: 24px; font-size: 13px; z-index: 20;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4); white-space: nowrap; }

.lock-card button.lock-link { background: none; border: none; color: var(--muted); font-size: 13px;
  margin-top: 18px; cursor: pointer; text-decoration: underline; padding: 6px; font-weight: 500; }
.sync-status { margin: 0 14px 8px; padding: 8px 12px; border-radius: 8px; background: var(--panel-2);
  font-size: 13px; color: var(--muted); }

/* ===================== Lock screen ===================== */
.lock {
  position: fixed; inset: 0; z-index: 25;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  background: radial-gradient(1200px 600px at 50% -10%, #18203a 0%, var(--bg) 60%);
}
.lock-card { width: 100%; max-width: 340px; text-align: center; }
.lock-logo { font-size: 48px; margin-bottom: 8px; }
.lock-card h1 { margin: 0 0 4px; font-size: 26px; letter-spacing: 0.5px; }
.lock-card form { display: flex; flex-direction: column; gap: 12px; margin-top: 22px; }
.lock-card input {
  padding: 15px 16px; font-size: 16px;
  background: var(--panel); border: 1px solid var(--line);
  color: var(--text); border-radius: var(--radius); outline: none;
}
.lock-card input:focus { border-color: var(--accent); }
.lock-card button {
  padding: 15px; font-size: 16px; font-weight: 600;
  background: var(--accent); color: #fff; border: none;
  border-radius: var(--radius); cursor: pointer;
}

/* ===================== App shell ===================== */
.app { display: flex; flex-direction: column; height: 100dvh; }
.topbar {
  display: flex; align-items: center; gap: 8px;
  padding: max(env(safe-area-inset-top), 12px) 14px 12px;
  background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.crumbs { flex: 1; font-weight: 600; font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  width: 38px; height: 38px; border-radius: 10px; font-size: 20px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.toolbar { display: flex; gap: 8px; padding: 12px 14px; align-items: center; flex-wrap: wrap; }
.toolbar input[type="search"] {
  flex: 1 1 100%; min-width: 0; padding: 11px 14px; font-size: 15px;
  background: var(--panel); border: 1px solid var(--line); color: var(--text);
  border-radius: 10px; outline: none;
}
.toolbar input[type="search"]:focus { border-color: var(--accent); }
.toolbar .row { display: flex; gap: 8px; flex: 1; }
.btn {
  white-space: nowrap; padding: 11px 13px; font-size: 14px; font-weight: 600;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 10px; cursor: pointer; display: inline-flex; align-items: center; flex: 1; justify-content: center;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }

.upload-bar {
  margin: 0 14px 8px; height: 30px; border-radius: 8px; background: var(--panel-2);
  position: relative; overflow: hidden; display: flex; align-items: center; justify-content: center;
  font-size: 13px;
}
.upload-fill { position: absolute; left: 0; top: 0; bottom: 0; width: 0%; background: var(--accent); opacity: 0.35; transition: width 0.2s; }
.upload-bar span { position: relative; z-index: 1; }

/* ===================== Grid ===================== */
.grid {
  flex: 1; overflow-y: auto; padding: 6px 14px 40px;
  display: grid; gap: 10px;
  grid-template-columns: repeat(auto-fill, minmax(108px, 1fr));
  align-content: start;
}
.tile {
  position: relative; aspect-ratio: 1; border-radius: 12px; overflow: hidden;
  background: var(--panel); border: 1px solid var(--line); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.tile img, .tile video { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile.folder { flex-direction: column; gap: 6px; }
.tile.folder .ico { font-size: 40px; }
.tile .label {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 16px 8px 6px;
  font-size: 12px; color: #fff; background: linear-gradient(transparent, rgba(0,0,0,0.75));
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tile.folder .label { position: static; background: none; padding: 0 6px 8px; color: var(--text); }
.tile .play {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 34px; color: #fff; text-shadow: 0 1px 6px rgba(0,0,0,0.6); pointer-events: none;
}
.tile .del {
  position: absolute; top: 6px; right: 6px; width: 26px; height: 26px; border-radius: 50%;
  background: rgba(0,0,0,0.55); color: #fff; border: none; font-size: 14px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; z-index: 2;
}
.empty { text-align: center; color: var(--muted); padding: 60px 20px; }

/* ===================== Viewer ===================== */
.viewer {
  position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,0.95);
  display: flex; align-items: center; justify-content: center; padding: 12px;
}
.viewer-content { max-width: 100%; max-height: 100%; display: flex; }
.viewer-content img, .viewer-content video { max-width: 100%; max-height: 92dvh; border-radius: 8px; }
.viewer-close {
  position: absolute; top: max(env(safe-area-inset-top), 14px); right: 16px;
  width: 42px; height: 42px; border-radius: 50%; background: rgba(255,255,255,0.12);
  color: #fff; border: none; font-size: 20px; cursor: pointer; z-index: 41;
}
.spinner { text-align: center; padding: 40px; color: var(--muted); }
