/* ───────────────────────────────────────────────
   Base Reset + Tokens
─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-app: #0d0d1a;
  --bg-card: #1a1a2e;
  --bg-surface: #16213e;
  --accent1: #667eea;
  --accent2: #764ba2;
  --accent-grad: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  --text-primary: #f0f0f5;
  --text-secondary: #a0a0c0;
  --border: rgba(255,255,255,0.08);
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 8px 32px rgba(0,0,0,0.4);
}

html { scroll-behavior: smooth; }

body {
  background: var(--bg-app);
  color: var(--text-primary);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ───────────────────────────────────────────────
   App Container
─────────────────────────────────────────────── */
#app {
  max-width: 520px;
  margin: 0 auto;
  padding-bottom: 40px;
}

/* ───────────────────────────────────────────────
   Header
─────────────────────────────────────────────── */
.app-header {
  background: linear-gradient(180deg, rgba(102,126,234,0.15) 0%, transparent 100%);
  border-bottom: 1px solid var(--border);
  padding: 20px 24px 16px;
  text-align: center;
}
.header-inner { display: flex; flex-direction: column; gap: 4px; }
.logo {
  font-size: 1.5rem;
  font-weight: 800;
  background: var(--accent-grad);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.tagline { font-size: 0.8rem; color: var(--text-secondary); }

/* ───────────────────────────────────────────────
   Wizard Steps
─────────────────────────────────────────────── */
.wizard-steps {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px 16px;
  gap: 0;
}
.step {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  opacity: 0.35;
  transition: opacity 0.3s;
}
.step.active, .step.done { opacity: 1; }
.step.done .step-num {
  background: #44cc77 !important;
}
.step.done .step-num::after { content: ' ✓'; }
.step-num {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--bg-surface);
  border: 2px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.85rem; font-weight: 700;
  transition: background 0.3s;
}
.step.active .step-num {
  background: var(--accent-grad);
  border-color: transparent;
}
.step-label { font-size: 0.65rem; color: var(--text-secondary); white-space: nowrap; }
.step-divider {
  flex: 1;
  height: 2px;
  background: var(--border);
  min-width: 24px;
  max-width: 40px;
}

/* ───────────────────────────────────────────────
   Wizard Panels
─────────────────────────────────────────────── */
.wizard-panel {
  display: none;
  padding: 0 16px;
  animation: fadeSlideIn 0.35s ease;
}
.wizard-panel.active { display: block; }

@keyframes fadeSlideIn {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

.panel-title {
  font-size: 1.3rem;
  font-weight: 700;
  text-align: center;
  margin-bottom: 6px;
}
.panel-sub {
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.88rem;
  margin-bottom: 24px;
}

/* ───────────────────────────────────────────────
   Template Cards
─────────────────────────────────────────────── */
.template-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  margin-bottom: 28px;
}
@media (min-width: 420px) {
  .template-grid { grid-template-columns: 1fr 1fr; }
}
.template-card {
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.2s, transform 0.2s, box-shadow 0.2s;
  -webkit-tap-highlight-color: transparent;
}
.template-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.template-card.selected {
  border-color: var(--accent1);
  box-shadow: 0 0 0 3px rgba(102,126,234,0.25);
}
.template-preview {
  height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}
