/* ==================== Design Tokens & Global Styles ==================== */
:root {
  /* Tree-specific dimensions */
  --node-width: 220px;
  --node-height: 120px;
  --emoji-size: 48px;
  --emoji-offset: 50px;
  --node-spacing-x: 320px;
  --node-spacing-y: 200px;

  /* Semantic Colors */
  --surface-primary: #f9fafb;
  --text-primary: #111;
  --interactive-primary: #0ea5e9;
  
  /* Design Tokens */
  --brand-50: #f0f9ff;
  --brand-100: #e0f2fe;
  --brand-200: #bae6fd;
  --brand-300: #7dd3fc;
  --brand-400: #38bdf8;
  --brand-500: #0ea5e9;
  --brand-600: #0284c7;
  --brand-700: #0369a1;

  /* Gray Scale */
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-900: #111;

  /* Error Colors */
  --error-50: #fef2f2;
  --error-100: #fee2e2;
  --error-500: #ef4444;
  --error-600: #dc2626;

  /* Typography */
  --font-primary: 'Inter', system-ui, sans-serif;
  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.25rem;
  --text-2xl: 1.5rem;
  --text-3xl: 1.875rem;
  --text-4xl: 2.25rem;

  /* Spacing */
  --sp-1: 0.25rem;
  --sp-2: 0.5rem;
  --sp-3: 0.75rem;
  --sp-4: 1rem;
  --sp-6: 1.5rem;
  --sp-8: 2rem;
  --sp-10: 2.5rem;
  --sp-12: 3rem;
  --sp-16: 4rem;

  /* Shadows */
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-base: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);

  /* Tree Specific */
  --zoom-min: 0.1;
  --zoom-max: 2;
  --transition-duration: 750ms;
  --tree-margin-top: 40px;
  --tree-margin-bottom: 40px;
  --tree-margin-sides: 120px;
}

/* Base Styles */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  margin: 0;
  padding: 0;
  font-family: var(--font-primary);
  background: var(--surface-primary);
  color: var(--text-primary);
  line-height: 1.5;
  height: 100vh;
  overflow: hidden;
  transition: background 0.3s, color 0.3s;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.container {
  width: 100vw;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

/* Tree Container */
.roadmap-container {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: var(--surface-primary);
  transition: background 0.3s ease-out;
}

/* Tree SVG Container */
.roadmap-container svg {
  width: 100%;
  height: 100%;
  overflow: visible;
}

/* Main centering group */
.main-group {
  pointer-events: none; /* Allow clicks to pass through to transform layer */
}

/* Transform layer for zoom and pan */
.transform-layer {
  transform-origin: 0 0;
  transition: transform 0.3s ease-out;
}

/* Tree Links */
.link {
  fill: none;
  stroke: var(--gray-200);
  stroke-width: 2;
  transition: all 0.3s ease-out;
}

/* Tree Nodes */
.node {
  transition: transform 0.3s ease-out;
}

.node-content {
  transition: all 0.3s ease-out;
  transform-origin: center center;
}

/* Loading State - Center the icon exactly where tree will spawn */
.loading-state .empty-canvas-content {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

/* Add responsive scaling */
@media (max-width: 1200px) {
  .roadmap-container {
    padding: var(--sp-8);
  }
}

@media (max-width: 768px) {
  .roadmap-container {
    padding: var(--sp-4);
  }

  .quick-help {
    left: var(--sp-2);
    right: var(--sp-2);
    width: auto;
    max-height: min(66vh, 520px);
    overflow-y: auto;
  }
}

/* Settings & Help */
.settings-cog {
  position: fixed;
  bottom: var(--sp-4);
  left: var(--sp-4);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: white;
  border: 1px solid var(--gray-200);
  color: var(--gray-600);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease-out;
  z-index: 1000;
}

.debug-button {
  position: fixed;
  bottom: var(--sp-4);
  right: calc(var(--sp-4) + 56px);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: white;
  border: 1px solid var(--gray-200);
  color: var(--gray-600);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease-out;
  z-index: 1000;
}

/* Export Button */
.export-button {
  position: fixed;
  bottom: var(--sp-4);
  right: var(--sp-4);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: white;
  border: 1px solid var(--gray-200);
  color: var(--gray-600);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease-out;
  z-index: 1000;
}

.export-button:hover,
.settings-cog:hover,
.debug-button:hover {
  background: var(--gray-50);
  color: var(--brand-500);
  border-color: var(--brand-200);
}

.settings-cog:focus-visible,
.export-button:focus-visible,
.debug-button:focus-visible,
.settings-option:focus-visible {
  outline: 2px solid var(--brand-300);
  outline-offset: 2px;
}

.quick-help {
  position: fixed;
  bottom: calc(var(--sp-4) + 52px);
  left: var(--sp-4);
  width: min(420px, calc(100vw - (var(--sp-4) * 2)));
  max-height: min(70vh, 560px);
  padding: var(--sp-4);
  background: white;
  border: 1px solid var(--gray-200);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  transform: translateY(20px);
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease-out;
  z-index: 999;
}

.quick-help.active {
  transform: translateY(0);
  opacity: 1;
  visibility: visible;
}

.quick-help-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--sp-3);
}

