/* ══════════ FOOTER PLAYGROUND STYLES ══════════ */

:root {
  --playground-bg: #f9f9fb;
  --playground-grid: rgba(0, 0, 0, 0.04);
  --playground-text: #1d1d1f;
  --playground-text-muted: #86868b;
  --toolbar-bg: rgba(255, 255, 255, 0.8);
  --toolbar-border: rgba(0, 0, 0, 0.08);
  --toolbar-shadow: 0 8px 32px rgba(0, 0, 0, 0.08);
  --toolbar-btn-hover: rgba(0, 0, 0, 0.04);
  --toolbar-btn-active: #1d1d1f;
  --toolbar-btn-active-icon: #ffffff;
}

[data-theme="dark"] {
  --playground-bg: #0d0d0f;
  --playground-grid: rgba(255, 255, 255, 0.03);
  --playground-text: #f5f5f7;
  --playground-text-muted: #86868b;
  --toolbar-bg: rgba(20, 20, 25, 0.85);
  --toolbar-border: rgba(255, 255, 255, 0.08);
  --toolbar-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  --toolbar-btn-hover: rgba(255, 255, 255, 0.08);
  --toolbar-btn-active: #f5f5f7;
  --toolbar-btn-active-icon: #0d0d0f;
}

.playground-section {
  position: relative;
  width: 100%;
  height: 520px;
  background-color: var(--playground-bg);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: background-color 0.4s ease, border-color 0.4s ease;
}

/* Grid paper background pattern */
.playground-section.has-grid {
  background-image: 
    linear-gradient(to right, var(--playground-grid) 1px, transparent 1px),
    linear-gradient(to bottom, var(--playground-grid) 1px, transparent 1px);
  background-size: 20px 20px;
}

/* Playground Header */
.playground-header {
  position: absolute;
  top: 24px;
  left: 32px;
  z-index: 10;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-family: var(--font-sans);
}

.playground-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--playground-text);
  margin: 0;
  letter-spacing: -0.015em;
  transition: color 0.4s ease;
}

.playground-meta {
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--playground-text-muted);
  letter-spacing: 0.02em;
}

/* Drawing Canvas */
.playground-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 1;
  cursor: crosshair;
  touch-action: none;
}

/* Floating Glassmorphic Toolbar */
.playground-toolbar {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  display: flex;
  background: var(--toolbar-bg);
  border: 1px solid var(--toolbar-border);
  box-shadow: var(--toolbar-shadow);
  backdrop-filter: blur(16px) saturate(120%);
  -webkit-backdrop-filter: blur(16px) saturate(120%);
  border-radius: 12px;
  padding: 8px 12px;
  pointer-events: auto;
  transition: background-color 0.4s ease, border-color 0.4s ease, box-shadow 0.4s ease, transform 0.3s ease;
}

/* Align toolbar items horizontally */
.toolbar-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.toolbar-divider {
  width: 1px;
  height: 20px;
  background-color: var(--toolbar-border);
  margin: 0 4px;
  transition: background-color 0.4s ease;
}

/* Buttons in Toolbar */
.toolbar-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  color: var(--playground-text);
  border-radius: 8px;
  cursor: pointer;
  outline: none;
  position: relative;
  transition: background-color 0.2s ease, color 0.2s ease, transform 0.15s ease;
}

.toolbar-btn:hover {
  background-color: var(--toolbar-btn-hover);
  transform: translateY(-1px);
}

.toolbar-btn:active {
  transform: translateY(0) scale(0.96);
}

.toolbar-btn.is-active {
  background-color: var(--toolbar-btn-active);
  color: var(--toolbar-btn-active-icon);
}

.toolbar-btn svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
  stroke: currentColor;
  stroke-width: 0;
  pointer-events: none;
}

.toolbar-btn .svg-icon {
  width: 18px;
  height: 18px;
  fill: none !important;
  stroke: currentColor !important;
  stroke-width: 2.2px !important;
  pointer-events: none;
  display: block;
}

.toolbar-btn .material-symbols-rounded {
  font-size: 18px;
  font-variation-settings: 'FILL' 0, 'wght' 450, 'GRAD' 0, 'opsz' 24;
  pointer-events: none;
  display: block;
}

.toolbar-btn.is-active .material-symbols-rounded {
  font-variation-settings: 'FILL' 1, 'wght' 500, 'GRAD' 0, 'opsz' 24;
}

/* Tooltip on hover */
.playground-toolbar [data-tooltip]::before,
.color-palette-popover [data-tooltip]::before {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%) translateY(4px);
  background-color: #1c1c1e;
  color: #ffffff;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 500;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s ease;
  z-index: 20;
}

