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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  overflow: hidden;
  background: #f9fafb;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  cursor: crosshair;
  background: white;
}

/* Intro Overlay */
.intro-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: white;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: opacity 0.5s ease;
}

.intro-overlay.fade-out {
  opacity: 0;
  pointer-events: none;
}

#intro-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

.intro-message {
  position: relative;
  z-index: 1001;
  text-align: center;
  padding: 0 20px;
  opacity: 0;
  transition: opacity 0.5s ease;
  margin-top: 40vh;
}

.intro-message.show {
  opacity: 1;
}

.intro-message p {
  font-size: 24px;
  color: #a02c92;
  font-weight: 400;
  line-height: 1.5;
}

/* Top Bar */
#top-bar-container {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1100;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.5s ease;
}

#top-bar-container.show {
  opacity: 1;
}

.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 20px;
  padding-top: max(12px, env(safe-area-inset-top));
  padding-left: max(20px, env(safe-area-inset-left));
  padding-right: max(20px, env(safe-area-inset-right));
  pointer-events: none;
}

.top-bar-group {
  pointer-events: auto;
}

.top-bar-group {
  display: flex;
  gap: 8px;
}

.top-bar-btn {
  width: 40px;
  height: 40px;
  border: none;
  background: transparent;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  color: #374151;
}

.top-bar-btn:hover {
  background: #f3f4f6;
}

.top-bar-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.top-bar-btn svg {
  width: 20px;
  height: 20px;
}

.top-bar-btn.primary {
  background: #000000;
  color: white;
}

.top-bar-btn.primary:hover {
  background: #333333;
}

/* Toolbar */
#toolbar-container {
  overflow: visible;
  opacity: 0;
  transition: opacity 0.5s ease;
}

#toolbar-container.show {
  opacity: 1;
}

