@import url('https://fonts.googleapis.com/css2?family=Lora:ital,wght@0,400;0,600;1,400&family=DM+Mono:wght@300&display=swap');

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

:root {
  --bg: #05070a;
  --bg-panel: rgba(13, 17, 23, 0.92);
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.15);
  --text: rgba(255, 255, 255, 0.9);
  --muted: rgba(255, 255, 255, 0.35);
  --accent: #5ec6e6;
  --hover-bg: rgba(255, 255, 255, 0.1);
  --sidebar-w: 260px;
  --topbar-h: 40px;
}

html { font-size: 13px; }

html, body {
  width: 100%;
  height: 100%;
  background: var(--bg);
  overflow: hidden;
  font-family: 'DM Mono', monospace;
  color: var(--text);
}

/* ═══════════════════════════════════════════════════════════════════
   APP SHELL
   ═══════════════════════════════════════════════════════════════════ */

#app {
  display: flex;
  flex-direction: column;
  width: 100vw;
  height: 100vh;
  user-select: none;
}

/* ── Top bar ─────────────────────────────────────────────────────── */

#topbar {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 8px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 10;
}

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

#site-label {
  font-family: 'Lora', serif;
  font-size: 0.95rem;
  color: rgba(255, 255, 255, 0.55);
  font-style: italic;
  letter-spacing: 0.01em;
}

#particle-count {
  font-size: 0.62rem;
  letter-spacing: 0.15rem;
  text-transform: uppercase;
  color: var(--muted);
}

.tb-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: none;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--muted);
  cursor: pointer;
  transition: all 0.15s;
}

.tb-btn:hover {
  color: var(--text);
  background: var(--hover-bg);
  border-color: var(--border);
}

.tb-btn.active {
  color: var(--accent);
  border-color: rgba(94, 198, 230, 0.3);
}

.tb-btn i { width: 16px; height: 16px; }

.tb-divider {
  width: 1px;
  height: 16px;
  background: var(--border);
}

#zoom-level {
  font-size: 0.58rem;
  color: var(--muted);
  letter-spacing: 0.05rem;
  min-width: 34px;
  text-align: center;
}

/* ═══════════════════════════════════════════════════════════════════
   MAIN LAYOUT
   ═══════════════════════════════════════════════════════════════════ */

#main-layout {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* ── Sidebar ─────────────────────────────────────────────────────── */

#sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  transition: width 0.25s cubic-bezier(0.4, 0, 0.2, 1),
              border-color 0.25s;
  overflow: hidden;
  z-index: 5;
}

#sidebar.collapsed {
  width: 0;
  border-right-color: transparent;
}

#sidebar-scroll {
  width: var(--sidebar-w);
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 2px 0;
}

/* Scrollbar */
#sidebar-scroll::-webkit-scrollbar { width: 3px; }
#sidebar-scroll::-webkit-scrollbar-track { background: transparent; }
#sidebar-scroll::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); border-radius: 2px; }
#sidebar-scroll::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.18); }

/* ── Collapsible panels ──────────────────────────────────────────── */

.panel {
  border-bottom: 1px solid var(--border);
}

.panel-header {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 8px 12px;
  background: none;
  border: none;
  color: var(--muted);
  font-family: inherit;
  font-size: 0.58rem;
  letter-spacing: 0.18rem;
  text-transform: uppercase;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}

.panel-header:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.02);
}

.panel-chevron {
  width: 12px;
  height: 12px;
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  flex-shrink: 0;
}

.panel:not(.open) .panel-chevron {
  transform: rotate(-90deg);
}

.panel-body {
  padding: 0 12px 12px;
  overflow: hidden;
  max-height: 1200px;
  transition: max-height 0.3s cubic-bezier(0.4, 0, 0.2, 1),
              padding 0.25s,
              opacity 0.2s;
  opacity: 1;
}

.panel:not(.open) .panel-body {
  max-height: 0;
  padding-top: 0;
  padding-bottom: 0;
  opacity: 0;
}

/* ═══════════════════════════════════════════════════════════════════
   CANVAS AREA
   ═══════════════════════════════════════════════════════════════════ */

