* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  background-color: #faf9f6;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

body {
  display: flex;
}

#main-canvas {
  flex: 0 0 auto;  /* Don't grow/shrink, respect explicit width */
  display: block;
}

/* Page Title (Hypnotrochoid) */
.page-title {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  margin: 0;
  font-family: 'Saira Stencil One', system-ui, -apple-system, sans-serif;
  font-size: 48px;
  font-weight: 400;
  color: rgba(26, 54, 93, 0.85);
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  letter-spacing: 2px;
  pointer-events: none;
  user-select: none;
}

/* Contextual Hint (State-based Instructions) */
.contextual-hint {
  position: fixed;
  top: 90px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 90;
  max-width: 600px;
  padding: 12px 24px;
  background-color: rgba(26, 54, 93, 0.95);
  color: white;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  backdrop-filter: blur(8px);
  opacity: 0;
  transition: opacity 300ms ease;
  pointer-events: none;
  user-select: none;
}

.contextual-hint.visible {
  opacity: 1;
}

.contextual-hint.hidden {
  display: none;
}

.contextual-hint-text {
  margin: 0;
  font-size: 14px;
  font-weight: 500;
  text-align: center;
  letter-spacing: 0.3px;
  line-height: 1.5;
}

.contextual-hint-text strong {
  font-weight: 700;
  color: #fbbf24;
}

/* Page Footer (Attribution) */
.page-footer {
  position: fixed;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  text-align: center;
  font-size: 11px;
  color: rgba(100, 100, 100, 0.6);
  pointer-events: none;
  user-select: none;
}

.footer-line {
  line-height: 1.4;
}

.page-footer a {
  color: rgba(26, 54, 93, 0.7);
  text-decoration: none;
  pointer-events: auto;
  transition: color 150ms ease;
}

.page-footer a:hover {
  color: rgba(26, 54, 93, 1);
  text-decoration: underline;
}

/* Hide scrollbars */
::-webkit-scrollbar {
  display: none;
}

html {
  -ms-overflow-style: none;
  scrollbar-width: none;
}

