/* Common Styles - Shared across all pages */

/* CSS Variables and Root Styles */
:root {
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  color: #f1f5f9;
  background-color: #0f172a;
  /* Unified color palette variables */
  --primary: #326fd1;
  --primary-rgb: 50, 111, 209;
  --primary-strong: #2563eb;
  --primary-strong-rgb: 37, 99, 235;
  --secondary: #fbbf24;
  --secondary-rgb: 251, 191, 36;
  --secondary-strong: #f59e0b;
  --secondary-strong-rgb: 245, 158, 11;
  --surface: #1e293b;
  --surface-alt: #0f172a;
  --surface-dark: #020617;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --text-inverse: #1e293b;
  --border: #334155;
  --border-strong: #475569;
  --success: #10b981;
  --warning: #f59e0b;
  --error: #ef4444;
  --info: #3b82f6;
  /* Gray scale */
  --gray-50: #f8fafc;
  --gray-100: #f1f5f9;
  --gray-200: #e2e8f0;
  --gray-300: #cbd5e1;
  --gray-400: #94a3b8;
  --gray-500: #64748b;
  --gray-600: #475569;
  --gray-700: #334155;
  --gray-800: #1e293b;
  --gray-900: #0f172a;
  /* Tier colors for civics and tech tree (15 tiers + 1 researched) */
  --tier-1: #3b82f6;   /* Blue */
  --tier-2: #06b6d4;   /* Cyan */
  --tier-3: #10b981;   /* Emerald */
  --tier-4: #84cc16;   /* Lime */
  --tier-5: #eab308;   /* Yellow */
  --tier-6: #f97316;   /* Orange */
  --tier-7: #ef4444;   /* Red */
  --tier-8: #ec4899;   /* Pink */
  --tier-9: #a855f7;   /* Purple */
  --tier-10: #6366f1;  /* Indigo */
  --tier-11: #14b8a6;  /* Teal */
  --tier-12: #22c55e;  /* Green */
  --tier-13: #f59e0b;  /* Amber */
  --tier-14: #fb7185;  /* Rose */
  --tier-15: #8b5cf6;  /* Violet */
  --researched: #06d6a0; /* Mint for researched */

  /* Legacy variables for backward compatibility */
  --accent: var(--primary);
  --accent-strong: var(--primary-strong);
  --era-color: var(--text);
  --tech-color: var(--primary);
  --wonder-color: var(--secondary);
  --mobile-header-height: 40px;
  --mobile-controls-height: 50px;
  --mobile-menu-gap: 0.5rem;
  --mobile-safe-top: env(safe-area-inset-top, 0px);
}

/* Optimization Progress Indicator */
.optimization-progress {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
}

.progress-content {
  background: var(--surface-dark);
  border: 2px solid var(--primary);
  border-radius: 12px;
  padding: 2rem 3rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--surface);
  border-top: 4px solid var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.progress-text {
  color: var(--text);
  font-size: 1.2rem;
  font-weight: 600;
}

.progress-detail {
  color: var(--text-muted);
  font-size: 0.95rem;
  text-align: center;
  min-height: 1.5rem;
}

/* Base HTML Elements */
* {
  box-sizing: border-box;
}

html {
  overflow: hidden;
}

body {
  margin: 0;
  height: 100dvh;
  background: var(--surface-alt);
  color: inherit;
  display: flex;
  flex-direction: column;
}

.mobile-scroll-wrapper {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.page-header {
  padding: 1.5rem 0.5rem 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  flex-shrink: 0;
}

.page-header h1 {
  margin: 0;
  font-size: clamp(2rem, 4vw, 2.5rem);
  font-weight: 600;
  text-align: center;
}

.header-navigation {
  margin-right: 0.5rem;
  position: relative;
}

/* Navigation flash animation */
@keyframes flash-attention {
  0%, 100% {
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.2);
    border-color: var(--border);
  }
  50% {
    box-shadow: 0 0 20px rgba(var(--primary-rgb), 0.8), 0 0 40px rgba(var(--primary-rgb), 0.4);
    border-color: var(--primary);
  }
}

.settings-button.flash-attention {
  animation: flash-attention 1s ease-in-out 3;
}


/* Controls */
.controls {
  display: flex;
  justify-content: center;
  gap: 1rem;
  align-items: center;
  padding: 0 0.5rem 0.25rem;
  flex-shrink: 0;
  flex-wrap: nowrap;
}

.edit-controls {
  visibility: hidden;
  position: fixed;
  top: 1rem;
  right: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  align-items: flex-end;
  z-index: 100;
}

.manual-help {
  color: var(--text-muted);
  font-size: 0.8rem;
  background: var(--surface);
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  margin-top: 0.25rem;
}


.manual-help kbd {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0.1rem 0.3rem;
  font-size: 0.75rem;
  font-family: monospace;
}

.control {
  font-size: 0.95rem;
  color: var(--text-muted);
}

.control--search {
  position: relative;
  flex: 1;
  max-width: 900px;
}

.control--search input[type='text'] {
  width: 100%;
  padding: 0.25rem 2.5rem 0.25rem 1rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 1.05rem;
  font-family: inherit;
  color: inherit;
  transition: border-color 200ms ease, box-shadow 200ms ease;
}

.control--search input[type='text']:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(var(--primary-rgb), 0.1);
}

.control--search input[type='text']::placeholder {
  color: var(--text-muted);
  opacity: 0.7;
}

.search-clear {
  position: absolute;
  right: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  width: 24px;
  height: 24px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 1;
  transition: all 200ms ease;
  padding: 0;
}

.search-clear:hover,
.search-clear:focus-visible {
  background: rgba(255, 255, 255, 0.1);
  color: var(--accent);
}