#canvas-area {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 8px;
  min-width: 0;
  background: var(--bg);
}

#canvas-area.scrollable {
  overflow: auto;
  align-items: flex-start;
  justify-content: flex-start;
  padding: 12px;
}

#canvas-wrap {
  position: relative;
  border-radius: 8px;
  overflow: hidden;
  box-shadow:
    0 0 0 1px var(--border),
    0 20px 60px rgba(0, 0, 0, 0.6),
    0 0 40px rgba(94, 198, 230, 0.02);
  will-change: transform;
  flex-shrink: 0;
}

canvas#sim {
  display: block;
  cursor: none;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

canvas#brush-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

/* Canvas overlay labels */
#fps-label,
#weather-label,
#mat-label,
#temp-label {
  position: absolute;
  font-size: 0.6rem;
  letter-spacing: 0.12rem;
  text-transform: uppercase;
  pointer-events: none;
}

#fps-label { bottom: 8px; right: 10px; color: rgba(255, 255, 255, 0.2); }
#weather-label { top: 8px; left: 10px; color: rgba(255, 255, 255, 0.25); }
#mat-label { top: 8px; right: 10px; color: rgba(255, 255, 255, 0.25); }
#temp-label { bottom: 8px; left: 10px; color: rgba(255, 255, 255, 0.3); }

#pause-label {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 0.75rem;
  letter-spacing: 0.25rem;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.8);
  pointer-events: none;
  background: rgba(5, 7, 10, 0.7);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 6px;
  padding: 6px 16px;
  opacity: 0;
  transition: opacity 0.15s;
}

/* ═══════════════════════════════════════════════════════════════════
   MATERIAL PALETTE
   ═══════════════════════════════════════════════════════════════════ */

#palette-container {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(1.8rem, 1fr));
  gap: 3px;
}

.mat-btn {
  position: relative;
  width: 100%;
  aspect-ratio: 1/1;
  border-radius: 5px;
  border: 2px solid transparent;
  cursor: pointer;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  background: rgba(255, 255, 255, 0.03);
}

.mat-btn:hover {
  transform: translateY(-1px);
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.2);
}

.mat-btn.active {
  border-color: #fff;
  box-shadow: 0 0 10px rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.12);
}

.mat-btn .tip {
  display: none;
  position: absolute;
  bottom: 110%;
  left: 50%;
  transform: translateX(-50%);
  background: #000;
  color: #fff;
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 0.5rem;
  letter-spacing: 0.05rem;
  text-transform: uppercase;
  white-space: nowrap;
  z-index: 100;
  border: 1px solid var(--border);
  pointer-events: none;
}

.mat-btn:hover .tip { display: block; }

.mat-btn i { width: 0.9rem; height: 0.9rem; opacity: 0.8; }
.mat-btn.active i { opacity: 1; }

/* ── Material info box ───────────────────────────────────────────── */

#mat-info-box {
  margin-top: 6px;
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  border-radius: 6px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s, transform 0.15s;
  transform: translateY(3px);
  min-height: 4rem;
}

#mat-info-box.visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.mat-info-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}

.mat-info-swatch {
  width: 8px;
  height: 8px;
  border-radius: 2px;
  flex-shrink: 0;
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.mat-info-name {
  font-size: 0.65rem;
  letter-spacing: 0.05rem;
  color: var(--text);
  flex: 1;
}

.mat-info-temp {
  font-size: 0.55rem;
  letter-spacing: 0.04rem;
  color: var(--muted);
}

.mat-info-desc {
  font-size: 0.55rem;
  line-height: 1.5;
  color: rgba(255, 255, 255, 0.5);
  margin-bottom: 6px;
}

.mat-info-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
}

.mat-info-stat {
  font-size: 0.46rem;
  letter-spacing: 0.06rem;
  text-transform: uppercase;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1px 5px;
}

/* ═══════════════════════════════════════════════════════════════════
   TOOL CONTROLS
   ═══════════════════════════════════════════════════════════════════ */

#tool-controls {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.tool-row {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.6rem;
  color: var(--text);
}

#brush-range {
  flex: 1;
  height: 3px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 2px;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