.playground-toolbar [data-tooltip]:hover::before,
.color-palette-popover [data-tooltip]:hover::before {
  opacity: 0.95;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
}

/* Hide trigger tooltip when popover is open */
.color-picker-container:has(.color-palette-popover.is-open) [data-tooltip]::before {
  opacity: 0 !important;
  visibility: hidden !important;
}

/* Size selectors (horizontal row of dots) */
.size-selector {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 4px;
}

.size-dot-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border: none;
  background: transparent;
  border-radius: 50%;
  cursor: pointer;
  padding: 0;
  outline: none;
  position: relative;
}

.size-dot {
  background-color: var(--playground-text);
  border-radius: 50%;
  transition: background-color 0.4s ease, transform 0.2s ease;
}

/* Custom sizes for 5 dots */
.size-dot-btn[data-size="2"] .size-dot  { width: 2px; height: 2px; }
.size-dot-btn[data-size="5"] .size-dot  { width: 4px; height: 4px; }
.size-dot-btn[data-size="10"] .size-dot { width: 7px; height: 7px; }
.size-dot-btn[data-size="18"] .size-dot { width: 11px; height: 11px; }
.size-dot-btn[data-size="28"] .size-dot { width: 15px; height: 15px; }

/* Size active ring border selector */
.size-dot-btn.is-active::after {
  content: '';
  position: absolute;
  inset: -2px;
  border: 1.5px solid var(--playground-text);
  border-radius: 50%;
}

/* Color Picker Container & Popover Panel */
.color-picker-container {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.multicolour-icon {
  position: relative;
  display: block;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: conic-gradient(from 0deg, #ff3b30, #ff9500, #ffcc00, #34c759, #5ac8fa, #007aff, #5856d6, #ff2d55, #ff3b30);
  border: 1px solid rgba(0, 0, 0, 0.12);
  padding: 3.5px;
  box-sizing: border-box;
  -webkit-mask-image: -webkit-radial-gradient(circle, white, black);
  mask-image: radial-gradient(circle, white, black);
  transition: transform 0.2s ease;
}

.multicolour-icon::after {
  content: '';
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background-color: var(--active-color, #1d1d1f);
  border: 1px solid rgba(0, 0, 0, 0.08);
  box-sizing: border-box;
  transition: background-color 0.2s ease;
}

.color-btn--picker-trigger:hover .multicolour-icon {
  transform: scale(1.12);
}

.color-btn--picker-trigger.is-color-active {
  box-shadow: inset 0 0 0 1.5px var(--playground-text);
  background-color: var(--toolbar-btn-hover);
}

.color-palette-popover {
  position: absolute;
  bottom: calc(100% + 12px);
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--toolbar-bg);
  border: 1px solid var(--toolbar-border);
  box-shadow: var(--toolbar-shadow);
  backdrop-filter: blur(16px) saturate(120%);
  -webkit-backdrop-filter: blur(16px) saturate(120%);
  border-radius: 10px;
  padding: 8px 12px;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s cubic-bezier(0.16, 1, 0.3, 1), transform 0.2s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.2s;
}

.color-palette-popover.is-open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateX(-50%) translateY(0);
}

/* Caret pointing down from popover */
.color-palette-popover::after {
  content: '';
  position: absolute;
  bottom: -6px;
  left: 50%;
  transform: translateX(-50%);
  border-width: 6px 6px 0;
  border-style: solid;
  border-color: var(--toolbar-bg) transparent transparent;
  display: block;
  width: 0;
}

.popover-divider {
  width: 1px;
  height: 16px;
  background-color: var(--toolbar-border);
  margin: 0 4px;
}

.color-btn {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.08);
  cursor: pointer;
  padding: 0;
  outline: none;
  position: relative;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.color-btn:hover {
  transform: scale(1.15);
}

.color-btn.is-active::after {
  content: '';
  position: absolute;
  inset: -3px;
  border: 1.5px solid var(--playground-text);
  border-radius: 50%;
  transition: border-color 0.4s ease;
}

/* Color Wheel / Custom Color Picker */
.color-btn--picker {
  background: conic-gradient(red, orange, yellow, green, cyan, blue, violet, red);
  border: 1.5px solid rgba(0,0,0,0.1);
  overflow: hidden;
  -webkit-mask-image: -webkit-radial-gradient(circle, white, black);
  mask-image: radial-gradient(circle, white, black);
}

.color-picker-input {
  position: absolute;
  top: -10px;
  left: -10px;
  width: 40px;
  height: 40px;
  opacity: 0;
  cursor: pointer;
  pointer-events: auto;
}

/* Adjustments for custom cursor interaction */
.playground-section:hover ~ #cursor {
  mix-blend-mode: normal; /* keep cursor clear on drawing grid */
}

