/**
 * Modern Sleek Dark Design System
 * Glassmorphic panels, responsive flex layout, custom styled sliders, and pixelated canvas framing.
 */

:root {
  --bg-primary: #0A0D12;
  --bg-secondary: #121820;
  --bg-card: rgba(22, 30, 41, 0.75);
  --bg-card-hover: rgba(28, 38, 52, 0.9);
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-accent: rgba(56, 211, 159, 0.35);

  --text-main: #F0F4F8;
  --text-muted: #8B9BB0;
  --text-dim: #546478;

  --color-sheep: #4CC9F0;
  --color-wolf: #FF4D6D;
  --color-plant: #38D39F;
  --color-gold: #FFB703;

  --accent-primary: #2ECC71;
  --accent-primary-hover: #27AE60;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;

  --shadow-lg: 0 16px 36px rgba(0, 0, 0, 0.45);
  --font-ui: 'Outfit', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

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

body {
  background-color: var(--bg-primary);
  color: var(--text-main);
  font-family: var(--font-ui);
  min-height: 100vh;
  overflow-x: hidden;
  user-select: none;
}

/* --- Layout Grid --- */
.app-layout {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

/* --- Top Navigation Header --- */
.top-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 24px;
  background: rgba(18, 24, 32, 0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-subtle);
  z-index: 10;
  gap: 16px;
}

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

.logo-icon {
  font-size: 24px;
  width: 38px;
  height: 38px;
  background: rgba(56, 211, 159, 0.12);
  border: 1px solid rgba(56, 211, 159, 0.25);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
}

.brand h1 {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: #FFFFFF;
}

.tagline {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 500;
}

/* --- Stats Ribbon Badges --- */
.stats-ribbon {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.stat-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  padding: 5px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 500;
  transition: all 0.2s ease;
}

.stat-badge:hover {
  background: var(--bg-card-hover);
  border-color: rgba(255, 255, 255, 0.15);
}

.badge-val {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 0.95rem;
}

.badge-sheep .badge-val { color: var(--color-sheep); }
.badge-wolf .badge-val { color: var(--color-wolf); }
.badge-plant .badge-val { color: var(--color-plant); }
.badge-time .badge-val { color: var(--color-gold); }

.badge-label {
  color: var(--text-muted);
  font-size: 0.74rem;
}

/* --- Header Actions --- */
.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

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

.btn-primary {
  background: linear-gradient(135deg, #2ECC71, #10B981);
  color: #042914;
  box-shadow: 0 4px 14px rgba(46, 204, 113, 0.25);
}

.btn-primary:hover {
  background: linear-gradient(135deg, #34D399, #059669);
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(46, 204, 113, 0.35);
}

.btn-primary.btn-active {
  background: linear-gradient(135deg, #F59E0B, #D97706);
  color: #381A02;
  box-shadow: 0 4px 14px rgba(245, 158, 11, 0.25);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-main);
  border: 1px solid var(--border-subtle);
}

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

.btn-muted {
  opacity: 0.52;
  filter: grayscale(0.7);
  background: rgba(255, 255, 255, 0.04);
}

.btn-text {
  background: transparent;
  border: none;
  color: var(--color-sheep);
  font-size: 0.75rem;
  cursor: pointer;
  text-decoration: underline;
  padding: 2px 4px;
}

.btn-text:hover {
  color: #A0E9FF;
}

.btn-sm {
  padding: 5px 9px;
  font-size: 0.74rem;
  border-radius: 5px;
}

.btn-accent {
  background: linear-gradient(135deg, #05D9E8, #0056B3);
  color: #FFFFFF;
  box-shadow: 0 2px 8px rgba(5, 217, 232, 0.25);
}

.btn-accent:hover {
  background: linear-gradient(135deg, #37E7F6, #0070E0);
  transform: translateY(-1px);
}

.preset-buttons-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.preset-buttons-row .btn {
  flex: 1;
}

.toast-text {
  font-size: 0.75rem;
  font-weight: 600;
  color: #38D39F;
  background: rgba(56, 211, 159, 0.12);
  border: 1px solid rgba(56, 211, 159, 0.3);
  border-radius: var(--radius-sm);
  padding: 4px 8px;
  text-align: center;
  transition: all 0.2s ease;
}

.btn-action-weather {
  width: 100%;
  margin-top: 10px;
  background: rgba(76, 201, 240, 0.12);
  color: #8ED6FF;
  border: 1px dashed rgba(76, 201, 240, 0.35);
  padding: 7px;
  font-size: 0.8rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-action-weather:hover {
  background: rgba(76, 201, 240, 0.2);
  border-color: #8ED6FF;
}

/* --- Main Workspace Split View --- */
.main-workspace {
  display: flex;
  flex: 1;
  overflow: hidden;
  position: relative;
}

/* --- Left Sidebar Panel --- */
.sidebar-panel {
  width: 350px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 5;
}

.sidebar-scroll {
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.sidebar-scroll::-webkit-scrollbar {
  width: 5px;
}
.sidebar-scroll::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.12);
  border-radius: 10px;
}

.control-group {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.group-title {
  font-size: 0.82rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

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

/* Speed Multiplier Segmented Buttons */
.speed-selector {
  display: flex;
  gap: 6px;
  background: rgba(0, 0, 0, 0.25);
  padding: 3px;
  border-radius: var(--radius-sm);
}

.speed-btn {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.82rem;
  padding: 5px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.speed-btn:hover {
  color: #FFF;
}

.speed-btn.active {
  background: var(--accent-primary);
  color: #042914;
  font-weight: 700;
}

/* Sliders */
.slider-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.slider-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.82rem;
}

.slider-title {
  color: var(--text-main);
  font-weight: 500;
}

.slider-val {
  font-family: var(--font-mono);
  color: var(--color-plant);
  font-weight: 600;
  font-size: 0.85rem;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
  outline: none;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--color-plant);
  cursor: pointer;
  box-shadow: 0 0 8px rgba(56, 211, 159, 0.6);
  transition: transform 0.1s ease;
}

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

/* Tools Grid */
.tools-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}

.tool-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  padding: 8px 6px;
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  font-family: var(--font-ui);
  cursor: pointer;
  transition: all 0.2s ease;
}

.tool-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

.tool-btn.active {
  background: rgba(56, 211, 159, 0.15);
  border-color: var(--color-plant);
  color: #FFF;
  font-weight: 600;
}

/* Mini Population Chart in Sidebar */
.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.chart-legend-mini {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.68rem;
  color: var(--text-muted);
}

.leg-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
}
.sheep-dot { background: var(--color-sheep); }
.wolf-dot { background: var(--color-wolf); }
.plant-dot { background: var(--color-plant); }

.mini-chart-wrapper {
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 4px;
  height: 98px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#miniChart {
  width: 100%;
  height: 100%;
}

/* --- Center Canvas Viewport --- */
.canvas-viewport {
  flex: 1;
  display: flex;
  align-items: stretch;
  justify-content: stretch;
  background: #06080B;
  position: relative;
  overflow: hidden;
  padding: 0;
  width: 100%;
  height: 100%;
}

.canvas-container {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #4A8330;
}

#simCanvas {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: -moz-crisp-edges;
  image-rendering: -webkit-crisp-edges;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  cursor: crosshair;
}

/* --- Entity Inspector Floating Card --- */
.inspector-card {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 220px;
  background: rgba(14, 20, 28, 0.88);
  backdrop-filter: blur(14px);
  border: 1px solid rgba(255, 215, 0, 0.4);
  border-radius: var(--radius-md);
  padding: 12px;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.5);
  z-index: 20;
}

.insp-close {
  position: absolute;
  top: 6px;
  right: 8px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 16px;
  cursor: pointer;
}
.insp-close:hover { color: #FFF; }

.insp-title {
  font-weight: 700;
  font-size: 0.9rem;
  margin-bottom: 8px;
  color: #FFD700;
  padding-right: 14px;
}

.insp-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--text-muted);
  padding: 3px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}
