/**
 * Design System - Figma-like UI
 * Reusable styles for playground projects
 */

/* ========== CSS VARIABLES ========== */
:root {
  /* Dark theme (default) */
  --bg-canvas: #1a1a1a;
  --bg-dot: rgba(255, 255, 255, 0.08);
  --bg-panel: rgba(40, 40, 40, 0.95);
  --bg-panel-hover: rgba(50, 50, 50, 0.95);
  --bg-input: rgba(0, 0, 0, 0.3);
  --bg-input-hover: rgba(0, 0, 0, 0.4);

  --border-panel: rgba(255, 255, 255, 0.08);
  --border-input: rgba(255, 255, 255, 0.1);
  --border-input-focus: rgba(255, 255, 255, 0.25);

  --text-primary: rgba(255, 255, 255, 0.9);
  --text-secondary: rgba(255, 255, 255, 0.6);
  --text-muted: rgba(255, 255, 255, 0.4);

  --accent: #7c6df5;
  --accent-hover: #8b7ef7;

  /* Spacing */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;

  /* Typography */
  --font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-size-xs: 10px;
  --font-size-sm: 11px;
  --font-size-base: 12px;

  /* Borders */
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;

  /* Shadows */
  --shadow-panel: 0 2px 8px rgba(0, 0, 0, 0.3), 0 0 1px rgba(0, 0, 0, 0.2);

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-base: 200ms ease;
}

/* Light theme */
[data-theme="light"] {
  --bg-canvas: rgb(246, 244, 238);
  --bg-dot: rgba(0, 0, 0, 0.08);
  --bg-panel: rgba(255, 255, 255, 0.95);
  --bg-panel-hover: rgba(255, 255, 255, 0.98);
  --bg-input: rgba(0, 0, 0, 0.05);
  --bg-input-hover: rgba(0, 0, 0, 0.08);

  --border-panel: rgba(0, 0, 0, 0.08);
  --border-input: rgba(0, 0, 0, 0.12);
  --border-input-focus: rgba(0, 0, 0, 0.25);

  --text-primary: rgba(0, 0, 0, 0.9);
  --text-secondary: rgba(0, 0, 0, 0.6);
  --text-muted: rgba(0, 0, 0, 0.4);

  --shadow-panel: 0 2px 8px rgba(0, 0, 0, 0.1), 0 0 1px rgba(0, 0, 0, 0.1);
}

/* ========== BASE STYLES ========== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  color: var(--text-primary);
  background: var(--bg-canvas);
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}

/* ========== DOTTED CANVAS BACKGROUND ========== */
.canvas-bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  background-color: var(--bg-canvas);
  background-image: radial-gradient(var(--bg-dot) 1px, transparent 1px);
  background-size: 12px 12px;
  pointer-events: none;
}

/* ========== TOP LEFT: Title + Theme ========== */
.panel-topleft {
  position: fixed;
  top: var(--space-4);
  left: var(--space-4);
  z-index: 100;
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.page-title {
  font-size: 14px;
  color: #000;
  font-weight: 900;
  letter-spacing: 0.8px;
}

[data-theme="dark"] .page-title {
  color: #fff;
}

.page-title-link {
  color: var(--text-secondary);
  text-decoration: none;
  font-weight: 500;
  transition: color var(--transition-fast);
}

.page-title-link:hover {
  color: var(--text-primary);
  text-decoration: underline;
}

.page-title-sep {
  color: var(--text-muted);
  font-weight: 400;
  margin: 0 2px;
}

/* ========== THEME TOGGLE ========== */
.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: var(--bg-panel);
  border: 1px solid var(--border-panel);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-panel);
  color: var(--text-secondary);
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast);
}

.theme-toggle:hover {
  background: var(--bg-panel-hover);
  color: var(--text-primary);
}

.theme-toggle .icon-moon {
  display: none;
}

[data-theme="light"] .theme-toggle .icon-sun {
  display: none;
}

[data-theme="light"] .theme-toggle .icon-moon {
  display: block;
}

/* ========== BOTTOM LEFT: Theme + Zoom Controls ========== */
.panel-bottomleft {
  position: fixed;
  bottom: var(--space-4);
  left: var(--space-4);
  z-index: 100;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.theme-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: var(--bg-panel);
  border: 1px solid var(--border-panel);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-panel);
  color: var(--text-secondary);
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast);
}

.theme-btn:hover {
  background: var(--bg-panel-hover);
  color: var(--text-primary);
}

.theme-btn .icon-moon {
  display: none;
}

[data-theme="light"] .theme-btn .icon-sun {
  display: none;
}

[data-theme="light"] .theme-btn .icon-moon {
  display: block;
}