#cursor.is-hidden {
  opacity: 0 !important;
  pointer-events: none !important;
  visibility: hidden !important;
}

/* Responsive Rules */
@media (max-width: 820px) {
  .playground-section {
    height: 480px;
  }
  
  .playground-header {
    top: 16px;
    left: 20px;
  }
  
  .playground-toolbar {
    bottom: 16px;
    width: calc(100% - 24px);
    max-width: 420px;
    overflow-x: visible;
    padding: 10px 12px;
    border-radius: 16px;
  }
  
  .playground-toolbar::-webkit-scrollbar {
    display: none;
  }

  .publish-container,
  .publish-container.is-visible {
    max-width: none !important;
    transform: none !important;
    overflow: visible !important;
    opacity: 1 !important;
    pointer-events: auto !important;
  }

  .toolbar-row {
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px 6px;
  }
  
  .toolbar-divider {
    display: none !important;
  }

  .size-selector {
    gap: 6px;
    padding: 0;
  }
  
  /* Prevent tooltip overflow on mobile */
  .toolbar-btn[data-tooltip]::before {
    display: none;
  }

  .playground-gallery-link {
    top: 16px;
    right: 20px;
    padding: 6px 10px;
    font-size: 0.75rem;
  }

  /* Positioned above the toolbar and fixed in viewport on mobile */
  .publish-popover {
    position: fixed !important;
    bottom: 110px !important; /* aligned directly above toolbar */
    top: auto !important;
    left: 50% !important;
    transform: translateX(-50%) translateY(12px) !important;
    width: calc(100% - 32px) !important;
    max-width: 280px !important;
    padding: 16px 18px !important;
    border-radius: 14px !important;
    border: 1.5px solid var(--accent) !important; /* highlight border */
    box-shadow: 
      0 0 0 1px rgba(12, 140, 233, 0.1),
      0 20px 48px rgba(0, 0, 0, 0.5),
      0 0 24px rgba(12, 140, 233, 0.25) !important; /* highlight glow */
    z-index: 1000 !important;
    transition: opacity 0.25s cubic-bezier(0.16, 1, 0.3, 1), transform 0.25s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.25s !important;
  }

  .publish-popover.is-open {
    transform: translateX(-50%) translateY(0) !important;
  }

  /* Hide caret on fixed viewport modal */
  .publish-popover::after {
    display: none !important;
  }
}

/* ══════════ NEW GALLERY LINK & PUBLISH POPOVER STYLES ══════════ */

/* Gallery Timeline Link */
.playground-gallery-link {
  position: absolute;
  top: 24px;
  right: 32px;
  z-index: 10;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: var(--toolbar-bg);
  border: 1px solid var(--toolbar-border);
  box-shadow: var(--toolbar-shadow);
  backdrop-filter: blur(16px) saturate(120%);
  -webkit-backdrop-filter: blur(16px) saturate(120%);
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--playground-text);
  text-decoration: none;
  pointer-events: auto;
  transition: background-color 0.2s ease, border-color 0.2s ease, transform 0.2s ease, color 0.2s ease;
}

.playground-gallery-link:hover {
  background-color: var(--toolbar-btn-hover);
  transform: translateY(-1px);
  color: var(--accent);
}

.playground-gallery-link:active {
  transform: translateY(0) scale(0.98);
}

.playground-gallery-link .material-symbols-rounded {
  font-size: 16px;
}