/* Toolkit Tray */
.toolkit-tray {
  width: 80px;
  height: calc(100vh - 150px);  /* Leave space for settings panel at top */
  position: fixed;
  left: 0;
  top: 130px;  /* Start below settings panel */
  background-color: rgba(248, 246, 242, 0.75);
  border-right: 1px solid rgba(224, 221, 216, 0.5);
  backdrop-filter: blur(12px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

/* Ring Thumbnail */
.ring-thumbnail {
  cursor: pointer;
  transition: transform 150ms ease;
}

.ring-thumbnail:hover {
  transform: scale(1.05);
}

/* State-based styles */
.ring-thumbnail.disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.ring-thumbnail.placing {
  opacity: 0.7;
  cursor: crosshair;
}

/* Controls (vertical stack, bottom-right) */
.controls {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 10;
  display: none; /* Hidden until ring is placed */
  flex-direction: column;
  gap: 10px;
}

/* Info button (top-right, left of export button) */
.info-button {
  position: fixed;
  top: 20px;
  right: 130px;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  background-color: rgba(26, 54, 93, 0.85);
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  cursor: pointer;
  text-decoration: none;
  backdrop-filter: blur(12px);
  transition: background-color 150ms ease, transform 150ms ease, border-color 150ms ease;
}

.info-icon {
  font-family: 'Courier New', Courier, monospace;
  font-size: 22px;
  font-weight: bold;
  color: white;
  line-height: 1;
  user-select: none;
}

.info-button:hover {
  background-color: rgba(42, 74, 109, 0.9);
  border-color: rgba(255, 255, 255, 0.5);
  transform: translateY(-1px) scale(1.05);
}

.info-button:active {
  transform: translateY(0);
}

/* Export button (separate, top-right) */
.export-button {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 10;
  padding: 10px 20px;
  background-color: rgba(26, 54, 93, 0.85);
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  backdrop-filter: blur(12px);
  transition: background-color 150ms ease, transform 150ms ease;
}

.export-button:hover {
  background-color: rgba(42, 74, 109, 0.9);
  transform: translateY(-1px);
}

.export-button:active {
  transform: translateY(0);
}

/* Action buttons */
.remove-gear-button,
.remove-ring-button,
.clear-button {
  padding: 10px 20px;
  background-color: #4A4A4A;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  transition: background-color 150ms ease;
  white-space: nowrap;
}

.remove-gear-button:hover,
.remove-ring-button:hover,
.clear-button:hover {
  background-color: #333;
}

.remove-gear-button {
  background-color: #6B7280;
}

.remove-gear-button:hover {
  background-color: #4B5563;
}

.remove-ring-button {
  background-color: #F59E0B;
}

.remove-ring-button:hover {
  background-color: #D97706;
}

.clear-button {
  background-color: #DC2626;
}

.clear-button:hover {
  background-color: #B91C1C;
}

/* Gear Thumbnails */
.gear-thumbnail {
  cursor: pointer;
  transition: transform 150ms ease, opacity 150ms ease;
  margin: 4px 0;
}

.gear-thumbnail:hover:not(.disabled) {
  transform: scale(1.08);
}

.gear-thumbnail.disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

.gear-thumbnail.selected {
  opacity: 0.5;
  transform: scale(0.95);
}

/* Invalid gear preview cursor */
.canvas-invalid-preview {
  cursor: not-allowed !important;
}

/* DEPRECATED: Old color palette (replaced by style-picker) */
.color-palette {
  display: none !important;
}

.color-swatch {
  width: 36px;
  height: 36px;
  border-radius: 6px;
  border: 3px solid transparent;
  cursor: pointer;
  transition: all 150ms ease;
  position: relative;
  padding: 0;
  outline: none;
}

.color-swatch:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.color-swatch:active {
  transform: translateY(0);
}

.color-swatch.selected {
  border-color: #4A4A4A;
  box-shadow: 0 0 0 2px #FFFFFF, 0 4px 12px rgba(0, 0, 0, 0.2);
  transform: scale(1.1);
}

.color-swatch.selected:hover {
  transform: scale(1.1) translateY(-2px);
}

/* Accessibility: Focus styles for keyboard navigation */
.color-swatch:focus-visible {
  outline: 2px solid #4A4A4A;
  outline-offset: 2px;
}

/* DEPRECATED: Old thickness controls (replaced by style-picker) */
.thickness-controls {
  display: none !important;
}

.thickness-button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 60px;
  height: 60px;
  padding: 8px;
  background-color: white;
  border: 2px solid #E0DDD8;
  border-radius: 6px;
  cursor: pointer;
  transition: all 150ms ease;
}

.thickness-button:hover {
  border-color: #4A4A4A;
  transform: translateY(-2px);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

.thickness-button.selected {
  background-color: #1a365d;
  border-color: #1a365d;
}

.thickness-button.selected .thickness-label {
  color: white;
}

.thickness-button.selected .thickness-preview {
  background-color: white;
}

.thickness-preview {
  width: 30px;
  background-color: #4A4A4A;
  border-radius: 2px;
  transition: background-color 150ms ease;
}

.thickness-label {
  font-size: 11px;
  font-weight: 500;
  color: #4A4A4A;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  transition: color 150ms ease;
}

/* Accessibility: Focus styles for thickness buttons */
.thickness-button:focus-visible {
  outline: 2px solid #4A4A4A;
  outline-offset: 2px;
}

/* Undo Toast (User Story 4: Clearing Canvas with Undo Safety) */
.undo-toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  background-color: rgba(26, 32, 44, 0.95);
  color: white;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(8px);
  opacity: 0;
  transition: opacity 200ms ease;
}

.undo-toast.visible {
  opacity: 1;
}

.undo-toast.hidden {
  display: none;
}

.undo-toast-message {
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0.3px;
}

.undo-button {
  padding: 6px 16px;
  background-color: #3182CE;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: background-color 150ms ease;
}

.undo-button:hover {
  background-color: #2C5282;
}

.undo-button:active {
  background-color: #2A4365;
}

/* Export Modal (User Story 3: Exporting Finished Artwork) */
.export-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 200ms ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.export-modal {
  background-color: white;
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  max-width: 500px;
  width: 90%;
  animation: slideUp 200ms ease;
}

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

.export-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid #E0DDD8;
}

.export-modal-title {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  color: #1a202c;
}

.export-modal-close {
  background: none;
  border: none;
  font-size: 28px;
  line-height: 1;
  color: #718096;
  cursor: pointer;
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: background-color 150ms ease, color 150ms ease;
}

.export-modal-close:hover {
  background-color: #F7FAFC;
  color: #2D3748;
}

.export-modal-body {
  padding: 24px;
}

.export-modal-description {
  margin: 0 0 20px 0;
  font-size: 15px;
  color: #4A5568;
  line-height: 1.5;
}

.export-format-buttons {
  display: flex;
  gap: 16px;
}

.export-format-button {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 24px 20px;
  background-color: white;
  border: 2px solid #E0DDD8;
  border-radius: 8px;
  cursor: pointer;
  transition: all 200ms ease;
}

