/* ==========================================================================
   Fractal Mountains 3D - Modern Design System & Styling
   ========================================================================== */

:root {
  --bg-primary: #0a0e17;
  --bg-secondary: #111827;
  --bg-card: rgba(17, 24, 39, 0.75);
  --bg-card-hover: rgba(31, 41, 55, 0.85);
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-active: rgba(0, 242, 254, 0.4);

  --accent-cyan: #00f2fe;
  --accent-blue: #4facfe;
  --accent-purple: #8b5cf6;
  --accent-emerald: #10b981;
  --accent-amber: #f59e0b;

  --text-primary: #f9fafb;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;

  --font-family: 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --shadow-glow: 0 0 25px rgba(0, 242, 254, 0.2);
}

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

body {
  font-family: var(--font-family);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  overflow: hidden;
  height: 100vh;
  width: 100vw;
  display: flex;
}

/* App Container Layout */
#app-container {
  display: flex;
  width: 100%;
  height: 100%;
  position: relative;
}

/* ==========================================================================
   Sidebar: Controls & 2D Heightmap
   ========================================================================== */
#sidebar {
  width: 420px;
  min-width: 380px;
  height: 100%;
  background: var(--bg-card);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  z-index: 20;
  box-shadow: 10px 0 30px rgba(0, 0, 0, 0.5);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Header */
.sidebar-header {
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

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

.brand-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--accent-cyan), var(--accent-purple));
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-glow);
}

.brand-icon svg {
  width: 20px;
  height: 20px;
  fill: #fff;
}

.brand-title {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(90deg, #ffffff, #93c5fd);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-badge {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(0, 242, 254, 0.12);
  color: var(--accent-cyan);
  border: 1px solid rgba(0, 242, 254, 0.3);
}

/* Scrollable Settings Content */
.sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px 22px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.sidebar-content::-webkit-scrollbar {
  width: 6px;
}
.sidebar-content::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 4px;
}

/* Section Box */
.section-box {
  background: rgba(255, 255, 255, 0.025);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  transition: border-color 0.2s ease;
}

.section-box:hover {
  border-color: rgba(255, 255, 255, 0.14);
}

.step-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 2px;
}

.step-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  font-size: 0.75rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent-cyan), var(--accent-blue));
  color: #000;
}

.step-badge.step-2 {
  background: linear-gradient(135deg, var(--accent-purple), #ec4899);
  color: #fff;
}

.step-title {
  font-size: 0.92rem;
  font-weight: 600;
  color: #fff;
  letter-spacing: -0.01em;
}

.step-desc {
  font-size: 0.78rem;
  color: var(--text-secondary);
  line-height: 1.35;
  margin-top: -6px;
}

/* Control Row & Input Groups */
.control-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.control-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.control-val {
  font-family: monospace;
  font-size: 0.78rem;
  color: var(--accent-cyan);
  background: rgba(0, 242, 254, 0.08);
  padding: 1px 6px;
  border-radius: 4px;
}

/* Form Controls */
select, input[type="number"], input[type="text"] {
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  font-family: var(--font-family);
  font-size: 0.85rem;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  outline: none;
  transition: all 0.2s ease;
  width: 100%;
}

select:focus, input[type="number"]:focus, input[type="text"]:focus {
  border-color: var(--accent-cyan);
  box-shadow: 0 0 0 2px rgba(0, 242, 254, 0.15);
}

.seed-row {
  display: flex;
  gap: 8px;
}

/* Fantasy Map Designer & Brush Toolbar */
.brush-section-label {
  font-size: 0.70rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #d4af37;
  font-weight: 700;
  margin-top: 4px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.brush-toolbar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 7px;
}

.brush-btn {
  background: linear-gradient(145deg, rgba(28, 23, 17, 0.95), rgba(16, 12, 8, 0.98));
  border: 1px solid rgba(212, 175, 55, 0.25);
  border-radius: var(--radius-sm);
  color: #e2d9c8;
  padding: 8px 4px;
  font-size: 0.73rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  user-select: none;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.05);
  position: relative;
  overflow: hidden;
}

.brush-btn::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(212, 175, 55, 0.4), transparent);
}

.brush-btn span.emoji {
  font-size: 1.25rem;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.5));
  transition: transform 0.2s ease;
}

.brush-btn:hover {
  background: linear-gradient(145deg, rgba(42, 34, 25, 0.95), rgba(24, 18, 12, 0.98));
  border-color: rgba(212, 175, 55, 0.55);
  color: #ffffff;
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.6), 0 0 12px rgba(212, 175, 55, 0.25);
}

.brush-btn:hover span.emoji {
  transform: scale(1.15);
}

.brush-btn.active {
  background: linear-gradient(145deg, rgba(55, 42, 26, 0.98), rgba(35, 25, 14, 0.98));
  border-color: #f1c40f;
  color: #fff;
  box-shadow: 0 0 16px rgba(241, 196, 15, 0.45), inset 0 0 10px rgba(212, 175, 55, 0.25);
}