.balloon-preview {
  background: linear-gradient(160deg, #1a0033, #2d0050);
}
.gifts-preview {
  background: linear-gradient(160deg, #001a33, #003366);
}
.preview-balloon {
  font-size: 2.2rem;
  position: absolute;
  animation: floatUp 3s ease-in-out infinite;
}
.b1 { left: 20%; animation-delay: 0s; }
.b2 { left: 50%; animation-delay: 0.8s; }
.b3 { left: 75%; animation-delay: 1.6s; }

@keyframes floatUp {
  0%   { transform: translateY(30px); opacity: 0.8; }
  50%  { transform: translateY(-10px) rotate(-8deg); opacity: 1; }
  100% { transform: translateY(30px); opacity: 0.8; }
}

.preview-gift {
  font-size: 2rem;
  position: absolute;
  animation: fallDown 2.5s ease-in-out infinite;
}
.g1 { left: 20%; animation-delay: 0s; }
.g2 { left: 50%; animation-delay: 0.7s; }
.g3 { left: 75%; animation-delay: 1.4s; }

@keyframes fallDown {
  0%   { transform: translateY(-20px); opacity: 0.8; }
  50%  { transform: translateY(60px) rotate(15deg); opacity: 1; }
  100% { transform: translateY(-20px); opacity: 0.8; }
}

.template-info { padding: 14px; }
.template-info h3 { font-size: 1rem; font-weight: 700; margin-bottom: 4px; }
.template-info p  { font-size: 0.78rem; color: var(--text-secondary); line-height: 1.5; margin-bottom: 8px; }
.badge {
  display: inline-block;
  background: rgba(102,126,234,0.15);
  border: 1px solid rgba(102,126,234,0.3);
  color: var(--accent1);
  font-size: 0.7rem;
  padding: 2px 10px;
  border-radius: 20px;
}

/* ───────────────────────────────────────────────
   Customize Form
─────────────────────────────────────────────── */
.customize-form { display: flex; flex-direction: column; gap: 20px; margin-bottom: 28px; }

.form-group { display: flex; flex-direction: column; gap: 8px; }
.form-group label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
}
.form-group input,
.form-group select {
  background: var(--bg-card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 1rem;
  padding: 12px 14px;
  outline: none;
  transition: border-color 0.2s;
  width: 100%;
  -webkit-appearance: none;
}
.form-group input::placeholder { color: rgba(160,160,192,0.5); }
.form-group input:focus,
.form-group select:focus { border-color: var(--accent1); }
.form-group select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23a0a0c0' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}

/* Color Picker */
.color-picker {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.color-swatch {
  flex: 1;
  min-width: 60px;
  height: 52px;
  border-radius: var(--radius-sm);
  border: 2px solid transparent;
  cursor: pointer;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 4px;
  transition: border-color 0.2s, transform 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.color-swatch span {
  font-size: 0.6rem;
  color: #fff;
  font-weight: 700;
  text-shadow: 0 1px 3px rgba(0,0,0,0.6);
}
.color-swatch.selected { border-color: #fff; transform: scale(1.08); }
.color-swatch:hover { transform: scale(1.06); }

/* Theme Picker */
.theme-picker, .difficulty-picker {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.theme-btn, .diff-btn {
  flex: 1;
  padding: 10px 8px;
  background: var(--bg-card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  -webkit-tap-highlight-color: transparent;
  min-width: 70px;
}
.theme-btn.selected, .diff-btn.selected {
  background: rgba(102,126,234,0.2);
  border-color: var(--accent1);
  color: #fff;
}
.theme-btn:hover, .diff-btn:hover { border-color: rgba(102,126,234,0.5); }

/* ───────────────────────────────────────────────
   Buttons
─────────────────────────────────────────────── */
.panel-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  margin-top: 4px;
}
.preview-actions { justify-content: space-between; }

.btn-primary, .btn-secondary, .btn-ghost {
  padding: 13px 24px;
  border-radius: 30px;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  border: none;
  transition: opacity 0.2s, transform 0.15s;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}
.btn-primary {
  background: var(--accent-grad);
  color: #fff;
  box-shadow: 0 4px 20px rgba(102,126,234,0.4);
}
.btn-primary:hover { opacity: 0.9; transform: translateY(-1px); }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

.btn-secondary {
  background: rgba(102,126,234,0.15);
  border: 1.5px solid rgba(102,126,234,0.4);
  color: #fff;
}
.btn-ghost {
  background: transparent;
  border: 1.5px solid var(--border);
  color: var(--text-secondary);
}
.btn-ghost:hover { color: var(--text-primary); border-color: rgba(255,255,255,0.25); }

/* ───────────────────────────────────────────────
   Phone Frame (Preview)
─────────────────────────────────────────────── */
.preview-wrapper {
  display: flex;
  justify-content: center;
  margin-bottom: 24px;
}
.phone-frame {
  width: 260px;
  height: 520px;
  background: #111;
  border-radius: 36px;
  border: 6px solid #333;
  box-shadow: 0 20px 60px rgba(0,0,0,0.7), inset 0 0 0 2px rgba(255,255,255,0.05);
  position: relative;
  overflow: hidden;
}
.phone-notch {
  position: absolute;
  top: 0; left: 50%;
  transform: translateX(-50%);
  width: 90px; height: 22px;
  background: #111;
  border-radius: 0 0 16px 16px;
  z-index: 5;
}
.phone-screen {
  width: 100%; height: 100%;
  background: #0d0d1a;
  overflow: hidden;
  position: relative;
}
.phone-screen canvas {
  width: 100% !important;
  height: 100% !important;
  touch-action: none;
}
.preview-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--text-secondary);
}
.preview-placeholder span { font-size: 3rem; }
.preview-placeholder p   { font-size: 0.85rem; }

/* ───────────────────────────────────────────────
   Share Panel
─────────────────────────────────────────────── */
.share-success {
  text-align: center;
  padding: 16px 0;
}
.success-icon {
  font-size: 4rem;
  margin-bottom: 12px;
  animation: popIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
@keyframes popIn {
  from { transform: scale(0); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}
.share-success h2 { font-size: 1.6rem; font-weight: 800; margin-bottom: 8px; }
#shareSubtitle { color: var(--text-secondary); font-size: 0.9rem; margin-bottom: 28px; }

.share-link-box {
  display: flex;
  background: var(--bg-card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin-bottom: 20px;
}
.share-link-box input {
  flex: 1;
  background: transparent;
  border: none;
  padding: 12px 14px;
  color: var(--text-primary);
  font-size: 0.85rem;
  outline: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.btn-copy {
  background: var(--accent-grad);
  border: none;
  padding: 12px 16px;
  color: #fff;
  font-weight: 700;
  font-size: 0.85rem;
  cursor: pointer;
  white-space: nowrap;
  transition: opacity 0.2s;
}
.btn-copy:hover { opacity: 0.85; }

.share-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-bottom: 24px;
}
.share-actions a.btn-primary { text-decoration: none; display: inline-flex; align-items: center; }

.qr-hint {
  background: rgba(102,126,234,0.08);
  border: 1px solid rgba(102,126,234,0.2);
  border-radius: var(--radius-sm);
  padding: 14px;
}
.qr-hint p { font-size: 0.85rem; color: var(--text-secondary); }

/* ───────────────────────────────────────────────
   Scrollbar (desktop)
─────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ───────────────────────────────────────────────
   Platformer template card (spans full width)
─────────────────────────────────────────────── */
.template-card--wide {
  grid-column: 1 / -1;
}
.template-card--wide .template-preview {
  height: 100px;
}
.platform-preview {
  background: linear-gradient(160deg, #0d0020, #1a003a);
  position: relative;
  overflow: hidden;
}
.platform-ground {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 16px;
  background: #4a2d8a;
  border-top: 3px solid #7b59c0;
}
.platform-block {
  position: absolute;
  height: 10px;
  border-radius: 3px;
  background: #7b59c0;
  border-top: 2px solid #a07edc;
}
.p-b1 { bottom: 20px; left: 14%; width: 18%; }
.p-b2 { bottom: 40px; left: 42%; width: 20%; }
.p-b3 { bottom: 28px; right: 10%; width: 18%; }
.platform-char {
  position: absolute;
  font-size: 1.6rem;
  bottom: 16px;
  left: 14%;
  animation: platformJump 1.4s ease-in-out infinite;
}
@keyframes platformJump {
  0%, 100% { transform: translateY(0); }
  45%       { transform: translateY(-28px); }
  55%       { transform: translateY(-28px); }
}
.platform-star {
  position: absolute;
  font-size: 1rem;
  animation: starSpin 2s linear infinite;
}
.ps1 { top: 14px; left: 48%; }
.ps2 { top: 22px; right: 14%; animation-delay: 0.8s; }
@keyframes starSpin {
  0%   { transform: scale(1) rotate(0deg); }
  50%  { transform: scale(1.3) rotate(180deg); }
  100% { transform: scale(1) rotate(360deg); }
}

/* ───────────────────────────────────────────────
   Character Editor
─────────────────────────────────────────────── */
.char-editor {
  display: none; /* shown by JS when platformer is selected */
  background: rgba(102,126,234,0.07);
  border: 1.5px solid rgba(102,126,234,0.2);
  border-radius: var(--radius);
  padding: 16px;
}
.char-editor > label {
  font-size: 0.95rem !important;
  font-weight: 700 !important;
  color: var(--text-primary) !important;
  margin-bottom: 14px;
  display: block;
}

.char-customizer {
  display: flex;
  gap: 16px;
  align-items: flex-start;
}

/* Canvas preview */
.char-preview-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
.char-preview-wrap canvas {
  border-radius: var(--radius-sm);
  background: rgba(0,0,0,0.35);
  border: 2px solid rgba(102,126,234,0.3);
  display: block;
}
.char-preview-label {
  font-size: 0.68rem;
  color: var(--text-secondary);
  text-align: center;
}

/* Option columns */
.char-options {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}
.char-opt-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.char-opt-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* Color swatches (skin & hair) */
.char-swatches {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
}
.char-swatch {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2.5px solid transparent;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s;
  -webkit-tap-highlight-color: transparent;
  outline: none;
}
.char-swatch:hover     { transform: scale(1.12); }
.char-swatch.selected  { border-color: #fff; transform: scale(1.15); box-shadow: 0 0 0 2px rgba(102,126,234,0.6); }

/* Tag buttons (hat & accessory) */
.char-tag-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.char-tag {
  padding: 5px 10px;
  background: var(--bg-card);
  border: 1.5px solid var(--border);
  border-radius: 20px;
  color: var(--text-secondary);
  font-size: 0.74rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
}
.char-tag:hover { border-color: rgba(102,126,234,0.5); color: var(--text-primary); }
.char-tag.selected {
  background: rgba(102,126,234,0.22);
  border-color: var(--accent1);
  color: #fff;
}
