/* ==========================================================================
   🎨 ぬりえメーカー - Mobile & Tablet Optimized Design System
   ========================================================================== */

:root {
  --primary: #FF6B8B;
  --primary-hover: #FF4A71;
  --secondary: #4D96FF;
  --secondary-hover: #357AE8;
  --success: #6BCB77;
  --success-hover: #4EAF5B;
  --warning: #FFD93D;
  --warning-hover: #E2BF25;
  --danger: #FF4B4B;
  --neutral-dark: #2F3E46;
  --bg-gradient: linear-gradient(135deg, #FFF5F7 0%, #FFF0F2 50%, #E8F4F8 100%);
  --panel-bg: rgba(255, 255, 255, 0.88);
  --glass-shadow: 0 12px 32px 0 rgba(255, 107, 139, 0.1);
  --card-shadow: 0 8px 24px rgba(0, 0, 0, 0.04);
  --inner-shadow: inset 0 2px 6px rgba(0,0,0,0.06);
  --border-radius-lg: 24px;
  --border-radius-md: 16px;
  --font-family: 'Kosugi Maru', 'Outfit', system-ui, sans-serif;
  --accent-color: #FF6B8B;
}

/* Base Styles */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent; /* Disable touch blue outline on mobile */
}

body {
  font-family: var(--font-family);
  background: var(--bg-gradient);
  color: var(--neutral-dark);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-x: hidden;
  padding: 20px 12px;
}

/* Container */
.container {
  width: 100%;
  max-width: 900px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ==========================================================================
   Header Styles
   ========================================================================== */
header {
  text-align: center;
  margin-bottom: 2px;
  animation: fadeInDown 0.6s ease-out;
}

.logo-area {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.logo-emoji {
  font-size: 2.8rem;
  filter: drop-shadow(0 4px 6px rgba(0,0,0,0.1));
  animation: bounceEmoji 3s infinite ease-in-out;
}

header h1 {
  font-size: 2rem;
  font-weight: 800;
  background: linear-gradient(45deg, #FF6B8B, #FF9E79, #4D96FF);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 2px 2px rgba(255,255,255,0.8));
}

.subtitle {
  font-size: 0.9rem;
  color: #7d8a90;
  font-weight: 600;
  margin-top: 4px;
}

/* ==========================================================================
   Step Indicator (Tabs)
   ========================================================================== */
.step-indicator {
  display: flex;
  background: rgba(255, 255, 255, 0.75);
  backdrop-filter: blur(10px);
  border-radius: var(--border-radius-md);
  padding: 5px;
  box-shadow: var(--glass-shadow);
  border: 1px solid rgba(255, 255, 255, 0.5);
}

.step-tab {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px;
  border-radius: 12px;
  font-weight: bold;
  color: #8c969a;
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.2);
  cursor: default;
  font-size: 0.95rem;
}

.step-tab.active {
  background: var(--primary);
  color: white;
  box-shadow: 0 4px 12px rgba(255, 107, 139, 0.25);
}

.step-tab.clickable {
  cursor: pointer;
}

.step-num {
  background: rgba(255,255,255,0.3);
  border-radius: 50%;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
}

.step-tab.active .step-num {
  background: white;
  color: var(--primary);
}

/* ==========================================================================
   Panels & Sections
   ========================================================================== */
.panel {
  background: var(--panel-bg);
  backdrop-filter: blur(16px);
  border-radius: var(--border-radius-lg);
  padding: 20px;
  box-shadow: var(--glass-shadow);
  border: 1px solid rgba(255, 255, 255, 0.6);
  display: flex;
  flex-direction: column;
  gap: 16px;
  animation: scaleIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.05);
}

.section-title {
  font-size: 1.1rem;
  font-weight: bold;
  margin-bottom: 8px;
  color: var(--neutral-dark);
  text-align: center;
  position: relative;
  display: inline-block;
  align-self: center;
}

.section-title::after {
  content: '';
  position: absolute;
  bottom: -4px;
  left: 5%;
  width: 90%;
  height: 3px;
  background: linear-gradient(90deg, transparent, var(--primary), transparent);
  border-radius: 2px;
}

/* ==========================================================================
   STEP 1: Outline Creation Styles
   ========================================================================== */
.mode-selector {
  display: flex;
  flex-direction: column;
}

.mode-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

/* Orientation Selector Style */
.orientation-selector {
  display: flex;
  flex-direction: column;
  margin-bottom: 8px;
}

.orientation-cards {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.orientation-card {
  cursor: pointer;
}

.orientation-card input[type="radio"] {
  display: none;
}

.orientation-card-inner {
  background: white;
  border: 3px solid #EBF1F5;
  border-radius: var(--border-radius-md);
  padding: 14px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  text-align: center;
  transition: all 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.2);
  box-shadow: var(--card-shadow);
}

.orientation-card input[type="radio"]:checked + .orientation-card-inner {
  border-color: var(--primary);
  background: #FFF0F3;
  transform: scale(1.04) translateY(-2px);
  box-shadow: 0 8px 16px rgba(255, 107, 139, 0.15);
}

.orientation-icon {
  font-size: 2rem;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.08));
}