#brush-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  background: #fff;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 0 8px rgba(0, 0, 0, 0.5);
}

.action-btn {
  flex: 1;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.56rem;
  padding: 5px;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.08rem;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.action-btn:hover {
  background: var(--hover-bg);
  border-color: rgba(255, 255, 255, 0.3);
}

.action-btn.active {
  background: rgba(94, 198, 230, 0.15);
  border-color: var(--accent);
  color: var(--accent);
}

.action-btn i { width: 11px; height: 11px; }

/* ═══════════════════════════════════════════════════════════════════
   ENVIRONMENT CONTROLS
   ═══════════════════════════════════════════════════════════════════ */

#env-controls {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.group-header {
  font-size: 0.5rem;
  letter-spacing: 0.15rem;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 2px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.group-header::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.seg-group {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
}

.seg-btn {
  font-family: inherit;
  font-size: 0.56rem;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 3px 6px;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  gap: 3px;
}

.seg-btn:hover {
  color: var(--text);
  background: var(--hover-bg);
}

.seg-btn.active {
  color: #fff;
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.2);
}

.seg-btn .icon { font-size: 10px; }

/* ── Layer config ────────────────────────────────────────────────── */

#layer-config {
  display: flex;
  gap: 4px;
  margin-top: 6px;
  padding: 6px;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 6px;
  border: 1px dashed rgba(255, 255, 255, 0.1);
}

.layer-slot {
  flex: 1;
  height: 2rem;
  border-radius: 5px;
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
  background: var(--bg);
  transition: all 0.15s;
}

.layer-slot:hover {
  border-color: var(--accent);
  background: var(--hover-bg);
}

.layer-slot.active {
  border-color: var(--accent);
  box-shadow: 0 0 6px rgba(94, 198, 230, 0.2);
}

.layer-slot .slot-label {
  font-size: 0.5rem;
  position: absolute;
  top: -10px;
  left: 0;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08rem;
}

/* ═══════════════════════════════════════════════════════════════════
   FLOATING TOOLBAR
   ═══════════════════════════════════════════════════════════════════ */

#floating-toolbar {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: none;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  background: rgba(13, 17, 23, 0.92);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  z-index: 100;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
}

#floating-toolbar.visible {
  opacity: 1;
  pointer-events: auto;
}

.ft-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: none;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--muted);
  cursor: pointer;
  transition: all 0.15s;
}

.ft-btn:hover {
  color: var(--text);
  background: var(--hover-bg);
  border-color: var(--border);
}

.ft-btn i { width: 16px; height: 16px; }

.ft-sep {
  width: 1px;
  height: 20px;
  background: var(--border);
  margin: 0 2px;
}

.ft-label {
  font-size: 0.55rem;
  color: var(--muted);
  letter-spacing: 0.05rem;
  text-transform: uppercase;
  padding: 0 4px;
}

/* ═══════════════════════════════════════════════════════════════════
   FULLSCREEN MODE
   ═══════════════════════════════════════════════════════════════════ */

body.fullscreen #topbar {
  display: none;
}

body.fullscreen #sidebar {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  z-index: 20;
  box-shadow: 4px 0 24px rgba(0, 0, 0, 0.6);
  background: rgba(13, 17, 23, 0.96);
}

body.fullscreen #sidebar.collapsed {
  width: 0;
  box-shadow: none;
}

body.fullscreen #canvas-area {
  padding: 0;
}

body.fullscreen #canvas-wrap {
  border-radius: 0;
  box-shadow: none;
}

body.fullscreen #floating-toolbar {
  display: flex;
}

/* ═══════════════════════════════════════════════════════════════════
   KEYBOARD SHORTCUTS MODAL
   ═══════════════════════════════════════════════════════════════════ */

#shortcuts-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.shortcuts-content {
  background: #1a1a2e;
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  padding: 20px 24px;
  max-width: 380px;
  width: 90vw;
}

.shortcuts-title {
  font-size: 0.8rem;
  letter-spacing: 0.15rem;
  text-transform: uppercase;
  color: var(--text);
  margin-bottom: 16px;
}