/* Publish Container & Popover Panel */
.publish-container {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  max-width: 0;
  opacity: 0;
  overflow: hidden;
  transform: scale(0.92);
  pointer-events: none;
  /* Collapse transition: opacity and scale run first (no delay), max-width collapses with a delay */
  transition: 
    max-width 0.4s cubic-bezier(0.16, 1, 0.3, 1) 0.15s,
    opacity 0.2s ease,
    transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.publish-container.is-visible {
  max-width: 140px; /* plenty of space for divider + button */
  opacity: 1;
  overflow: visible; /* allow popover to float above */
  transform: scale(1);
  pointer-events: auto;
  /* Expand transition: max-width expands first (no delay), opacity and scale fade in with a delay */
  transition: 
    max-width 0.4s cubic-bezier(0.16, 1, 0.3, 1),
    opacity 0.3s ease 0.15s,
    transform 0.3s cubic-bezier(0.16, 1, 0.3, 1) 0.15s;
}

/* Prevent layout squishing of children during max-width animation */
.publish-container .toolbar-divider,
.publish-container .toolbar-btn {
  flex-shrink: 0;
}

/* Filled Publish Button */
.toolbar-btn.toolbar-btn--filled {
  background-color: var(--accent);
  color: var(--toolbar-btn-active-icon);
  width: auto;
  padding: 0 14px;
  gap: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  box-shadow: 0 2px 8px var(--accent-glow);
  transition: background-color 0.2s ease, transform 0.15s ease, box-shadow 0.2s ease;
}

.toolbar-btn.toolbar-btn--filled:hover {
  background-color: var(--accent-hover);
  color: var(--toolbar-btn-active-icon);
  transform: translateY(-1px);
}

.toolbar-btn.toolbar-btn--filled:active {
  transform: translateY(0) scale(0.96);
}

.toolbar-btn.toolbar-btn--filled .btn-text {
  font-family: var(--font-sans);
  pointer-events: none;
}

.toolbar-btn.toolbar-btn--filled .material-symbols-rounded {
  font-size: 16px;
  font-variation-settings: 'FILL' 1, 'wght' 500, 'GRAD' 0, 'opsz' 24;
}

.publish-popover {
  position: absolute;
  bottom: calc(100% + 12px);
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--toolbar-bg);
  border: 1px solid var(--toolbar-border);
  box-shadow: var(--toolbar-shadow);
  backdrop-filter: blur(16px) saturate(120%);
  -webkit-backdrop-filter: blur(16px) saturate(120%);
  border-radius: 12px;
  padding: 12px 14px;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  width: 240px;
  transition: opacity 0.25s cubic-bezier(0.16, 1, 0.3, 1), transform 0.25s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.25s;
}

.publish-popover.is-open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateX(-50%) translateY(0);
}

/* Caret pointing down from publish popover */
.publish-popover::after {
  content: '';
  position: absolute;
  bottom: -6px;
  left: 50%;
  transform: translateX(-50%);
  border-width: 6px 6px 0;
  border-style: solid;
  border-color: var(--toolbar-bg) transparent transparent;
  display: block;
  width: 0;
}

.publish-popover__title {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--playground-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 2px;
  text-align: left;
}

.publish-form {
  display: flex;
  gap: 6px;
  width: 100%;
}

.publish-input {
  flex: 1;
  background: color-mix(in srgb, var(--playground-text) 5%, transparent);
  border: 1px solid var(--toolbar-border);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 0.8rem;
  color: var(--playground-text);
  outline: none;
  font-family: var(--font-sans);
  min-width: 0;
  transition: border-color 0.2s ease, background-color 0.2s ease;
}

.publish-input::placeholder {
  color: var(--playground-text-muted);
  opacity: 0.7;
}

.publish-input:focus {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--playground-text) 2%, transparent);
}

.publish-submit-btn {
  background-color: var(--accent);
  color: var(--toolbar-btn-active-icon);
  border: none;
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font-sans);
  transition: background-color 0.2s ease, transform 0.15s ease;
}

.publish-submit-btn:hover {
  background-color: var(--accent-hover);
  transform: translateY(-0.5px);
}

.publish-submit-btn:active {
  transform: translateY(0);
}

/* Canvas Floating Text Input */
.canvas-text-input {
  border: none !important;
  outline: none !important;
  background: transparent !important;
  box-shadow: none !important;
  padding: 0 !important;
  margin: 0 !important;
  font-family: var(--font-sans) !important;
}

/* Playground Toast Notification */
.playground-toast {
  position: absolute;
  bottom: 84px; /* sits right above the toolbar */
  left: 50%;
  transform: translate3d(-50%, 10px, 0);
  z-index: 110;
  background: var(--toolbar-bg);
  border: 1px solid rgba(255, 59, 48, 0.25);
  box-shadow: var(--toolbar-shadow);
  backdrop-filter: blur(16px) saturate(120%);
  -webkit-backdrop-filter: blur(16px) saturate(120%);
  color: var(--playground-text);
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 500;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s cubic-bezier(0.16, 1, 0.3, 1), transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.3s;
  display: flex;
  align-items: center;
  gap: 8px;
}

.playground-toast.is-show {
  opacity: 1;
  visibility: visible;
  transform: translate3d(-50%, 0, 0);
}

.playground-toast .material-symbols-rounded {
  color: #ff3b30;
  font-size: 16px;
  display: block;
}