.orientation-name {
  font-weight: bold;
  font-size: 0.9rem;
  color: var(--neutral-dark);
}

.mode-card {
  cursor: pointer;
}

.mode-card input[type="radio"] {
  display: none;
}

.mode-card-inner {
  background: white;
  border: 3px solid #EBF1F5;
  border-radius: var(--border-radius-md);
  padding: 14px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  text-align: center;
  transition: all 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.2);
  box-shadow: var(--card-shadow);
}

.mode-card input[type="radio"]:checked + .mode-card-inner {
  border-color: var(--primary);
  background: #FFF0F3;
  transform: scale(1.04) translateY(-2px);
  box-shadow: 0 8px 16px rgba(255, 107, 139, 0.15);
}

.mode-icon {
  font-size: 2rem;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.08));
}

.mode-name {
  font-weight: bold;
  font-size: 0.9rem;
  color: var(--neutral-dark);
}

.mode-desc {
  font-size: 0.72rem;
  color: #8c969a;
  font-weight: 600;
}

/* Controls Top */
.controls-top {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  border-radius: 50px;
  font-size: 0.95rem;
  font-weight: bold;
  cursor: pointer;
  border: none;
  touch-action: manipulation; /* Faster taps on mobile */
  transition: all 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.15);
  box-shadow: 0 4px 12px rgba(0,0,0,0.06);
}

.btn:active {
  transform: scale(0.96);
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover {
  background: var(--primary-hover);
  box-shadow: 0 6px 15px rgba(255, 107, 139, 0.2);
}

.btn-secondary {
  background: var(--secondary);
  color: white;
}

.btn-secondary:hover {
  background: var(--secondary-hover);
  box-shadow: 0 6px 15px rgba(77, 150, 255, 0.2);
}

.btn-success {
  background: var(--success);
  color: white;
}

.btn-success:hover {
  background: var(--success-hover);
  box-shadow: 0 6px 15px rgba(107, 203, 119, 0.2);
}

.btn-warning {
  background: var(--warning);
  color: var(--neutral-dark);
}

.btn-warning:hover {
  background: var(--warning-hover);
  box-shadow: 0 6px 15px rgba(255, 217, 61, 0.2);
}

.btn-cancel {
  background: #EBF1F5;
  color: var(--neutral-dark);
}

.btn-share {
  background: #E040FB;
  color: white;
}

.btn-share:hover {
  background: #D500F9;
  box-shadow: 0 6px 15px rgba(224, 64, 251, 0.2);
}

/* Control Card & Sliders */
.control-card {
  background: white;
  border-radius: var(--border-radius-md);
  padding: 16px;
  box-shadow: var(--card-shadow);
  border: 1px solid #EBF1F5;
}

.control-card-title {
  font-size: 0.95rem;
  font-weight: bold;
  margin-bottom: 12px;
  color: var(--neutral-dark);
}

.slider-container {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 12px;
}

.slider-container:last-child {
  margin-bottom: 0;
}

.slider-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
  font-weight: bold;
}

