/**
 * Apple-Quality Playground UI
 * Professional, minimalist design inspired by Apple's design language
 * @version 2.0.0
 */

/* ========== ROOT VARIABLES ========== */

:root {
  /* Apple Color Palette */
  --apple-blue: #007AFF;
  --apple-blue-light: #5AC8FA;
  --apple-blue-dark: #0051D5;
  --apple-green: #34C759;
  --apple-orange: #FF9500;
  --apple-red: #FF3B30;
  --apple-purple: #AF52DE;
  --apple-pink: #FF2D55;
  --apple-teal: #5AC8FA;
  --apple-indigo: #5856D6;

  /* Grays */
  --apple-gray-1: #8E8E93;
  --apple-gray-2: #AEAEB2;
  --apple-gray-3: #C7C7CC;
  --apple-gray-4: #D1D1D6;
  --apple-gray-5: #E5E5EA;
  --apple-gray-6: #F2F2F7;

  /* Dark Mode */
  --apple-dark-1: #1C1C1E;
  --apple-dark-2: #2C2C2E;
  --apple-dark-3: #3A3A3C;
  --apple-dark-4: #48484A;
  --apple-dark-5: #636366;
  --apple-dark-6: #8E8E93;

  /* Surfaces */
  --surface-primary: #FFFFFF;
  --surface-secondary: var(--apple-gray-6);
  --surface-tertiary: var(--apple-gray-5);
  --surface-elevated: #FFFFFF;

  /* Text */
  --text-primary: #000000;
  --text-secondary: var(--apple-gray-1);
  --text-tertiary: var(--apple-gray-2);

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.07);
  --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1);
  --shadow-xl: 0 20px 25px rgba(0, 0, 0, 0.15);

  /* Spacing */
  --spacing-xs: 4px;
  --spacing-sm: 8px;
  --spacing-md: 16px;
  --spacing-lg: 24px;
  --spacing-xl: 32px;
  --spacing-2xl: 48px;

  /* Border Radius */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;
  --radius-full: 9999px;

  /* Typography */
  --font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'SF Pro Text', 'Helvetica Neue', sans-serif;
  --font-size-xs: 11px;
  --font-size-sm: 13px;
  --font-size-base: 15px;
  --font-size-lg: 17px;
  --font-size-xl: 20px;
  --font-size-2xl: 24px;
  --font-size-3xl: 32px;

  /* Transitions */
  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-base: 200ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 300ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* Dark Mode */
[data-theme="dark"] {
  --surface-primary: var(--apple-dark-1);
  --surface-secondary: var(--apple-dark-2);
  --surface-tertiary: var(--apple-dark-3);
  --surface-elevated: var(--apple-dark-2);

  --text-primary: #FFFFFF;
  --text-secondary: var(--apple-gray-3);
  --text-tertiary: var(--apple-gray-2);

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.5);
  --shadow-xl: 0 20px 25px rgba(0, 0, 0, 0.6);
}

/* ========== PLAYGROUND LAYOUT ========== */

.playground-container {
  display: grid;
  grid-template-areas:
    "toolbar toolbar toolbar"
    "sidebar canvas inspector";
  grid-template-columns: 280px 1fr 300px;
  grid-template-rows: 60px 1fr;
  height: 100vh;
  background: var(--surface-secondary);
  font-family: var(--font-family);
  color: var(--text-primary);
  overflow: hidden;
}

/* ========== TOOLBAR ========== */

.playground-toolbar {
  grid-area: toolbar;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--spacing-lg);
  background: var(--surface-elevated);
  border-bottom: 1px solid var(--apple-gray-5);
  box-shadow: var(--shadow-sm);
  z-index: 100;
}

[data-theme="dark"] .playground-toolbar {
  border-bottom-color: var(--apple-dark-3);
}

.toolbar-section {
  display: flex;
  align-items: center;
  gap: var(--spacing-md);
}

.toolbar-title {
  font-size: var(--font-size-lg);
  font-weight: 600;
  letter-spacing: -0.3px;
  color: var(--text-primary);
}

.toolbar-button {
  display: inline-flex;
  align-items: center;
  gap: var(--spacing-sm);
  padding: 6px 12px;
  font-size: var(--font-size-sm);
  font-weight: 500;
  color: var(--apple-blue);
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
}