.brush-btn.active::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 15%;
  right: 15%;
  height: 2px;
  background: #f1c40f;
  box-shadow: 0 0 8px #f1c40f;
  border-radius: 2px;
}

/* Preset buttons */
.preset-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 7px;
}

.preset-btn {
  background: linear-gradient(145deg, rgba(24, 20, 15, 0.85), rgba(14, 11, 8, 0.95));
  border: 1px solid rgba(212, 175, 55, 0.22);
  border-radius: var(--radius-sm);
  color: #d1c4af;
  padding: 8px 10px;
  font-size: 0.74rem;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
  transition: all 0.2s ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 2px 5px rgba(0,0,0,0.3);
}

.preset-btn:hover {
  background: linear-gradient(145deg, rgba(38, 30, 20, 0.95), rgba(20, 15, 10, 0.98));
  color: #fff;
  border-color: rgba(212, 175, 55, 0.55);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(212, 175, 55, 0.2);
}

/* Button styles for Parchment Printing */
.btn-parchment {
  background: linear-gradient(135deg, #d4af37, #b8860b);
  color: #150f06;
  font-family: 'Cinzel', serif;
  font-weight: 700;
  letter-spacing: 0.04em;
  box-shadow: 0 4px 16px rgba(212, 175, 55, 0.35);
  border: 1px solid rgba(255, 235, 150, 0.3);
}

.btn-parchment:hover {
  background: linear-gradient(135deg, #f1c40f, #d4af37);
  transform: translateY(-1px);
  box-shadow: 0 6px 22px rgba(241, 196, 15, 0.5);
  color: #0d0903;
}

.btn-print {
  background: linear-gradient(135deg, #2c3e50, #1a252f);
  color: #ecf0f1;
  border: 1px solid rgba(255, 255, 255, 0.15);
  font-weight: 600;
}

.btn-print:hover {
  background: linear-gradient(135deg, #34495e, #243342);
  border-color: rgba(255, 255, 255, 0.3);
  transform: translateY(-1px);
}

.sketch-tip {
  font-size: 0.73rem;
  color: #d1c4af;
  background: rgba(30, 22, 14, 0.4);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border-left: 3px solid #d4af37;
  line-height: 1.4;
  border: 1px solid rgba(212, 175, 55, 0.15);
  border-left-width: 3px;
}

#canvas-2d.painting {
  cursor: crosshair;
}

/* Range Sliders */
input[type="range"] {
  -webkit-appearance: none;
  width: 100%;
  height: 5px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.12);
  outline: none;
  cursor: pointer;
  transition: background 0.2s;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--accent-cyan);
  cursor: pointer;
  box-shadow: 0 0 8px var(--accent-cyan);
  transition: transform 0.15s ease, background-color 0.15s ease;
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.25);
  background: #fff;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 600;
  font-family: var(--font-family);
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent-cyan), var(--accent-blue));
  color: #050b14;
  box-shadow: 0 4px 15px rgba(0, 242, 254, 0.25);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(0, 242, 254, 0.4);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.06);
  border-color: var(--border-subtle);
  color: var(--text-primary);
}

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

.btn-success {
  background: linear-gradient(135deg, var(--accent-purple), #ec4899);
  color: #fff;
  box-shadow: 0 4px 15px rgba(139, 92, 246, 0.25);
}

.btn-success:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(139, 92, 246, 0.4);
}

.btn-stl {
  background: linear-gradient(135deg, #10b981, #059669);
  color: #fff;
  box-shadow: 0 4px 15px rgba(16, 185, 129, 0.3);
  font-weight: 700;
}

.btn-stl:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(16, 185, 129, 0.45);
}

.btn-sm {
  padding: 6px 10px;
  font-size: 0.75rem;
}

/* 2D Canvas Preview Card */
.canvas-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: rgba(0, 0, 0, 0.45);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  padding: 12px;
  position: relative;
  gap: 10px;
}

.canvas-container {
  width: 100%;
  max-width: 360px;
  aspect-ratio: 1;
  position: relative;
  border-radius: var(--radius-sm);
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.7), 0 0 15px rgba(212, 175, 55, 0.15);
  border: 1px solid rgba(212, 175, 55, 0.35);
  background: #140e08;
}

#canvas-2d {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: auto;
}

.canvas-controls {
  display: flex;
  gap: 6px;
  width: 100%;
  justify-content: center;
}

/* Toggles & Checkbox Grid */
.toggle-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
}

.checkbox-label input[type="checkbox"] {
  accent-color: var(--accent-cyan);
  width: 15px;
  height: 15px;
  cursor: pointer;
}

/* Exports Section */
.export-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

/* ==========================================================================
   Main 3D Viewport
   ========================================================================== */
#viewport-3d {
  flex: 1;
  height: 100%;
  position: relative;
  overflow: hidden;
  background: radial-gradient(circle at 60% 30%, #151d30 0%, #0a0e17 80%);
}

#viewport-3d canvas {
  width: 100% !important;
  height: 100% !important;
  outline: none;
}