.zoom-panel {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1);
  background: var(--bg-panel);
  border: 1px solid var(--border-panel);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-panel);
}

.zoom-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast);
}

.zoom-btn:hover {
  background: var(--bg-input);
  color: var(--text-primary);
}

.zoom-value {
  min-width: 36px;
  text-align: center;
  font-size: var(--font-size-xs);
  font-weight: 500;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

.zoom-divider {
  width: 1px;
  height: 16px;
  background: var(--border-panel);
  margin: 0 var(--space-1);
}

/* Theme toggle icons */
.zoom-btn .icon-moon {
  display: none;
}

[data-theme="light"] .zoom-btn .icon-sun {
  display: none;
}

[data-theme="light"] .zoom-btn .icon-moon {
  display: block;
}

/* ========== RIGHT PANELS ========== */
.panels-right {
  position: fixed;
  top: 60px;
  right: var(--space-4);
  width: 180px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  background: transparent;
  pointer-events: none;
}

.panels-right > * {
  pointer-events: auto;
}

/* ========== COLLAPSIBLE PANELS ========== */
.collapsible-panel {
  background: var(--bg-panel);
  border: 1px solid var(--border-panel);
  border-radius: var(--radius-md);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  overflow: hidden;
}

.collapsible-panel .panel-toggle {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  padding: var(--space-2) var(--space-3);
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-family: var(--font-family);
  font-size: var(--font-size-sm);
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition-fast);
}

.collapsible-panel .panel-toggle:hover {
  background: var(--bg-input);
}

.collapsible-panel .panel-toggle span {
  flex: 1;
  text-align: left;
}

.collapsible-panel .panel-toggle .chevron {
  transition: transform var(--transition-fast);
  color: var(--text-muted);
}

.collapsible-panel.open .panel-toggle .chevron {
  transform: rotate(180deg);
}

.collapsible-panel .panel-content {
  display: none;
  padding: var(--space-2) var(--space-3) var(--space-3);
  border-top: 1px solid var(--border-panel);
}

.collapsible-panel.open .panel-content {
  display: block;
}

/* ========== FORM CONTROLS ========== */
.control-group {
  margin-bottom: var(--space-3);
}

.control-group:last-child {
  margin-bottom: 0;
}

.control-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-1);
  font-size: var(--font-size-xs);
  color: var(--text-secondary);
}

.control-value {
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.control-select,
.control-input {
  width: 100%;
  padding: var(--space-1) var(--space-2);
  background: var(--bg-input);
  border: 1px solid var(--border-input);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-family);
  font-size: var(--font-size-sm);
  outline: none;
  transition: border-color var(--transition-fast), background var(--transition-fast);
}

.control-select {
  padding-right: var(--space-5);
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 6px center;
  background-size: 10px;
}

.control-select:hover,
.control-input:hover {
  background: var(--bg-input-hover);
}

.control-select:focus,
.control-input:focus {
  border-color: var(--border-input-focus);
}

/* Slider */
.control-slider {
  width: 100%;
  height: 4px;
  background: var(--bg-input);
  border-radius: 2px;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

.control-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  background: var(--text-primary);
  border-radius: 50%;
  cursor: pointer;
  transition: transform var(--transition-fast);
}

.control-slider::-webkit-slider-thumb:hover {
  transform: scale(1.2);
}

.control-slider::-moz-range-thumb {
  width: 12px;
  height: 12px;
  background: var(--text-primary);
  border: none;
  border-radius: 50%;
  cursor: pointer;
}

/* Color Input */
.control-color {
  width: 100%;
  height: 28px;
  padding: 2px;
  background: var(--bg-input);
  border: 1px solid var(--border-input);
  border-radius: var(--radius-sm);
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}

.control-color::-webkit-color-swatch-wrapper {
  padding: 0;
}

.control-color::-webkit-color-swatch {
  border: none;
  border-radius: calc(var(--radius-sm) - 2px);
}

.control-color::-moz-color-swatch {
  border: none;
  border-radius: calc(var(--radius-sm) - 2px);
}

/* Toggle */
.toggle-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.control-toggle {
  position: relative;
  display: inline-block;
  width: 32px;
  height: 18px;
  cursor: pointer;
}

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

.control-toggle-track {
  position: absolute;
  inset: 0;
  background: var(--bg-input);
  border-radius: 9px;
  transition: background var(--transition-fast);
}

.control-toggle-track::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  background: var(--text-secondary);
  border-radius: 50%;
  transition: transform var(--transition-fast), background var(--transition-fast);
}

.control-toggle input:checked + .control-toggle-track {
  background: var(--accent);
}

.control-toggle input:checked + .control-toggle-track::after {
  transform: translateX(14px);
  background: white;
}

