:root {
  --bg: #090E17;
  --bg-elev: #111827;
  --bg-card: #161F30;
  --stroke: #293548;
  --text: #F1F5F9;
  --muted: #94A3B8;
  --accent: #FF6B1A;
  --accent-soft: rgba(255, 107, 26, 0.16);
  --cyan: #22D3EE;
  --cyan-soft: rgba(34, 211, 238, 0.14);
  --green: #10B981;
  --amber: #F59E0B;
  --purple: #A855F7;
  --stage-light: #D8D8D8;
  --stage-dark: #141B26;
  --radius: 14px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.accent-text { color: var(--accent) !important; }
.cyan-text { color: var(--cyan) !important; }
.amber-text { color: var(--amber) !important; }
.muted-text { color: var(--muted) !important; }

.view {
  display: none;
  min-height: 100%;
  flex-direction: column;
}
.view.active {
  display: flex;
}
.builder-view.active {
  height: 100dvh;
  overflow: hidden;
}

/* Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 56px;
  padding: max(8px, env(safe-area-inset-top)) 14px 8px;
  background: var(--bg-elev);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 13.5px;
  letter-spacing: 0.08em;
  color: var(--accent);
}
.brand-icon {
  width: 28px;
  height: 28px;
  border-radius: 7px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.pill-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  height: 36px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--stroke);
  background: rgba(17, 24, 39, 0.92);
  color: var(--text);
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.08s ease, border-color 0.15s ease, background 0.15s ease;
  white-space: nowrap;
}
.pill-btn:hover { border-color: #3B4C66; }
.pill-btn:active { transform: scale(0.96); }
.pill-btn.icon-only { width: 36px; padding: 0; font-size: 16px; }
.pill-btn.active {
  border-color: var(--cyan);
  color: var(--cyan);
  background: var(--cyan-soft);
}
.pill-btn.accent-pill {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 44px;
  padding: 0 16px;
  border-radius: 11px;
  border: 1px solid transparent;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  color: var(--text);
  transition: opacity 0.15s ease, transform 0.08s ease;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn.primary { background: var(--accent); }
.btn.success { background: var(--green); }
.btn.tonal { background: var(--cyan-soft); color: var(--cyan); border-color: rgba(34, 211, 238, 0.25); }
.btn.outline { background: transparent; border-color: var(--stroke); color: var(--text); }
.btn.danger { background: rgba(239, 68, 68, 0.18); border-color: rgba(239, 68, 68, 0.5); color: #FCA5A5; }
.btn.full-width { width: 100%; }

/* Container */
.container {
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  padding: 16px 14px 36px;
}
.container.narrow { max-width: 720px; }

/* Demo Card */
.demo-card {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 16px;
  margin-bottom: 16px;
  border-radius: var(--radius);
  background: linear-gradient(135deg, rgba(34, 211, 238, 0.12), rgba(255, 107, 26, 0.12));
  border: 1px solid rgba(34, 211, 238, 0.35);
}
.demo-info { flex: 1 1 280px; }
.demo-info h2 { margin: 6px 0 4px; font-size: 17px; }
.demo-info p { margin: 0; font-size: 13px; color: var(--muted); line-height: 1.45; }

.badge {
  display: inline-block;
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.06);
}
.badge.cyan { color: var(--cyan); background: var(--cyan-soft); }
.badge.accent { color: var(--accent); background: var(--accent-soft); }
.badge.amber { color: var(--amber); background: rgba(245, 158, 11, 0.16); }
.badge.green { color: var(--green); background: rgba(16, 185, 129, 0.16); }
.badge.purple { color: var(--purple); background: rgba(168, 85, 247, 0.16); }

/* Catalog Controls */
.catalog-controls {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
}
.search-input, .series-select, .text-input {
  width: 100%;
  height: 42px;
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid var(--stroke);
  background: var(--bg-card);
  color: var(--text);
  font-size: 14px;
  outline: none;
}
.search-input:focus, .series-select:focus, .text-input:focus {
  border-color: var(--cyan);
}
.filter-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
.tab-group { display: flex; gap: 6px; }
.series-select {
  width: auto;
  min-width: 165px;
  height: 36px;
  font-size: 12.5px;
  font-weight: 600;
}
.storage-summary {
  margin-left: auto;
  font-size: 12px;
  color: var(--muted);
}

.status-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  border-radius: 12px;
  background: var(--bg-card);
  border: 1px solid var(--stroke);
  font-size: 13px;
  color: var(--muted);
}
.spinner {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--stroke);
  border-top-color: var(--cyan);
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Catalog Grid */
.catalog-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
  gap: 14px;
}