.export-format-button:hover {
  border-color: #1a365d;
  background-color: #F7FAFC;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.export-format-button:active {
  transform: translateY(0);
}

.export-format-icon {
  font-size: 32px;
  font-weight: 700;
  color: #1a365d;
  letter-spacing: -0.5px;
}

.export-format-label {
  font-size: 16px;
  font-weight: 600;
  color: #2D3748;
}

.export-format-details {
  font-size: 13px;
  color: #718096;
  text-align: center;
}

/* Accessibility: Focus styles for export modal */
.export-modal-close:focus-visible,
.export-format-button:focus-visible {
  outline: 2px solid #1a365d;
  outline-offset: 2px;
}

/* Hint Overlay (User Story 6: First-Load Onboarding) */
.hint-overlay {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 50;
  pointer-events: none;
  opacity: 0;
  transition: opacity 1.5s ease-in-out;
}

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

.hint-overlay.fading-out {
  opacity: 0;
}

.hint-overlay.hidden {
  display: none;
}

.hint-text {
  margin: 0;
  padding: 16px 24px;
  background-color: rgba(26, 32, 44, 0.85);
  color: white;
  font-size: 16px;
  font-weight: 500;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
  backdrop-filter: blur(8px);
  text-align: center;
  letter-spacing: 0.3px;
}

/* ============================================================================
   Style Picker (Collapsed Panel for Color + Thickness Selection)
   ============================================================================ */

.style-picker {
  position: fixed;
  bottom: 20px;
  left: 0;
  width: 80px;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Collapsed preview (always visible) */
.style-preview {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px;
  background-color: rgba(248, 246, 242, 0.75);
  border: 1px solid rgba(224, 221, 216, 0.5);
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  backdrop-filter: blur(12px);
}

.color-preview,
.thickness-preview {
  width: 40px;
  height: 40px;
  border-radius: 6px;
  border: 2px solid #E0DDD8;
  cursor: pointer;
  transition: all 150ms ease;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: white;
}

.color-preview:hover,
.thickness-preview:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
  border-color: #4A4A4A;
}

.color-preview:active,
.thickness-preview:active {
  transform: translateY(0);
}

/* Line preview inside thickness button */
.line-preview {
  width: 30px;
  height: 3px;
  border-radius: 2px;
  background-color: #4A4A4A;
}

/* Expanded pickers (shown on click) */
.expanded-picker {
  position: absolute;
  bottom: 0;
  left: 90px;
  padding: 12px 16px;
  background-color: rgba(248, 246, 242, 0.8);
  border: 1px solid rgba(224, 221, 216, 0.5);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  backdrop-filter: blur(12px);
  display: none;
  flex-wrap: wrap;
  gap: 10px;
  max-width: 400px;
  animation: slideInFromLeft 150ms ease;
}