.toolbar-button:hover {
  background: var(--apple-gray-6);
}

[data-theme="dark"] .toolbar-button:hover {
  background: var(--apple-dark-3);
}

.toolbar-button:active {
  transform: scale(0.96);
}

.toolbar-button-primary {
  color: white;
  background: var(--apple-blue);
}

.toolbar-button-primary:hover {
  background: var(--apple-blue-dark);
}

.toolbar-divider {
  width: 1px;
  height: 24px;
  background: var(--apple-gray-4);
  margin: 0 var(--spacing-sm);
}

[data-theme="dark"] .toolbar-divider {
  background: var(--apple-dark-4);
}

/* ========== SIDEBAR ========== */

.playground-sidebar {
  grid-area: sidebar;
  background: var(--surface-primary);
  border-right: 1px solid var(--apple-gray-5);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

[data-theme="dark"] .playground-sidebar {
  border-right-color: var(--apple-dark-3);
}

.sidebar-section {
  padding: var(--spacing-lg);
  border-bottom: 1px solid var(--apple-gray-5);
}

[data-theme="dark"] .sidebar-section {
  border-bottom-color: var(--apple-dark-3);
}

.sidebar-section-title {
  font-size: var(--font-size-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
  margin-bottom: var(--spacing-md);
}

.sidebar-list {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-xs);
  list-style: none;
  padding: 0;
  margin: 0;
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  padding: 10px 12px;
  font-size: var(--font-size-base);
  color: var(--text-primary);
  background: transparent;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
  text-align: left;
  width: 100%;
}

.sidebar-item:hover {
  background: var(--apple-gray-6);
}

[data-theme="dark"] .sidebar-item:hover {
  background: var(--apple-dark-3);
}

.sidebar-item.active {
  background: var(--apple-blue);
  color: white;
}

.sidebar-item-icon {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* ========== CANVAS ========== */

.playground-canvas {
  grid-area: canvas;
  position: relative;
  background: var(--surface-primary);
  overflow: hidden;
}

.canvas-wrapper {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

.canvas-grid {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image:
    linear-gradient(var(--apple-gray-5) 1px, transparent 1px),
    linear-gradient(90deg, var(--apple-gray-5) 1px, transparent 1px);
  background-size: 20px 20px;
  opacity: 0.5;
  pointer-events: none;
}

[data-theme="dark"] .canvas-grid {
  background-image:
    linear-gradient(var(--apple-dark-3) 1px, transparent 1px),
    linear-gradient(90deg, var(--apple-dark-3) 1px, transparent 1px);
}

.canvas-hud {
  position: absolute;
  bottom: var(--spacing-lg);
  left: var(--spacing-lg);
  display: flex;
  align-items: center;
  gap: var(--spacing-md);
  padding: 8px 16px;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid var(--apple-gray-5);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
}

[data-theme="dark"] .canvas-hud {
  background: rgba(28, 28, 30, 0.9);
  border-color: var(--apple-dark-4);
}

.canvas-node {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 80px;
  min-height: 80px;
  padding: var(--spacing-md);
  background: white;
  border: 2px solid var(--apple-blue);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  cursor: move;
  transition: all var(--transition-base);
  user-select: none;
}

.canvas-node:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-xl);
}

.canvas-node.selected {
  border-color: var(--apple-purple);
  border-width: 3px;
  box-shadow: 0 0 0 4px rgba(175, 82, 222, 0.2), var(--shadow-xl);
}

.canvas-node-label {
  font-size: var(--font-size-lg);
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: var(--spacing-xs);
}

.canvas-node-notation {
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
}

.canvas-node-type-treatment {
  border-color: var(--apple-green);
}

.canvas-node-type-outcome {
  border-color: var(--apple-red);
}

.canvas-node-type-covariate {
  border-color: var(--apple-blue);
}

.canvas-node-type-unobserved {
  border-color: var(--apple-gray-3);
  border-style: dashed;
}

/* ========== INSPECTOR ========== */

.playground-inspector {
  grid-area: inspector;
  background: var(--surface-primary);
  border-left: 1px solid var(--apple-gray-5);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

[data-theme="dark"] .playground-inspector {
  border-left-color: var(--apple-dark-3);
}

.inspector-section {
  padding: var(--spacing-lg);
  border-bottom: 1px solid var(--apple-gray-5);
}

[data-theme="dark"] .inspector-section {
  border-bottom-color: var(--apple-dark-3);
}

.inspector-section-title {
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: var(--spacing-md);
}

.inspector-property {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--spacing-sm) 0;
  font-size: var(--font-size-sm);
}

.inspector-property-label {
  color: var(--text-secondary);
}

.inspector-property-value {
  color: var(--text-primary);
  font-weight: 500;
}

.inspector-input {
  width: 100%;
  padding: 8px 12px;
  font-size: var(--font-size-base);
  font-family: var(--font-family);
  color: var(--text-primary);
  background: var(--surface-secondary);
  border: 1px solid var(--apple-gray-4);
  border-radius: var(--radius-md);
  outline: none;
  transition: all var(--transition-fast);
}

.inspector-input:focus {
  border-color: var(--apple-blue);
  box-shadow: 0 0 0 4px rgba(0, 122, 255, 0.1);
}

[data-theme="dark"] .inspector-input {
  border-color: var(--apple-dark-4);
}

.inspector-button {
  width: 100%;
  padding: 10px 16px;
  font-size: var(--font-size-base);
  font-weight: 500;
  color: white;
  background: var(--apple-blue);
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.inspector-button:hover {
  background: var(--apple-blue-dark);
}

.inspector-button:active {
  transform: scale(0.98);
}

.inspector-badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 8px;
  font-size: var(--font-size-xs);
  font-weight: 600;
  color: white;
  background: var(--apple-blue);
  border-radius: var(--radius-sm);
}

.inspector-badge-success {
  background: var(--apple-green);
}

.inspector-badge-warning {
  background: var(--apple-orange);
}

.inspector-badge-error {
  background: var(--apple-red);
}

/* ========== CARDS ========== */

.apple-card {
  background: var(--surface-elevated);
  border: 1px solid var(--apple-gray-5);
  border-radius: var(--radius-lg);
  padding: var(--spacing-lg);
  box-shadow: var(--shadow-sm);
  transition: all var(--transition-base);
}

[data-theme="dark"] .apple-card {
  border-color: var(--apple-dark-3);
}

.apple-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.apple-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--spacing-md);
}