/* HUD Overlay Bar (Top) */
.hud-top-bar {
  position: absolute;
  top: 20px;
  left: 24px;
  right: 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  pointer-events: none;
  z-index: 10;
}

.hud-group {
  display: flex;
  gap: 8px;
  pointer-events: auto;
  background: rgba(17, 24, 39, 0.7);
  backdrop-filter: blur(12px);
  padding: 6px 10px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.35);
}

.hud-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-secondary);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-weight: 600;
  font-family: var(--font-family);
  cursor: pointer;
  transition: all 0.15s ease;
}

.hud-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.hud-badge {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.hud-badge span {
  color: var(--accent-cyan);
  font-weight: 600;
}

/* HUD Controls Hint (Bottom) */
.hud-bottom-hint {
  position: absolute;
  bottom: 20px;
  right: 24px;
  background: rgba(17, 24, 39, 0.7);
  backdrop-filter: blur(12px);
  padding: 8px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  font-size: 0.72rem;
  color: var(--text-muted);
  pointer-events: none;
  display: flex;
  gap: 14px;
}

.hud-bottom-hint kbd {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: monospace;
}

/* ==========================================================================
   Malla Hexagonal & Avatar de Jugador
   ========================================================================== */
.archetype-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.archetype-btn {
  background: linear-gradient(145deg, rgba(28, 22, 15, 0.95), rgba(16, 12, 8, 0.98));
  border: 1px solid rgba(212, 175, 55, 0.25);
  border-radius: var(--radius-sm);
  color: #dfd5c4;
  padding: 6px 4px;
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  user-select: none;
}

.archetype-btn span.emoji {
  font-size: 1.15rem;
}

.archetype-btn:hover {
  background: linear-gradient(145deg, rgba(42, 33, 22, 0.98), rgba(24, 18, 12, 0.98));
  border-color: rgba(212, 175, 55, 0.6);
  color: #fff;
  transform: translateY(-1px);
}

.archetype-btn.active {
  background: linear-gradient(145deg, rgba(65, 48, 28, 0.98), rgba(42, 28, 15, 0.98));
  border-color: #f1c40f;
  color: #fff;
  box-shadow: 0 0 12px rgba(241, 196, 15, 0.4), inset 0 0 8px rgba(212, 175, 55, 0.25);
}

.avatar-status-card {
  background: rgba(20, 15, 10, 0.85);
  border: 1px solid rgba(212, 175, 55, 0.3);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.avatar-status-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.72rem;
  color: #d4af37;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.avatar-status-coord {
  background: #f1c40f;
  color: #1a1006;
  font-weight: 800;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 0.72rem;
  font-family: 'Cinzel', monospace;
}

.avatar-status-desc {
  font-size: 0.75rem;
  color: #e5dac6;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Image Heightmap Upload & Dropzone */
.image-upload-box {
  border: 2px dashed rgba(212, 175, 55, 0.35);
  background: rgba(18, 14, 10, 0.7);
  border-radius: var(--radius-sm);
  padding: 14px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.image-upload-box:hover, .image-upload-box.dragover {
  border-color: #f1c40f;
  background: rgba(35, 25, 15, 0.85);
  box-shadow: 0 0 16px rgba(241, 196, 15, 0.25);
}

.image-dropzone-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 100%;
}

/* Modal de Cartografía HD Ampliada */
.cartography-modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(5, 7, 12, 0.88);
  backdrop-filter: blur(14px);
  z-index: 100;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 16px;
}

.cartography-modal.active {
  display: flex;
}

.cartography-modal-content {
  max-width: 90vmin;
  max-height: 85vmin;
  aspect-ratio: 1;
  border: 2px solid rgba(212, 175, 55, 0.45);
  border-radius: var(--radius-md);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.9), 0 0 30px rgba(212, 175, 55, 0.25);
  background: #15100a;
  overflow: hidden;
}

.cartography-modal-content canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.cartography-modal-bar {
  display: flex;
  gap: 12px;
  align-items: center;
}

/* Responsive adjustment */
@media (max-width: 900px) {
  body {
    flex-direction: column;
    overflow-y: auto;
  }
  #sidebar {
    width: 100%;
    min-width: 100%;
    height: auto;
  }
  #viewport-3d {
    height: 60vh;
    min-height: 400px;
  }
}

/* ==========================================================================
   Importación de Imágenes (Heightmap)
   ========================================================================== */
.image-upload-box {
  border: 2px dashed rgba(212, 175, 55, 0.4);
  border-radius: var(--radius-md);
  background: rgba(22, 17, 12, 0.7);
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.25s ease;
  position: relative;
  overflow: hidden;
}

.image-upload-box:hover,
.image-upload-box.drag-over {
  border-color: #f1c40f;
  background: rgba(45, 34, 20, 0.85);
  box-shadow: 0 0 16px rgba(241, 196, 15, 0.25);
}

.image-dropzone-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 100%;
  pointer-events: none;
}

.image-dropzone-content button {
  pointer-events: auto;
}