.shortcuts-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 14px;
  align-items: center;
}

.shortcuts-grid kbd {
  font-family: inherit;
  font-size: 0.58rem;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 8px;
  color: var(--accent);
  text-align: center;
}

.shortcuts-grid span {
  font-size: 0.58rem;
  color: var(--muted);
}

.shortcuts-close {
  margin-top: 16px;
  width: 100%;
  padding: 6px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.58rem;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.1rem;
  transition: background 0.15s;
}

.shortcuts-close:hover {
  background: var(--hover-bg);
}

/* ═══════════════════════════════════════════════════════════════════
   MOBILE BOTTOM BAR
   ═══════════════════════════════════════════════════════════════════ */

#mobile-bar {
  display: none;
  height: 52px;
  background: var(--bg-panel);
  border-top: 1px solid var(--border);
  padding: 0 8px;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  z-index: 10;
}

#mb-material {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  cursor: pointer;
  min-width: 70px;
  -webkit-tap-highlight-color: transparent;
}

#mb-material:active {
  background: var(--hover-bg);
}

#mb-swatch {
  width: 16px;
  height: 16px;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  flex-shrink: 0;
}

#mb-name {
  font-size: 0.6rem;
  letter-spacing: 0.08rem;
  text-transform: uppercase;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mb-sep {
  width: 1px;
  height: 20px;
  background: var(--border);
  flex-shrink: 0;
}

#mb-brush-group {
  display: flex;
  align-items: center;
  gap: 2px;
}

#mb-brush-val {
  font-size: 0.6rem;
  color: var(--muted);
  min-width: 14px;
  text-align: center;
}

.mb-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: none;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--muted);
  cursor: pointer;
  font-size: 1rem;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.mb-btn:active {
  background: var(--hover-bg);
  border-color: var(--border);
}

.mb-btn.active {
  color: var(--accent);
  border-color: rgba(94, 198, 230, 0.3);
  background: rgba(94, 198, 230, 0.1);
}

.mb-btn i { width: 18px; height: 18px; }

/* ═══════════════════════════════════════════════════════════════════
   PORTRAIT MODE
   ═══════════════════════════════════════════════════════════════════ */

#canvas-wrap.portrait {
  transform: rotate(90deg);
}

/* ═══════════════════════════════════════════════════════════════════
   MOBILE SIDEBAR BACKDROP
   ═══════════════════════════════════════════════════════════════════ */

#sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 14;
}

#sidebar-backdrop.visible {
  display: block;
}

/* ═══════════════════════════════════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {
  html { font-size: 11px; }

  #mobile-bar { display: flex; }

  #particle-count { display: none; }
  #site-label { display: none; }

  #topbar {
    height: 36px;
    padding: 0 6px;
  }

  .tb-btn {
    width: 32px;
    height: 32px;
  }

  #sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 15;
    width: 280px;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.6);
    background: rgba(13, 17, 23, 0.98);
  }

  #sidebar.collapsed {
    width: 0;
    box-shadow: none;
  }

  #sidebar-scroll {
    width: 280px;
  }

  #canvas-area {
    padding: 4px;
  }

  /* Bigger palette buttons for touch */
  #palette-container {
    grid-template-columns: repeat(auto-fill, minmax(2.4rem, 1fr));
    gap: 4px;
  }

  .mat-btn {
    min-height: 2.4rem;
  }

  /* Bigger action/seg buttons for touch */
  .action-btn {
    padding: 8px;
    font-size: 0.6rem;
  }

  .seg-btn {
    padding: 5px 8px;
    font-size: 0.6rem;
  }

  /* Hide canvas overlay labels on mobile - info is in mobile bar */
  #mat-label { display: none; }
}

@media (max-width: 480px) {
  html { font-size: 10px; }

  #sidebar {
    width: 100vw;
  }

  #sidebar-scroll {
    width: 100vw;
  }

  #topbar {
    height: 32px;
  }

  /* Hide zoom controls on small phones */
  #zoom-level,
  #zoom-out-btn,
  #zoom-in-btn,
  #zoom-fit-btn { display: none; }

  .tb-divider { display: none; }
}
