/* Telegram Theme Variables & Fallbacks */
:root {
  --bg-color: var(--tg-theme-bg-color, #0f141c);
  --secondary-bg-color: var(--tg-theme-secondary-bg-color, #1a222d);
  --text-color: var(--tg-theme-text-color, #ffffff);
  --hint-color: var(--tg-theme-hint-color, #8e9cae);
  --link-color: var(--tg-theme-link-color, #38bdf8);
  --button-color: var(--tg-theme-button-color, #2481cc);
  --button-text-color: var(--tg-theme-button-text-color, #ffffff);
  
  --accent-gold: #f59e0b;
  --accent-gold-glow: rgba(245, 158, 11, 0.35);
  --neon-cyan: #00f2fe;
  --neon-pink: #ff007f;
  --neon-green: #00ff88;
  --neon-yellow: #ffff00;
  
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --card-bg: rgba(26, 34, 45, 0.75);
  --border-color: rgba(255, 255, 255, 0.08);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Montserrat', 'Segoe UI', Roboto, sans-serif;
  background-color: var(--bg-color);
  color: var(--text-color);
  min-height: 100vh;
  padding-bottom: 90px;
  overflow-x: hidden;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.app-container {
  max-width: 520px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* Header */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-icon {
  font-size: 26px;
}

.brand-text h1 {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.sub-text {
  font-size: 12px;
  color: var(--hint-color);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  background: var(--secondary-bg-color);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  cursor: pointer;
  color: var(--text-color);
}

.pro-badge-btn {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  border: none;
  border-radius: 20px;
  padding: 6px 14px;
  color: #fff;
  font-weight: 700;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  box-shadow: 0 2px 10px var(--accent-gold-glow);
  transition: transform 0.15s ease;
}

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

.pro-badge-btn.is-pro-active {
  background: linear-gradient(135deg, #10b981, #059669);
  box-shadow: 0 2px 10px rgba(16, 185, 129, 0.3);
}

/* User stats bar */
.user-stats-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--secondary-bg-color);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  font-size: 13px;
}

.stats-label {
  color: var(--hint-color);
  margin-right: 6px;
}

.stats-value {
  font-weight: 700;
  color: var(--text-color);
}

.stats-link {
  color: var(--link-color);
  text-decoration: none;
  font-weight: 600;
}

/* Mode selector tabs */
.mode-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  background: rgba(0, 0, 0, 0.2);
  padding: 4px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
}

.mode-tab {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 10px;
  border: none;
  background: transparent;
  color: var(--hint-color);
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: left;
}

.mode-tab.active {
  background: var(--secondary-bg-color);
  color: var(--text-color);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

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

.mode-title {
  display: block;
  font-size: 13px;
  font-weight: 700;
}

.mode-res {
  display: block;
  font-size: 11px;
  opacity: 0.7;
}

.tag-pro {
  background: var(--accent-gold);
  color: #000;
  font-size: 9px;
  font-weight: 800;
  padding: 1px 4px;
  border-radius: 4px;
  vertical-align: middle;
  margin-left: 2px;
}

/* Canvas Editor Area */
.editor-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.canvas-wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  max-width: 380px;
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  border: 2px dashed rgba(255, 255, 255, 0.15);
  background-color: #1e2632;
  /* Checkerboard pattern for transparent alpha */
  background-image: 
    linear-gradient(45deg, #151c25 25%, transparent 25%), 
    linear-gradient(-45deg, #151c25 25%, transparent 25%), 
    linear-gradient(45deg, transparent 75%, #151c25 75%), 
    linear-gradient(-45deg, transparent 75%, #151c25 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
  touch-action: none;
}

.canvas-wrapper.has-image {
  border-style: solid;
  border-color: rgba(255, 255, 255, 0.1);
}

#stickerCanvas {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  cursor: grab;
}

#stickerCanvas:active {
  cursor: grabbing;
}

/* Upload Prompt Overlay */
.upload-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background: rgba(15, 20, 28, 0.85);
  backdrop-filter: blur(4px);
  padding: 20px;
  text-align: center;
  gap: 8px;
}

.upload-icon-pulse {
  font-size: 48px;
  animation: pulse 2s infinite ease-in-out;
}

@keyframes pulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.1); }
  100% { transform: scale(1); }
}

.upload-placeholder h3 {
  font-size: 16px;
  font-weight: 700;
}

.upload-placeholder p {
  font-size: 13px;
  color: var(--hint-color);
  margin-bottom: 8px;
}

.upload-btn {
  background: var(--button-color);
  color: var(--button-text-color);
  padding: 10px 18px;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(36, 129, 204, 0.4);
  transition: transform 0.15s ease;
}

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

/* Floating overlay controls inside canvas */
.canvas-overlay-controls {
  position: absolute;
  right: 10px;
  bottom: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 10;
}

.canvas-ctrl-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #fff;
  font-size: 18px;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.canvas-ctrl-btn:active {
  background: rgba(0, 0, 0, 0.85);
}

.photo-actions-bar {
  display: flex;
  gap: 10px;
  width: 100%;
  max-width: 380px;
  justify-content: center;
}

.change-photo-btn {
  background: var(--secondary-bg-color);
  border: 1px solid var(--border-color);
  color: var(--text-color);
  padding: 8px 14px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.secondary-btn {
  background: var(--secondary-bg-color);
  border: 1px solid var(--border-color);
  color: var(--text-color);
  padding: 8px 14px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

/* Control Cards */
.controls-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.control-card {
  background: var(--secondary-bg-color);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.section-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--hint-color);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Outline Options Grid */
.outline-options {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.outline-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 8px 6px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-color);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s ease;
}

.outline-btn.active {
  border-color: var(--link-color);
  background: rgba(56, 189, 248, 0.15);
}

.preview-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  flex-shrink: 0;
}

.dot-none { background: #333; color: #888; }
.dot-white { background: #ffffff; box-shadow: 0 0 4px #fff; }
.dot-cyan { background: var(--neon-cyan); box-shadow: 0 0 6px var(--neon-cyan); }
.dot-pink { background: var(--neon-pink); box-shadow: 0 0 6px var(--neon-pink); }
.dot-green { background: var(--neon-green); box-shadow: 0 0 6px var(--neon-green); }
.dot-yellow { background: var(--neon-yellow); box-shadow: 0 0 6px var(--neon-yellow); }

/* Text input controls */
.input-group {
  width: 100%;
}

.input-group input {
  width: 100%;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  color: #fff;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
  user-select: text;
}

.input-group input:focus {
  border-color: var(--link-color);
}

.slider-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.slider-label {
  font-size: 12px;
  color: var(--hint-color);
  white-space: nowrap;
}

.slider-row input[type="range"] {
  flex: 1;
  accent-color: var(--button-color);
}

/* Emoji Trigger */
.emoji-selector-wrapper {
  display: flex;
  align-items: center;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.custom-emoji-input {
  width: 48px;
  height: 40px;
  text-align: center;
  font-size: 20px;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: #fff;
  flex-shrink: 0;
}

.quick-emojis {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
}

.quick-emojis::-webkit-scrollbar {
  display: none;
}

.emoji-chip {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: 18px;
  padding: 6px 10px;
  cursor: pointer;
  flex-shrink: 0;
}

.emoji-chip:active {
  transform: scale(0.9);
}

/* Footer & Main Submit Button */
.footer-actions {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 12px 16px;
  background: rgba(15, 20, 28, 0.92);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: center;
  z-index: 100;
}

.main-submit-btn {
  width: 100%;
  max-width: 520px;
  background: var(--button-color);
  color: var(--button-text-color);
  border: none;
  border-radius: var(--radius-md);
  padding: 14px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: 0 4px 16px rgba(36, 129, 204, 0.4);
  transition: opacity 0.2s, transform 0.15s;
}

.main-submit-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  box-shadow: none;
}

.main-submit-btn:not(:disabled):active {
  transform: scale(0.98);
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 1000;
}

.modal-card {
  position: relative;
  background: #19222d;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 24px;
  width: 100%;
  max-width: 400px;
  text-align: center;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
  animation: modalEnter 0.25s ease-out;
}

@keyframes modalEnter {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

.modal-close-btn {
  position: absolute;
  top: 14px;
  right: 14px;
  background: transparent;
  border: none;
  color: var(--hint-color);
  font-size: 18px;
  cursor: pointer;
}

.modal-icon {
  font-size: 40px;
  margin-bottom: 10px;
}

.modal-icon-success {
  font-size: 48px;
  margin-bottom: 10px;
}

.modal-card h2 {
  font-size: 20px;
  margin-bottom: 8px;
}

.modal-desc {
  font-size: 13px;
  color: var(--hint-color);
  margin-bottom: 16px;
  line-height: 1.4;
}

.pro-perks-list {
  list-style: none;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: rgba(0, 0, 0, 0.2);
  padding: 14px;
  border-radius: var(--radius-md);
  margin-bottom: 16px;
  font-size: 13px;
}

.pro-perks-list li {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pro-price-box {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 8px;
  margin-bottom: 16px;
}

.price-value {
  font-size: 24px;
  font-weight: 800;
  color: var(--accent-gold);
}

.price-duration {
  font-size: 12px;
  color: var(--hint-color);
}

.buy-stars-btn {
  width: 100%;
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  padding: 14px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 14px var(--accent-gold-glow);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.buy-stars-btn:active {
  transform: scale(0.98);
}

.primary-btn {
  background: var(--button-color);
  color: var(--button-text-color);
  border: none;
  border-radius: var(--radius-md);
  padding: 12px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.full-width {
  width: 100%;
}

.telegram-link-btn {
  background: #229ed9;
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  padding: 14px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 8px;
}

.success-preview-container {
  margin: 16px 0;
  display: flex;
  justify-content: center;
}

.success-preview-img {
  width: 140px;
  height: 140px;
  object-fit: contain;
  border-radius: var(--radius-md);
  background: #242f3d;
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.4);
}

/* Spinner */
.btn-spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #ffffff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  display: inline-block;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Toast */
.toast-notification {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%) translateY(-100px);
  background: #1e293b;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.15);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
  padding: 10px 18px;
  border-radius: 30px;
  font-size: 13px;
  font-weight: 600;
  z-index: 2000;
  transition: transform 0.3s cubic-bezier(0.18, 0.89, 0.32, 1.28);
  pointer-events: none;
}

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