* { margin: 0; padding: 0; box-sizing: border-box; }
body { background: #141414; color: #e0e0e0; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; display: flex; height: 100vh; overflow: hidden; font-size: 13px; }

/* Sidebar */
#sidebar { width: 280px; min-width: 280px; background: #1a1a1a; padding: 12px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; border-right: 1px solid #2a2a2a; }
#sidebar h1 { font-size: 15px; color: #fff; margin-bottom: 4px; }
#sidebar h2 { font-size: 12px; color: #fff; text-transform: uppercase; letter-spacing: 1px; margin-bottom: 16px; }

.section { background: #141414; border-radius: 6px; padding: 10px; }

/* Presets */
.preset-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.preset-btn { background: #2a2a2a; border: 1px solid #444; color: #e0e0e0; padding: 6px 4px; border-radius: 4px; cursor: pointer; font-size: 11px; transition: background 0.15s; }
.preset-btn:hover { background: #444; }
.preset-btn.active { background: #fff; color: #141414; font-weight: 600; }

/* Mode grid */
#mode-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px; }
#mode-grid .cell { width: 100%; aspect-ratio: 1; border: 1px solid #2a2a2a; border-radius: 2px; cursor: pointer; background: #141414; font-size: 9px; display: flex; align-items: center; justify-content: center; color: #555; transition: background 0.1s; }
#mode-grid .cell:hover { border-color: #fff; }
#mode-grid .cell.active { background: #fff; color: #141414; font-weight: 700; }
#mode-grid .cell.disabled { opacity: 0.2; cursor: default; pointer-events: none; }
#mode-grid .hex-cell { background: #1a1a1a; font-size: 8px; }
#mode-grid .hex-cell:hover { background: #444; }
#mode-grid .hex-cell.active { background: #fff; color: #141414; font-weight: 700; }

/* Sliders */
#amplitude-sliders { max-height: 150px; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
.slider-row { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; }
.slider-row:last-child { margin-bottom: 0; }
.slider-row label { font-size: 11px; min-width: 40px; color: #999; }
.slider-row input[type=range] { flex: 1; height: 4px; accent-color: #fff; }
.slider-row .val { font-size: 10px; min-width: 28px; text-align: right; color: #fff; }

input[type=range] { -webkit-appearance: none; background: #2a2a2a; border-radius: 2px; height: 4px; outline: none; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 12px; height: 12px; background: #fff; border-radius: 50%; cursor: pointer; }

/* Checkboxes */
.check-row { display: flex; align-items: center; gap: 8px; font-size: 12px; cursor: pointer; }
.check-row input { accent-color: #fff; }

/* Animation */
.anim-controls { display: flex; align-items: center; gap: 6px; }
.anim-btn { background: #2a2a2a; border: 1px solid #444; color: #fff; width: 28px; height: 28px; border-radius: 4px; cursor: pointer; font-size: 14px; display: flex; align-items: center; justify-content: center; }
.anim-btn:hover { background: #444; }
#time-slider { flex: 1; }

/* Wave Reflection wave list */
.wr-wave-item { background: #0f3460; border: 1px solid #1a4a7a; border-radius: 4px; padding: 8px; margin-bottom: 4px; position: relative; }
.wr-wave-item .wr-wave-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.wr-wave-item .wr-wave-header span { font-size: 11px; font-weight: 600; color: #7ec8e3; }
.wr-wave-item .wr-remove { background: none; border: none; color: #666; cursor: pointer; font-size: 14px; padding: 0 4px; }
.wr-wave-item .wr-remove:hover { color: #e74c3c; }
.wr-wave-item .slider-row { margin-bottom: 2px; }
.wr-wave-item select { background: #1a1a2e; color: #fff; border: 1px solid #444; border-radius: 4px; font-size: 11px; padding: 3px 4px; flex: 1; }

/* Export */
#export-btn { width: 100%; padding: 8px; background: #fff; color: #141414; border: none; border-radius: 4px; font-weight: 600; cursor: pointer; font-size: 12px; }
#export-btn:hover { background: #ccc; }

/* Color by Area */
.band-row { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; }
.band-row input[type=color] { width: 24px; height: 20px; border: 1px solid #444; border-radius: 3px; background: none; cursor: pointer; padding: 0; }
.band-row .band-label { font-size: 10px; color: #999; flex: 1; }
.band-row .band-remove { background: none; border: none; color: #666; cursor: pointer; font-size: 14px; padding: 0 2px; }
.band-row .band-remove:hover { color: #e84393; }
.band-row input[type=number]::-webkit-inner-spin-button,
.band-row input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.color-preset-grid { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.color-preset-btn { background: #2a2a2a; border: 1px solid #444; color: #e0e0e0; padding: 4px 8px; border-radius: 4px; cursor: pointer; font-size: 10px; }
.color-preset-btn:hover { background: #444; }

/* Saved configs */
.saved-config-row { display: flex; align-items: center; gap: 4px; padding: 4px 0; border-bottom: 1px solid #333; font-size: 11px; }
.saved-config-row:last-child { border-bottom: none; }
.saved-config-name { flex: 1; background: none; border: 1px solid transparent; color: #e0e0e0; font-size: 11px; padding: 2px 4px; border-radius: 3px; cursor: text; min-width: 0; }
.saved-config-name:hover { border-color: #555; }
.saved-config-name:focus { border-color: #888; outline: none; background: #2a2a2a; }
.saved-config-date { color: #666; font-size: 10px; white-space: nowrap; }
.saved-config-btn { background: none; border: 1px solid #444; color: #aaa; padding: 2px 6px; border-radius: 3px; cursor: pointer; font-size: 10px; height: 22px; display: inline-flex; align-items: center; justify-content: center; }
.saved-config-btn:hover { background: #444; color: #fff; }
.saved-config-btn.delete:hover { color: #e84393; }

/* Paint mode */
.paint-palette { display: grid; grid-template-columns: repeat(10, 1fr); gap: 3px; margin: 6px 0; }
.paint-swatch { width: 100%; aspect-ratio: 1; border-radius: 50%; border: 2px solid transparent; cursor: pointer; }
.paint-swatch:hover { border-color: #888; }
.paint-swatch.active { border-color: #fff; }
.paint-info { font-size: 11px; color: #888; margin-top: 4px; }
.paint-btn { background: #2a2a2a; border: 1px solid #444; color: #e0e0e0; padding: 6px 10px; border-radius: 4px; cursor: pointer; font-size: 11px; }
.paint-btn:hover { background: #444; }
.paint-done-btn { background: #fff; color: #141414; border: none; padding: 6px 10px; border-radius: 4px; cursor: pointer; font-size: 11px; font-weight: 600; }
.paint-done-btn:hover { background: #ccc; }

/* Main area */
#main { flex: 1; display: flex; align-items: center; justify-content: center; padding: 20px; position: relative; }
#tile-canvas { display: none; }
#display-canvas { max-width: 100%; max-height: 100%; border-radius: 4px; image-rendering: auto; }
#pool-frame { display: none; position: absolute; top: 0; left: 0; width: 100%; height: 100%; border: none; }
#main.pool-view #display-canvas { display: none; }
#main.pool-view #pool-frame { display: block; }

/* Display modes */
#main.display-panel { padding: 0; }
#main.display-panel #display-canvas { width: 100% !important; height: 100% !important; border-radius: 0; object-fit: cover; }
#main.display-viewport { position: fixed; inset: 0; z-index: 100; padding: 0; }
#main.display-viewport #display-canvas { width: 100% !important; height: 100% !important; border-radius: 0; object-fit: cover; }
#main:fullscreen { padding: 0; background: #000; }
#main:fullscreen #display-canvas { width: 100% !important; height: 100% !important; border-radius: 0; object-fit: cover; }
#viewport-close { display: none; position: fixed; top: 12px; right: 12px; z-index: 101; background: rgba(0,0,0,0.6); color: #fff; border: 1px solid rgba(255,255,255,0.3); border-radius: 50%; width: 32px; height: 32px; cursor: pointer; font-size: 16px; line-height: 30px; text-align: center; }
#main.display-viewport ~ #viewport-close { display: block; }

/* View toggle */
.view-toggle { display: flex; gap: 0; }
.view-btn { flex: 1; background: #2a2a2a; border: 1px solid #444; color: #888; padding: 6px 4px; cursor: pointer; font-size: 11px; text-align: center; transition: background 0.15s; }
.view-btn:first-child { border-radius: 4px 0 0 4px; }
.view-btn:last-child { border-radius: 0 4px 4px 0; }
.view-btn:hover { background: #444; }
.view-btn.active { background: #fff; color: #141414; font-weight: 600; }
#pattern-type-toggle .view-btn { border-radius: 4px; }
/* Mobile layout */
#mobile-handle, #mobile-quick-bar, #mobile-eyedropper { display: none; }
#mobile-expand-bar, #mobile-close-btn { display: none; }

@media (max-width: 768px) {
  body { flex-direction: column; height: 100vh; overflow: hidden; }

  #main {
    order: -1; flex: none; width: 100%; padding: 0;
    display: flex; align-items: flex-start; justify-content: center;
  }
  #display-canvas { width: 100% !important; height: auto !important; border-radius: 0; display: block; }

  #sidebar {
    width: 100%; min-width: unset; border-right: none;
    border-top: 1px solid #2a2a2a;
    overflow-y: auto; overflow-x: hidden;
    flex: 1; min-height: 0;
    -webkit-overflow-scrolling: touch;
  }

  #mobile-handle { display: flex; order: -10; }
  #mobile-expand-bar { order: -9; }
  #mobile-quick-bar { display: none !important; }
  #mobile-eyedropper { display: inline-block; }

  #sidebar h1 { order: -4; }
  #sidebar-nav { display: none !important; }
  #section-pattern-type { order: -3; }
  #section-start { order: -2; }
  #section-animation { order: -1; }
  #section-view { order: 0; }

  /* Touch-friendly targets */
  input[type=range]::-webkit-slider-thumb { width: 24px; height: 24px; }
  input[type=range] { height: 6px; }
  .slider-row { margin-bottom: 16px; }
  .check-row { margin-bottom: 12px; font-size: 14px; }
  .section > * + * { margin-top: 10px; }
  #amplitude-sliders { max-height: none; overflow-y: visible; }
  #mode-grid .cell { min-height: 32px; }
  .preset-btn { padding: 8px 6px; font-size: 12px; }
  .paint-swatch { width: 100%; }

  /* Mobile expand/fullscreen controls */
  #mobile-expand-bar {
    display: flex; align-items: center; justify-content: center;
    padding: 10px 12px; border-bottom: 1px solid #2a2a2a; margin: -12px -12px 8px -12px;
    cursor: pointer;
  }
  #mobile-expand-bar span { font-size: 13px; font-weight: 600; color: #fff; }
  #mobile-expand-chevron {
    color: #888; font-size: 18px; margin-left: 8px; transition: transform 0.2s;
  }

  #sidebar.mobile-fullscreen {
    position: fixed; inset: 0; z-index: 200;
    overflow-y: auto; border-top: none; border-radius: 0;
  }
  #sidebar.mobile-fullscreen #mobile-expand-chevron { transform: rotate(180deg); }
  #sidebar.mobile-fullscreen #mobile-close-btn { display: none; }
}

#light-grid .lcell {
  width: 100%; aspect-ratio: 1;
  border: 2px solid transparent; border-radius: 2px;
  cursor: pointer; transition: border-color 0.1s;
}
#light-grid .lcell:hover { border-color: rgba(255,255,255,0.5); }
#light-grid .lcell.selected { border-color: #fff; }