@keyframes slideInFromLeft {
  from {
    opacity: 0;
    transform: translateX(-10px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* Color picker styles */
.color-picker {
  justify-content: center;
}

.color-picker .color-swatch {
  width: 36px;
  height: 36px;
  border-radius: 6px;
  border: 3px solid transparent;
  cursor: pointer;
  transition: all 150ms ease;
  padding: 0;
}

.color-picker .color-swatch:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.color-picker .color-swatch.selected {
  border-color: #4A4A4A;
  box-shadow: 0 0 0 2px #FFFFFF, 0 4px 12px rgba(0, 0, 0, 0.2);
  transform: scale(1.1);
}

/* Thickness picker styles */
.thickness-picker {
  justify-content: center;
}

.thickness-picker .thickness-button {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 12px 16px;
  background-color: white;
  border: 2px solid #E0DDD8;
  border-radius: 6px;
  cursor: pointer;
  transition: all 150ms ease;
  min-width: 70px;
}

.thickness-picker .thickness-button:hover {
  border-color: #4A4A4A;
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.thickness-picker .thickness-button.selected {
  background-color: #1a365d;
  border-color: #1a365d;
  color: white;
}

.thickness-picker .thickness-line {
  width: 40px;
  background-color: #4A4A4A;
  border-radius: 2px;
}

.thickness-picker .thickness-button.selected .thickness-line {
  background-color: white;
}

.thickness-picker .thickness-button span {
  font-size: 12px;
  font-weight: 500;
}

/* ============================================================================
   Settings Panel (Theme Controls)
   ============================================================================ */

.settings-panel {
  position: fixed;
  top: 20px;
  left: 0;
  width: 80px;
  z-index: 10;
  background-color: rgba(248, 246, 242, 0.75);
  border: 1px solid rgba(224, 221, 216, 0.5);
  border-radius: 8px;
  padding: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  backdrop-filter: blur(12px);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.setting-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.setting-label {
  font-size: 9px;
  font-weight: 600;
  color: #4A4A4A;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  text-align: center;
}

.theme-toggle {
  display: flex;
  gap: 4px;
  width: 100%;
}

.theme-button {
  flex: 1;
  padding: 6px 4px;
  background-color: white;
  border: 2px solid #E0DDD8;
  border-radius: 4px;
  cursor: pointer;
  font-size: 16px;
  font-weight: 500;
  color: #4A4A4A;
  transition: all 150ms ease;
  white-space: nowrap;
  text-align: center;
  line-height: 1;
}

/* Color swatch specific styles */
.theme-button.theme-swatch {
  width: 30px;
  height: 30px;
  padding: 0;
  border-radius: 50%;
  border: 3px solid transparent;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.1);
}

.theme-button.theme-swatch:hover {
  transform: scale(1.1);
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.2);
}

.theme-button.theme-swatch.active {
  border-color: #1a365d;
  box-shadow: 0 0 0 1px #1a365d, 0 2px 8px rgba(26, 54, 93, 0.3);
  transform: scale(1.05);
}

.theme-button:hover {
  border-color: #4A4A4A;
  transform: translateY(-1px);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}

/* ============================================================================
   Dark Theme Styles
   ============================================================================ */

body.dark-theme .toolkit-tray {
  background-color: rgba(26, 26, 26, 0.8);
  border-right: 1px solid rgba(60, 60, 60, 0.5);
}

body.dark-theme .settings-panel {
  background-color: rgba(26, 26, 26, 0.8);
  border: 1px solid rgba(60, 60, 60, 0.5);
}

body.dark-theme .setting-label {
  color: #e0e0e0;
}

body.dark-theme .style-preview {
  background-color: rgba(26, 26, 26, 0.8);
  border: 1px solid rgba(60, 60, 60, 0.5);
}

body.dark-theme .expanded-picker {
  background-color: rgba(26, 26, 26, 0.85);
  border: 1px solid rgba(60, 60, 60, 0.5);
}

body.dark-theme .info-button {
  background-color: rgba(42, 74, 109, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.3);
}

body.dark-theme .info-button:hover {
  background-color: rgba(58, 94, 135, 0.95);
}

body.dark-theme .export-button {
  background-color: rgba(42, 74, 109, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.3);
}

body.dark-theme .export-button:hover {
  background-color: rgba(58, 94, 135, 0.95);
}

body.dark-theme .page-title {
  color: rgba(200, 200, 200, 0.85);
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

body.dark-theme .page-footer {
  color: rgba(180, 180, 180, 0.5);
}

body.dark-theme .page-footer a {
  color: rgba(200, 200, 200, 0.7);
}

body.dark-theme .page-footer a:hover {
  color: rgba(220, 220, 220, 1);
}

body.dark-theme .contextual-hint {
  background-color: rgba(42, 74, 109, 0.95);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

body.dark-theme .contextual-hint-text strong {
  color: #fcd34d;
}

/* ============================================================================
   Mobile Warning Overlay
   ============================================================================ */

/* Hide by default on desktop */
.mobile-warning-overlay {
  display: none;
}

/* Show on tablets and mobile devices */
@media (max-width: 1024px) {
  .mobile-warning-overlay {
    display: flex;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 9999;
    background: linear-gradient(135deg, #1a365d 0%, #2c5282 100%);
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
  }

  .mobile-warning-content {
    max-width: 500px;
    text-align: center;
    color: white;
  }

  .mobile-warning-title {
    font-size: 32px;
    font-weight: 700;
    margin: 0 0 24px 0;
    color: white;
    letter-spacing: -0.5px;
  }

  .mobile-warning-text {
    font-size: 18px;
    line-height: 1.6;
    margin: 16px 0;
    color: rgba(255, 255, 255, 0.9);
  }

  .mobile-warning-link {
    display: inline-block;
    margin-top: 32px;
    padding: 14px 28px;
    background-color: rgba(255, 255, 255, 0.15);
    color: white;
    text-decoration: none;
    border-radius: 8px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    font-weight: 600;
    font-size: 16px;
    transition: all 200ms ease;
  }

  .mobile-warning-link:hover {
    background-color: rgba(255, 255, 255, 0.25);
    border-color: rgba(255, 255, 255, 0.5);
    transform: translateY(-2px);
  }
}