.set-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px;
  border-radius: var(--radius);
  background: var(--bg-card);
  border: 1px solid var(--stroke);
  transition: border-color 0.15s ease;
}
.set-card:hover { border-color: #3B4C66; }

.set-card-top {
  display: flex;
  gap: 12px;
}
.set-cover {
  width: 88px;
  height: 110px;
  border-radius: 10px;
  object-fit: cover;
  background: #0D1320;
  border: 1px solid rgba(255, 255, 255, 0.06);
  flex-shrink: 0;
}
.set-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.set-meta-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
}
.eyebrow {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--cyan);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.status-tag {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--muted);
  white-space: nowrap;
}
.status-tag.offline { color: var(--green); }
.status-tag.update { color: var(--amber); }
.status-tag.downloading { color: var(--cyan); }

.set-name {
  margin: 3px 0 4px;
  font-size: 16.5px;
  font-weight: 800;
  line-height: 1.25;
}
.set-desc {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.35;
}
.set-actions {
  display: flex;
  gap: 8px;
}
.set-actions .btn-main { flex: 1; height: 40px; font-size: 13.5px; }
.set-actions .btn-icon { width: 40px; height: 40px; padding: 0; }

/* Progress Bar */
.progress-block { margin-top: 12px; }
.progress-block.compact { margin-top: 8px; }
.progress-header {
  display: flex;
  justify-content: space-between;
  font-size: 12.5px;
  margin-bottom: 5px;
}
.progress-track {
  height: 7px;
  border-radius: 99px;
  background: #26334A;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  border-radius: 99px;
  transition: width 0.2s ease;
}
.progress-fill.accent { background: var(--accent); }
.progress-fill.cyan { background: var(--cyan); }
.progress-fill.green { background: var(--green); }

/* Set Overview */
.hero-card {
  padding: 16px;
  border-radius: var(--radius);
  background: var(--bg-card);
  border: 1px solid var(--stroke);
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.hero-top { display: flex; gap: 16px; }
.hero-cover {
  width: 112px;
  height: 140px;
  border-radius: 10px;
  object-fit: cover;
  background: #0D1320;
  flex-shrink: 0;
}
.hero-meta h1 { margin: 4px 0 6px; font-size: 22px; line-height: 1.2; }
.hero-meta p { margin: 0 0 6px; font-size: 13px; line-height: 1.4; }
.hero-secondary-actions { display: flex; gap: 8px; }
.hero-secondary-actions .btn { flex: 1; height: 40px; }

.section-heading {
  margin: 22px 0 12px;
  font-size: 16.5px;
  font-weight: 800;
}

.bags-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.bag-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  border-radius: var(--radius);
  background: var(--bg-card);
  border: 1px solid var(--stroke);
  cursor: pointer;
  transition: border-color 0.15s ease;
}
.bag-card:hover { border-color: var(--cyan); }
.bag-card-top { display: flex; align-items: center; gap: 12px; }
.bag-thumb {
  width: 58px;
  height: 72px;
  border-radius: 8px;
  object-fit: cover;
  background: #CFD3D8;
  flex-shrink: 0;
}
.bag-title { font-size: 15px; font-weight: 700; margin: 3px 0 2px; }
.bag-sub { font-size: 12px; color: var(--muted); }
.bag-prog-row { display: flex; align-items: center; gap: 10px; }
.bag-prog-row .progress-track { flex: 1; height: 6px; }
.bag-pct { font-size: 12px; font-weight: 700; color: var(--muted); min-width: 36px; text-align: right; }

/* Builder View */
.builder-topbar { min-height: 52px; padding: max(6px, env(safe-area-inset-top)) 10px 6px; }
.step-pill {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  padding: 0 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--stroke);
  font-size: 13px;
  font-weight: 700;
  overflow: hidden;
  white-space: nowrap;
}
.step-pill span:last-child { overflow: hidden; text-overflow: ellipsis; }
.timer-btn { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 12px; }

.thin-progress { height: 3px; background: #1E293B; width: 100%; }
.thin-progress-fill { height: 100%; background: var(--cyan); transition: width 0.2s ease; }

.stage-container {
  position: relative;
  flex: 1;
  min-height: 0;
  background: var(--stage-light);
  overflow: hidden;
  user-select: none;
  touch-action: none;
  transition: background 0.2s ease;
}
.stage-container.dark { background: var(--stage-dark); }

.canvas-tilt-wrap {
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.06s linear;
}
#builderCanvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
}
#builderCanvas:active { cursor: grabbing; }

