/* ==================== Custom Fonts (@font-face) ==================== */
@font-face {
  font-family: 'AquaMonstera';
  src: url('assets/fonts/AquaMonstera.otf') format('opentype');
  font-display: swap;
}
@font-face {
  font-family: 'Brains';
  src: url('assets/fonts/Brains.ttf') format('truetype');
  font-display: swap;
}
@font-face {
  font-family: 'LampPost';
  src: url('assets/fonts/LampPost.ttf') format('truetype');
  font-display: swap;
}
@font-face {
  font-family: 'SkirtGirl';
  src: url('assets/fonts/SkirtGirl.ttf') format('truetype');
  font-display: swap;
}

/* ==================== CSS Variables & Reset ==================== */
:root {
  --bg-app: #FFF5F0;
  --bg-panel: #FFFFFF;
  --bg-canvas-area: #FAF0EB;
  --bg-toolbar: #FFFFFF;
  --accent-pink: #FF6B9D;
  --accent-purple: #9B59B6;
  --accent-gold: #FFD700;
  --accent-teal: #00CEC9;
  --accent-coral: #FF9FF3;
  --text-primary: #2D1B4E;
  --text-secondary: #8E7BA8;
  --text-muted: #B0A0C0;
  --border-color: #F0E0EC;
  --shadow-sm: 0 2px 8px rgba(255, 107, 157, 0.08);
  --shadow-md: 0 4px 20px rgba(255, 107, 157, 0.12);
  --shadow-lg: 0 8px 40px rgba(155, 89, 182, 0.18);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 20px;
  --toolbar-w: 84px;
  --panel-w: 300px;
  --toolbar-h-mobile: 64px;
  --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  --bounce: cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: 'Fredoka', 'ZCOOL KuaiLe', -apple-system, BlinkMacSystemFont, sans-serif;
  color: var(--text-primary);
  background: var(--bg-app);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
  outline: none;
}

/* ==================== Birthday Overlay ==================== */
.birthday-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  background: linear-gradient(135deg, #FF6B9D, #9B59B6, #6C5CE7);
  cursor: pointer;
  animation: overlayFadeIn 0.6s ease;
}

.birthday-overlay.hiding {
  animation: overlayFadeOut 0.5s ease forwards;
}

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

@keyframes overlayFadeOut {
  from { opacity: 1; transform: scale(1); }
  to { opacity: 0; transform: scale(1.05); }
}

#confetti-canvas {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.birthday-text-wrapper {
  position: relative;
  z-index: 2;
  text-align: center;
}

.birthday-text {
  font-family: 'Pacifico', cursive;
  font-size: clamp(32px, 7vw, 72px);
  display: flex;
  gap: 2px;
  justify-content: center;
  flex-wrap: wrap;
}

.birthday-text span {
  display: inline-block;
  opacity: 0;
  animation: letterBounce 0.6s var(--bounce) forwards;
  animation-delay: calc(var(--i) * 0.08s);
  background: linear-gradient(180deg, #FFD700, #FF6B9D);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 4px 8px rgba(0,0,0,0.2));
}

.birthday-text span.space {
  width: 0.3em;
}

@keyframes letterBounce {
  0% { opacity: 0; transform: translateY(-60px) scale(0.5) rotate(-20deg); }
  60% { opacity: 1; transform: translateY(10px) scale(1.1) rotate(5deg); }
  100% { opacity: 1; transform: translateY(0) scale(1) rotate(0); }
}

.birthday-subtitle {
  margin-top: 20px;
  font-size: clamp(18px, 3vw, 28px);
  color: #FFF;
  font-weight: 400;
  opacity: 0;
  animation: subtitleFade 0.8s ease 1.2s forwards;
  text-shadow: 0 2px 10px rgba(0,0,0,0.2);
}

.birthday-hint {
  margin-top: 30px;
  font-size: 14px;
  color: rgba(255,255,255,0.7);
  opacity: 0;
  animation: hintPulse 2s ease 2s infinite;
}

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

@keyframes hintPulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 0.9; }
}

