/* Magic Spirograph: Spiral Art — Stylesheet */

:root {
  --sp-bg-card: rgba(18, 25, 42, 0.9);
  --sp-primary: #3b82f6;
  --sp-cyan: #00f0ff;
  --sp-gold: #ffd000;
  --sp-pink: #ff2a85;
  --sp-purple: #b026ff;
  --sp-board-size: min(calc(100dvh - 130px), 70vw, 640px);
}

body {
  background: radial-gradient(circle at 50% 30%, #162038 0%, #060912 100%);
  color: #f8fafc;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  overflow: hidden;
}

.spiro-field {
  display: flex;
  flex: 1;
  min-height: 0;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 16px;
  width: 100%;
  padding: 8px 16px;
  box-sizing: border-box;
  overflow: hidden;
}

/* Toolbar */
.spiro-toolbar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  background: var(--sp-bg-card);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 24px;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.55);
  z-index: 10;
  max-height: 94%;
  overflow-y: auto;
  scrollbar-width: thin;
}

.toolbar-divider {
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.18), transparent);
  margin: 2px 0;
}

.tool-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.section-label {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #94a3b8;
  text-align: center;
}

/* Gear Buttons */
.gear-buttons {
  display: flex;
  gap: 6px;
}

.gear-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 8px 4px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.06);
  border: 2px solid transparent;
  color: #e2e8f0;
  cursor: pointer;
  transition: all 0.18s cubic-bezier(0.34, 1.56, 0.64, 1);
  min-height: 52px;
}

.gear-icon {
  line-height: 1;
}

.gear-icon.sm { font-size: 1.1rem; }
.gear-icon.md { font-size: 1.35rem; }
.gear-icon.lg { font-size: 1.6rem; }

.gear-name {
  font-size: 0.72rem;
  font-weight: 700;
  margin-top: 3px;
}

.gear-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  transform: translateY(-2px);
}

.gear-btn.active {
  background: linear-gradient(135deg, rgba(0, 240, 255, 0.25), rgba(176, 38, 255, 0.25));
  border-color: var(--sp-cyan);
  box-shadow: 0 0 14px rgba(0, 240, 255, 0.4);
  color: #ffffff;
  transform: scale(1.05);
}

/* Pen Hole Position Buttons */
.hole-buttons {
  display: flex;
  gap: 6px;
}

.hole-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 38px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.06);
  border: 2px solid transparent;
  color: #e2e8f0;
  font-weight: 800;
  font-size: 0.92rem;
  cursor: pointer;
  transition: all 0.18s ease;
}

.hole-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  transform: translateY(-2px);
}

.hole-btn.active {
  background: rgba(255, 255, 255, 0.2);
  border-color: #ffffff;
  box-shadow: 0 0 10px rgba(255, 255, 255, 0.5);
  color: #ffffff;
}

/* Color Palette Swatches */
.color-palette {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  padding: 4px;
}

.color-swatch-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.3);
  padding: 0;
  cursor: pointer;
  position: relative;
  transition: all 0.18s cubic-bezier(0.34, 1.56, 0.64, 1);
  outline: none;
}

.color-swatch-btn:hover {
  transform: scale(1.18);
  border-color: #ffffff;
}

.color-swatch-btn.active {
  transform: scale(1.22);
  border-color: #ffffff;
  box-shadow: 0 0 14px currentColor, 0 0 2px 2px #ffffff;
}

.color-swatch-btn.rainbow-swatch {
  background: conic-gradient(red, yellow, lime, aqua, blue, magenta, red) !important;
}

/* Action Buttons */
.action-buttons {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}

.tool-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 8px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.06);
  border: 2px solid transparent;
  color: #f8fafc;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.18s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-sizing: border-box;
}

.tool-btn .tool-icon {
  font-size: 1.25rem;
}

.tool-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  transform: translateY(-2px);
}

.tool-btn:disabled,
.tool-btn[disabled] {
  opacity: 0.38;
  cursor: not-allowed;
  pointer-events: none;
  transform: none !important;
  box-shadow: none !important;
}

.spin-btn {
  background: linear-gradient(135deg, #059669, #10b981);
  border-color: #34d399;
}

.spin-btn.active {
  background: linear-gradient(135deg, #d97706, #f59e0b);
  border-color: #fbbf24;
  box-shadow: 0 0 16px rgba(245, 158, 11, 0.6);
  animation: pulse-spin 1.8s infinite ease-in-out;
}

@keyframes pulse-spin {
  0%, 100% { box-shadow: 0 0 12px rgba(245, 158, 11, 0.5); }
  50% { box-shadow: 0 0 24px rgba(251, 191, 36, 0.85); }
}

.save-btn {
  grid-column: span 2;
  background: linear-gradient(135deg, #2563eb, #7c3aed);
  border-color: #60a5fa;
}

/* Center Spirograph Board */
.spiro-board-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  min-width: 0;
  min-height: 0;
}

.spiro-viewport {
  position: relative;
  width: var(--sp-board-size);
  height: var(--sp-board-size);
  border-radius: 50%;
  background: #04060b;
  border: 4px solid rgba(255, 255, 255, 0.15);
  box-shadow:
    0 16px 42px rgba(0, 0, 0, 0.75),
    0 0 40px rgba(0, 240, 255, 0.2),
    inset 0 0 35px rgba(0, 0, 0, 0.85);
  overflow: hidden;
  touch-action: none;
  cursor: grab;
  outline: none;
}

.spiro-viewport:active {
  cursor: grabbing;
}

.spiro-viewport:focus-visible {
  box-shadow:
    0 16px 42px rgba(0, 0, 0, 0.75),
    0 0 0 3px var(--sp-cyan),
    0 0 30px rgba(0, 240, 255, 0.6);
}

.spiro-canvas,
.gear-canvas,
.fx-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  display: block;
}

.gear-canvas {
  pointer-events: none;
  z-index: 3;
}

.fx-canvas {
  pointer-events: none;
  z-index: 5;
}

/* Responsive */
@media (max-width: 820px) {
  :root {
    --sp-board-size: min(48dvh, 86vw, 380px);
  }

  .spiro-field {
    flex-direction: column-reverse;
    gap: 8px;
    padding: 4px 8px;
  }

  .spiro-toolbar {
    flex-direction: row;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 6px;
    padding: 6px 10px;
    max-height: 38vh;
    border-radius: 18px;
  }

  .toolbar-divider {
    display: none;
  }

  .tool-section {
    flex-direction: row;
    align-items: center;
  }

  .section-label {
    display: none;
  }

  .gear-buttons {
    gap: 4px;
  }

  .gear-btn {
    min-height: 42px;
    padding: 4px 6px;
  }

  .gear-name {
    display: none;
  }

  .hole-btn {
    height: 36px;
    min-width: 34px;
  }

  .color-palette {
    grid-template-columns: repeat(4, 1fr);
    gap: 4px;
  }

  .color-swatch-btn {
    width: 28px;
    height: 28px;
  }

  .tool-btn {
    min-height: 40px;
    padding: 4px 8px;
    font-size: 0.8rem;
  }

  .tool-btn .tool-label {
    display: none;
  }

  .action-buttons {
    grid-template-columns: repeat(4, 1fr);
    gap: 4px;
  }

  .save-btn {
    grid-column: span 1;
  }
}