.loupe-canvas {
  position: absolute;
  width: 190px;
  height: 190px;
  border-radius: 50%;
  border: 3px solid var(--cyan);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
  pointer-events: none;
  z-index: 15;
  background: var(--stage-light);
}
.confetti-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 18;
}

.badges-container {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: 62%;
  pointer-events: none;
}
.ctx-badge {
  display: inline-block;
  width: fit-content;
  padding: 6px 12px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 700;
  color: #F8FAFC;
  border: 1px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}

.side-tools {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}
.zoom-box {
  display: flex;
  flex-direction: column;
  width: 48px;
  border-radius: 10px;
  border: 1px solid var(--stroke);
  background: rgba(17, 24, 39, 0.92);
  overflow: hidden;
}
.zoom-box button {
  border: none;
  background: transparent;
  color: var(--text);
  height: 32px;
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
}
.zoom-box .zoom-val {
  height: 22px;
  font-size: 10.5px;
  color: var(--muted);
  font-weight: 600;
}
.tool-btn { height: 34px; padding: 0 10px; font-size: 12px; }
.tool-btn.active {
  background: rgba(11, 25, 42, 0.94);
  border-color: var(--cyan);
  color: var(--cyan);
}

/* Builder Footer */
.builder-footer {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 68px;
  padding: 8px 10px max(8px, env(safe-area-inset-bottom));
  background: var(--bg-elev);
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}
.nav-prev { min-width: 52px; font-size: 22px; padding: 0 14px; }
.nav-next { min-width: 104px; }
.scrubber-wrap {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.scrubber-labels {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 11.5px;
  color: var(--muted);
}
.scrubber-labels span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scrubber-labels span:last-child { white-space: nowrap; font-variant-numeric: tabular-nums; }
.step-range {
  width: 100%;
  accent-color: var(--cyan);
  cursor: pointer;
}

/* Modals & Drawer */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(4, 8, 15, 0.78);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-card {
  width: 100%;
  max-width: 460px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  border-radius: 16px;
  background: var(--bg-elev);
  border: 1px solid var(--stroke);
  overflow: hidden;
}
.drawer-panel {
  width: 100%;
  max-width: 520px;
  height: 86vh;
  display: flex;
  flex-direction: column;
  border-radius: 16px;
  background: var(--bg-elev);
  border: 1px solid var(--stroke);
  overflow: hidden;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--stroke);
}
.modal-header h3 { margin: 0; font-size: 16px; }
.modal-body {
  padding: 16px;
  overflow-y: auto;
  font-size: 13.5px;
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.modal-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--stroke);
}
.modal-footer .btn { height: 38px; font-size: 13px; }

.drawer-chips {
  display: flex;
  gap: 6px;
  padding: 10px 14px;
  overflow-x: auto;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}
.steps-drawer-list {
  flex: 1;
  overflow-y: auto;
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.step-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--bg-card);
  border: 1px solid var(--stroke);
  cursor: pointer;
}
.step-row.current { border-color: var(--cyan); }
.step-row-thumb {
  width: 44px;
  height: 54px;
  border-radius: 6px;
  object-fit: cover;
  background: #CBD5E1;
  flex-shrink: 0;
}
.step-row-info { flex: 1; min-width: 0; }
.step-row-title { font-size: 13.5px; font-weight: 700; }
.step-row-sub { font-size: 11.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.step-row-done { font-size: 16px; font-weight: 800; color: var(--muted); }
.step-row-done.done { color: var(--green); }

.led-check-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--bg-card);
  border: 1px solid var(--stroke);
  cursor: pointer;
}
.led-check-item input { margin-top: 3px; accent-color: var(--cyan); width: 17px; height: 17px; }

.empty-state {
  text-align: center;
  padding: 40px 16px;
  color: var(--muted);
}

/* Drag & Drop */
.drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(9, 14, 23, 0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.drop-box {
  max-width: 420px;
  width: 100%;
  padding: 36px 24px;
  border-radius: 20px;
  border: 2px dashed var(--cyan);
  background: var(--bg-card);
  text-align: center;
}
.drop-icon { font-size: 42px; margin-bottom: 10px; }

/* Toast */
.toast {
  position: fixed;
  bottom: 84px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 90;
  padding: 10px 18px;
  border-radius: 12px;
  background: #1E293B;
  border: 1px solid var(--cyan);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  max-width: 90vw;
  text-align: center;
}

@media (max-width: 600px) {
  .timer-btn { display: none; }
  .hero-cover { width: 92px; height: 115px; }
  .hero-meta h1 { font-size: 19px; }
  .catalog-grid { grid-template-columns: 1fr; }
}