/* ==================== App Layout ==================== */
.app {
  display: flex;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

/* ==================== Left Toolbar ==================== */
.toolbar {
  width: var(--toolbar-w);
  height: 100%;
  background: var(--bg-toolbar);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 0;
  border-right: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  z-index: 10;
  flex-shrink: 0;
}

.toolbar-header {
  margin-bottom: 16px;
}

.toolbar-logo {
  font-size: 32px;
  display: block;
  animation: logoBounce 2s ease infinite;
}

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

.toolbar-nav {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}

.tool-btn {
  width: 64px;
  height: 56px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  transition: all var(--transition);
  position: relative;
}

.tool-btn:hover {
  background: rgba(255, 107, 157, 0.08);
  color: var(--accent-pink);
}

.tool-btn.active {
  background: linear-gradient(135deg, #FF6B9D, #9B59B6);
  color: #fff;
  box-shadow: 0 4px 12px rgba(255, 107, 157, 0.35);
}

.tool-btn.active::before {
  content: '';
  position: absolute;
  left: -1px;
  top: 50%;
  transform: translateY(-50%);
  width: 4px;
  height: 32px;
  background: #FFD700;
  border-radius: 0 4px 4px 0;
}

.tool-icon {
  width: 22px;
  height: 22px;
}

.tool-label {
  font-size: 11px;
  font-weight: 500;
}

.toolbar-footer {
  margin-top: auto;
}

/* ==================== Canvas Area ==================== */
.canvas-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-canvas-area);
  position: relative;
  min-width: 0;
  overflow: hidden;
}

.canvas-toolbar {
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.canvas-toolbar-left,
.canvas-toolbar-right {
  display: flex;
  align-items: center;
  gap: 4px;
}

.aspect-ratio-group {
  display: flex;
  gap: 4px;
  background: var(--bg-app);
  padding: 4px;
  border-radius: var(--radius-md);
}

.ratio-btn {
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  transition: all var(--transition);
}

.ratio-btn.active {
  background: linear-gradient(135deg, #FF6B9D, #9B59B6);
  color: #fff;
  box-shadow: 0 2px 8px rgba(255, 107, 157, 0.3);
}

.ratio-btn:hover:not(.active) {
  background: rgba(255, 107, 157, 0.08);
}

.icon-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  transition: all var(--transition);
}

.icon-btn:hover:not(:disabled) {
  background: rgba(255, 107, 157, 0.1);
  color: var(--accent-pink);
}

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

.icon-btn.danger:hover {
  background: rgba(231, 76, 60, 0.1);
  color: #E74C3C;
}

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

.canvas-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow: auto;
  position: relative;
}

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

.canvas {
  position: relative;
  background: #fff;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  transition: width 0.3s ease, height 0.3s ease;
}

.canvas-bg {
  position: absolute;
  inset: 0;
  background: #FFFFFF;
  z-index: 0;
}

.canvas-elements {
  position: absolute;
  inset: 0;
  z-index: 1;
}

.canvas-empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  z-index: 2;
  pointer-events: none;
  opacity: 0.5;
}

.empty-icon {
  font-size: 64px;
  animation: emptyFloat 3s ease infinite;
}

@keyframes emptyFloat {
  0%, 100% { transform: translateY(0) rotate(0); }
  50% { transform: translateY(-8px) rotate(5deg); }
}

.empty-text {
  font-size: 16px;
  color: var(--text-secondary);
}

/* ==================== Background Popover ==================== */
.bg-popover {
  position: absolute;
  top: 52px;
  right: 16px;
  background: var(--bg-panel);
  border-radius: var(--radius-md);
  padding: 12px;
  display: none;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  box-shadow: var(--shadow-lg);
  z-index: 20;
  border: 1px solid var(--border-color);
}

.bg-popover.show {
  display: grid;
  animation: popoverIn 0.2s ease;
}

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

.bg-option {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  border: 2px solid transparent;
  cursor: pointer;
  transition: all var(--transition);
}

.bg-option:hover {
  transform: scale(1.1);
}

.bg-option.active {
  border-color: var(--accent-pink);
  box-shadow: 0 2px 8px rgba(255, 107, 157, 0.3);
}

/* ==================== Properties Panel ==================== */
.properties-panel {
  width: var(--panel-w);
  height: 100%;
  background: var(--bg-panel);
  border-left: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
  z-index: 10;
}

.panel-header {
  padding: 18px 20px 12px;
  border-bottom: 1px solid var(--border-color);
}

.panel-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
}

.panel-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
}

.panel-content::-webkit-scrollbar {
  width: 4px;
}

.panel-content::-webkit-scrollbar-thumb {
  background: var(--accent-pink);
  border-radius: 2px;
}

