/* ============ Felic Studio Design Tokens ============ */
:root {
  /* Brand palette */
  --fs-navy:   #252a64;
  --fs-flame:  #ea5f28;
  --fs-cream:  #f4f1e4;
  --fs-sky:    #81acff;
  --fs-ink:    #11132f;

  /* Surface layers (navy family, dark) */
  --bg:        #0c0e2a;   /* deepest – 3D viewport */
  --bg-2:      #14183d;   /* sidebar bg */
  --panel:     #1b2050;   /* panel body */
  --panel-2:   #252a64;   /* panel header = fs-navy */

  /* Borders */
  --border:    rgba(129, 172, 255, 0.13);
  --border-md: rgba(129, 172, 255, 0.22);

  /* Text */
  --text:      #f4f1e4;                    /* cream */
  --muted:     rgba(244, 241, 228, 0.48);

  /* Accent */
  --accent:    #ea5f28;   /* flame – CTA, active */
  --accent-2:  #ff7a45;   /* lighter flame for text */
  --accent-soft: rgba(234, 95, 40, 0.13);

  /* Selection (sky) */
  --sel:       #81acff;
  --sel-soft:  rgba(129, 172, 255, 0.14);

  /* Semantic */
  --success:   #2f8f5a;
  --warn:      #c9892d;
  --danger:    #c83b3b;

  /* LED marker */
  --led:       var(--accent);
  --led-soft:  var(--accent-soft);

  /* Shadows */
  --shadow:       0 8px 24px rgba(8, 12, 42, 0.45);
  --shadow-flame: 0 6px 18px rgba(234, 95, 40, 0.28);
  --shadow-inset: inset 0 1px 0 rgba(255,255,255,0.06);

  /* Radii */
  --r-sm:  8px;
  --r-md:  14px;
  --r-lg:  22px;

  /* Fonts */
  --font-sans:       'Barlow', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-condensed:  'Barlow Condensed', 'Arial Narrow', sans-serif;
  --font-mono:       'JetBrains Mono', 'Fira Code', ui-monospace, monospace;

  /* Layout */
  --topbar-h:    60px;
  --statusbar-h: 28px;
}

/* ============ Reset ============ */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0; height: 100%;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  font-size: 13px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button { font-family: inherit; }

kbd {
  background: var(--panel);
  border: 1px solid var(--border-md);
  border-bottom-width: 2px;
  padding: 1px 6px;
  border-radius: 5px;
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--sel);
}
code {
  background: var(--panel);
  padding: 1px 6px;
  border-radius: 5px;
  font-size: 11.5px;
  font-family: var(--font-mono);
  color: var(--sel);
}

/* ============ Top Bar ============ */
.topbar {
  height: var(--topbar-h);
  background: var(--fs-navy);
  border-bottom: 1px solid rgba(129,172,255,0.12);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  gap: 12px;
  box-shadow: 0 2px 12px rgba(8,12,42,0.40);
}

.brand { display: flex; align-items: center; gap: 12px; }
.logo-img {
  width: 36px; height: 36px;
  border-radius: 9px;
  display: block;
  box-shadow: 0 2px 8px rgba(0,0,0,0.30);
}
.brand-title {
  font-family: var(--font-condensed);
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--fs-cream);
}
.brand-sub {
  font-size: 10.5px;
  color: rgba(244,241,228,0.50);
  letter-spacing: 0.02em;
  margin-top: 1px;
}

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

/* ============ Buttons ============ */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 14px;
  border-radius: var(--r-md);
  border: 1px solid transparent;
  background: rgba(255,255,255,0.07);
  color: var(--fs-cream);
  cursor: pointer;
  font-family: var(--font-sans);
  font-size: 12.5px;
  font-weight: 600;
  transition: background 140ms, box-shadow 140ms, transform 80ms;
  user-select: none;
  white-space: nowrap;
}
.btn:hover  { background: rgba(255,255,255,0.13); }
.btn:active { transform: translateY(1px); }

