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

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #f5f5f5;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  /* Prevent ALL native zoom behaviors */
  touch-action: none;
  overscroll-behavior: none;
}

/* ===========================================
   VIEW MANAGEMENT
=========================================== */

.view {
  display: none;
  width: 100%;
  height: 100%;
}

.view.active {
  display: flex;
  flex-direction: column;
}

/* ===========================================
   LANDING VIEW
=========================================== */

.landing-view {
  justify-content: center;
  align-items: center;
  padding: 24px;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

.landing-content {
  text-align: center;
  max-width: 320px;
  width: 100%;
}

.landing-title {
  font-size: 48px;
  font-weight: 700;
  color: #333;
  margin-bottom: 8px;
}

.landing-subtitle {
  font-size: 16px;
  color: #666;
  margin-bottom: 48px;
}

.landing-btn {
  display: block;
  width: 100%;
  padding: 18px 24px;
  margin-bottom: 16px;
  border: none;
  border-radius: 12px;
  font-size: 18px;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.1s ease, opacity 0.1s ease;
}

.landing-btn:active {
  transform: scale(0.98);
  opacity: 0.9;
}

.landing-btn.primary {
  background: #333;
  color: white;
}

.landing-btn.secondary {
  background: white;
  color: #333;
  border: 2px solid #e0e0e0;
}

/* ===========================================
   SETUP VIEW (Create/Join)
=========================================== */

.setup-view {
  justify-content: center;
  align-items: center;
  padding: 24px;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

.setup-content {
  text-align: center;
  width: 100%;
  max-width: none;
  overflow-y: auto;
  max-height: 100dvh;
  padding: 24px;
  padding-bottom: max(48px, env(safe-area-inset-bottom));
  position: relative;
  z-index: 1; /* Above preview canvas */
  pointer-events: none; /* Allow clicks through to canvas */
}

/* On mobile, enable native scrolling in the content area */
@media (pointer: coarse) {
  .setup-content {
    pointer-events: auto;
    touch-action: pan-y;
  }
}

.setup-content > * {
  max-width: 400px;
  margin-left: auto;
  margin-right: auto;
}

/* Only interactive elements capture pointer events */
.setup-content button,
.setup-content input,
.setup-content .stroke-size-dot,
.setup-content .color-wheel-wrapper,
.setup-content .color-in-use-swatch {
  pointer-events: auto;
}

.setup-title {
  font-size: 28px;
  font-weight: 600;
  color: var(--setup-text-color, #333);
  margin-bottom: 32px;
}

.setup-label {
  font-size: 14px;
  color: var(--setup-text-color, #666);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
  text-align: center;
}

/* Color Wheel */
.color-wheel-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 32px;
}

.color-wheel-wrapper {
  display: flex;
  justify-content: center;
  align-items: center;
}

.selected-color-preview {
  margin-top: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.selected-color-swatch {
  width: 48px;
  height: 48px;
  border-radius: 50%;
}

.selected-color-label {
  font-size: 14px;
  color: var(--setup-text-color, #666);
}

.color-wheel-container.compact {
  margin-bottom: 20px;
}

.color-wheel-container.compact .selected-color-swatch {
  width: 36px;
  height: 36px;
}

.colors-in-use-container {
  margin-bottom: 20px;
  text-align: center;
}

.colors-in-use-label {
  font-size: 12px;
  color: var(--setup-text-color, #999);
  margin-bottom: 8px;
}

.colors-in-use-swatches {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}

.color-in-use-swatch {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  cursor: pointer;
  transition: transform 0.1s;
}

.color-in-use-swatch:hover {
  transform: scale(1.15);
}

.room-code-input {
  width: 100%;
  padding: 16px;
  font-size: 32px;
  font-weight: 700;
  text-align: center;
  letter-spacing: 8px;
  text-transform: uppercase;
  border: 2px solid #e0e0e0;
  border-radius: 12px;
  margin-bottom: 24px;
  font-family: monospace;
}

.room-code-input:focus {
  outline: none;
  border-color: #333;
}

/* ===========================================
   STROKE SIZE CONTROL
=========================================== */

.stroke-size-container {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
  max-width: 400px;
  height: 100px;
  margin-bottom: 24px;
}

.stroke-size-container .setup-label {
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
}

.stroke-size-arrows {
  position: absolute;
  right: calc(1%);
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 4px;
  pointer-events: none;
  opacity: 0.5;
}

.stroke-arrow {
  width: 20px;
  height: 20px;
  display: block;
}

.stroke-arrow path {
  stroke: var(--setup-text-color, #333);
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

.stroke-size-dot {
  position: absolute;
  right: 20%;
  top: 50%;
  transform: translate(50%, -50%);
  width: var(--thumb-size, 24px);
  height: var(--thumb-size, 24px);
  border-radius: 50%;
  background: var(--thumb-color, rgba(51, 51, 51, 0.8));
  cursor: ns-resize;
  touch-action: none;
  user-select: none;
  /* Ensure minimum hit area of 44px for accessibility */
  box-shadow: 0 0 0 max(0px, calc((44px - var(--thumb-size, 24px)) / 2))
    transparent;
}

.stroke-size-dot:active {
  cursor: grabbing;
}

/* ===========================================
   SETUP PREVIEW CANVAS (FULL SCREEN BACKGROUND)
=========================================== */

.setup-preview-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
  z-index: 0; /* Behind content */
}

.clear-preview-btn {
  background: transparent;
  border: none;
  color: var(--setup-text-color, #666);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
  margin-top: 16px;
  padding: 0;
  transition: opacity 0.1s ease;
}

.clear-preview-btn:active {
  opacity: 0.7;
}

.room-code-display {
  font-size: 48px;
  font-weight: 700;
  letter-spacing: 8px;
  color: #333;
  margin-bottom: 8px;
  font-family: monospace;
}

.room-code-hint {
  font-size: 14px;
  color: #888;
  margin-bottom: 32px;
}

.setup-btn {
  display: block;
  width: 100%;
  padding: 18px 24px;
  margin-bottom: 12px;
  border: none;
  border-radius: 12px;
  font-size: 18px;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.1s ease, opacity 0.1s ease;
}

.setup-btn:active {
  transform: scale(0.98);
  opacity: 0.9;
}

.setup-btn.primary {
  background: #333;
  color: white;
}

.setup-btn.secondary {
  background: transparent;
  color: var(--setup-text-color, #666);
  font-weight: 700;
}

.setup-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.waiting-text {
  font-size: 16px;
  color: #666;
  margin-top: 16px;
}

.waiting-spinner {
  display: inline-block;
  animation: spin 1s linear infinite;
}

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

/* ===========================================
   GRID VIEW
=========================================== */

.grid-view {
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
    env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.grid-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: max(16px, calc(12px + env(safe-area-inset-top)))
    max(16px, env(safe-area-inset-right)) 12px
    max(16px, env(safe-area-inset-left));
}

.grid-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.grid-title {
  font-size: 20px;
  font-weight: 600;
  color: #333;
}

.room-code-badge {
  font-size: 14px;
  font-weight: 600;
  color: #666;
  background: #f0f0f0;
  padding: 8px 12px;
  border-radius: 6px;
  font-family: monospace;
  letter-spacing: 2px;
  display: inline-flex;
  align-items: center;
  height: 100%;
}

.player-indicator {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  flex-shrink: 0;
  cursor: pointer;
  transition: transform 0.1s;
}

.player-indicator:hover {
  transform: scale(1.1);
}

/* Dot indicator for colors in use */
.color-in-use-indicator {
  position: absolute;
  top: 2px;
  right: 2px;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid rgba(0, 0, 0, 0.3);
  border-radius: 50%;
  width: 8px;
  height: 8px;
  pointer-events: none;
}

.grid-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.leave-btn {
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  background: #ff4444;
  color: white;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  touch-action: manipulation;
}

.leave-btn:active {
  opacity: 0.8;
}

.share-btn {
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  background: #333;
  color: white;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  touch-action: manipulation;
}

.share-btn:active {
  opacity: 0.8;
}

.grid-container {
  flex: 1;
  position: relative;
  min-height: 0;
  background: #f5f5f5;
}

#grid-canvas {
  touch-action: none;
}

/* ===========================================
   FLOATING CONTROLS (Fullscreen Drawing)
=========================================== */

/* Floating Close Button (FAB) */
.floating-close-btn {
  position: fixed;
  top: max(16px, env(safe-area-inset-top));
  right: 16px;
  z-index: 100;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: rgba(51, 51, 51, 0.95);
  backdrop-filter: blur(10px);
  color: white;
  font-size: 28px;
  font-weight: 300;
  border-radius: 50%;
  cursor: pointer;
  touch-action: manipulation;
  line-height: 1;
}

.floating-close-btn:active {
  transform: scale(0.95);
  opacity: 0.8;
}

/* Floating Reset Zoom Button */
.floating-reset-btn {
  position: fixed;
  bottom: max(16px, env(safe-area-inset-bottom));
  left: 16px;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: #333;
  cursor: pointer;
  touch-action: manipulation;
  transition: opacity 0.15s ease, transform 0.1s ease;
  padding: 8px;
}

.floating-reset-btn:active {
  transform: scale(0.95);
  opacity: 0.8;
}

/* Floating Stabilize Toggle */
.floating-stabilize-btn {
  display: none; /* Hidden for now */
  position: fixed;
  bottom: max(16px, env(safe-area-inset-bottom));
  right: 16px;
  z-index: 100;
  min-width: auto;
  padding: 10px 16px;
  border: none;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(10px);
  color: #333;
  font-size: 13px;
  font-weight: 500;
  border-radius: 20px;
  cursor: pointer;
  touch-action: manipulation;
  transition: all 0.15s ease;
}

.floating-stabilize-btn:active {
  transform: scale(0.95);
}

.floating-stabilize-btn.selected {
  background: rgba(51, 51, 51, 0.95);
  color: white;
}

/* Fade-in animation for floating controls */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.floating-close-btn {
  animation: fadeIn 0.3s ease;
}

/* ===========================================
   TOAST NOTIFICATIONS
=========================================== */

.toast {
  position: fixed;
  bottom: max(80px, calc(80px + env(safe-area-inset-bottom)));
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: rgba(51, 51, 51, 0.95);
  color: white;
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  z-index: 1000;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s ease, transform 0.3s ease;
  max-width: 80vw;
  text-align: center;
}

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

/* ===========================================
   DEBUG HUD
=========================================== */

.debug-hud {
  position: fixed;
  top: max(80px, calc(80px + env(safe-area-inset-top)));
  right: 16px;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  border-radius: 12px;
  padding: 16px;
  font-size: 12px;
  font-family: monospace;
  z-index: 999;
  max-width: 280px;
  display: none;
}

.debug-hud.visible {
  display: block;
}

.debug-hud-title {
  font-weight: 600;
  margin-bottom: 8px;
  font-size: 14px;
  color: #333;
}

.debug-hud-line {
  margin: 4px 0;
  color: #666;
}

.debug-hud-line strong {
  color: #333;
}

.debug-hud-button {
  width: 100%;
  padding: 8px 12px;
  margin-top: 12px;
  background: #333;
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}

.debug-hud-button:active {
  opacity: 0.8;
}

.debug-toggle-btn {
  position: fixed;
  bottom: max(80px, calc(80px + env(safe-area-inset-bottom)));
  right: 16px;
  width: 36px;
  height: 36px;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(10px);
  border: none;
  border-radius: 50%;
  font-size: 16px;
  cursor: pointer;
  touch-action: manipulation;
  z-index: 1000;
  display: none; /* Hidden by default - remove this line to show */
}

.debug-toggle-btn.visible {
  display: flex; /* Uncomment the line above and this will show the button */
  align-items: center;
  justify-content: center;
}

.debug-toggle-btn:active {
  transform: scale(0.95);
}

/* ===========================================
   UNDO/REDO BUTTONS
=========================================== */

.floating-undo-btn,
.floating-redo-btn {
  position: fixed;
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: #333;
  cursor: pointer;
  touch-action: manipulation;
  transition: opacity 0.15s ease, transform 0.1s ease;
  padding: 8px;
}

.floating-undo-btn svg,
.floating-redo-btn svg,
.floating-reset-btn svg {
  width: 28px;
  height: 28px;
}

.floating-undo-btn svg path,
.floating-redo-btn svg path,
.floating-reset-btn svg path {
  stroke: currentColor;
  stroke-width: 3.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

.floating-undo-btn {
  right: 136px; /* Position to the left of redo */
}

.floating-redo-btn {
  right: 76px; /* Position to the left of size toggle area */
}

.floating-undo-btn:disabled,
.floating-redo-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.floating-undo-btn:not(:disabled):active,
.floating-redo-btn:not(:disabled):active {
  transform: scale(0.95);
  opacity: 0.8;
}