.badge {
  background: #FFF0F3;
  color: var(--primary);
  padding: 2px 7px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 800;
  border: 1px solid #FFD2DC;
}

/* Custom Sliders */
input[type="range"] {
  -webkit-appearance: none;
  width: 100%;
  height: 8px;
  border-radius: 4px;
  background: #EBF1F5;
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  border: 3.5px solid white;
  box-shadow: 0 2px 6px rgba(0,0,0,0.12);
  transition: transform 0.1s;
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.15);
}

/* Slider thumb colored blue for guidance opacity */
#photoOpacitySlider::-webkit-slider-thumb {
  background: var(--secondary);
}

/* Action buttons row */
.action-buttons {
  display: flex;
  gap: 10px;
  margin-top: 5px;
}

.action-buttons .btn {
  flex: 1;
}

/* ==========================================================================
   STEP 2: Painting Toolbar Styles (Pill Horizontal Scroll Row)
   ========================================================================== */
.paint-toolbar-wrapper {
  width: 100%;
  overflow-x: auto;
  white-space: nowrap;
  padding: 8px 10px;
  border-radius: var(--border-radius-md);
  background: white;
  box-shadow: var(--card-shadow);
  border: 1px solid #EBF1F5;
  scrollbar-width: none; /* Hide scrollbar for Firefox */
  -webkit-overflow-scrolling: touch; /* Momentum scrolling on iOS */
}

.paint-toolbar-wrapper::-webkit-scrollbar {
  display: none; /* Hide scrollbar for Chrome/Safari/Edge */
}

.paint-toolbar {
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
  align-items: center;
  width: max-content;
}

/* Unified Pill Button Styling */
.paint-toolbar .tool-btn,
.paint-toolbar .action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 50px;
  border: 1px solid #c7d2fe; /* Light purple-blue border */
  background: white;
  color: #1e1b4b; /* Rich indigo text */
  font-weight: bold;
  font-size: 0.85rem;
  cursor: pointer;
  height: 38px;
  flex-shrink: 0;
  transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.15);
  box-shadow: 0 2px 4px rgba(0,0,0,0.02);
}

.paint-toolbar .tool-btn:hover:not(:disabled),
.paint-toolbar .action-btn:hover:not(:disabled) {
  background: #f8fafc;
  border-color: #818cf8;
  transform: translateY(-1px);
}

.paint-toolbar .tool-btn.active {
  background: #4F46E5 !important; /* Premium active indigo background */
  border-color: #4F46E5 !important;
  color: white !important;
  box-shadow: 0 4px 10px rgba(79, 70, 229, 0.35);
}

/* Specific styling for Paint Bucket (タッチで塗る) - Beautiful Orange Pill */
.paint-toolbar #toolBucket {
  background: #FFF7ED !important;
  border-color: #FED7AA !important;
  color: #C2410C !important;
}

.paint-toolbar #toolBucket:hover:not(:disabled) {
  background: #FFEDD5 !important;
}

.paint-toolbar #toolBucket.active {
  background: #EA580C !important;
  border-color: #EA580C !important;
  color: white !important;
  box-shadow: 0 4px 10px rgba(234, 88, 12, 0.35);
}

/* Specific styling for Reset (白紙) as shown in attached picture (yellowish pill) */
.paint-toolbar .btn-reset {
  background: #FEF3C7 !important; /* Cream/light-yellow */
  border-color: #FCD34D !important;
  color: #92400E !important; /* Amber text */
}

.paint-toolbar .btn-reset:hover {
  background: #FDE68A !important;
}

.paint-toolbar .action-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  border-color: #e2e8f0 !important;
  color: #94a3b8 !important;
  background: #f8fafc !important;
}