/* ==================== Panel Content Styles ==================== */
.upload-zone {
  border: 2px dashed var(--accent-pink);
  border-radius: var(--radius-md);
  padding: 32px 20px;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
  background: rgba(255, 107, 157, 0.04);
}

.upload-zone:hover {
  background: rgba(255, 107, 157, 0.08);
  border-color: var(--accent-purple);
  transform: scale(1.02);
}

.upload-zone .upload-icon {
  font-size: 40px;
  margin-bottom: 8px;
}

.upload-zone .upload-text {
  font-size: 14px;
  color: var(--text-secondary);
  font-weight: 500;
}

.upload-zone .upload-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

.section-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 10px;
  margin-top: 18px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.sticker-categories {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.sticker-cat-btn {
  padding: 6px 14px;
  font-size: 12px;
  font-weight: 500;
  border-radius: 20px;
  background: var(--bg-app);
  color: var(--text-secondary);
  transition: all var(--transition);
}

.sticker-cat-btn.active {
  background: linear-gradient(135deg, #FF6B9D, #9B59B6);
  color: #fff;
}

.sticker-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.sticker-item {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  border-radius: var(--radius-sm);
  background: var(--bg-app);
  cursor: pointer;
  transition: all var(--transition);
  border: 2px solid transparent;
  overflow: hidden;
  position: relative;
}

.sticker-item img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  pointer-events: none;
}

.sticker-item .sticker-emoji-text {
  font-size: 32px;
  line-height: 1;
}

.sticker-item.loading::after {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--bg-app);
  display: flex;
  align-items: center;
  justify-content: center;
}

.sticker-item:hover {
  background: rgba(255, 107, 157, 0.1);
  border-color: var(--accent-pink);
  transform: scale(1.08);
}

.sticker-item:active {
  transform: scale(0.95);
}

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

.template-item {
  aspect-ratio: 1.5;
  border-radius: var(--radius-sm);
  background: var(--bg-app);
  cursor: pointer;
  padding: 6px;
  transition: all var(--transition);
  border: 2px solid transparent;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.template-item:hover {
  border-color: var(--accent-pink);
  transform: scale(1.04);
}

.template-item.active {
  border-color: var(--accent-pink);
  background: rgba(255, 107, 157, 0.08);
}

.template-row {
  display: flex;
  gap: 3px;
  flex: 1;
}

.template-cell {
  background: #FFD0E0;
  border-radius: 3px;
  flex: 1;
}

.template-name {
  font-size: 10px;
  color: var(--text-secondary);
  text-align: center;
  margin-top: 2px;
}

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

.border-item {
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  position: relative;
  background: var(--bg-app);
  border: 2px solid transparent;
}

.border-item:hover {
  transform: scale(1.05);
}

.border-item.active {
  border-color: var(--accent-pink);
}

.border-preview {
  width: 60%;
  height: 60%;
  background: linear-gradient(135deg, #FFD700, #FF6B9D);
  border-radius: 4px;
}

.border-preview img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 4px;
}

.border-name {
  position: absolute;
  bottom: 4px;
  font-size: 9px;
  color: var(--text-secondary);
}

/* 图片贴纸在画布上的渲染 */
.element-content .sticker-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  -webkit-user-drag: none;
}

/* 边框图片覆盖层 */
.element-content .border-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: fill;
  pointer-events: none;
  z-index: 10;
}

.text-presets {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
}

.text-preset {
  padding: 12px;
  border-radius: var(--radius-sm);
  background: var(--bg-app);
  cursor: pointer;
  transition: all var(--transition);
  text-align: center;
  border: 2px solid transparent;
}

.text-preset:hover {
  border-color: var(--accent-pink);
  transform: translateX(4px);
}

.text-input-group {
  margin-bottom: 14px;
}

.text-input {
  width: 100%;
  padding: 10px 14px;
  border: 2px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  color: var(--text-primary);
  background: var(--bg-app);
  transition: border-color var(--transition);
  outline: none;
}

.text-input:focus {
  border-color: var(--accent-pink);
}

.btn-primary {
  width: 100%;
  padding: 12px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, #FF6B9D, #9B59B6);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  transition: all var(--transition);
  box-shadow: 0 4px 12px rgba(255, 107, 157, 0.3);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(255, 107, 157, 0.4);
}

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

