/* Magic Kaleidoscope — Visual Styles */

:root {
  --k-bg-dark: #070a12;
  --k-bg-card: rgba(18, 24, 38, 0.88);
  --k-border-glow: rgba(110, 150, 255, 0.35);
  --k-gold: #ffd700;
  --k-cyan: #00f0ff;
  --k-accent: #b026ff;
  --k-lens-size: min(78vmin, 620px);
}

body {
  background: radial-gradient(circle at 50% 40%, #12192c 0%, #060911 100%);
  color: #f1f5f9;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  overflow: hidden;
}

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

/* Toolbar Styling */
.kaleidoscope-toolbar {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  background: var(--k-bg-card);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--k-border-glow);
  border-radius: 20px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
  z-index: 10;
  max-height: 96%;
  overflow-y: auto;
  scrollbar-width: thin;
}

.toolbar-separator {
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.15), 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;
}

/* Rays Selection */
.rays-buttons {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}

.ray-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 6px 8px;
  min-width: 46px;
  min-height: 46px;
  border-radius: 12px;
  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);
}

.ray-btn .ray-icon {
  font-size: 1.15rem;
  line-height: 1;
}

.ray-btn .ray-num {
  font-size: 0.8rem;
  font-weight: 800;
  margin-top: 2px;
}

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

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

/* Tool Buttons (Brush, Rainbow, Stars) */
.tool-btn {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  min-height: 44px;
  padding: 6px 12px;
  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;
  display: flex;
  align-items: center;
  justify-content: center;
}

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

.tool-btn:active:not(:disabled) {
  transform: scale(0.94);
}

.tool-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.tool-btn.active {
  background: linear-gradient(135deg, rgba(255, 42, 133, 0.25), rgba(176, 38, 255, 0.35));
  border-color: #ff2a85;
  box-shadow: 0 0 16px rgba(255, 42, 133, 0.4);
}

/* 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 (Size, Spin, Undo, Clear, Save) */
.action-buttons {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}

.action-buttons .tool-btn {
  justify-content: center;
  padding: 8px;
}

.size-toggle-btn .size-dot {
  display: inline-block;
  background: #ffffff;
  border-radius: 50%;
  box-shadow: 0 0 8px rgba(255, 255, 255, 0.8);
  transition: all 0.2s ease;
}

.size-dot.small { width: 8px; height: 8px; }
.size-dot.medium { width: 14px; height: 14px; }
.size-dot.large { width: 22px; height: 22px; }

.spin-btn.active {
  background: linear-gradient(135deg, #059669, #10b981);
  border-color: #34d399;
  box-shadow: 0 0 16px rgba(16, 185, 129, 0.6);
  animation: pulse-spin 2s infinite ease-in-out;
}

.spin-btn .tool-icon {
  display: inline-block;
  transition: transform 0.3s ease;
}

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

.save-btn:hover {
  box-shadow: 0 0 16px rgba(96, 165, 250, 0.6);
}

.instruction-banner {
  cursor: pointer;
}

/* Keyboard Focus Rings */
.ray-btn:focus-visible,
.tool-btn:focus-visible,
.color-swatch-btn:focus-visible,
.instruction-banner:focus-visible {
  outline: 3px solid var(--k-gold);
  outline-offset: 2px;
}

/* Center Stage & Lens */
.kaleidoscope-stage-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  min-height: 0;
  min-width: 0;
  position: relative;
}

.lens-wrapper {
  position: relative;
  width: var(--k-lens-size);
  height: var(--k-lens-size);
  aspect-ratio: 1 / 1;
  max-width: 100%;
  max-height: 100%;
  border-radius: 50%;
  box-shadow:
    0 0 0 4px rgba(255, 215, 0, 0.4),
    0 0 0 10px rgba(15, 23, 42, 0.9),
    0 0 40px rgba(0, 240, 255, 0.25),
    inset 0 0 30px rgba(0, 0, 0, 0.8);
  background: #04060b;
  overflow: hidden;
  touch-action: none;
}

.lens-frame-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  pointer-events: none;
  box-shadow: inset 0 0 25px rgba(0, 0, 0, 0.85);
  border: 3px solid rgba(255, 215, 0, 0.6);
  z-index: 5;
}

.lens-rotator {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  transform-origin: center center;
  touch-action: none;
  will-change: transform;
}

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

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

.guide-cross {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 14px;
  height: 14px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.7) 0%, transparent 70%);
  pointer-events: none;
  z-index: 4;
  opacity: 0.6;
  transition: opacity 0.5s ease;
}

.guide-cross.hidden {
  opacity: 0;
}

@keyframes pulse-spin {
  0%, 100% { box-shadow: 0 0 12px rgba(16, 185, 129, 0.5); }
  50% { box-shadow: 0 0 24px rgba(52, 211, 153, 0.9); }
}

/* Responsive Layout */
@media (max-width: 820px) and (orientation: portrait) {
  .kaleidoscope-field {
    flex-direction: column-reverse;
    gap: 8px;
    padding: 4px 8px;
  }

  .kaleidoscope-stage-container {
    height: auto;
    flex: 1 1 auto;
    max-height: calc(100% - 120px);
  }

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

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

  .section-label {
    display: none;
  }

  .toolbar-separator {
    width: 1px;
    height: 32px;
    margin: 0 4px;
  }

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

  .ray-btn {
    min-width: 38px;
    min-height: 38px;
    padding: 3px;
  }

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

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

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

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

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

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

  :root {
    --k-lens-size: min(84vw, 52vh, 440px);
  }
}

@media (max-height: 520px) and (orientation: landscape) {
  .kaleidoscope-field {
    padding: 4px 8px;
    gap: 10px;
  }

  .kaleidoscope-toolbar {
    padding: 6px 8px;
    gap: 4px;
  }

  .tool-btn {
    min-height: 34px;
    padding: 4px 6px;
  }

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

  .ray-btn {
    min-width: 34px;
    min-height: 34px;
    padding: 2px;
  }

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

  :root {
    --k-lens-size: min(80vh, calc(100vw - 180px), 480px);
  }
}