.toolbar-divider {
  width: 1px;
  height: 24px;
  background-color: #cbd5e1;
  margin: 0 4px;
  flex-shrink: 0;
  align-self: center;
}

.tool-icon {
  font-size: 1.15rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Sliders Sub-Toolbar */
.paint-sub-toolbar {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  align-items: center;
  background: white;
  border-radius: var(--border-radius-md);
  padding: 10px 16px;
  box-shadow: var(--card-shadow);
  border: 1px solid #EBF1F5;
  margin-top: -6px; /* Blends nicely with top toolbar wrapper */
}

.brush-settings {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brush-slider-wrapper {
  flex: 1;
}

.brush-preview-container {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: #F5F8FA;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #EBF1F5;
  box-shadow: var(--inner-shadow);
  flex-shrink: 0;
}

#brushPreview {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent-color);
  transition: background-color 0.15s;
}

.reference-settings {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* Copy Toast Notification Style */
.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: rgba(15, 23, 42, 0.92); /* Dark slate premium background */
  color: white;
  padding: 12px 28px;
  border-radius: 50px;
  font-weight: bold;
  font-size: 0.9rem;
  z-index: 2000;
  box-shadow: 0 10px 25px rgba(0,0,0,0.2);
  pointer-events: none;
  opacity: 0;
  border: 1px solid rgba(255, 255, 255, 0.1);
  transition: transform 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.25), opacity 0.3s;
}

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

.text-danger {
  color: var(--danger) !important;
}

/* Palette Container & Circular Swatches */
.palette-container {
  background: white;
  border-radius: var(--border-radius-md);
  padding: 12px;
  box-shadow: var(--card-shadow);
  border: 1px solid #EBF1F5;
  width: 100%;
}

.palette-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  align-items: center;
}

.color-swatch {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid white;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
  touch-action: manipulation;
  transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.2);
}

.color-swatch:hover {
  transform: scale(1.1);
}

.color-swatch.active {
  transform: scale(1.15);
  box-shadow: 0 0 0 2px white, 0 0 0 4.5px var(--accent-color), 0 3px 8px rgba(0, 0, 0, 0.15);
  z-index: 2;
}

/* Custom Rainbow Color Picker */
.custom-color-picker-wrapper {
  position: relative;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  cursor: pointer;
  background: conic-gradient(red, yellow, green, cyan, blue, magenta, red);
  border: 2px solid white;
  box-shadow: 0 2px 6px rgba(0,0,0,0.12);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.2);
  overflow: hidden;
}

.custom-color-picker-wrapper:hover {
  transform: scale(1.1);
}

.custom-color-picker-wrapper.active {
  transform: scale(1.15);
  box-shadow: 0 0 0 2px white, 0 0 0 4.5px var(--accent-color);
  z-index: 2;
}

#customColorPicker {
  position: absolute;
  top: -10px;
  left: -10px;
  width: 62px;
  height: 62px;
  cursor: pointer;
  opacity: 0;
}

.picker-rainbow-icon {
  font-size: 1.2rem;
  pointer-events: none;
}

