/* ==========================================================================
   Procedural Terrain Generator — Design System & Stylesheet
   Vanilla CSS — High Performance & Responsive
   ========================================================================== */

:root {
  /* Color Palette */
  --bg-main: #0a0d14;
  --bg-surface: #111726;
  --bg-surface-elevated: #182238;
  --bg-card: #151d2e;
  --bg-input: #0e1320;
  
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-medium: rgba(255, 255, 255, 0.14);
  --border-focus: #3b82f6;

  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --accent-primary: #3b82f6;
  --accent-primary-hover: #2563eb;
  --accent-cyan: #06b6d4;
  --accent-emerald: #10b981;
  --accent-amber: #f59e0b;

  /* Typography */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', Menlo, Consolas, monospace;

  /* Layout Constants */
  --header-height: 64px;
  --sidebar-width: 360px;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.5);
  --shadow-hud: 0 8px 32px rgba(0, 0, 0, 0.6);
}

/* Reset & Box Sizing */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg-main);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.font-mono {
  font-family: var(--font-mono);
}

/* App Root Container */
#app-root {
  display: flex;
  flex-direction: column;
  width: 100vw;
  height: 100vh;
  position: relative;
  overflow: hidden;
}

/* ==========================================================================
   Header Component
   ========================================================================== */

.app-header {
  height: var(--header-height);
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  z-index: 30;
  flex-shrink: 0;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-md);
}

.brand-text {
  display: flex;
  flex-direction: column;
}

.brand-title {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: #ffffff;
}

.brand-subtitle {
  font-size: 11px;
  color: var(--text-secondary);
  letter-spacing: 0.02em;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Seed Input in Header */
.seed-control-group {
  display: flex;
  align-items: center;
  background: var(--bg-input);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-md);
  padding: 3px 4px 3px 10px;
  gap: 8px;
  transition: border-color 0.15s ease;
}

.seed-control-group:focus-within {
  border-color: var(--accent-primary);
}

.seed-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.05em;
}

.seed-input {
  background: transparent;
  border: none;
  color: #ffffff;
  font-size: 13px;
  font-weight: 600;
  width: 90px;
  outline: none;
}

/* Generic Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 500;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
  white-space: nowrap;
}

.btn-primary {
  background-color: var(--accent-primary);
  color: #ffffff;
  box-shadow: 0 1px 3px rgba(59, 130, 246, 0.3);
}

.btn-primary:hover {
  background-color: var(--accent-primary-hover);
}

.btn-primary:active {
  transform: translateY(1px);
}

.btn-secondary {
  background-color: var(--bg-surface-elevated);
  border-color: var(--border-medium);
  color: var(--text-primary);
}

.btn-secondary:hover {
  background-color: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.25);
}

.btn-icon {
  padding: 8px;
  background: transparent;
  color: var(--text-secondary);
}

.btn-icon:hover {
  color: var(--text-primary);
  background: var(--bg-surface-elevated);
}

.sidebar-toggle-btn {
  display: none;
}

/* ==========================================================================
   Main App Workspace & Layout
   ========================================================================== */

.app-main {
  display: flex;
  flex: 1;
  height: calc(100vh - var(--header-height));
  position: relative;
  overflow: hidden;
}

/* Map Canvas Container */
.canvas-container {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: #080b12;
  cursor: crosshair;
  user-select: none;
  touch-action: none;
}

.map-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
}

/* ==========================================================================
   Floating HUD Overlays
   ========================================================================== */

.floating-hud {
  position: absolute;
  background: rgba(17, 23, 38, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-hud);
  z-index: 20;
  pointer-events: auto;
}

/* Real-time Terrain Inspector HUD */
.inspector-hud {
  bottom: 20px;
  left: 20px;
  width: 320px;
  overflow: hidden;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.hud-header {
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.03);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.hud-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
}

.inspector-body {
  padding: 12px 14px;
}

.inspector-empty {
  padding: 8px 0;
  text-align: center;
}

.inspector-hint {
  font-size: 12px;
  color: var(--text-muted);
}

.inspector-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.inspector-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.inspector-item.full-width {
  grid-column: span 2;
}

.inspector-item .label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.inspector-item .value {
  font-size: 12px;
  color: var(--text-primary);
  font-weight: 500;
}

.val-bar-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
}

.progress-bar {
  flex: 1;
  height: 4px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: #38bdf8;
  border-radius: var(--radius-full);
}

.progress-bar.moisture .progress-fill {
  background: #34d399;
}

.biome-badge-large {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  margin-top: 4px;
}

.biome-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.biome-title {
  font-size: 12px;
  font-weight: 600;
  color: #ffffff;
  flex: 1;
}

.biome-type-tag {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Minimap HUD */
.minimap-hud {
  top: 20px;
  left: 20px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.minimap-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 4px;
}

.minimap-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
}

.minimap-badge {
  font-size: 9px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--accent-cyan);
  background: rgba(6, 182, 212, 0.12);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
}

.minimap-wrapper {
  width: 200px;
  height: 100px;
  background: #000;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border-subtle);
}

.minimap-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* Zoom HUD Controls */
.zoom-hud {
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  padding: 6px;
  gap: 6px;
}

