/* ============================================
   Geometric Design Gallery - Style
   ============================================ */

:root {
  --bg-primary: #0a0a0a;
  --bg-card: #161616;
  --bg-card-hover: #1e1e1e;
  --bg-modal: rgba(0, 0, 0, 0.92);
  --bg-controls: #1a1a1a;
  --bg-canvas: #000000;
  --text-primary: #e8e8e8;
  --text-secondary: #888;
  --text-muted: #555;
  --accent: #4a9eff;
  --accent-hover: #6bb3ff;
  --border: #2a2a2a;
  --border-light: #333;
  --radius: 12px;
  --radius-sm: 8px;
  --transition: 0.25s ease;
}

/* ---- Light Theme ---- */
body.light-theme {
  --bg-primary: #f5f5f5;
  --bg-card: #ffffff;
  --bg-card-hover: #f0f0f0;
  --bg-modal: rgba(255, 255, 255, 0.95);
  --bg-controls: #f8f8f8;
  --bg-canvas: #ffffff;
  --text-primary: #1a1a1a;
  --text-secondary: #666;
  --text-muted: #999;
  --accent: #2563eb;
  --accent-hover: #3b82f6;
  --border: #e0e0e0;
  --border-light: #d0d0d0;
}

body.light-theme .card-preview {
  background: #f0f0f0;
}

body.light-theme .modal-close {
  color: var(--text-muted);
}

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

body {
  background-color: var(--bg-primary);
  color: var(--text-primary);
  font-family: 'Helvetica Neue', 'Segoe UI', Arial, sans-serif;
  line-height: 1.6;
  min-height: 100vh;
}

/* ---- Header ---- */
.site-header {
  text-align: center;
  padding: 48px 20px 32px;
}

.site-header h1 {
  font-size: 1.8rem;
  font-weight: 300;
  letter-spacing: 3px;
  color: var(--text-primary);
}

.site-header p {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-top: 8px;
  letter-spacing: 1px;
}

/* ---- Gallery Grid ---- */
.gallery-grid {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 24px 60px;
}

/* ---- Category Accordion ---- */
.category-section {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.category-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  background: var(--bg-card);
  color: var(--text-primary);
  transition: background var(--transition);
  list-style: none;
  user-select: none;
}

.category-header::-webkit-details-marker {
  display: none;
}

.category-header::before {
  content: "▶";
  font-size: 0.7rem;
  margin-right: 10px;
  transition: transform 0.2s ease;
  color: var(--accent);
}

.category-section[open] > .category-header::before {
  transform: rotate(90deg);
}

.category-header:hover {
  background: var(--bg-card-hover);
}

.category-count {
  font-size: 0.8rem;
  font-weight: 400;
  color: var(--text-secondary);
  background: var(--bg-card-hover);
  padding: 2px 10px;
  border-radius: 12px;
}

.category-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 24px;
  padding: 20px;
}

@media (max-width: 900px) {
  .category-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 560px) {
  .gallery-grid {
    padding: 0 16px 40px;
  }
  .category-grid {
    grid-template-columns: 1fr;
    gap: 16px;
    padding: 12px;
  }
  .category-header {
    padding: 12px 16px;
    font-size: 1rem;
  }
}

/* ---- Card ---- */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: transform var(--transition), border-color var(--transition), box-shadow var(--transition);
}

.card:hover {
  transform: translateY(-4px);
  border-color: var(--accent);
  box-shadow: 0 8px 30px rgba(74, 158, 255, 0.1);
}