.shortcut-item {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  color: var(--gray-600);
  font-size: var(--text-sm);
  min-height: 32px;
}

.shortcut-key {
  padding: 2px 6px;
  background: var(--gray-100);
  border-radius: 4px;
  font-family: monospace;
  font-size: var(--text-xs);
  color: var(--gray-700);
}

/* Settings Section */
.settings-section {
  margin-top: var(--sp-4);
  padding-top: var(--sp-4);
  border-top: 1px solid var(--gray-200);
}

.settings-title {
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--gray-700);
  margin-bottom: var(--sp-2);
}

.settings-option {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2);
  border: none;
  background: none;
  color: var(--gray-600);
  cursor: pointer;
  border-radius: 6px;
  width: 100%;
  transition: all 0.2s ease-out;
}

.settings-option:hover {
  background: var(--gray-50);
  color: var(--brand-500);
}

.settings-panel {
  margin-top: var(--sp-2);
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  border-radius: 10px;
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  padding: 0;
  pointer-events: none;
  transition: max-height 0.25s ease, opacity 0.25s ease;
}

.settings-panel.active {
  max-height: 520px;
  opacity: 1;
  padding: var(--sp-3);
  pointer-events: auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

.settings-panel-content {
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
  font-size: var(--text-sm);
}

.settings-group {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  background: white;
  border: 1px solid var(--gray-200);
  border-radius: 10px;
  padding: var(--sp-2);
}

.settings-group.collapsed {
  gap: 0;
}

.settings-group-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: var(--sp-2) var(--sp-2);
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--gray-700);
  font: inherit;
  cursor: pointer;
  transition: background-color 0.2s ease-out;
}

.settings-group-toggle:hover {
  background: var(--gray-50);
}

.settings-group-toggle:focus-visible {
  outline: 2px solid var(--brand-300);
  outline-offset: 2px;
}

.settings-group-toggle-label {
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.settings-group-toggle-icon {
  font-size: 18px;
  color: var(--gray-500);
  transition: transform 0.2s ease-out;
}

.settings-group:not(.collapsed) .settings-group-toggle-icon {
  transform: rotate(180deg);
}

.settings-group-body {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  padding: var(--sp-1) var(--sp-1) var(--sp-1);
}

.settings-group-title {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--gray-600);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.settings-field {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--sp-1);
  color: var(--gray-700);
}

.settings-field span {
  font-weight: 500;
}

.settings-model-meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-1);
}

.settings-model-chip {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--gray-200);
  background: var(--gray-50);
  color: var(--gray-600);
  font-size: var(--text-xs);
  line-height: 1.2;
  white-space: nowrap;
}

.settings-model-chip.ok {
  background: var(--brand-50);
  border-color: var(--brand-200);
  color: var(--brand-700);
}

.settings-model-chip.warn {
  background: var(--error-50);
  border-color: var(--error-100);
  color: var(--error-600);
}

.settings-model-chip.info {
  background: var(--gray-100);
  border-color: var(--gray-300);
  color: var(--gray-700);
}

.settings-provider-status {
  font-size: var(--text-xs);
  color: var(--gray-500);
}

.settings-provider-status.ok {
  color: var(--gray-600);
}