.btn-primary {
  background: var(--fs-flame);
  color: var(--fs-cream);
  border-color: transparent;
  box-shadow: var(--shadow-flame);
}
.btn-primary:hover { background: #c24a18; box-shadow: 0 8px 22px rgba(234,95,40,0.38); }

.btn-navy {
  background: var(--fs-navy);
  color: var(--fs-cream);
  border-color: rgba(129,172,255,0.18);
  box-shadow: var(--shadow-inset);
}
.btn-navy:hover { background: #1e2253; }

.btn-success {
  background: var(--success);
  color: var(--fs-cream);
}
.btn-success:hover { background: #236b44; }

.btn-ghost {
  background: transparent;
  border-color: var(--border-md);
  color: var(--muted);
}
.btn-ghost:hover { background: var(--sel-soft); color: var(--text); border-color: var(--sel); }

.btn-sm { padding: 5px 10px; font-size: 11.5px; border-radius: var(--r-sm); }
.btn-icon { line-height: 1; }

.divider { width: 1px; height: 22px; background: rgba(129,172,255,0.18); margin: 0 4px; }

/* ============ Mode switch ============ */
.mode-switch {
  display: inline-flex; padding: 3px;
  background: rgba(0,0,0,0.25);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
}
.mode-btn {
  padding: 5px 16px; border: none; background: transparent;
  color: var(--muted); cursor: pointer; border-radius: 6px;
  font-family: var(--font-sans); font-size: 12px; font-weight: 600;
  transition: all 140ms;
}
.mode-btn.active {
  background: var(--fs-flame);
  color: var(--fs-cream);
  box-shadow: 0 2px 8px rgba(234,95,40,0.30);
}

/* ============ Layout ============ */
.layout {
  display: grid;
  grid-template-columns: 280px 1fr 320px;
  height: calc(100vh - var(--topbar-h) - var(--statusbar-h));
  overflow: hidden;
}

.sidebar {
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow: hidden;
  gap: 1px;
}
.sidebar-right { border-right: none; border-left: 1px solid var(--border); }

.panel {
  background: var(--panel);
  display: flex; flex-direction: column;
  border-bottom: 1px solid var(--border);
  min-height: 0;
}
.panel:last-child { border-bottom: none; }

.panel-header {
  padding: 9px 12px;
  background: var(--panel-2);
  border-bottom: 1px solid var(--border);
  font-family: var(--font-condensed);
  font-size: 11px; font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: rgba(244,241,228,0.70);
  display: flex; justify-content: space-between; align-items: center;
}

.panel-body {
  padding: 10px 12px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}
.panel-body::-webkit-scrollbar { width: 6px; }
.panel-body::-webkit-scrollbar-track { background: transparent; }
.panel-body::-webkit-scrollbar-thumb { background: rgba(129,172,255,0.15); border-radius: 4px; }
.panel-body::-webkit-scrollbar-thumb:hover { background: rgba(129,172,255,0.28); }

/* ============ Badges ============ */
.badge {
  display: inline-flex; align-items: center;
  background: rgba(255,255,255,0.07);
  color: var(--muted);
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 700;
  font-family: var(--font-condensed);
  letter-spacing: 0.05em;
}
.badge-accent { background: var(--accent-soft); color: var(--accent-2); }

/* ============ Object Tree ============ */
.search-row { margin-bottom: 8px; }
.search-row input {
  width: 100%;
  background: var(--bg);
  border: 1.5px solid var(--border);
  color: var(--text);
  padding: 7px 10px;
  border-radius: var(--r-sm);
  font-size: 12px;
  font-family: var(--font-sans);
  outline: none;
  transition: border-color 120ms;
}
.search-row input:focus { border-color: var(--accent); }
.search-row input::placeholder { color: var(--muted); }

.auto-detect-row { display: flex; gap: 6px; margin-bottom: 8px; flex-wrap: wrap; }
.auto-detect-row .btn { flex: 1; justify-content: center; }

.object-tree, .led-list {
  list-style: none; margin: 0; padding: 0;
}
.tree-item, .led-item {
  display: flex; align-items: center; gap: 6px;
  padding: 5px 8px;
  border-radius: var(--r-sm);
  cursor: pointer;
  font-size: 12px;
  transition: background 100ms;
  position: relative;
}
.tree-item:hover, .led-item:hover { background: var(--sel-soft); }
.tree-item.selected, .led-item.selected {
  background: var(--sel-soft);
  color: var(--sel);
}
.tree-item.is-led { color: var(--accent-2); }
.tree-item.is-partial { color: var(--warn); }
.tree-item.is-group > .obj-icon { opacity: 0.7; font-size: 10px; }

.tree-item .led-marker {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
  box-shadow: 0 0 6px rgba(234,95,40,0.50);
}
.tree-item .led-marker.partial { background: var(--warn); box-shadow: 0 0 6px rgba(201,137,45,0.50); }
.tree-item .obj-icon { flex-shrink: 0; font-size: 11px; color: var(--muted); }
.tree-item .obj-name {
  flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tree-item .toggle-led {
  background: transparent;
  border: 1px solid var(--border-md);
  color: var(--muted);
  padding: 2px 7px;
  border-radius: 6px;
  font-size: 10.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all 120ms;
  white-space: nowrap;
  flex-shrink: 0;
}
.tree-item .toggle-led:hover { border-color: var(--accent); color: var(--accent-2); }
.tree-item.is-led .toggle-led {
  background: var(--accent-soft);
  color: var(--accent-2);
  border-color: rgba(234,95,40,0.35);
}

/* LED list */
.led-item { padding: 7px 8px; }
.led-item .led-color {
  width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0;
  box-shadow: 0 0 5px currentColor;
}
.led-item .led-name {
  font-weight: 600; font-size: 12px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.led-item .led-info { font-size: 10.5px; color: var(--muted); font-family: var(--font-mono); }
.led-item .led-remove {
  background: transparent; border: none; color: var(--muted);
  cursor: pointer; padding: 2px 5px; border-radius: 5px; font-size: 11px;
  transition: all 120ms;
}
.led-item .led-remove:hover { background: var(--danger); color: white; }

.empty-state {
  text-align: center; color: var(--muted);
  padding: 24px 12px; font-size: 12px;
}
.empty-state div:first-child { font-weight: 700; margin-bottom: 5px; letter-spacing: 0.01em; }
.empty-state small { font-size: 11px; opacity: 0.80; line-height: 1.55; }
.empty-state.hidden { display: none; }
.hidden { display: none !important; }

/* ============ Workspace ============ */
.workspace { position: relative; overflow: hidden; }
.view {
  position: absolute; inset: 0;
  display: none;
  flex-direction: column;
  background: var(--bg);
}
.view.view-active { display: flex; }

.three-container { flex: 1; position: relative; min-height: 0; }
.three-container canvas { display: block; outline: none; }

/* 3D view floating toolbar */
.view-toolbar {
  position: absolute; top: 12px; left: 12px;
  display: flex; gap: 4px;
  background: rgba(20, 24, 61, 0.88);
  border: 1px solid var(--border);
  padding: 4px;
  border-radius: var(--r-sm);
  backdrop-filter: blur(8px);
  z-index: 10;
  box-shadow: var(--shadow);
}
.tool-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text);
  padding: 5px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-family: var(--font-sans);
  font-size: 11.5px; font-weight: 600;
  transition: all 120ms;
  white-space: nowrap;
}
.tool-btn:hover { background: var(--sel-soft); border-color: var(--border); }
.tool-btn.active {
  background: var(--accent-soft);
  color: var(--accent-2);
  border-color: rgba(234,95,40,0.35);
}
.tool-sep { width: 1px; background: var(--border); margin: 2px 3px; }

.view-hint {
  position: absolute; bottom: 12px; left: 12px;
  background: rgba(20, 24, 61, 0.85);
  border: 1px solid var(--border);
  padding: 6px 11px;
  border-radius: var(--r-sm);
  font-size: 11px; color: var(--muted);
  backdrop-filter: blur(6px);
  z-index: 10;
  pointer-events: none;
}
.view-hint kbd { margin-right: 2px; }

/* ============ 2D Editor toolbar ============ */
.canvas2d-toolbar {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 12px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.tool-group {
  display: flex; align-items: center; gap: 6px;
  padding-right: 10px;
  border-right: 1px solid var(--border);
}
.tool-group:last-child { border-right: none; }
.tool-label { font-size: 11px; color: var(--muted); font-weight: 600; white-space: nowrap; }

.tool-group input[type="number"], .tool-group select {
  background: var(--panel);
  border: 1.5px solid var(--border);
  color: var(--text);
  padding: 4px 8px;
  border-radius: var(--r-sm);
  font-family: var(--font-sans);
  font-size: 12px;
  width: 70px; outline: none;
  transition: border-color 120ms;
}
.tool-group input[type="number"]:focus,
.tool-group select:focus { border-color: var(--accent); }
.tool-group input[type="range"] { width: 100px; accent-color: var(--accent); }

/* 2D canvas area */
.canvas2d-container {
  flex: 1; position: relative;
  background-color: #080b20;
  background-image:
    linear-gradient(rgba(129,172,255,0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(129,172,255,0.04) 1px, transparent 1px);
  background-size: 20px 20px;
  overflow: hidden;
  cursor: default;
}
.canvas2d-container.tool-pan { cursor: grab; }
.canvas2d-container.tool-pan.panning { cursor: grabbing; }
.canvas2d-container.marquee-active { cursor: crosshair; }
#canvas2d { position: absolute; top: 0; left: 0; }

/* ============ Properties panel ============ */
.prop-group { margin-bottom: 14px; }
.prop-group:last-child { margin-bottom: 0; }
.prop-group-title {
  font-family: var(--font-condensed);
  font-size: 10.5px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.14em;
  color: var(--muted);
  margin-bottom: 7px;
}
.prop-row {
  display: grid; grid-template-columns: 90px 1fr;
  align-items: center; gap: 8px; margin-bottom: 6px;
}
.prop-row label { font-size: 12px; color: rgba(244,241,228,0.70); }
.prop-row input, .prop-row select {
  background: var(--bg);
  border: 1.5px solid var(--border);
  color: var(--text);
  padding: 5px 8px;
  border-radius: var(--r-sm);
  font-family: var(--font-sans);
  font-size: 12px; outline: none; width: 100%;
  transition: border-color 120ms;
}
.prop-row input:focus, .prop-row select:focus { border-color: var(--accent); }
.prop-row input:disabled { opacity: 0.40; cursor: default; }
.prop-color { width: 28px !important; height: 24px; padding: 0 !important; cursor: pointer; }

/* ============ Stats grid ============ */
.stat-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
}
.stat {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 8px 10px;
}
.stat-label {
  font-family: var(--font-condensed);
  font-size: 10px; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.12em;
}
.stat-value {
  font-size: 17px; font-weight: 700;
  color: var(--accent-2);
  margin-top: 2px;
  font-family: var(--font-condensed);
}

/* ============ Quick guide ============ */
.small-text { font-size: 12px; line-height: 1.65; color: rgba(244,241,228,0.70); }
.howto { padding-left: 18px; margin: 0; }
.howto li { margin-bottom: 7px; }
.howto b { color: var(--accent-2); }

/* ============ Status bar ============ */
.statusbar {
  height: var(--statusbar-h);
  background: var(--bg-2);
  border-top: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 14px;
  gap: 16px;
  font-size: 11.5px; color: var(--muted);
  font-family: var(--font-condensed);
  letter-spacing: 0.04em;
}
.statusbar .spacer { flex: 1; }

/* ============ Loading overlay ============ */
.loading-overlay {
  position: absolute; inset: 0;
  background: rgba(10, 12, 35, 0.88);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 16px;
  z-index: 50;
  backdrop-filter: blur(5px);
}
.loading-overlay.hidden { display: none; }
.spinner {
  width: 34px; height: 34px;
  border: 3px solid rgba(129,172,255,0.18);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.85s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============ Toast notifications ============ */
.toast-host {
  position: fixed; top: 76px; right: 16px;
  display: flex; flex-direction: column; gap: 8px;
  z-index: 200;
  pointer-events: none;
}
.toast {
  min-width: 240px;
  padding: 10px 14px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-left-width: 4px;
  border-radius: var(--r-sm);
  box-shadow: var(--shadow);
  font-size: 12.5px;
  animation: toastIn 0.22s ease;
  pointer-events: auto;
}
.toast.info    { border-left-color: var(--sel); }
.toast.success { border-left-color: var(--success); }
.toast.warn    { border-left-color: var(--warn); }
.toast.error   { border-left-color: var(--danger); }
@keyframes toastIn {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}
.toast.fade-out { opacity: 0; transform: translateX(20px); transition: all 0.22s; }

/* ============ Project / Save dialogs ============ */
dialog {
  background: var(--panel);
  border: 1px solid var(--border-md);
  border-radius: var(--r-md);
  color: var(--text);
  padding: 0;
  min-width: 420px;
  max-width: 600px;
  box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(0,0,0,0.60); backdrop-filter: blur(3px); }

.dlg-shell { display: flex; flex-direction: column; }
.dlg-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  background: var(--panel-2);
  border-bottom: 1px solid var(--border);
  font-family: var(--font-condensed);
  font-weight: 700; font-size: 13px; letter-spacing: 0.06em; text-transform: uppercase;
  border-radius: var(--r-md) var(--r-md) 0 0;
}
.dlg-body {
  padding: 12px;
  max-height: 400px;
  overflow-y: auto;
}
.dlg-body::-webkit-scrollbar { width: 6px; }
.dlg-body::-webkit-scrollbar-thumb { background: var(--border-md); border-radius: 4px; }
.dlg-footer {
  padding: 10px 16px;
  background: var(--bg-2);
  border-top: 1px solid var(--border);
  display: flex; gap: 8px; justify-content: flex-end;
  border-radius: 0 0 var(--r-md) var(--r-md);
}

.proj-list { list-style: none; margin: 0; padding: 0; }
.proj-row {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  border-radius: var(--r-sm);
  transition: background 100ms;
}
.proj-row:last-child { border-bottom: none; }
.proj-row:hover { background: var(--sel-soft); }
.proj-name { font-size: 13px; font-weight: 600; }
.proj-meta { font-size: 11px; color: var(--muted); font-family: var(--font-mono); }

/* ============ Video controls ============ */
#video-controls { flex-wrap: nowrap; }
#vid-seek { width: 110px; accent-color: var(--accent); }
#vid-time { white-space: nowrap; font-family: var(--font-mono); font-size: 11px; }

/* ============ Responsive ============ */
@media (max-width: 1100px) {
  .layout { grid-template-columns: 240px 1fr 280px; }
}
@media (max-width: 900px) {
  .layout { grid-template-columns: 200px 1fr; }
  .sidebar-right { display: none; }
  .brand-sub { display: none; }
}