.apple-card-title {
  font-size: var(--font-size-lg);
  font-weight: 600;
  color: var(--text-primary);
}

.apple-card-body {
  font-size: var(--font-size-base);
  line-height: 1.5;
  color: var(--text-secondary);
}

/* ========== RESPONSIVE ========== */

@media (max-width: 1024px) {
  .playground-container {
    grid-template-areas:
      "toolbar"
      "canvas";
    grid-template-columns: 1fr;
    grid-template-rows: 60px 1fr;
  }

  .playground-sidebar,
  .playground-inspector {
    position: fixed;
    top: 60px;
    bottom: 0;
    width: 300px;
    z-index: 200;
    transform: translateX(-100%);
    transition: transform var(--transition-base);
  }

  .playground-sidebar {
    left: 0;
  }

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

  .playground-inspector {
    right: 0;
    left: auto;
    transform: translateX(100%);
  }

  .playground-inspector.open {
    transform: translateX(0);
  }
}

@media (max-width: 768px) {
  .playground-toolbar {
    padding: 0 var(--spacing-md);
  }

  .toolbar-title {
    font-size: var(--font-size-base);
  }

  .playground-sidebar,
  .playground-inspector {
    width: 100%;
    max-width: 320px;
  }

  .canvas-hud {
    bottom: var(--spacing-md);
    left: var(--spacing-md);
    font-size: var(--font-size-xs);
  }
}

/* ========== ANIMATIONS ========== */

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slideIn {
  from {
    transform: translateX(-100%);
  }
  to {
    transform: translateX(0);
  }
}

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

.fade-in {
  animation: fadeIn var(--transition-base);
}

.slide-in {
  animation: slideIn var(--transition-base);
}

.pulse {
  animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

/* ========== ACCESSIBILITY ========== */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Focus visible for keyboard navigation */
.toolbar-button:focus-visible,
.sidebar-item:focus-visible,
.inspector-button:focus-visible,
.inspector-input:focus-visible {
  outline: 2px solid var(--apple-blue);
  outline-offset: 2px;
}