.settings-provider-status.warn {
  color: var(--error-600);
}

.settings-control {
  width: 100%;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

.settings-input {
  width: 100%;
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  padding: 6px 8px;
  font-size: var(--text-sm);
  background: white;
  color: var(--gray-700);
}

.settings-slider {
  flex: 1;
  accent-color: var(--brand-500);
}

.settings-value {
  min-width: 36px;
  text-align: right;
  font-size: var(--text-xs);
  color: var(--gray-500);
}

.settings-toggle {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-size: var(--text-sm);
  color: var(--gray-600);
}

.settings-toggle input {
  accent-color: var(--brand-500);
}

.settings-hint {
  font-size: var(--text-xs);
  color: var(--gray-500);
}

.settings-actions {
  display: flex;
  justify-content: flex-end;
}

.settings-reset {
  border: 1px solid var(--brand-200);
  background: var(--brand-50);
  color: var(--brand-600);
  padding: 6px 10px;
  border-radius: 8px;
  font-size: var(--text-sm);
  cursor: pointer;
  transition: all 0.2s ease-out;
}

.settings-reset:hover {
  background: var(--brand-100);
}

.settings-input:focus-visible,
.settings-reset:focus-visible {
  outline: 2px solid var(--brand-300);
  outline-offset: 2px;
}

/* Initial Input Styling */
.initial-input-container {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 80%;
  max-width: 600px;
  opacity: 1;
  transition: all 0.8s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 1000;
  perspective: 1000px;
}

.initial-input {
  width: 100%;
  padding: 1.5rem;
  font-size: 1.5rem;
  border: 2px solid var(--brand-200);
  border-radius: 12px;
  background: white;
  box-shadow: var(--shadow-lg);
  text-align: center;
  transition: all 0.8s cubic-bezier(0.4, 0, 0.2, 1);
  transform-origin: center center;
  backface-visibility: hidden;
  color: var(--text-primary);
}

.initial-input:focus {
  outline: none;
  border-color: var(--brand-500);
  box-shadow: 0 0 0 3px var(--brand-100), var(--shadow-lg);
}

.initial-input::placeholder {
  color: var(--gray-400);
  opacity: 0.7;
}

/* Animation States */
.initial-input-container.animating {
  transform: translate(-50%, -200%) scale(0.6) rotateX(45deg);
  opacity: 0;
  pointer-events: none;
  filter: blur(10px);
}

.initial-input-container.hidden {
  display: none;
}

/* Subtle Pulse Animation */
@keyframes subtle-pulse {
  0% { transform: translate(-50%, -50%) scale(1); }
  50% { transform: translate(-50%, -50%) scale(1.02); }
  100% { transform: translate(-50%, -50%) scale(1); }
}

.initial-input-container:not(:focus-within):not(.animating) {
  animation: subtle-pulse 2s infinite;
}

/* Dark Mode Support */
[data-theme="dark"] .initial-input {
  background: var(--surface-2);
  border-color: var(--brand-300);
}

[data-theme="dark"] .initial-input:focus {
  border-color: var(--brand-400);
  box-shadow: 0 0 0 3px var(--brand-900), var(--shadow-lg);
}

/* Empty State */
.empty-canvas {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--gray-400);
}

.empty-canvas-content {
  text-align: center;
}

.empty-canvas-content .material-icons-round {
  font-size: 48px;
  margin-bottom: var(--sp-4);
  color: var(--gray-300);
}

.empty-canvas-content h2 {
  font-size: var(--text-xl);
  font-weight: 600;
  margin-bottom: var(--sp-2);
  color: var(--gray-700);
}

.empty-canvas-content p {
  font-size: var(--text-base);
  color: var(--gray-500);
}

/* Loading State */
.loading-state {
  color: var(--gray-600);
}

.loading-state .material-icons-round {
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0% { opacity: 1; }
  50% { opacity: 0.5; }
  100% { opacity: 1; }
}

/* Error State */
.error-state {
  color: var(--error-600);
}

.error-state button {
  background: var(--error-50);
  border: 1px solid var(--error-100);
  color: var(--error-600);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease-out;
}

.error-state button:hover {
  background: var(--error-100);
} 