.toolbar {
  position: fixed;
  bottom: 20px;
  bottom: max(20px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 8px;
  background: white;
  padding: 12px 16px;
  border-radius: 50px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
  z-index: 1100;
  max-width: calc(100vw - 40px);
  overflow-x: auto;
  overflow-y: visible;
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* IE/Edge */
}

.toolbar::-webkit-scrollbar {
  display: none; /* Chrome/Safari */
}

.toolbar-group {
  display: flex;
  gap: 4px;
  position: relative;
  overflow: visible;
}

.toolbar-group:not(:last-child) {
  padding-right: 8px;
  border-right: 1px solid #e5e7eb;
}

.toolbar-btn {
  width: 44px;
  height: 44px;
  border: none;
  background: transparent;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  color: #374151;
}

.toolbar-btn:hover {
  background: #f3f4f6;
}

.toolbar-btn.active {
  background: #e5e7eb;
  color: #374151;
}

.toolbar-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.toolbar-btn svg {
  width: 24px;
  height: 24px;
}

.toolbar-btn.primary {
  background: #000000;
  color: white;
  border-radius: 50%;
}

.toolbar-btn.primary:hover {
  background: #333333;
}

.size-btn {
  position: relative;
}

.size-btn svg {
  width: 44px;
  height: 44px;
}

.size-btn svg circle {
  stroke: #374151;
  stroke-width: 1;
  fill: #374151;
}

.color-btn {
  border: 2px solid #e5e7eb;
  border-radius: 50%;
}

/* Dropdowns */
.size-dropdown,
.color-dropdown {
  position: fixed;
  bottom: 90px;
  background: white;
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  z-index: 101;
}

.color-dropdown {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
  max-height: 400px;
  overflow-y: auto;
}

.size-option {
  width: 44px;
  height: 44px;
  border: none;
  background: transparent;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  overflow: visible;
}

.color-option {
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.size-option:hover,
.color-option:hover {
  background: #f3f4f6;
}

.size-option.active,
.color-option.active {
  background: #e5e7eb;
}

.color-option {
  border: 2px solid #e5e7eb;
}

.color-option:hover {
  transform: scale(1.1);
  background: transparent !important;
}

.color-section-title {
  grid-column: 1 / -1;
  padding: 8px 4px 4px;
  font-size: 11px;
  font-weight: 600;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.opacity-option {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #fff 0%, #000 100%);
}

.opacity-option .opacity-label {
  font-size: 10px;
  font-weight: 600;
  color: #fff;
  text-shadow: 0 0 3px rgba(0, 0, 0, 0.8);
  pointer-events: none;
}

.opacity-mode-options {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 4px 0;
}

.opacity-mode-option {
  display: flex;
  align-items: center;
  padding: 8px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.2s;
  user-select: none;
}

.opacity-mode-option:hover {
  background: #f3f4f6;
}

.opacity-mode-option.active {
  background: #e5e7eb;
}

.opacity-mode-option input[type="radio"] {
  margin: 0 8px 0 0;
  cursor: pointer;
}

.opacity-mode-option span {
  font-size: 13px;
  color: #374151;
  font-weight: 500;
}

.size-option svg {
  width: 44px;
  height: 44px;
}

/* Modal */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal {
  background: white;
  border-radius: 16px;
  padding: 32px;
  max-width: 500px;
  width: 90%;
  position: relative;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  font-size: 24px;
  cursor: pointer;
  color: #6b7280;
  border-radius: 8px;
  transition: background 0.2s;
}

.modal-close:hover {
  background: #f3f4f6;
}

.modal h2 {
  margin-bottom: 16px;
  color: #111827;
}

.modal p {
  margin-bottom: 16px;
  color: #6b7280;
}

.share-link {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.share-link input {
  flex: 1;
  padding: 12px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  font-size: 14px;
  font-family: monospace;
}

.share-link button {
  padding: 12px 24px;
  border: none;
  background: #2563eb;
  color: white;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 500;
  transition: background 0.2s;
}

.share-link button:hover {
  background: #1d4ed8;
}

.share-hint {
  font-size: 14px;
  color: #9ca3af;
}

.saved-links {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.link-item label {
  display: block;
  margin-bottom: 8px;
  font-weight: 500;
  color: #374151;
  font-size: 14px;
}

.edit-url-details {
  margin-top: 8px;
  border-top: 1px solid #e5e7eb;
  padding-top: 16px;
}

.edit-url-details summary {
  cursor: pointer;
  font-size: 14px;
  color: #6b7280;
  padding: 8px 0;
  user-select: none;
  list-style: none;
}

.edit-url-details summary::-webkit-details-marker {
  display: none;
}

.edit-url-details summary::before {
  content: "▶ ";
  display: inline-block;
  transition: transform 0.2s;
}

.edit-url-details[open] summary::before {
  transform: rotate(90deg);
}

.edit-url-details .link-item {
  margin-top: 12px;
}

/* Loading State */
.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  min-height: 150px;
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 4px solid #e5e7eb;
  border-top-color: #000000;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-message {
  margin-top: 16px;
  color: #6b7280;
  font-size: 14px;
  font-weight: 500;
}

/* Playback Controls */
.playback-controls {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 12px;
  background: white;
  padding: 12px 20px;
  border-radius: 16px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
  z-index: 100;
  flex-wrap: wrap;
  max-width: 90vw;
}

.control-btn {
  width: 44px;
  height: 44px;
  border: none;
  background: #000000;
  color: white;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.control-btn:hover {
  background: #333333;
}

.control-btn svg {
  width: 20px;
  height: 20px;
}

.progress-bar {
  width: 200px;
  height: 6px;
  background: #e5e7eb;
  border-radius: 3px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(to right, #FFD700, #FF6347, #8B008B);
  transition: width 0.1s linear;
}

.speed-controls {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: #f3f4f6;
  border-radius: 8px;
}

.speed-btn {
  padding: 4px 12px;
  border: none;
  background: transparent;
  color: #6b7280;
  font-size: 12px;
  font-weight: 600;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
}

.speed-btn:hover {
  background: #e5e7eb;
  color: #374151;
}

.speed-btn.active {
  background: #000000;
  color: white;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

/* Action Buttons */
.action-buttons {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 12px;
  z-index: 100;
}

.action-btn {
  padding: 12px 24px;
  border: 1px solid #e5e7eb;
  background: white;
  border-radius: 12px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.2s;
  color: #374151;
}

.action-btn:hover {
  background: #f3f4f6;
}

.action-btn.primary {
  background: #000000;
  color: white;
  border: none;
}

.action-btn.primary:hover {
  background: #333333;
}

/* Loading and Error */
.loading,
.error {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  padding: 20px 32px;
  background: white;
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
  z-index: 100;
}

.error {
  color: #dc2626;
}

/* Preview Overlay */
.preview-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  animation: fadeIn 0.2s ease;
}

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

#preview-canvas {
  width: 100%;
  height: 100%;
  max-width: 90vw;
  max-height: 90vh;
}

.preview-controls {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2001;
}

.preview-btn {
  padding: 12px 32px;
  border: none;
  background: white;
  color: #111827;
  border-radius: 12px;
  cursor: pointer;
  font-size: 16px;
  font-weight: 500;
  transition: all 0.2s;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.preview-btn:hover {
  background: #f3f4f6;
  transform: scale(1.05);
}

/* Clear Confirmation Popover */
.clear-popover {
  position: fixed;
  z-index: 1000;
  animation: fadeIn 0.15s ease;
}

.clear-popover-content {
  background: white;
  border-radius: 12px;
  padding: 16px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
  min-width: 200px;
}

.clear-popover-content p {
  margin: 0 0 12px 0;
  font-size: 14px;
  font-weight: 500;
  color: #111827;
  text-align: center;
}

.clear-popover-buttons {
  display: flex;
  gap: 8px;
}

.clear-popover-btn {
  flex: 1;
  padding: 8px 16px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.clear-popover-btn.cancel {
  background: #f3f4f6;
  color: #374151;
}

.clear-popover-btn.cancel:hover {
  background: #e5e7eb;
}

.clear-popover-btn.confirm {
  background: #dc2626;
  color: white;
}

.clear-popover-btn.confirm:hover {
  background: #b91c1c;
}

/* Mobile Optimizations */
@media (max-width: 640px) {
  .toolbar {
    bottom: 10px;
    padding: 8px;
    gap: 4px;
  }

  .toolbar-btn {
    width: 40px;
    height: 40px;
  }

  .modal {
    padding: 24px;
  }

  .action-buttons {
    flex-direction: column;
    width: 90%;
  }

  .action-btn {
    width: 100%;
  }
}

/* Privacy Link (web only) */
.privacy-link {
  position: fixed;
  bottom: 20px;
  right: 20px;
  font-size: 12px;
  color: #999;
  text-decoration: none;
  z-index: 100;
  opacity: 0.7;
  transition: opacity 0.2s ease, color 0.2s ease;
}

.privacy-link:hover {
  opacity: 1;
  color: #666;
}

/* Hide privacy link in Capacitor app */
@media (display-mode: standalone) {
  .privacy-link {
    display: none;
  }
}

@media (max-width: 600px) {
  .privacy-link {
    font-size: 11px;
    bottom: 15px;
    right: 15px;
  }
}

/* iOS App Badge (web only) */
.ios-app-badge {
  position: fixed;
  z-index: 100;
  opacity: 0.9;
  transition: opacity 0.2s ease, transform 0.2s ease;
  text-decoration: none;
}

.ios-app-badge img {
  display: block;
  height: 40px;
  width: auto;
}

.ios-app-badge:hover {
  opacity: 1;
  transform: scale(1.05);
}

/* Desktop: bottom left corner */
@media (min-width: 769px) {
  .ios-app-badge {
    bottom: 20px;
    left: 20px;
  }
}

/* Mobile: top center aligned with top toolbar */
@media (max-width: 768px) {
  .ios-app-badge {
    top: 12px;
    top: max(12px, env(safe-area-inset-top));
    left: 50%;
    transform: translateX(-50%);
  }

  .ios-app-badge:hover {
    transform: translateX(-50%) scale(1.05);
  }
}

/* Hide iOS app badge in Capacitor app */
@media (display-mode: standalone) {
  .ios-app-badge {
    display: none;
  }
}
