/* ── Global Styles & Reset ──────────────────────────────────── */
:root {
  --bg-primary: #0a0f16;
  --bg-secondary: #131c26;
  --bg-card: rgba(19, 28, 38, 0.82);
  --bg-card-hover: rgba(28, 41, 55, 0.95);
  --bg-input: #1a2533;
  --text-primary: #ffffff;
  --text-secondary: #8fa0b3;
  --text-muted: #5e7083;
  
  --accent-color: #2481cc;
  --accent-blue: #2481cc;
  --accent-hover: #1e6eb0;
  --accent-gradient: linear-gradient(135deg, #2481cc 0%, #00c6ff 100%);
  --accent-glow: rgba(36, 129, 204, 0.45);
  
  --border-color: rgba(255, 255, 255, 0.09);
  --border-active: #2481cc;
  --warning-bg: rgba(255, 170, 0, 0.12);
  --warning-border: rgba(255, 170, 0, 0.35);
  --warning-text: #ffb830;
  
  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 22px;
  --radius-full: 999px;
  
  --font-main: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
  --transition: all 0.22s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Telegram WebApp Theme Mapping */
body.tg-theme {
  --bg-primary: var(--tg-theme-bg-color, #0a0f16);
  --bg-secondary: var(--tg-theme-secondary-bg-color, #131c26);
  --text-primary: var(--tg-theme-text-color, #ffffff);
  --text-secondary: var(--tg-theme-hint-color, #8fa0b3);
  --accent-blue: var(--tg-theme-button-color, #2481cc);
}

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

body {
  font-family: var(--font-main);
  background-color: var(--bg-primary);
  background-image: radial-gradient(circle at top right, rgba(36, 129, 204, 0.12) 0%, transparent 60%),
                    radial-gradient(circle at bottom left, rgba(0, 242, 254, 0.08) 0%, transparent 50%);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  overflow-x: hidden;
  padding: 12px 12px 90px;
}

.app-container {
  width: 100%;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* ── Lucide Icon Utilities ─────────────────────────────────── */
.lucide {
  width: 18px;
  height: 18px;
  stroke-width: 2.2px;
  display: inline-block;
  vertical-align: middle;
}

.section-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-primary);
}

.section-label .lucide {
  color: #00f2fe;
  width: 17px;
  height: 17px;
}

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

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

.brand-logo {
  width: 44px;
  height: 44px;
  background: var(--accent-gradient);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  box-shadow: 0 4px 18px var(--accent-glow);
}

.brand-logo .lucide {
  width: 24px;
  height: 24px;
}

.brand-info h1 {
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, #ffffff 0%, #d8ecff 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-info .subtitle {
  font-size: 0.76rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.user-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-card);
  padding: 6px 12px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-color);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-primary);
}

.user-dot {
  width: 7px;
  height: 7px;
  background: #10b981;
  border-radius: 50%;
  box-shadow: 0 0 8px #10b981;
}

.user-icon {
  width: 14px;
  height: 14px;
  color: var(--text-secondary);
}

/* ── Live Preview Section ───────────────────────────────────── */
.preview-section {
  position: sticky;
  top: 8px;
  z-index: 50;
}

.preview-card {
  background: var(--bg-card);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  box-shadow: 0 10px 36px rgba(0, 0, 0, 0.45);
}

.preview-header {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.preview-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: #00f2fe;
  background: rgba(0, 242, 254, 0.12);
  border: 1px solid rgba(0, 242, 254, 0.25);
  padding: 4px 10px;
  border-radius: var(--radius-full);
}

.preview-tag .lucide {
  width: 13px;
  height: 13px;
}

.preview-theme-toggle {
  display: flex;
  background: var(--bg-input);
  padding: 3px;
  border-radius: var(--radius-full);
  gap: 2px;
  border: 1px solid var(--border-color);
}

.theme-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  padding: 6px 8px;
  border-radius: var(--radius-full);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.theme-btn .lucide {
  width: 15px;
  height: 15px;
}

.theme-btn.active {
  background: var(--accent-blue);
  color: #ffffff;
  box-shadow: 0 2px 8px var(--accent-glow);
}

.canvas-wrapper {
  width: 120px;
  height: 120px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px dashed rgba(255, 255, 255, 0.16);
  transition: var(--transition);
}

.canvas-wrapper.bg-dark {
  background-color: #0e1621;
}

.canvas-wrapper.bg-light {
  background-color: #e5ebf0;
}

.canvas-wrapper.bg-grid {
  background-color: #1a2533;
  background-image: linear-gradient(45deg, #121b26 25%, transparent 25%), 
                    linear-gradient(-45deg, #121b26 25%, transparent 25%), 
                    linear-gradient(45deg, transparent 75%, #121b26 75%), 
                    linear-gradient(-45deg, transparent 75%, #121b26 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0px;
}

#emojiCanvas {
  width: 100px;
  height: 100px;
  image-rendering: -webkit-optimize-contrast;
  image-rendering: crisp-edges;
}

/* Telegram Simulated Chat Bubble */
.telegram-sim-bubble {
  width: 100%;
  background: #2b5278;
  border-radius: 16px 16px 4px 16px;
  padding: 10px 14px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
  transition: var(--transition);
}

.bubble-content {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 0.95rem;
  color: #ffffff;
}

.sim-emoji-holder {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  vertical-align: middle;
}

.sim-emoji-holder img {
  width: 24px;
  height: 24px;
  object-fit: contain;
}

.bubble-time {
  font-size: 0.7rem;
  color: rgba(255, 255, 255, 0.65);
  white-space: nowrap;
}

/* ── Form Controls ──────────────────────────────────────────── */
.editor-form {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.char-counter {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-secondary);
}

.input-container {
  position: relative;
  width: 100%;
}

input[type="text"] {
  width: 100%;
  background: var(--bg-input);
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 14px 44px 14px 16px;
  color: var(--text-primary);
  font-family: var(--font-main);
  font-size: 1.05rem;
  font-weight: 700;
  text-transform: uppercase;
  outline: none;
  transition: var(--transition);
}

input[type="text"]:focus {
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.clear-input-btn {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(255, 255, 255, 0.08);
  border: none;
  color: var(--text-secondary);
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition);
}

.clear-input-btn .lucide {
  width: 14px;
  height: 14px;
}

.clear-input-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
}

/* Warning Alert Box */
.warning-alert {
  background: var(--warning-bg);
  border: 1px solid var(--warning-border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  display: flex;
  gap: 12px;
  align-items: flex-start;
  animation: fadeIn 0.25s ease-in-out;
}

.warning-alert.hidden {
  display: none;
}

.alert-icon {
  color: var(--warning-text);
  margin-top: 2px;
}

.alert-icon .lucide {
  width: 20px;
  height: 20px;
}

.alert-body p {
  font-size: 0.82rem;
  color: var(--warning-text);
  line-height: 1.4;
  margin-bottom: 8px;
}

.btn-split {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--warning-text);
  color: #000;
  border: none;
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  transition: var(--transition);
}

.btn-split .lucide {
  width: 14px;
  height: 14px;
}

.btn-split:hover {
  opacity: 0.9;
  transform: translateY(-1px);
}

/* Two Lines Switch Control */
.two-lines-control {
  display: flex;
  align-items: center;
  margin-top: 4px;
}

.switch-label {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
}

.switch-label input {
  display: none;
}

.switch-slider {
  width: 40px;
  height: 22px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-full);
  position: relative;
  transition: var(--transition);
}

.switch-slider::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  background: var(--text-secondary);
  border-radius: 50%;
  transition: var(--transition);
}

.switch-label input:checked + .switch-slider {
  background: var(--accent-blue);
}

.switch-label input:checked + .switch-slider::after {
  transform: translateX(18px);
  background: #ffffff;
}

.switch-text {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.inline-icon {
  width: 15px;
  height: 15px;
  color: var(--text-secondary);
}

.line-2-container.hidden {
  display: none;
}

/* ── Fonts Grid ─────────────────────────────────────────────── */
.font-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.font-btn {
  background: var(--bg-card);
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition);
  color: var(--text-primary);
}

.font-btn .font-name {
  font-size: 1.15rem;
  letter-spacing: 0.04em;
}

.font-btn .font-desc {
  font-size: 0.72rem;
  color: var(--text-secondary);
  font-family: var(--font-main);
  margin-top: 2px;
}

.font-btn.active, .font-btn:hover {
  background: var(--bg-card-hover);
  border-color: var(--accent-blue);
  box-shadow: 0 4px 14px var(--accent-glow);
}

/* ── Styles Grid ────────────────────────────────────────────── */
.style-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.style-btn {
  background: var(--bg-card);
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  transition: var(--transition);
  color: var(--text-primary);
}

.style-preview {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 1.4rem;
  letter-spacing: 0.05em;
}

.style-label {
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.style-btn.active {
  border-color: var(--accent-blue);
  background: var(--bg-card-hover);
  box-shadow: 0 4px 14px var(--accent-glow);
}

/* Style Variants Preview */
.classic-white {
  color: #ffffff;
  text-shadow: 0 0 2px #000, 1px 1px 2px #000;
}

.neon-cyan {
  color: #ffffff;
  text-shadow: 0 0 6px #00f2fe, 0 0 14px #4facfe;
}

.neon-pink {
  color: #ffffff;
  text-shadow: 0 0 6px #ff2a85, 0 0 14px #ff758c;
}

.neon-green {
  color: #ffffff;
  text-shadow: 0 0 6px #00ff66, 0 0 14px #10b981;
}

.neon-gold {
  color: #ffffff;
  text-shadow: 0 0 6px #ffd700, 0 0 14px #ffaa00;
}

.grad-fire {
  background: linear-gradient(180deg, #ff416c, #ff4b2b);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.grad-violet {
  background: linear-gradient(180deg, #e94057, #8a2387);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.grad-cyan {
  background: linear-gradient(180deg, #00c6ff, #0072ff);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.stroke-only {
  color: transparent;
  -webkit-text-stroke: 1.5px #ffffff;
}

.shadow-3d {
  color: #ffffff;
  text-shadow: 1px 1px #000, 2px 2px #000, 3px 3px #000;
}

/* ── Multi-Item Pack Section ────────────────────────────────── */
.pack-items-section {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.section-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.btn-secondary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(36, 129, 204, 0.16);
  color: #00f2fe;
  border: 1px solid rgba(0, 242, 254, 0.3);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  transition: var(--transition);
}

.btn-secondary .lucide {
  width: 14px;
  height: 14px;
}

.btn-secondary:hover {
  background: rgba(0, 242, 254, 0.25);
}

.pack-items-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 44px;
}

.pack-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  padding: 6px 12px;
  border-radius: var(--radius-full);
  font-size: 0.82rem;
  font-weight: 700;
  animation: fadeIn 0.2s ease;
}

.pack-chip-text {
  color: var(--text-primary);
}

.btn-remove-chip {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 13px;
  display: flex;
  align-items: center;
  transition: var(--transition);
}

.btn-remove-chip:hover {
  color: #ff4d4f;
}

/* ── Primary Action Button ──────────────────────────────────── */
.btn-primary {
  width: 100%;
  background: var(--accent-gradient);
  color: #ffffff;
  border: none;
  border-radius: var(--radius-md);
  padding: 16px 20px;
  font-family: var(--font-main);
  font-size: 1.05rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  text-decoration: none;
  cursor: pointer;
  box-shadow: 0 6px 20px var(--accent-glow);
  transition: var(--transition);
}

.btn-primary .lucide {
  width: 20px;
  height: 20px;
}

.btn-primary:hover {
  opacity: 0.95;
  transform: translateY(-2px);
  box-shadow: 0 8px 26px rgba(36, 129, 204, 0.65);
}

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

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* ── Modals ─────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
  animation: fadeIn 0.2s ease;
}

.modal-overlay.hidden {
  display: none;
}

.modal-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 400px;
  padding: 28px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 16px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.6);
}

.guard-card {
  border-color: rgba(255, 170, 0, 0.35);
}

.guard-icon {
  width: 64px;
  height: 64px;
  background: rgba(255, 170, 0, 0.15);
  color: #ffb830;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.guard-icon .lucide {
  width: 32px;
  height: 32px;
}

.modal-icon-success {
  width: 64px;
  height: 64px;
  background: rgba(16, 185, 129, 0.15);
  color: #10b981;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-icon-success .lucide {
  width: 34px;
  height: 34px;
}

.modal-header h3 {
  font-size: 1.3rem;
  font-weight: 800;
}

.modal-header p {
  font-size: 0.86rem;
  color: var(--text-secondary);
  margin-top: 6px;
  line-height: 1.5;
}

.modal-body {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.pack-link-box {
  display: flex;
  gap: 6px;
  width: 100%;
}

.pack-link-box input {
  font-size: 0.85rem;
  padding: 10px;
  text-transform: none;
}

.btn-copy {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  padding: 0 14px;
  font-weight: 700;
  font-size: 0.82rem;
  cursor: pointer;
  white-space: nowrap;
  transition: var(--transition);
}

.btn-copy .lucide {
  width: 14px;
  height: 14px;
}

.btn-copy:hover {
  background: rgba(255, 255, 255, 0.12);
}

.btn-outline-guard {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  padding: 12px;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  transition: var(--transition);
}

.btn-outline-guard .lucide {
  width: 16px;
  height: 16px;
}

.btn-outline-guard:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-primary);
}

.btn-close-modal {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-weight: 600;
  cursor: pointer;
  padding: 8px 16px;
}

/* ── Toast Notification ─────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #131c26;
  border: 1px solid var(--border-color);
  color: #fff;
  padding: 10px 20px;
  border-radius: var(--radius-full);
  font-size: 0.85rem;
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  z-index: 200;
  animation: slideUp 0.25s ease;
}

.toast.hidden {
  display: none;
}

/* ── Keyframe Animations ────────────────────────────────────── */
@keyframes fadeIn {
  from { opacity: 0; transform: scale(0.96); }
  to { opacity: 1; transform: scale(1); }
}

@keyframes slideUp {
  from { opacity: 0; transform: translate(-50%, 16px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}