.property-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.property-label {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 500;
}

.property-value {
  font-size: 13px;
  color: var(--text-primary);
  font-weight: 600;
}

input[type="range"] {
  width: 100%;
  height: 6px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--bg-app);
  border-radius: 3px;
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: linear-gradient(135deg, #FF6B9D, #9B59B6);
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(255, 107, 157, 0.4);
  border: 2px solid #fff;
}

input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: linear-gradient(135deg, #FF6B9D, #9B59B6);
  cursor: pointer;
  border: 2px solid #fff;
}

input[type="color"] {
  width: 36px;
  height: 36px;
  border: 2px solid var(--border-color);
  border-radius: var(--radius-sm);
  cursor: pointer;
  background: none;
  padding: 0;
}

input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 0;
}

input[type="color"]::-webkit-color-swatch {
  border: none;
  border-radius: 4px;
}

select {
  padding: 8px 12px;
  border: 2px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: inherit;
  color: var(--text-primary);
  background: var(--bg-app);
  cursor: pointer;
  outline: none;
}

.action-buttons {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

.action-btn {
  flex: 1;
  padding: 10px;
  border-radius: var(--radius-sm);
  background: var(--bg-app);
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  transition: all var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.action-btn:hover {
  background: rgba(255, 107, 157, 0.1);
  color: var(--accent-pink);
}

.action-btn.danger:hover {
  background: rgba(231, 76, 60, 0.1);
  color: #E74C3C;
}

/* ==================== Canvas Elements ==================== */
.canvas-element {
  position: absolute;
  left: 0;
  top: 0;
  cursor: grab;
  touch-action: none;
}

.canvas-element:active {
  cursor: grabbing;
}

.canvas-element.selected {
  outline: 2px solid var(--accent-pink);
  outline-offset: 2px;
}

.element-content {
  width: 100%;
  height: 100%;
  overflow: hidden;
  position: relative;
}

.element-content img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
  -webkit-user-drag: none;
}

.element-content .sticker-emoji {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  line-height: 1;
}

.element-content .text-content {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  word-break: break-word;
  pointer-events: none;
  line-height: 1.2;
  padding: 4px;
}

/* Placeholder element (template slots) */
.canvas-element.placeholder .element-content {
  border: 2px dashed var(--accent-pink);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 107, 157, 0.06);
  cursor: pointer;
}

.canvas-element.placeholder .placeholder-icon {
  font-size: 32px;
  color: var(--accent-pink);
}

/* Element handles */
.element-handles {
  position: absolute;
  inset: -2px;
  pointer-events: none;
  z-index: 100;
}

.element-handles .handle {
  position: absolute;
  width: 14px;
  height: 14px;
  background: #fff;
  border: 2px solid var(--accent-pink);
  border-radius: 50%;
  pointer-events: auto;
  touch-action: none;
}

.element-handles .handle-tl { top: -7px; left: -7px; cursor: nwse-resize; }
.element-handles .handle-tr { top: -7px; right: -7px; cursor: nesw-resize; }
.element-handles .handle-bl { bottom: -7px; left: -7px; cursor: nesw-resize; }
.element-handles .handle-br { bottom: -7px; right: -7px; cursor: nwse-resize; }

.element-handles .handle-rotate {
  top: -28px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent-gold);
  border-color: var(--accent-purple);
  cursor: grab;
}

.element-handles .handle-rotate::before {
  content: '';
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  width: 2px;
  height: 12px;
  background: var(--accent-pink);
}

.element-handles .handle-delete {
  top: -12px;
  right: -12px;
  width: 22px;
  height: 22px;
  background: #FF3B5C;
  border: 2px solid #fff;
  color: #fff;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  cursor: pointer;
  pointer-events: auto;
  touch-action: none;
  box-shadow: 0 2px 8px rgba(255, 59, 92, 0.4);
}

/* ==================== Mobile Toolbar ==================== */
.mobile-toolbar {
  display: none;
}

