/* ── Reset & base ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0d0d0d;
  --surface: #1a1a1a;
  --surface2: #242424;
  --accent: #c084fc;       /* soft violet */
  --accent2: #818cf8;      /* indigo */
  --text: #f0f0f0;
  --text-muted: #888;
  --border: #333;
  --radius: 16px;
  --tab-h: 64px;
  --top-h: 52px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 15px;
  overflow: hidden;
}

#app { height: 100%; position: relative; }

/* ── Screens ──────────────────────────────────────────────────────── */
.screen {
  display: none;
  height: 100%;
  flex-direction: column;
}
.screen.active { display: flex; }

/* ── Loading ──────────────────────────────────────────────────────── */
#loading {
  align-items: center;
  justify-content: center;
  gap: 16px;
}
.loading-spinner {
  width: 40px; height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Empty hero (no avatar) ───────────────────────────────────────── */
#screen-empty {
  align-items: center;
  justify-content: center;
  padding: 32px;
  text-align: center;
}
.empty-hero { max-width: 340px; }
.empty-hero .empty-icon { font-size: 72px; margin-bottom: 16px; }
.empty-icon-row {
  display: flex;
  justify-content: center;
  gap: 6px;
  font-size: 44px;
  margin-bottom: 18px;
  filter: drop-shadow(0 4px 14px rgba(192,132,252,0.3));
}
.empty-icon-row span {
  display: inline-block;
  animation: float 3s ease-in-out infinite;
}
.empty-icon-row span:nth-child(1) { animation-delay: 0s;   }
.empty-icon-row span:nth-child(2) { animation-delay: 0.2s; }
.empty-icon-row span:nth-child(3) { animation-delay: 0.4s; }
.empty-icon-row span:nth-child(4) { animation-delay: 0.6s; }
.empty-icon-row span:nth-child(5) { animation-delay: 0.8s; }
@keyframes float {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-6px); }
}
.empty-hint {
  margin-top: 14px;
  font-size: 13px;
  color: var(--text-muted);
  min-height: 20px;
}
.empty-hint.success { color: #22c55e; }
.empty-hint.error   { color: #ef4444; }
.empty-hero h1 {
  font-size: 26px; font-weight: 700;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 12px;
}
.empty-hero p { color: var(--text-muted); line-height: 1.5; margin-bottom: 32px; }

/* ── Top bar ──────────────────────────────────────────────────────── */
.top-bar {
  height: var(--top-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.app-title { font-size: 18px; font-weight: 700; letter-spacing: -0.3px; }
.credits-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.credits-btn:active { background: var(--accent); }

/* ── Tab content ──────────────────────────────────────────────────── */
.tab-content {
  flex: 1;
  overflow: hidden;
  position: relative;
}
.tab {
  display: none;
  height: 100%;
  overflow-y: auto;
  padding: 16px 16px calc(var(--tab-h) + var(--safe-bottom) + 8px);
}
.tab.active { display: block; }

/* ── Bottom nav ───────────────────────────────────────────────────── */
.bottom-nav {
  height: calc(var(--tab-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.15s;
  padding: 6px 0;
}
.nav-item.active { color: var(--accent); }
.nav-icon { font-size: 22px; }
.nav-label { font-size: 10px; font-weight: 500; }

.nav-create {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  border-radius: 12px;
  margin: 6px 4px;
  flex: 1.3;
}
.nav-create .nav-icon, .nav-create .nav-label { color: white; }
.nav-create.active { color: white; }

/* ── Buttons ──────────────────────────────────────────────────────── */
.btn-primary, .btn-secondary {
  display: block;
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
}
.btn-primary:active, .btn-secondary:active { opacity: 0.8; transform: scale(0.98); }

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: white;
  margin-bottom: 10px;
}
.btn-secondary {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-large { padding: 18px; font-size: 17px; }

/* ── Slider ───────────────────────────────────────────────────────── */
.slider-container {
  position: relative;
  height: 340px;
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 16px;
  background: var(--surface);
}
.slider {
  display: flex;
  height: 100%;
  transition: transform 0.35s cubic-bezier(0.25,0.46,0.45,0.94);
}
.slide {
  min-width: 100%;
  height: 100%;
  object-fit: cover;
  background: var(--surface2);
}
.slide img {
  width: 100%; height: 100%;
  object-fit: cover;
}
.slider-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(0,0,0,0.5);
  color: white;
  border: none;
  width: 36px; height: 36px;
  border-radius: 50%;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
}
.slider-btn.prev { left: 10px; }
.slider-btn.next { right: 10px; }
.slider-dots {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 6px;
}
.dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: rgba(255,255,255,0.4);
  transition: background 0.2s;
}
.dot.active { background: white; }

/* ── Home actions ─────────────────────────────────────────────────── */
.home-actions { display: flex; flex-direction: column; gap: 10px; }

/* ── Section title ────────────────────────────────────────────────── */
.section-title {
  font-size: 18px; font-weight: 700;
  margin-bottom: 14px;
}

/* ── Create cards ─────────────────────────────────────────────────── */
.create-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 20px;
}
.create-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 12px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
}
.create-card:active { transform: scale(0.97); border-color: var(--accent); }
.create-card-icon { font-size: 36px; margin-bottom: 8px; }
.create-card-title { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.create-card-desc { font-size: 12px; color: var(--text-muted); margin-bottom: 8px; line-height: 1.4; }
.create-card-cost {
  font-size: 13px; font-weight: 700;
  color: var(--accent);
}
.create-note { color: var(--text-muted); font-size: 13px; margin-bottom: 16px; line-height: 1.5; }

/* ── History grid ─────────────────────────────────────────────────── */
.history-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
.history-item {
  aspect-ratio: 1;
  border-radius: 12px;
  overflow: hidden;
  background: var(--surface);
  position: relative;
}
.history-item img {
  width: 100%; height: 100%;
  object-fit: cover;
}
.history-badge {
  position: absolute;
  bottom: 6px; left: 6px;
  background: rgba(0,0,0,0.6);
  color: white;
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 8px;
}
.history-note { font-size: 12px; color: var(--text-muted); margin-bottom: 12px; }
.empty-state { text-align: center; padding: 40px 0; color: var(--text-muted); }
.empty-state .empty-icon { font-size: 48px; margin-bottom: 12px; }

/* ── Avatars grid ─────────────────────────────────────────────────── */
.avatars-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}
.avatar-card {
  border-radius: 12px;
  overflow: hidden;
  background: var(--surface);
  border: 2px solid transparent;
  cursor: pointer;
  transition: border-color 0.15s;
}
.avatar-card.active-av { border-color: var(--accent); }
.avatar-card img { width: 100%; aspect-ratio: 1; object-fit: cover; }
.avatar-card-label {
  font-size: 11px;
  padding: 4px 8px;
  color: var(--text-muted);
}

/* ── Profile ──────────────────────────────────────────────────────── */
.profile-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px;
  text-align: center;
  margin-bottom: 16px;
}
.profile-avatar-icon { font-size: 56px; margin-bottom: 10px; }
.profile-name { font-size: 20px; font-weight: 700; }
.profile-username { font-size: 14px; color: var(--text-muted); margin-top: 2px; }

.profile-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}
.stat-item {
  background: var(--surface);
  border-radius: 12px;
  padding: 14px;
  text-align: center;
}
.stat-value { font-size: 22px; font-weight: 700; color: var(--accent); }
.stat-label { font-size: 11px; color: var(--text-muted); margin-top: 3px; }