/* Paint Footer */
.paint-footer {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.paint-footer .btn {
  flex: 1;
}

/* ==========================================================================
   Canvas Display Container (Dual Layers)
   ========================================================================== */
.canvas-outer-container {
  display: flex;
  justify-content: center;
  width: 100%;
}

.canvas-container {
  position: relative;
  background: white;
  border-radius: var(--border-radius-lg);
  padding: 12px;
  box-shadow: var(--glass-shadow);
  border: 1px solid rgba(255, 255, 255, 0.7);
  width: 100%;
  min-height: 320px;
  max-height: 60vh;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

/* Canvas Placeholder */
.placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #a4b0be;
  text-align: center;
  font-weight: bold;
  height: 280px;
  cursor: pointer;
  transition: all 0.25s;
  padding: 16px;
  border: 3px dashed #DFE6ED;
  border-radius: var(--border-radius-md);
  width: 100%;
}

.placeholder:hover {
  border-color: var(--primary);
  background: #FFF5F7;
  color: var(--primary);
}

.placeholder-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.placeholder-icon {
  font-size: 3rem;
  animation: floatIcon 3s infinite ease-in-out;
}

/* Spinner Loader */
.loader {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(255, 255, 255, 0.85); /* Semi-transparent overlay */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-weight: bold;
  color: var(--primary);
  z-index: 10; /* Overlay the canvas layers (1, 2, 3) */
  border-radius: var(--border-radius-lg);
}

.spinner {
  width: 44px;
  height: 44px;
  border: 4px solid rgba(255, 107, 139, 0.2);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s infinite linear;
}

/* Layered Canvas Wrapper */
.canvas-wrapper {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  box-shadow: var(--inner-shadow);
  background-color: #FFFFFF;
  border-radius: 12px;
  overflow: hidden;
  touch-action: none; /* Crucial: Disables browser scroll/pan on drawing area! */
}

.canvas-layer {
  position: absolute;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 8px;
}

/* Layer 1 (Bottom): Reference original image guide */
#referenceImage {
  z-index: 1;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
}

/* Layer 2 (Middle): Paint canvas */
#paintCanvas {
  z-index: 2;
  background-color: transparent;
  touch-action: none; /* Crucial: Disables browser scroll/pan on drawing area! */
}

/* Layer 3 (Top): Extracted outline canvas */
#outlineCanvas {
  z-index: 3;
  mix-blend-mode: multiply;
  pointer-events: none; /* Passes all clicks, drags, touches down to paintCanvas */
  touch-action: none; /* Crucial: Disables browser scroll/pan on drawing area! */
}

/* ==========================================================================
   Modals (Save Methods)
   ========================================================================== */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(40, 20, 30, 0.45);
  backdrop-filter: blur(8px);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-content {
  background: white;
  border-radius: var(--border-radius-lg);
  padding: 24px;
  width: 100%;
  max-width: 440px;
  text-align: center;
  box-shadow: 0 20px 48px rgba(255, 64, 129, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.5);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-content h2 {
  font-size: 1.3rem;
  color: var(--neutral-dark);
}

.modal-desc {
  font-size: 0.85rem;
  color: #6C7A82;
  font-weight: 600;
}

.modal-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.modal-buttons .btn {
  width: 100%;
  padding: 14px;
  border-radius: 14px;
  text-align: center;
}

.modal-buttons small {
  font-size: 0.72rem;
  opacity: 0.8;
  font-weight: normal;
  display: block;
  margin-top: 1px;
}

/* In-App Camera Viewfinder Styles */
.camera-modal-content {
  max-width: 540px !important;
  background: #1A1A1A !important;
  color: white !important;
  border: 1px solid rgba(255, 255, 255, 0.15) !important;
}

.camera-modal-content h2 {
  color: white !important;
}

.camera-viewport-container {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  background: #000;
  border-radius: var(--border-radius-md);
  overflow: hidden;
  border: 2px solid rgba(255, 255, 255, 0.2);
}

#cameraVideo {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

#cameraVideo.mirrored {
  transform: scaleX(-1);
}

.camera-flash {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: white;
  opacity: 0;
  pointer-events: none;
  z-index: 10;
}

.camera-flash.flash-active {
  opacity: 1;
  transition: none;
}

.camera-modal-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
}

@media (min-width: 480px) {
  .camera-modal-buttons {
    flex-direction: row;
  }
  .camera-modal-buttons .btn {
    flex: 1;
  }
}

/* Footer */
footer {
  margin-top: 15px;
  color: #8c969a;
  font-size: 0.75rem;
  font-weight: bold;
  text-align: center;
}

/* ==========================================================================
   TABLET & MOBILE OPTIMIZATIONS (MEDIA QUERIES)
   ========================================================================== */