/* ==================== Export Modal ==================== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
}

.modal.show {
  display: flex;
}

.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  animation: fadeIn 0.2s ease;
}

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

.modal-content {
  position: relative;
  background: #fff;
  border-radius: var(--radius-lg);
  padding: 28px;
  max-width: 420px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: modalIn 0.3s var(--bounce);
}

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

.modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--bg-app);
  color: var(--text-secondary);
  transition: all var(--transition);
}

.modal-close:hover {
  background: rgba(231, 76, 60, 0.1);
  color: #E74C3C;
}

.modal-title {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 20px;
  text-align: center;
  background: linear-gradient(135deg, #FF6B9D, #9B59B6);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.export-preview {
  margin-bottom: 20px;
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-md);
  background: var(--bg-app);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100px;
}

.export-preview img {
  max-width: 100%;
  max-height: 400px;
  display: block;
}

.export-info {
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.export-options {
  display: flex;
  gap: 10px;
}

.export-btn {
  flex: 1;
  padding: 14px 8px;
  border-radius: var(--radius-sm);
  background: var(--bg-app);
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 600;
  transition: all var(--transition);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.export-btn:hover {
  background: rgba(255, 107, 157, 0.1);
  color: var(--accent-pink);
  transform: translateY(-2px);
}

.export-btn.share {
  background: linear-gradient(135deg, #00CEC9, #6C5CE7);
  color: #fff;
}

.export-btn.share:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 206, 201, 0.4);
}

/* ==================== Toast ==================== */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(45, 27, 78, 0.92);
  color: #fff;
  padding: 12px 24px;
  border-radius: 24px;
  font-size: 14px;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  z-index: 10000;
  transition: all 0.3s var(--bounce);
  backdrop-filter: blur(8px);
  white-space: nowrap;
}

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

/* ==================== Sound Button Animation ==================== */
.sound-card {
  text-align: center;
  padding: 40px 20px;
}

