* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', Roboto, sans-serif;
  background: #000;
  min-height: 100vh;
  overflow: hidden;
  user-select: none;
}

.app-container {
  position: relative;
  width: 100%;
  height: 100vh;
  max-width: 500px;
  margin: 0 auto;
  background: #000;
}

.story-canvas {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  overflow: hidden;
}

.story-canvas.has-image {
  background: #000;
}

.story-canvas .background-image {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: none;
}

.story-canvas.has-image .background-image {
  display: block;
}

.confetti-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 12;
}

.gradient-1 {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.gradient-2 {
  background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
}

.gradient-3 {
  background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
}

.gradient-4 {
  background: linear-gradient(135deg, #43e97b 0%, #38f9d7 100%);
}

.gradient-5 {
  background: linear-gradient(135deg, #fa709a 0%, #fee140 100%);
}

.gradient-6 {
  background: linear-gradient(135deg, #a8edea 0%, #fed6e3 100%);
}

.gradient-7 {
  background: linear-gradient(135deg, #ff9a9e 0%, #fecfef 100%);
}

.gradient-8 {
  background: linear-gradient(135deg, #ffecd2 0%, #fcb69f 100%);
}

.gradient-9 {
  background: #000000;
}

.gradient-10 {
  background: #ffffff;
}

.effects-layer {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
  z-index: 10;
}

.content-layer {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 5;
}

.main-text {
  position: absolute;
  font-size: 32px;
  font-weight: 700;
  color: #fff;
  text-align: center;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
  max-width: 90%;
  word-wrap: break-word;
  line-height: 1.4;
  padding: 16px 20px;
  cursor: grab;
  touch-action: none;
  display: none;
  border-radius: 8px;
  transition: box-shadow 0.2s;
}

.main-text.visible {
  display: block;
}

.main-text.dragging {
  cursor: grabbing;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.5), 0 10px 40px rgba(0, 0, 0, 0.3);
}

.text-style-classic {
  font-family: -apple-system, BlinkMacSystemFont, sans-serif;
}

.text-style-typewriter {
  font-family: 'Courier New', monospace;
}

.text-style-elegant {
  font-family: Georgia, serif;
  font-style: italic;
}

.text-style-bold {
  font-family: Impact, sans-serif;
  text-transform: uppercase;
  letter-spacing: 2px;
}

.text-style-neon {
  font-family: 'Arial Black', sans-serif;
  text-shadow: 0 0 10px currentColor, 0 0 20px currentColor, 0 0 40px currentColor;
}

.top-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  padding: 16px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  z-index: 100;
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0.3) 0%, transparent 100%);
  pointer-events: none;
}

.top-bar>* {
  pointer-events: auto;
}

.top-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: none;
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.top-btn:hover {
  background: rgba(0, 0, 0, 0.6);
  transform: scale(1.05);
}

.side-tools {
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 16px;
  z-index: 100;
}

.side-tool {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: none;
  color: #fff;
  font-size: 22px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.side-tool:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: scale(1.1);
}

.bottom-controls {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 20px 16px;
  padding-bottom: max(20px, env(safe-area-inset-bottom));
  background: linear-gradient(to top, rgba(0, 0, 0, 0.5) 0%, transparent 100%);
  z-index: 100;
}

.input-container {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.text-input {
  flex: 1;
  background: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 24px;
  padding: 14px 20px;
  font-size: 16px;
  color: #fff;
  outline: none;
  font-family: inherit;
}

.text-input::placeholder {
  color: rgba(255, 255, 255, 0.6);
}

.send-btn {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  border: none;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
}

.send-btn:hover {
  transform: scale(1.1);
}

.effects-carousel {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding: 8px 0;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.effects-carousel::-webkit-scrollbar {
  display: none;
}

.effect-chip {
  flex-shrink: 0;
  padding: 10px 18px;
  background: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 20px;
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 6px;
}

.effect-chip:hover {
  background: rgba(255, 255, 255, 0.25);
}

.effect-chip.active {
  background: #fff;
  color: #000;
  border-color: #fff;
}

.panel {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: #1c1c1e;
  border-radius: 24px 24px 0 0;
  padding: 20px;
  padding-bottom: max(20px, env(safe-area-inset-bottom));
  z-index: 200;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  max-height: 70vh;
  overflow-y: auto;
}

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

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.panel-title {
  color: #fff;
  font-size: 18px;
  font-weight: 600;
}

.panel-close {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  border: none;
  color: #fff;
  font-size: 18px;
  cursor: pointer;
}

.gradient-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
}

.gradient-option {
  aspect-ratio: 1;
  border-radius: 12px;
  border: 3px solid transparent;
  cursor: pointer;
  transition: all 0.2s;
}

.gradient-option:hover {
  transform: scale(1.05);
}

.gradient-option.active {
  border-color: #fff;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.3);
}

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

.style-option {
  padding: 16px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  border: 2px solid transparent;
  color: #fff;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
}

.style-option:hover {
  background: rgba(255, 255, 255, 0.15);
}

.style-option.active {
  border-color: #667eea;
  background: rgba(102, 126, 234, 0.2);
}

.style-preview {
  font-size: 18px;
  margin-bottom: 8px;
}

.style-name {
  font-size: 12px;
  opacity: 0.7;
}

.image-upload-area {
  border: 2px dashed rgba(255, 255, 255, 0.3);
  border-radius: 16px;
  padding: 40px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  margin-bottom: 16px;
}

.image-upload-area:hover {
  border-color: rgba(255, 255, 255, 0.5);
  background: rgba(255, 255, 255, 0.05);
}

.image-upload-area .icon {
  font-size: 48px;
  margin-bottom: 12px;
}

.image-upload-area .text {
  color: rgba(255, 255, 255, 0.7);
  font-size: 14px;
}

.remove-image-btn {
  width: 100%;
  padding: 14px;
  background: rgba(255, 59, 48, 0.2);
  border: 1px solid rgba(255, 59, 48, 0.3);
  border-radius: 12px;
  color: #ff3b30;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  display: none;
}

.remove-image-btn.show {
  display: block;
}

#imageInput {
  display: none;
}

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

.effect-option {
  padding: 16px 8px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  border: 2px solid transparent;
  color: #fff;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
}

.effect-option:hover {
  background: rgba(255, 255, 255, 0.15);
}

.effect-option .icon {
  font-size: 28px;
  margin-bottom: 6px;
}

.effect-option .name {
  font-size: 11px;
  opacity: 0.8;
}

.overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 150;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}

.overlay.show {
  opacity: 1;
  pointer-events: auto;
}

.particle {
  position: absolute;
  pointer-events: none;
  z-index: 15;
}

.anim-jump {
  animation: textJump 0.6s ease;
}

.anim-spring {
  animation: textSpring 0.5s ease;
}

.anim-pulse {
  animation: textPulse 0.8s ease;
}

.anim-spin {
  animation: textSpin 0.8s ease;
}

.anim-glitch {
  animation: textGlitch 0.5s ease;
}

.anim-shatter {
  animation: textShatter 0.6s ease;
}

@keyframes textJump {

  0%,
  100% {
    transform: translateY(0) scale(1);
  }

  30% {
    transform: translateY(-30px) scale(1.1);
  }

  50% {
    transform: translateY(0) scale(0.95);
  }

  70% {
    transform: translateY(-15px) scale(1.05);
  }
}

@keyframes textSpring {

  0%,
  100% {
    transform: translateX(0);
  }

  20% {
    transform: translateX(-20px) rotate(-2deg);
  }

  40% {
    transform: translateX(20px) rotate(2deg);
  }

  60% {
    transform: translateX(-10px) rotate(-1deg);
  }

  80% {
    transform: translateX(10px) rotate(1deg);
  }
}

@keyframes textPulse {

  0%,
  100% {
    transform: scale(1);
  }

  50% {
    transform: scale(1.3);
  }
}

@keyframes textSpin {
  0% {
    transform: rotate(0deg) scale(1);
  }

  50% {
    transform: rotate(180deg) scale(0.8);
  }

  100% {
    transform: rotate(360deg) scale(1);
  }
}

@keyframes textGlitch {

  0%,
  100% {
    transform: translate(0);
    filter: none;
  }

  20% {
    transform: translate(-5px, 5px);
    filter: hue-rotate(90deg);
  }

  40% {
    transform: translate(5px, -5px);
    filter: hue-rotate(180deg);
  }

  60% {
    transform: translate(-3px, -3px);
    filter: hue-rotate(270deg);
  }

  80% {
    transform: translate(3px, 3px);
    filter: hue-rotate(360deg);
  }
}

@keyframes textShatter {
  0% {
    transform: scale(0);
    opacity: 0;
  }

  50% {
    transform: scale(1.5);
  }

  100% {
    transform: scale(1);
    opacity: 1;
  }
}

.text-rainbow {
  background: linear-gradient(90deg, #ff0000, #ff7f00, #ffff00, #00ff00, #0000ff, #4b0082, #8f00ff, #ff0000);
  background-size: 200% 100%;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: rainbowShift 3s linear infinite;
}

@keyframes rainbowShift {
  0% {
    background-position: 0% 50%;
  }

  100% {
    background-position: 200% 50%;
  }
}

@media (max-width: 400px) {
  .main-text {
    font-size: 26px;
  }

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

  .side-tools {
    right: 12px;
  }

  .side-tool {
    width: 42px;
    height: 42px;
    font-size: 18px;
  }
}