.settings-button {
  width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0;
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 200ms ease;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.2);
}

.settings-button:hover,
.settings-button:focus-visible {
  border-color: var(--accent);
  background: var(--surface);
  color: var(--accent);
}

.settings-container {
  position: relative;
  flex-shrink: 0;
}

.settings-menu {
  position: absolute;
  top: 100%;
  left: auto;
  right: 0;
  margin-top: 0.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(15, 23, 42, 0.2);
  min-width: 180px;
  max-width: 220px;
  max-height: calc(100vh - 4rem);
  z-index: 1000;
  backdrop-filter: blur(8px);
  opacity: 0;
  transform-origin: top right;
  transform: translateY(-10px) scale(0.95);
  transition: all 200ms ease-out;
  pointer-events: none;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.settings-menu.navigation-menu {
  left: 0;
  right: auto;
  transform-origin: top left;
}

.settings-menu.show {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.settings-menu-item {
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
}

.settings-menu-item:last-child {
  border-bottom: none;
}

.settings-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  user-select: none;
}

.settings-toggle input[type="checkbox"] {
  display: none;
}

.toggle-slider {
  position: relative;
  width: 36px;
  height: 20px;
  background: var(--border);
  border-radius: 10px;
  transition: background-color 200ms ease;
  flex-shrink: 0;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  background: white;
  border-radius: 50%;
  transition: transform 200ms ease;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.settings-toggle input[type="checkbox"]:checked + .toggle-slider {
  background: var(--accent);
}

.settings-toggle input[type="checkbox"]:checked + .toggle-slider::before {
  transform: translateX(16px);
}

.toggle-label {
  font-size: 0.75rem;
  color: var(--text);
  flex: 1;
  line-height: 1.2;
}

.settings-slider {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.slider-label {
  font-size: 0.75rem;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.slider-label span:last-child {
  font-weight: 600;
  color: var(--accent);
  min-width: 2rem;
  text-align: right;
}

.settings-slider input[type="range"] {
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: var(--border);
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
  transition: background-color 200ms ease;
}

.settings-slider input[type="range"]:hover {
  background: var(--border-strong);
}

.settings-slider input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  transition: transform 200ms ease, box-shadow 200ms ease;
}

.settings-slider input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.1);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

.settings-slider input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: none;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  transition: transform 200ms ease, box-shadow 200ms ease;
}

.settings-slider input[type="range"]::-moz-range-thumb:hover {
  transform: scale(1.1);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

/* Navigation Options */
.navigation-option {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  border-radius: 4px;
  transition: all 200ms ease;
  text-align: left;
}

.navigation-option-row {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.navigation-option-row .navigation-option {
  flex: 1;
  min-width: 0;
}

.navigation-option-open {
  width: 30px;
  height: 30px;
  border-radius: 6px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: all 200ms ease;
  text-decoration: none;
}

.navigation-option-open:hover,
.navigation-option-open:focus-visible {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(var(--primary-rgb), 0.1);
}

.navigation-option-open svg {
  display: block;
}

.navigation-option:hover,
.navigation-option:focus-visible {
  background: rgba(var(--primary-rgb), 0.1);
  color: var(--accent);
}

.navigation-option.active {
  background: var(--accent);
  color: white;
}

.navigation-option.active:hover,
.navigation-option.active:focus-visible {
  background: var(--accent-strong);
  color: white;
}

#resetView.control--button {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 40px;
  height: 40px;
  border: 1.5px solid var(--border);
  border-radius: 50%;
  padding: 0;
  background: var(--surface);
  color: var(--accent);
  cursor: pointer;
  transition: all 200ms ease;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.08);
}

.edit-controls .control--button {
  position: static;
  width: auto;
  height: auto;
  padding: 0.6rem 1.25rem;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 500;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 200ms ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.2);
}

#resetView.control--button:hover,
#resetView.control--button:focus-visible {
  border-color: var(--accent);
  background: var(--surface-alt);
}

.edit-controls .control--button:hover,
.edit-controls .control--button:focus-visible {
  border-color: var(--accent);
  background: var(--surface);
  color: var(--accent);
}

.edit-controls .control--primary {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.edit-controls .control--primary:hover,
.edit-controls .control--primary:focus-visible {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
}

.control--button svg {
  display: block;
}

main {
  padding: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}


/* Loading and Error States */
.loading-state,
.error-state {
  text-align: center;
  padding: 4rem 2rem;
  max-width: 600px;
  margin: 0 auto;
}

.loading-state h2,
.error-state h2 {
  color: var(--text);
  font-size: 1.5rem;
  margin-bottom: 1rem;
}

.loading-state p,
.error-state p {
  color: var(--text-muted);
  font-size: 1.1rem;
  margin: 0;
}

/* Responsive adjustments for common elements */
@media (max-width: 768px) {
  .wonder-tooltip {
    max-width: 90vw;
    max-height: 80vh;
    min-width: 300px;
  }

  .wonder-tooltip-header {
    padding: 1rem;
    gap: 0.75rem;
  }

  .wonder-icon {
    font-size: 1.5rem;
    min-width: 2.5rem;
  }

  .wonder-title h3 {
    font-size: 1.2rem;
  }

  .wonder-tooltip-content {
    padding: 1rem;
  }
}


@media (max-width: 600px) {
  .controls {
    gap: 0.75rem;
  }

  /* On smaller screens, position settings menu to the right to prevent overflow */
  .settings-menu {
    left: auto;
    right: 0;
  }

  /* Navigation menu should remain anchored to the left for right-opening behavior */
  .settings-menu.navigation-menu {
    left: 0;
    right: auto;
  }
}