.zoom-controls {
  display: flex;
  align-items: center;
  gap: 4px;
}

.zoom-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.15s ease;
}

.zoom-btn:hover {
  background: rgba(255, 255, 255, 0.15);
  border-color: rgba(255, 255, 255, 0.3);
}

.zoom-btn:active {
  transform: scale(0.95);
}

.zoom-badge {
  padding: 0 10px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-primary);
  min-width: 60px;
  text-align: center;
}

.zoom-presets {
  display: flex;
  align-items: center;
  gap: 4px;
}

.preset-btn {
  flex: 1;
  padding: 4px 8px;
  font-size: 10px;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s ease;
}

.preset-btn:hover {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.12);
}

/* ==========================================================================
   Sidebar Controls & Parameters
   ========================================================================== */

.controls-sidebar {
  width: var(--sidebar-width);
  background: var(--bg-surface);
  border-left: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  z-index: 25;
  flex-shrink: 0;
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar-inner {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Control Cards */
.control-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.card-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
}

/* Segmented Control for View Modes */
.segmented-control {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(70px, 1fr));
  gap: 4px;
  background: var(--bg-input);
  padding: 3px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-medium);
}

.segment-label {
  display: block;
  cursor: pointer;
}

.segment-label input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segment-btn {
  display: block;
  text-align: center;
  padding: 6px 4px;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  transition: all 0.15s ease;
  user-select: none;
}

.segment-label input:checked + .segment-btn {
  background: var(--accent-primary);
  color: #ffffff;
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

/* Form Controls */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.form-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-primary);
}

.param-val {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent-cyan);
  background: rgba(6, 182, 212, 0.1);
  padding: 1px 6px;
  border-radius: var(--radius-sm);
}

/* Select Dropdown */
.select-wrapper {
  position: relative;
}

.form-select {
  width: 100%;
  appearance: none;
  background: var(--bg-input);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-md);
  padding: 9px 32px 9px 12px;
  color: var(--text-primary);
  font-size: 13px;
  font-family: inherit;
  outline: none;
  cursor: pointer;
  transition: border-color 0.15s ease;
}

.form-select:focus {
  border-color: var(--accent-primary);
}

.select-arrow {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

/* Range Sliders */
.range-slider {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  height: 6px;
  background: var(--bg-input);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-full);
  outline: none;
  cursor: pointer;
}

.range-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #ffffff;
  border: 2px solid var(--accent-primary);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
  cursor: pointer;
  transition: transform 0.1s ease;
}

.range-slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #ffffff;
  border: 2px solid var(--accent-primary);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
  cursor: pointer;
}

.range-slider:active::-webkit-slider-thumb {
  transform: scale(1.15);
}

.slider-ticks {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: var(--text-muted);
  padding: 0 2px;
}

/* World Stats Bar */
.land-water-stats {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.stat-bar-container {
  display: flex;
  height: 8px;
  border-radius: var(--radius-full);
  overflow: hidden;
  background: rgba(255, 255, 255, 0.05);
}

.stat-bar {
  height: 100%;
  transition: width 0.3s ease;
}

.water-segment {
  background: #2c5e99;
}

.land-segment {
  background: #508c4b;
}

.stat-labels {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-secondary);
}

.stat-tag {
  display: flex;
  align-items: center;
  gap: 6px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.water-dot {
  background: #2c5e99;
}

.land-dot {
  background: #508c4b;
}

/* Biome Legend List */
.biome-legend-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 4px;
  max-height: 220px;
  overflow-y: auto;
  padding-right: 4px;
}

.legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.02);
  transition: background 0.15s ease;
}

.legend-row:hover {
  background: rgba(255, 255, 255, 0.06);
}

.legend-swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  flex-shrink: 0;
}

.legend-name {
  font-size: 11px;
  color: var(--text-primary);
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.legend-pct {
  font-size: 11px;
  color: var(--text-muted);
}

/* Navigation Tips Card */
.tips-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 11px;
  color: var(--text-secondary);
}

.tips-list li {
  position: relative;
  padding-left: 12px;
}

.tips-list li::before {
  content: '•';
  position: absolute;
  left: 0;
  color: var(--accent-cyan);
}

.tips-list strong {
  color: var(--text-primary);
}

/* Custom Scrollbars */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* ==========================================================================
   Responsive Design & Breakpoints
   ========================================================================== */

@media (max-width: 1024px) {
  :root {
    --sidebar-width: 320px;
  }

  .minimap-hud {
    display: none; /* Hide floating minimap on smaller screens to maximize view */
  }
}

@media (max-width: 768px) {
  .sidebar-toggle-btn {
    display: inline-flex;
  }

  .controls-sidebar {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 300px;
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: -8px 0 24px rgba(0, 0, 0, 0.6);
  }

  .controls-sidebar.open {
    transform: translateX(0);
  }

  .inspector-hud {
    width: calc(100% - 40px);
    left: 20px;
    right: 20px;
    bottom: 80px;
  }

  .zoom-hud {
    bottom: 20px;
    right: 20px;
  }

  .brand-subtitle {
    display: none;
  }

  .seed-control-group {
    padding: 2px 4px 2px 8px;
  }

  .seed-input {
    width: 60px;
  }
}
