/* ── CSS VARIABLES & RESET ── */
:root {
  --bg: #0b0c0e;
  --surface: #131519;
  --surface2: #1a1d23;
  --surface3: #22262f;
  --surface4: #2a2f3a;
  --border: rgba(255,255,255,0.065);
  --border-md: rgba(255,255,255,0.11);
  --border-hi: rgba(255,255,255,0.18);
  --text: #e2e4e9;
  --text-muted: #636878;
  --text-dim: #444955;
  --accent: #7b68ee;
  --accent-soft: rgba(123,104,238,0.16);
  --accent-border: rgba(123,104,238,0.4);
  --green: #3ecf8e;
  --green-soft: rgba(62,207,142,0.15);
  --red: #f06a6a;
  --red-soft: rgba(240,106,106,0.12);
  --yellow: #f5c542;
  --shadow-sm: 0 1px 4px rgba(0,0,0,0.4);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.55), 0 1px 4px rgba(0,0,0,0.3);
  --shadow-lg: 0 12px 40px rgba(0,0,0,0.7), 0 2px 8px rgba(0,0,0,0.4);
  --radius: 11px;
  --radius-sm: 7px;
  --radius-xs: 4px;
  --sidebar-w: 230px;
  --topbar-h: 52px;
  --font: 'DM Sans', sans-serif;
  --font-note: 'Space Grotesk', sans-serif;
  --font-mono: 'DM Mono', monospace;
  --transition: 0.16s ease;
}

/* ── LIGHT MODE ── */
html.light {
  --bg: #f4f5f8;
  --surface: #ffffff;
  --surface2: #f0f1f5;
  --surface3: #e6e8ed;
  --surface4: #d8dce4;
  --border: rgba(0,0,0,0.07);
  --border-md: rgba(0,0,0,0.12);
  --border-hi: rgba(0,0,0,0.20);
  --text: #111318;
  --text-muted: #5c6370;
  --text-dim: #9099a8;
  --accent-soft: rgba(123,104,238,0.10);
  --accent-border: rgba(123,104,238,0.35);
  --green-soft: rgba(62,207,142,0.12);
  --red-soft: rgba(240,106,106,0.10);
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.10), 0 1px 4px rgba(0,0,0,0.06);
  --shadow-lg: 0 12px 40px rgba(0,0,0,0.14), 0 2px 8px rgba(0,0,0,0.07);
}

/* Light-mode overrides for hardcoded dark values */
html.light #topbar {
  background: rgba(244,245,248,0.92);
}
html.light #canvas {
  background:
    radial-gradient(ellipse 70% 60% at 15% 85%, rgba(123,104,238,0.06) 0%, transparent 65%),
    radial-gradient(ellipse 50% 50% at 82% 18%, rgba(62,207,142,0.05) 0%, transparent 65%),
    var(--bg);
}
html.light #canvas::before {
  background-image: radial-gradient(circle, rgba(0,0,0,0.07) 1px, transparent 1px);
}
html.light #help-panel,
html.light #help-header { background: var(--surface2); }

/* Zone overrides for light mode */
html.light .zone-title            { color: rgba(0,0,0,0.50); }
html.light .zone-title:focus      { color: rgba(0,0,0,0.78); }
html.light .zone-title::placeholder { color: rgba(0,0,0,0.22); }
html.light .zone-delete-btn       { color: rgba(0,0,0,0.25); }
html.light .zone-resize-handle::after,
html.light .zone-resize-handle-left::after { background: rgba(0,0,0,0.14); }
html.light .zone-resize-handle:hover::after,
html.light .zone-resize-handle-left:hover::after { background: rgba(0,0,0,0.32); }
html.light .zone-resize-handle.dragging::after,
html.light .zone-resize-handle-left.dragging::after { background: rgba(0,0,0,0.5); }
html.light .zone-picker-swatch.selected { border-color: rgba(0,0,0,0.55); }

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%; width: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button { font-family: var(--font); cursor: pointer; }
input, textarea { font-family: var(--font); }

.hidden { display: none !important; }

/* ── APP LAYOUT ── */
#app {
  display: flex;
  height: 100vh;
  width: 100vw;
}

