:root {
  --bg: #0b0c0e;
  --surface: #121316;
  --elevated: #18191d;
  --fg: #ecece8;
  --muted: #9a9a96;
  --subtle: #6e6e6a;
  --border: #26272b;
  --accent: #d8dce4;
  --danger: #c45c5c;
  --ok: #6ea37c;
  --stage: #0e1013;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body, #app { height: 100%; }
body {
  background: var(--bg);
  color: var(--fg);
  font-family: "IBM Plex Sans", ui-sans-serif, system-ui, -apple-system, sans-serif;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, select { font-family: inherit; color: inherit; background: var(--elevated); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 10px; width: 100%; }
input:focus, select:focus { outline: 1px solid var(--accent); }

/* Loading */
#boot {
  position: fixed; inset: 0; z-index: 100;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; background: var(--bg);
}
#boot .title { font-size: 15px; letter-spacing: -0.02em; }
#boot .sub { font-size: 12px; color: var(--muted); }
#boot.hidden { display: none; }

/* Shell */
.app-shell {
  display: flex; flex-direction: column; height: 100%;
  max-width: 560px; margin: 0 auto;
  background: var(--bg);
}

/* Top bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 10px; gap: 8px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 6px; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  color: var(--muted); background: transparent;
}
.icon-btn:hover, .icon-btn:active { background: var(--elevated); color: var(--fg); }
.icon-btn:disabled { opacity: 0.35; pointer-events: none; }
.icon-btn.brand {
  width: 34px; height: 34px; border-radius: 10px;
  background: var(--elevated); color: var(--fg); font-weight: 700; font-size: 13px;
}
.btn-pill {
  height: 34px; padding: 0 14px; border-radius: 999px;
  background: var(--accent); color: var(--bg); font-size: 13px; font-weight: 600;
  display: inline-flex; align-items: center; gap: 6px;
}
.btn-pill.ghost {
  background: var(--elevated); color: var(--fg); border: 1px solid var(--border);
}
.btn-block {
  width: 100%; height: 40px; border-radius: 12px;
  background: var(--elevated); border: 1px solid var(--border);
  font-size: 13px; color: var(--fg);
}
.btn-block.primary { background: var(--accent); color: var(--bg); border-color: transparent; font-weight: 600; }
.btn-block:active { opacity: 0.85; }

/* Main views */
.views { flex: 1; min-height: 0; position: relative; }
.view { display: none; flex-direction: column; height: 100%; }
.view.active { display: flex; }

/* Canvas */
.canvas-view { background: var(--stage); }
.canvas-toolbar {
  display: flex; align-items: center; gap: 4px;
  padding: 6px 10px; color: var(--muted); font-size: 12px;
}
.canvas-toolbar .zoom { margin-left: auto; opacity: 0.7; }
.stage {
  flex: 1; min-height: 0;
  display: flex; align-items: center; justify-content: center;
  background-image:
    linear-gradient(to right, rgba(255,255,255,0.035) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255,255,255,0.035) 1px, transparent 1px);
  background-size: 24px 24px;
  position: relative;
}
.emoji-card {
  width: min(72vw, 280px); aspect-ratio: 1;
  border-radius: 22px;
  background: #1a1b1f;
  box-shadow: 0 18px 48px rgba(0,0,0,0.42);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden; position: relative;
}
#lottieBox { width: 88%; height: 88%; }
#lottieBox svg, #lottieBox canvas { width: 100% !important; height: 100% !important; }
.drop-hint {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px; color: var(--subtle); font-size: 13px; pointer-events: none;
}
.drop-hint.hidden { display: none; }

.timeline {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px calc(10px + var(--safe-b));
  border-top: 1px solid var(--border);
  background: rgba(18,19,22,0.92);
  backdrop-filter: blur(12px);
}
.timeline input[type=range] { flex: 1; accent-color: var(--accent); height: 4px; }
#frameLabel { font-size: 11px; color: var(--muted); min-width: 64px; text-align: right; font-variant-numeric: tabular-nums; }