@media (max-width: 768px) {
  body {
    padding: 10px 8px;
    background: #FFF5F7; /* Solid background on mobile for high speed rendering */
  }

  .container {
    gap: 12px;
  }

  header h1 {
    font-size: 1.6rem;
  }

  .logo-emoji {
    font-size: 2.2rem;
  }

  .subtitle {
    font-size: 0.8rem;
  }

  .panel {
    padding: 14px;
    gap: 12px;
    border-radius: var(--border-radius-md);
  }

  /* Compact tabs */
  .step-tab {
    padding: 8px;
    font-size: 0.85rem;
    gap: 5px;
  }

  .step-num {
    width: 20px;
    height: 20px;
    font-size: 0.75rem;
  }

  /* Mode selection cards */
  .mode-cards {
    gap: 8px;
  }

  .mode-card-inner {
    padding: 10px 4px;
    border-width: 2px;
  }

  .mode-icon {
    font-size: 1.6rem;
  }

  .mode-name {
    font-size: 0.8rem;
  }

  .mode-desc {
    display: none; /* Hide descriptions to conserve vertical screen space */
  }

  .btn {
    padding: 10px 18px;
    font-size: 0.85rem;
  }

  .controls-top {
    gap: 8px;
  }

  /* Compact controls card */
  .control-card {
    padding: 12px;
  }

  .slider-container {
    margin-bottom: 8px;
  }

  .slider-label {
    font-size: 0.8rem;
  }

  /* Canvas sizing in portrait mobile screen */
  .canvas-container {
    min-height: 260px;
    height: 48vh; /* Fluid viewport height scale */
    padding: 8px;
    border-radius: var(--border-radius-md);
  }

  /* ==========================================================================
     STEP 2: Mobile-First Compact Painting Toolbar Adjustments
     ========================================================================== */
  .paint-toolbar-wrapper {
    padding: 6px 8px;
  }

  .paint-toolbar .tool-btn,
  .paint-toolbar .action-btn {
    padding: 6px 12px;
    font-size: 0.8rem;
    height: 34px;
  }

  .paint-sub-toolbar {
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 8px 12px;
  }

  .brush-preview-container {
    width: 42px;
    height: 42px;
  }

  /* Horizontal scrolling touch color palette (Premium Mobile Native UI) */
  .palette-container {
    padding: 8px;
  }

  .palette-row {
    flex-wrap: nowrap;
    justify-content: flex-start;
    overflow-x: auto;
    gap: 12px;
    padding: 4px;
    scrollbar-width: none; /* Firefox */
    -webkit-overflow-scrolling: touch; /* Momentum scroll for iOS */
  }

  .palette-row::-webkit-scrollbar {
    display: none; /* Hide scrollbar completely on Chrome/Safari/Edge */
  }

  .color-swatch {
    width: 38px;
    height: 38px;
    flex-shrink: 0; /* Prevent swatches from squishing */
  }

  .custom-color-picker-wrapper {
    width: 38px;
    height: 38px;
    flex-shrink: 0;
  }
}

@media (max-width: 360px) {
  /* Ultra-small viewports (e.g. iPhone SE / mini) */
  header h1 {
    font-size: 1.4rem;
  }

  .logo-emoji {
    font-size: 1.8rem;
  }

  .step-tab {
    padding: 6px;
    font-size: 0.75rem;
  }

  .canvas-container {
    min-height: 220px;
    height: 40vh;
  }

  .color-swatch,
  .custom-color-picker-wrapper {
    width: 34px;
    height: 34px;
  }
}

/* ==========================================================================
   Animations
   ========================================================================== */
@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes fadeInDown {
  from {
    opacity: 0;
    transform: translateY(-16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes scaleIn {
  from {
    opacity: 0;
    transform: scale(0.97);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes bounceEmoji {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(-6px) rotate(4deg); }
}

@keyframes floatIcon {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

.animate-pop {
  animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.15);
}

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

/* RIPPLE EFFECT */
.ripple {
  position: relative;
  overflow: hidden;
}