#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  position: relative;
}

/* ── TOPBAR ── */
#topbar {
  position: relative;
  height: var(--topbar-h);
  background: rgba(11,12,14,0.88);
  backdrop-filter: blur(20px) saturate(1.3);
  -webkit-backdrop-filter: blur(20px) saturate(1.3);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 16px; gap: 10px;
  z-index: 50; flex-shrink: 0;
}

#topbar-tree-name {
  font-size: 14px; font-weight: 500; color: var(--text);
  padding: 4px 8px; border-radius: var(--radius-xs);
  border: 1px solid transparent;
  outline: none; min-width: 80px; max-width: 260px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: border-color var(--transition), background var(--transition);
  cursor: text;
}
#topbar-tree-name:empty::before { content: attr(placeholder); color: var(--text-dim); }
#topbar-tree-name:focus {
  border-color: var(--border-md);
  background: var(--surface2);
}

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

.tb-btn {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: var(--radius-sm);
  background: var(--surface2); border: 1px solid var(--border);
  color: var(--text-muted); font-size: 12px; font-weight: 400;
  transition: all var(--transition); white-space: nowrap;
}
.tb-btn:hover { background: var(--surface3); border-color: var(--border-md); color: var(--text); }
.tb-btn.active { background: var(--accent-soft); border-color: var(--accent-border); color: var(--accent); }
.tb-btn-danger:hover { background: var(--red-soft); border-color: rgba(240,106,106,0.3); color: var(--red); }

.tb-btn kbd {
  font-family: var(--font-mono); font-size: 10px;
  background: var(--surface4); border: 1px solid var(--border-md);
  color: var(--text-dim); padding: 1px 5px; border-radius: 3px;
}


/* ── TOAST ── */
#toast {
  position: fixed; bottom: 24px; left: 50%;
  transform: translateX(-50%) translateY(12px);
  background: var(--surface3); border: 1px solid var(--border-md);
  border-radius: 20px; padding: 7px 16px;
  font-size: 12px; color: var(--text-muted);
  box-shadow: var(--shadow-md);
  opacity: 0; transition: opacity 0.2s, transform 0.2s;
  pointer-events: none; z-index: 9999; white-space: nowrap;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── THEME TOGGLE & HELP BUTTON ── */
.tb-icon-btn { padding: 6px 8px; }
.tb-help-btn { margin-left: auto; }

/* Sun shown in dark mode, moon in light mode */
.icon-sun  { display: block; }
.icon-moon { display: none;  }
html.light .icon-sun  { display: none;  }
html.light .icon-moon { display: block; }

/* ── HELP MODAL ── */
#help-modal {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: center;
}

#help-backdrop {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

#help-panel {
  position: relative;
  background: var(--surface2);
  border: 1px solid var(--border-hi);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 400px; max-width: 92vw;
  max-height: 80vh; overflow-y: auto;
  animation: menuIn 0.15s ease forwards;
}

#help-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 13px; font-weight: 500; color: var(--text);
  position: sticky; top: 0; background: var(--surface2);
}

#help-close-btn {
  width: 24px; height: 24px; border-radius: 5px;
  background: none; border: none;
  color: var(--text-muted); font-size: 18px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.12s, color 0.12s;
}
#help-close-btn:hover { background: var(--surface3); color: var(--text); }

#help-body { padding: 14px 18px 18px; display: flex; flex-direction: column; gap: 18px; }

.help-section-title {
  font-size: 10px; font-weight: 500;
  letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--text-dim); margin-bottom: 8px;
  font-family: var(--font-mono);
}

.help-row {
  display: flex; align-items: baseline; gap: 10px;
  font-size: 12.5px; padding: 2px 0;
}

.help-row kbd {
  font-family: var(--font-mono); font-size: 11px;
  background: var(--surface4); border: 1px solid var(--border-md);
  color: var(--text-muted); padding: 2px 7px; border-radius: 4px;
  white-space: nowrap; flex-shrink: 0;
}

.help-row span { color: var(--text-muted); }
.help-note { font-size: 12px; color: var(--text-dim); line-height: 1.6; }

/* ── SCROLLBAR ── */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface4); border-radius: 4px; }