.profile-actions { display: flex; flex-direction: column; gap: 10px; }

/* Language selector */
.lang-section {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}
.lang-label {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 12px;
}
.lang-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.lang-option {
  background: var(--surface2);
  border: 2px solid var(--border);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: inherit;
}
.lang-option:active { transform: scale(0.97); }
.lang-option.active {
  border-color: var(--accent);
  background: linear-gradient(135deg, rgba(192,132,252,0.15), rgba(129,140,248,0.15));
  color: var(--accent);
}
.lang-flag { font-size: 18px; }

/* ── Tab actions ──────────────────────────────────────────────────── */
.tab-actions { margin-top: 16px; }

/* ── Overlays ──────────────────────────────────────────────────────── */
.overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.85);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
  animation: fade-in 0.2s ease;
}
.overlay.hidden { display: none; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.processing-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 32px 28px;
  text-align: center;
  max-width: 280px;
}
.processing-card .loading-spinner { margin: 0 auto 18px; }
.processing-card p { font-size: 15px; font-weight: 600; }
.processing-card .processing-sub {
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 400;
}

.result-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  max-height: 90vh;
}
.result-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  font-weight: 700;
  font-size: 15px;
}
.result-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
}
#result-img {
  width: 100%;
  max-height: 60vh;
  object-fit: contain;
  background: #000;
}
.result-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 14px;
}
.result-actions button { margin: 0; }