/* ========== BUTTONS ========== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-2) var(--space-3);
  background: var(--bg-input);
  border: 1px solid var(--border-input);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-family);
  font-size: var(--font-size-sm);
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition-fast), border-color var(--transition-fast);
}

.btn:hover {
  background: var(--bg-input-hover);
  border-color: var(--border-input-focus);
}

.btn-sm {
  padding: var(--space-1) var(--space-2);
  font-size: var(--font-size-xs);
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-full {
  width: 100%;
}

.btn-group {
  display: flex;
  gap: var(--space-2);
}

.btn-group .btn {
  flex: 1;
}

/* ========== CODE BLOCK ========== */
.code-block {
  padding: var(--space-2);
  background: var(--bg-input);
  border: 1px solid var(--border-input);
  border-radius: var(--radius-sm);
  font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
  font-size: 9px;
  line-height: 1.5;
  color: var(--text-secondary);
  white-space: pre;
  overflow-x: auto;
  max-height: 120px;
  margin-bottom: var(--space-2);
}

/* ========== UTILITIES ========== */
.flex {
  display: flex;
}

.items-center {
  align-items: center;
}

.gap-2 {
  gap: var(--space-2);
}

.gap-3 {
  gap: var(--space-3);
}

/* ========== TRANSITIONS ========== */
.collapsible-panel,
.theme-toggle,
.zoom-btn,
.control-select,
.control-input,
.control-slider,
.control-toggle-track,
.btn {
  transition:
    background-color var(--transition-base),
    border-color var(--transition-base),
    color var(--transition-base),
    box-shadow var(--transition-base);
}

/* ========== BOTTOM RIGHT: Branding Link ========== */
.branding-link {
  position: fixed;
  right: var(--space-4);
  bottom: calc(var(--space-4) + 5px);
  display: flex;
  align-items: center;
  gap: 6px;
  z-index: 100;
  background: transparent;
  border-radius: 6px;
  padding: 5px 0;
  backdrop-filter: blur(10px);
  text-decoration: none;
  color: rgba(255, 255, 255, 0.3);
  font-size: 12px;
  font-weight: 400;
  cursor: pointer;
  transition: all 0.2s ease;
  height: 26px;
}

.branding-link:hover {
  color: #fff;
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 3px;
}

[data-theme="light"] .branding-link {
  color: rgba(0, 0, 0, 0.3);
}

[data-theme="light"] .branding-link:hover {
  color: rgba(0, 0, 0, 0.8);
}

/* ========== INSTRUCTIONS PANEL ========== */
.instructions-panel .panel-toggle {
  justify-content: flex-start;
}

.instructions-panel .chevron-right {
  margin-left: auto;
  opacity: 0.5;
}

.instructions-panel:hover .chevron-right {
  opacity: 1;
}

/* ========== MODAL ========== */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}

.modal-overlay.open {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: var(--bg-panel);
  border: 1px solid var(--border-panel);
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
  width: 90%;
  max-width: 560px;
  max-height: 85vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transform: scale(0.95) translateY(10px);
  transition: transform 0.2s ease;
}

.modal-overlay.open .modal {
  transform: scale(1) translateY(0);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4);
  border-bottom: 1px solid var(--border-panel);
}

.modal-title {
  font-size: var(--font-size-base);
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
}

.modal-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast);
}

.modal-close:hover {
  background: var(--bg-input);
  color: var(--text-primary);
}

.modal-body {
  padding: var(--space-4);
  overflow-y: auto;
}

.modal-section {
  margin-bottom: var(--space-4);
}

.modal-section:last-child {
  margin-bottom: 0;
}

.modal-section h3 {
  font-size: var(--font-size-xs);
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 0 0 var(--space-2) 0;
}

.modal-section .code-block {
  margin-bottom: 0;
  max-height: none;
}

.options-list {
  list-style: none;
  padding: 0;
  margin: 0;
  font-size: var(--font-size-xs);
  color: var(--text-secondary);
}

.options-list li {
  padding: var(--space-1) 0;
  border-bottom: 1px solid var(--border-input);
}

.options-list li:last-child {
  border-bottom: none;
}

.options-list strong {
  color: var(--text-primary);
}

.modal-links {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.modal-link {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: var(--bg-input);
  border: 1px solid var(--border-input);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  text-decoration: none;
  font-size: var(--font-size-sm);
  transition: background var(--transition-fast), border-color var(--transition-fast);
}

.modal-link:hover {
  background: var(--bg-input-hover);
  border-color: var(--border-input-focus);
}

.modal-link svg {
  flex-shrink: 0;
  opacity: 0.7;
}