.card-preview {
  width: 100%;
  aspect-ratio: 1;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.card-preview canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.card-info {
  padding: 16px;
  border-top: 1px solid var(--border);
}

.card-info h3 {
  font-size: 0.95rem;
  font-weight: 500;
  margin-bottom: 4px;
}

.card-info p {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

/* ---- Modal Overlay ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-modal);
  z-index: 1000;
  display: none;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.modal-overlay.active {
  display: flex;
  align-items: center;
  justify-content: center;
}

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

.modal-content {
  display: flex;
  gap: 24px;
  max-width: 1100px;
  width: 95%;
  max-height: 90vh;
}

@media (max-width: 800px) {
  .modal-content {
    flex-direction: column;
    align-items: center;
    overflow-y: auto;
    max-height: 90vh;
  }
}

/* ---- Modal Canvas ---- */
.modal-canvas-wrap {
  flex-shrink: 0;
  position: relative;
}

.modal-canvas-wrap canvas {
  display: block;
  border-radius: var(--radius);
  background: #000;
  width: min(600px, 55vw);
  height: min(600px, 55vw);
}

@media (max-width: 800px) {
  .modal-canvas-wrap canvas {
    width: min(400px, 85vw);
    height: min(400px, 85vw);
  }
}

/* ---- Controls Panel ---- */
.controls-panel {
  flex: 1;
  min-width: 260px;
  max-width: 340px;
  background: var(--bg-controls);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  overflow-y: auto;
  max-height: 80vh;
}

@media (max-width: 800px) {
  .controls-panel {
    max-width: 100%;
    width: 100%;
    max-height: none;
  }
}

.controls-panel h2 {
  font-size: 1.1rem;
  font-weight: 500;
  margin-bottom: 6px;
}

.controls-panel .description {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 20px;
  line-height: 1.5;
}

/* ---- Control Group ---- */
.control-group {
  margin-bottom: 16px;
}

.control-group label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.control-group label .value {
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.control-group input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  background: var(--border-light);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

.control-group input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  transition: transform 0.15s ease;
}

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

.control-group input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  cursor: pointer;
}

.control-group input[type="color"] {
  -webkit-appearance: none;
  appearance: none;
  width: 36px;
  height: 28px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  background: transparent;
  cursor: pointer;
  padding: 2px;
}

.control-group select {
  width: 100%;
  padding: 6px 10px;
  background: var(--bg-primary);
  color: var(--text-primary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  cursor: pointer;
}

/* ---- Buttons ---- */
/* ---- Toggle Switch ---- */
.toggle-row {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.toggle-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--text-secondary);
  cursor: pointer;
}

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

.toggle-switch {
  position: relative;
  width: 36px;
  height: 20px;
  background: var(--border-light);
  border-radius: 10px;
  transition: background var(--transition);
}

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

.toggle-label input:checked + .toggle-switch {
  background: var(--accent);
}

.toggle-label input:checked + .toggle-switch::after {
  transform: translateX(16px);
  background: #fff;
}

/* ---- Buttons ---- */
.btn-row {
  display: flex;
  gap: 8px;
  margin-top: 20px;
  flex-wrap: wrap;
}

.btn {
  padding: 8px 16px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-primary);
  font-size: 0.8rem;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
}

.btn:hover {
  background: var(--border);
  border-color: var(--text-muted);
}

.btn-accent {
  background: var(--accent);
  border-color: var(--accent);
  color: #000;
  font-weight: 600;
}

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

/* ---- Close Button ---- */
.modal-close {
  position: fixed;
  top: 20px;
  right: 24px;
  z-index: 1010;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 2rem;
  cursor: pointer;
  line-height: 1;
  transition: color var(--transition);
}

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

/* ---- Footer ---- */
.site-footer {
  text-align: center;
  padding: 24px;
  color: var(--text-muted);
  font-size: 0.75rem;
  letter-spacing: 1px;
}

/* ---- Theme Toggle ---- */
.theme-toggle {
  position: fixed;
  top: 16px;
  right: 20px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.2rem;
  z-index: 100;
  transition: background var(--transition), border-color var(--transition);
}

.theme-toggle:hover {
  border-color: var(--accent);
}

/* ---- Math Info Panel ---- */
.math-info-panel {
  margin-top: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.math-info-panel summary {
  padding: 8px 12px;
  font-size: 0.8rem;
  color: var(--text-secondary);
  cursor: pointer;
  background: var(--bg-primary);
  user-select: none;
}

.math-info-panel summary:hover {
  color: var(--text-primary);
}

.math-info-body {
  padding: 10px 12px;
  font-size: 0.75rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

.math-formula {
  font-family: 'Courier New', monospace;
  color: var(--accent);
  margin-bottom: 6px;
  word-break: break-all;
}

.math-detail {
  margin-bottom: 4px;
}

.spectrum-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 8px;
  margin-bottom: 4px;
}

.spectrum-chart {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 40px;
}

.spectrum-bar {
  flex: 1;
  background: var(--accent);
  border-radius: 2px 2px 0 0;
  min-height: 2px;
  opacity: 0.7;
  transition: height 0.3s ease;
}

/* ---- Compare Canvas ---- */
.compare-canvas {
  border-radius: var(--radius);
  background: #000;
}

/* ---- Fullscreen ---- */
.modal-canvas-wrap:fullscreen {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
}

.modal-canvas-wrap:fullscreen canvas {
  width: 100vh !important;
  height: 100vh !important;
  max-width: 100vw;
  max-height: 100vh;
}

/* ---- Recording Button ---- */
.btn-recording {
  background: #e53e3e !important;
  border-color: #e53e3e !important;
  color: #fff !important;
  animation: pulse-red 1s infinite;
}

@keyframes pulse-red {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/* ---- Toast ---- */
.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--accent);
  color: #000;
  padding: 10px 24px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s ease;
  z-index: 2000;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---- GIF Progress ---- */
.gif-progress {
  margin-top: 12px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
  position: relative;
  height: 24px;
}

.gif-progress-bar {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.1s linear;
}

.gif-progress-text {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  color: var(--text-primary);
}

/* ---- Scrollbar ---- */
::-webkit-scrollbar {
  width: 6px;
}
::-webkit-scrollbar-track {
  background: var(--bg-primary);
}
::-webkit-scrollbar-thumb {
  background: var(--border-light);
  border-radius: 3px;
}