/* Layers */
.panel-head {
  padding: 12px 14px 8px; font-size: 11px; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--muted);
}
.layer-list { flex: 1; overflow-y: auto; padding: 0 8px 16px; }
.layer-row {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 12px;
  border: 1px solid transparent; margin-bottom: 4px;
}
.layer-row.active { background: var(--elevated); border-color: var(--border); }
.layer-row .name { flex: 1; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.layer-row .eye { color: var(--muted); font-size: 14px; padding: 4px; }

/* Edit / inspector */
.tabs {
  display: flex; gap: 4px; overflow-x: auto;
  padding: 10px 12px; border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.tab {
  padding: 6px 12px; border-radius: 999px; font-size: 11px;
  color: var(--muted); white-space: nowrap; flex-shrink: 0;
}
.tab.active { background: var(--elevated); color: var(--fg); }
.tab-body { flex: 1; overflow-y: auto; padding: 14px; }
.section-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--muted); margin: 14px 0 8px;
}
.section-label:first-child { margin-top: 0; }
.hint { font-size: 12px; color: var(--muted); line-height: 1.4; margin-bottom: 10px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.motion-btn, .fx-btn {
  height: 40px; border-radius: 12px;
  background: var(--elevated); border: 1px solid var(--border);
  font-size: 13px;
}
.motion-btn:active, .fx-btn:active { border-color: var(--accent); }
.color-swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch {
  width: 36px; height: 36px; border-radius: 10px;
  border: 2px solid var(--border);
}
.swatch.active { border-color: var(--accent); }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; font-size: 12px; color: var(--muted); }
.row { display: flex; gap: 8px; }

/* Bottom nav */
.bottom-nav {
  display: flex; border-top: 1px solid var(--border);
  background: var(--surface);
  padding-bottom: var(--safe-b);
  flex-shrink: 0;
}
.nav-item {
  flex: 1; height: 52px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; font-size: 10px; color: var(--muted);
}
.nav-item.active { color: var(--fg); }
.nav-item svg { width: 18px; height: 18px; }

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.55);
  z-index: 50; display: flex; align-items: flex-end; justify-content: center;
}
.modal-backdrop.hidden { display: none; }
.modal {
  width: 100%; max-width: 560px; max-height: 78vh;
  background: var(--surface); border-radius: 20px 20px 0 0;
  border: 1px solid var(--border); border-bottom: none;
  display: flex; flex-direction: column;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--border); font-size: 15px; font-weight: 600;
}
.modal-body { overflow-y: auto; padding: 14px; }
.tpl-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tpl-card {
  border: 1px solid var(--border); border-radius: 14px;
  background: var(--bg); padding: 12px; text-align: left;
}
.tpl-card:active { border-color: var(--accent); }
.tpl-swatch {
  aspect-ratio: 1; border-radius: 10px; border: 1px solid var(--border);
  margin-bottom: 8px; background: var(--elevated);
}
.tpl-name { font-size: 13px; font-weight: 600; word-break: break-word; }
.tpl-hint { font-size: 11px; color: var(--muted); margin-top: 2px; }

.fmt-list { display: flex; flex-direction: column; gap: 8px; }
.fmt-btn {
  height: 48px; border-radius: 14px; border: 1px solid var(--border);
  background: var(--elevated); font-size: 14px; text-align: left; padding: 0 16px;
}

@media (min-width: 720px) {
  .app-shell { max-width: 960px; border-left: 1px solid var(--border); border-right: 1px solid var(--border); }
  .bottom-nav { display: none; }
  .views { display: grid; grid-template-columns: 220px 1fr 300px; }
  .view { display: flex !important; }
  .view[data-view="layers"] { border-right: 1px solid var(--border); }
  .view[data-view="edit"] { border-left: 1px solid var(--border); }
}