.insp-row span:last-child {
  color: var(--text-main);
  font-family: var(--font-mono);
  font-weight: 500;
}
.capitalize {
  text-transform: capitalize;
}

/* --- Extinction Modal Overlay --- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(4, 6, 9, 0.85);
  backdrop-filter: blur(16px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
  padding: 20px;
  transition: opacity 0.3s ease;
}

/* --- Visibility Utilities --- */
.hidden,
.modal-backdrop.hidden,
.inspector-card.hidden,
.btn-fullscreen-exit.hidden {
  display: none !important;
}

.modal-card {
  background: var(--bg-secondary);
  border: 1px solid rgba(255, 77, 109, 0.35);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 680px;
  padding: 28px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.7);
  display: flex;
  flex-direction: column;
  gap: 20px;
  animation: modalPop 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalPop {
  0% { transform: scale(0.95); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.modal-header {
  text-align: center;
}

.modal-badge-skull {
  font-size: 32px;
  margin-bottom: 6px;
}

.modal-header h2 {
  font-size: 1.6rem;
  color: #FFF;
  font-weight: 700;
}

.modal-subtitle {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-top: 4px;
}

.modal-chart-section h3 {
  font-size: 0.85rem;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.04em;
  margin-bottom: 8px;
}

.extinction-chart-wrapper {
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 8px;
  height: 230px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#extinctionChart {
  width: 100%;
  height: 100%;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sc-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: uppercase;
  font-weight: 600;
}

.sc-val {
  font-family: var(--font-mono);
  font-size: 0.95rem;
  font-weight: 700;
  color: #FFF;
}

.sc-subvals {
  display: flex;
  gap: 8px;
  font-size: 0.82rem;
  color: var(--text-main);
}
.sc-subvals strong {
  font-family: var(--font-mono);
  color: #FFF;
}

.modal-actions {
  display: flex;
  gap: 12px;
  margin-top: 6px;
}

.btn-lg {
  flex: 1;
  padding: 12px;
  font-size: 0.95rem;
}

/* --- Toggle Switch for Continuous Mode --- */
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 38px;
  height: 20px;
  cursor: pointer;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: rgba(255, 255, 255, 0.15);
  transition: 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  border-radius: 20px;
  border: 1px solid var(--border-subtle);
}

.toggle-slider:before {
  position: absolute;
  content: "";
  height: 12px;
  width: 12px;
  left: 3px;
  bottom: 3px;
  background-color: #FFF;
  transition: 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  border-radius: 50%;
}

.toggle-switch input:checked + .toggle-slider {
  background: linear-gradient(135deg, #2ECC71, #10B981);
  box-shadow: 0 0 10px rgba(46, 204, 113, 0.4);
  border-color: #2ECC71;
}

.toggle-switch input:checked + .toggle-slider:before {
  transform: translateX(18px);
}

.group-subtitle {
  font-size: 0.72rem;
  color: var(--text-muted);
  line-height: 1.35;
  margin-top: -2px;
  margin-bottom: 6px;
}

/* --- Fullscreen / Screen Saver Mode --- */
.app-layout.fullscreen-mode .sidebar-panel,
.app-layout.fullscreen-mode .top-nav .brand,
.app-layout.fullscreen-mode .top-nav .header-actions {
  display: none !important;
}

.app-layout.fullscreen-mode .top-nav {
  position: fixed !important;
  top: 14px !important;
  left: 50% !important;
  transform: translateX(-50%) !important;
  z-index: 990 !important;
  width: auto !important;
  min-width: unset !important;
  max-width: calc(100vw - 220px) !important;
  background: rgba(14, 20, 28, 0.82) !important;
  backdrop-filter: blur(16px) !important;
  -webkit-backdrop-filter: blur(16px) !important;
  border: 1px solid rgba(255, 255, 255, 0.16) !important;
  border-radius: 30px !important;
  padding: 6px 14px !important;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45) !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  pointer-events: auto !important;
}

.app-layout.fullscreen-mode .top-nav .stats-ribbon {
  display: flex !important;
  align-items: center !important;
  gap: 8px !important;
  flex-wrap: nowrap !important;
}

.app-layout.fullscreen-mode .top-nav .stat-badge {
  background: rgba(255, 255, 255, 0.06) !important;
  border: 1px solid rgba(255, 255, 255, 0.12) !important;
  padding: 4px 10px !important;
  border-radius: 20px !important;
  font-size: 0.8rem !important;
  white-space: nowrap !important;
}

.app-layout.fullscreen-mode .main-workspace {
  position: absolute !important;
  top: 0 !important;
  left: 0 !important;
  height: 100vh !important;
  width: 100vw !important;
}

.app-layout.fullscreen-mode .canvas-viewport {
  width: 100vw !important;
  height: 100vh !important;
  padding: 0 !important;
}

.btn-fullscreen-exit {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: rgba(14, 20, 28, 0.75);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  font-family: var(--font-ui);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  opacity: 0.65;
}

.btn-fullscreen-exit:hover {
  opacity: 1;
  background: rgba(20, 30, 42, 0.95);
  border-color: var(--color-plant);
  transform: translateY(-1px);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.65);
}