.sound-icon-wrapper {
  width: 100px;
  height: 100px;
  margin: 0 auto 20px;
  border-radius: 50%;
  background: linear-gradient(135deg, #FF6B9D, #9B59B6);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 48px;
  cursor: pointer;
  transition: all var(--transition);
  box-shadow: 0 8px 24px rgba(255, 107, 157, 0.35);
  animation: soundPulse 2s ease infinite;
}

.sound-icon-wrapper:hover {
  transform: scale(1.1);
}

.sound-icon-wrapper.playing {
  animation: soundPlaying 0.5s ease infinite;
}

@keyframes soundPulse {
  0%, 100% { box-shadow: 0 8px 24px rgba(255, 107, 157, 0.35); }
  50% { box-shadow: 0 8px 40px rgba(255, 107, 157, 0.6); }
}

@keyframes soundPlaying {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}

.sound-text {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.sound-hint {
  font-size: 13px;
  color: var(--text-secondary);
}

/* ==================== Content Animations ==================== */
@keyframes contentPop {
  0% { transform: scale(0); opacity: 0; }
  60% { transform: scale(1.2); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

/* ==================== Complete Button ==================== */
.tool-btn.complete-btn { color: var(--accent-teal); }
.tool-btn.complete-btn.active { background: linear-gradient(135deg, #00CEC9, #6C5CE7); }
.mobile-tool-btn.complete-mobile-btn { color: var(--accent-teal); }

/* ==================== Canvas Border Overlay ==================== */
.canvas-border-overlay {
  position: absolute;
  inset: 0;
  z-index: 999;
  pointer-events: none;
}
.canvas-border-overlay:empty { display: none; }
.canvas-border-overlay img { width: 100%; height: 100%; object-fit: fill; }

/* ==================== Background Panel ==================== */
.bg-image-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.bg-image-item {
  aspect-ratio: 1; border-radius: var(--radius-sm); cursor: pointer; overflow: hidden;
  border: 3px solid transparent; transition: all var(--transition); position: relative; background: var(--bg-app);
}
.bg-image-item:hover { transform: scale(1.05); border-color: var(--accent-pink); }
.bg-image-item.active { border-color: var(--accent-pink); box-shadow: 0 2px 12px rgba(255,107,157,0.3); }
.bg-image-item img { width: 100%; height: 100%; object-fit: cover; }
.bg-image-item.blank-canvas {
  display: flex; align-items: center; justify-content: center; background: #fff; border: 2px dashed var(--border-color);
}
.bg-image-item.blank-canvas .blank-icon { font-size: 28px; color: var(--text-muted); }

/* ==================== Works Gallery ==================== */
.works-gallery { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; max-height: 60vh; overflow-y: auto; padding: 4px; }
.works-gallery::-webkit-scrollbar { width: 4px; }
.works-gallery::-webkit-scrollbar-thumb { background: var(--accent-pink); border-radius: 2px; }
.work-item { position: relative; border-radius: var(--radius-md); overflow: hidden; box-shadow: var(--shadow-sm); aspect-ratio: 1; background: var(--bg-app); }
.work-item img { width: 100%; height: 100%; object-fit: cover; }
.work-item .work-actions {
  position: absolute; bottom: 0; left: 0; right: 0; display: flex; gap: 4px; padding: 6px;
  background: linear-gradient(transparent, rgba(0,0,0,0.6)); opacity: 0; transition: opacity var(--transition);
}
.work-item:hover .work-actions { opacity: 1; }
.work-action-btn {
  flex: 1; padding: 6px; border-radius: var(--radius-sm); background: rgba(255,255,255,0.9);
  color: var(--text-primary); font-size: 12px; font-weight: 600; text-align: center; transition: all var(--transition);
}
.work-action-btn:hover { background: #fff; }
.work-action-btn.danger { background: rgba(231,76,60,0.9); color: #fff; }
.works-empty { grid-column: 1 / -1; text-align: center; padding: 60px 20px; color: var(--text-muted); }
.works-empty .empty-large-icon { font-size: 48px; margin-bottom: 12px; }

/* ==================== Complete Modal ==================== */
.complete-content { text-align: center; }
.complete-preview { margin: 16px auto 20px; max-width: 300px; border-radius: var(--radius-md); overflow: hidden; box-shadow: var(--shadow-md); }
.complete-preview img { width: 100%; display: block; }
.complete-text { font-size: 14px; color: var(--text-secondary); margin-bottom: 20px; line-height: 1.6; }
.complete-options { display: flex; gap: 10px; }
.complete-options .export-btn { flex: 1; }

/* ==================== Mobile Responsive ==================== */
@media (max-width: 768px) {
  :root {
    --toolbar-w: 0px;
    --panel-w: 100%;
  }

  .toolbar {
    display: none;
  }

  .properties-panel {
    position: fixed;
    bottom: var(--toolbar-h-mobile);
    left: 0;
    right: 0;
    width: 100%;
    height: 45vh;
    max-height: 360px;
    border-left: none;
    border-top: 1px solid var(--border-color);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    transform: translateY(100%);
    transition: transform 0.3s var(--bounce);
    z-index: 50;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.1);
  }

  .properties-panel.show {
    transform: translateY(0);
  }

  .properties-panel::before {
    content: '';
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 4px;
    background: var(--border-color);
    border-radius: 2px;
  }

  .panel-header {
    padding-top: 24px;
  }

  .mobile-toolbar {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--toolbar-h-mobile);
    background: var(--bg-panel);
    border-top: 1px solid var(--border-color);
    z-index: 100;
    box-shadow: 0 -2px 12px rgba(0,0,0,0.06);
    padding-bottom: env(safe-area-inset-bottom, 0);
  }

  .mobile-tool-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    color: var(--text-secondary);
    transition: all var(--transition);
    min-width: 0;
  }

  .mobile-tool-btn.active {
    color: var(--accent-pink);
  }

  .mt-icon {
    font-size: 20px;
  }

  .mt-label {
    font-size: 9px;
    font-weight: 500;
  }

  .canvas-container {
    padding: 12px;
    padding-bottom: 80px;
  }

  .canvas-toolbar {
    height: 44px;
    padding: 0 10px;
  }

  .ratio-btn {
    padding: 5px 10px;
    font-size: 12px;
  }

  .canvas-toolbar-right {
    gap: 2px;
  }

  .icon-btn {
    width: 32px;
    height: 32px;
  }

  .icon-btn svg {
    width: 16px;
    height: 16px;
  }

  .toolbar-divider {
    display: none;
  }

  .sticker-grid {
    grid-template-columns: repeat(5, 1fr);
  }

  .template-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .birthday-text {
    font-size: clamp(28px, 8vw, 56px);
  }

  .modal-content {
    padding: 20px;
  }

  .export-options {
    flex-direction: column;
  }

  .toast {
    bottom: calc(var(--toolbar-h-mobile) + 20px);
  }

  .bg-popover {
    right: 10px;
    top: 44px;
  }
}

@media (max-width: 380px) {
  .mobile-tool-btn .mt-label {
    display: none;
  }

  .mt-icon {
    font-size: 22px;
  }
}
