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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: #0f172a;
  color: #e2e8f0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: env(safe-area-inset-top, 20px) 20px env(safe-area-inset-bottom, 20px);
}

.container {
  width: 100%;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
}

/* === Header === */
.ring-icon { width: 64px; height: 64px; margin-top: 48px; margin-bottom: 12px; }

h1 {
  font-size: 1.75rem;
  font-weight: 700;
  background: linear-gradient(135deg, #fbbf24, #f59e0b, #d97706);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 8px;
  text-align: center;
}

.subtitle { color: #64748b; font-size: 0.9rem; margin-bottom: 32px; text-align: center; }

/* === Top bar (auth + stats) === */
.top-bar {
  width: 100%;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  position: relative;
}

.auth-btn {
  font-size: 0.85rem;
  padding: 8px 14px;
  border: 1px solid #334155;
  border-radius: 8px;
  background: transparent;
  color: #94a3b8;
  cursor: pointer;
  min-height: auto;
  min-width: auto;
  transition: border-color 0.2s, color 0.2s;
}

.auth-btn:hover { border-color: #f59e0b; color: #f59e0b; }

.user-menu {
  position: relative;
}

.user-menu-btn {
  font-size: 0.85rem;
  padding: 8px 14px;
  border: 1px solid #334155;
  border-radius: 8px;
  background: transparent;
  color: #fbbf24;
  cursor: pointer;
  min-height: auto;
  min-width: auto;
  display: flex;
  align-items: center;
  gap: 6px;
}

.user-menu-btn:hover { border-color: #f59e0b; }

.streak-pip {
  font-size: 0.75rem;
  background: #f59e0b;
  color: #0f172a;
  padding: 1px 6px;
  border-radius: 10px;
  font-weight: 700;
}

.user-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 4px;
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 10px;
  min-width: 200px;
  z-index: 100;
  overflow: hidden;
}

.user-dropdown.open { display: block; }

.user-dropdown-item {
  display: block;
  width: 100%;
  padding: 12px 16px;
  background: none;
  border: none;
  color: #e2e8f0;
  font-size: 0.9rem;
  text-align: left;
  cursor: pointer;
}

.user-dropdown-item:hover { background: #334155; }
.user-dropdown-item.pro-item { color: #fbbf24; }
.user-dropdown-item.danger { color: #f87171; }

.dropdown-divider { border-top: 1px solid #334155; }

/* === Quota bar === */
.quota-bar {
  width: 100%;
  display: none;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  font-size: 0.8rem;
  color: #64748b;
}

.quota-bar.visible { display: flex; }

.quota-track {
  flex: 1;
  height: 4px;
  background: #1e293b;
  border-radius: 2px;
  overflow: hidden;
}

.quota-fill {
  height: 100%;
  background: #f59e0b;
  border-radius: 2px;
  transition: width 0.3s ease;
}

.quota-fill.warning { background: #f87171; }

/* === Input === */
.input-group { width: 100%; display: flex; gap: 10px; margin-bottom: 32px; }

input[type="text"] {
  flex: 1;
  font-size: 16px;
  padding: 14px 16px;
  border: 2px solid #1e293b;
  border-radius: 12px;
  background: #1e293b;
  color: #e2e8f0;
  outline: none;
  transition: border-color 0.2s;
  min-height: 48px;
}

input[type="text"]:focus { border-color: #f59e0b; }
input[type="text"]::placeholder { color: #475569; }

button {
  font-size: 16px;
  font-weight: 600;
  padding: 14px 20px;
  border: none;
  border-radius: 12px;
  background: linear-gradient(135deg, #fbbf24, #f59e0b);
  color: #0f172a;
  cursor: pointer;
  min-height: 48px;
  min-width: 48px;
  transition: background 0.2s, transform 0.1s;
  white-space: nowrap;
}

button:active { transform: scale(0.96); }

button:disabled {
  background: #1e293b;
  color: #475569;
  cursor: not-allowed;
  transform: none;
}

/* === Results === */
.result { width: 100%; display: none; }
.result.visible { display: block; }

.result-label {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #38bdf8;
  margin-bottom: 12px;
  font-weight: 600;
}

.result-text {
  font-size: 1.05rem;
  line-height: 1.7;
  color: #f1f5f9;
  background: #1e293b;
  border-radius: 12px;
  padding: 20px;
}

.result-text a { color: #fbbf24; text-decoration: underline; text-underline-offset: 3px; }

.search-link {
  display: inline-block;
  margin-top: 14px;
  padding: 12px 20px;
  background: linear-gradient(135deg, #fbbf24, #f59e0b);
  color: #0f172a !important;
  font-weight: 600;
  border-radius: 10px;
  text-decoration: none !important;
  font-size: 0.95rem;
}

/* === Affiliate === */
.affiliate-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 12px;
  padding: 10px 16px;
  background: #334155;
  border-radius: 8px;
  color: #fbbf24 !important;
  text-decoration: none !important;
  font-size: 0.9rem;
  font-weight: 500;
  transition: background 0.2s;
}

.affiliate-link:hover { background: #475569; }

.affiliate-disclosure {
  font-size: 0.7rem;
  color: #475569;
  margin-top: 8px;
  font-style: italic;
}

/* === Loading === */
.loading { display: none; flex-direction: column; align-items: center; gap: 16px; padding: 40px 0; }
.loading.visible { display: flex; }

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid #1e293b;
  border-top-color: #f59e0b;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

.loading-text { color: #64748b; font-size: 0.95rem; }

/* === Error === */
.error {
  display: none;
  width: 100%;
  background: #7f1d1d;
  color: #fca5a5;
  padding: 16px 20px;
  border-radius: 12px;
  font-size: 0.95rem;
  line-height: 1.5;
}

.error.visible { display: block; }

/* === Install banner === */
.install-banner {
  display: none;
  width: 100%;
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 12px;
  padding: 14px 18px;
  margin-bottom: 20px;
  font-size: 0.9rem;
  color: #94a3b8;
  line-height: 1.5;
  text-align: center;
}

.install-banner.visible { display: block; }

.install-banner .install-btn {
  display: inline-block;
  margin-top: 8px;
  padding: 8px 16px;
  background: linear-gradient(135deg, #fbbf24, #f59e0b);
  color: #0f172a !important;
  font-weight: 600;
  border-radius: 8px;
  border: none;
  font-size: 0.9rem;
  cursor: pointer;
  text-decoration: none !important;
}

.install-banner .dismiss {
  color: #475569;
  font-size: 0.8rem;
  margin-left: 12px;
  cursor: pointer;
  background: none;
  border: none;
}

/* === Modal (auth, stats, history, upgrade) === */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-overlay.open { display: flex; }

.modal {
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 16px;
  padding: 28px 24px;
  width: 100%;
  max-width: 400px;
  max-height: 80vh;
  overflow-y: auto;
  position: relative;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 16px;
  background: none;
  border: none;
  color: #64748b;
  font-size: 1.4rem;
  cursor: pointer;
  min-height: auto;
  min-width: auto;
  padding: 4px;
}

.modal h2 {
  font-size: 1.3rem;
  font-weight: 700;
  color: #f1f5f9;
  margin-bottom: 16px;
}

.modal p {
  color: #94a3b8;
  font-size: 0.9rem;
  line-height: 1.6;
  margin-bottom: 16px;
}

/* === Auth modal === */
.phone-input {
  width: 100%;
  font-size: 16px;
  padding: 14px 16px;
  border: 2px solid #334155;
  border-radius: 12px;
  background: #0f172a;
  color: #e2e8f0;
  outline: none;
  margin-bottom: 12px;
}

.phone-input:focus { border-color: #f59e0b; }

.auth-submit {
  width: 100%;
  padding: 14px;
  font-size: 1rem;
}

.auth-error {
  color: #f87171;
  font-size: 0.85rem;
  margin-top: 8px;
  display: none;
}

.auth-error.visible { display: block; }

.code-input {
  width: 100%;
  font-size: 24px;
  padding: 14px 16px;
  border: 2px solid #334155;
  border-radius: 12px;
  background: #0f172a;
  color: #e2e8f0;
  outline: none;
  text-align: center;
  letter-spacing: 8px;
  margin-bottom: 12px;
}

.code-input:focus { border-color: #f59e0b; }

/* === Stats panel (modal) === */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 20px;
}

.stat-card {
  background: #0f172a;
  border-radius: 10px;
  padding: 16px;
  text-align: center;
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: #fbbf24;
}

.stat-label {
  font-size: 0.75rem;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 4px;
}

/* === Badges === */
.badges-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 10px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
  background: #334155;
  color: #94a3b8;
}

.badge.earned {
  background: linear-gradient(135deg, #fbbf2420, #f59e0b20);
  color: #fbbf24;
  border: 1px solid #fbbf2440;
}

/* === History panel === */
.history-item {
  background: #0f172a;
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 10px;
}

.history-query {
  font-weight: 600;
  color: #e2e8f0;
  font-size: 0.9rem;
  margin-bottom: 6px;
}

.history-answer {
  color: #94a3b8;
  font-size: 0.85rem;
  line-height: 1.5;
}

.history-date {
  color: #475569;
  font-size: 0.75rem;
  margin-top: 6px;
}

.history-empty {
  color: #64748b;
  text-align: center;
  padding: 40px 20px;
  font-size: 0.9rem;
}

.load-more-btn {
  width: 100%;
  padding: 10px;
  font-size: 0.85rem;
  background: #334155;
  border-radius: 8px;
  color: #94a3b8;
  border: none;
  cursor: pointer;
  margin-top: 8px;
}

.load-more-btn:hover { background: #475569; }

/* === Upgrade prompt (inline) === */
.upgrade-prompt {
  display: none;
  width: 100%;
  background: linear-gradient(135deg, #fbbf2410, #f59e0b10);
  border: 1px solid #fbbf2440;
  border-radius: 12px;
  padding: 16px 20px;
  text-align: center;
  margin-bottom: 16px;
}

.upgrade-prompt.visible { display: block; }

.upgrade-prompt p { color: #fbbf24; margin-bottom: 12px; }

.upgrade-btn {
  padding: 10px 20px;
  font-size: 0.9rem;
  border-radius: 8px;
}

/* === Toast notifications === */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: #1e293b;
  border: 1px solid #fbbf2440;
  border-radius: 10px;
  padding: 12px 16px;
  color: #fbbf24;
  font-size: 0.9rem;
  font-weight: 600;
  animation: toastIn 0.3s ease, toastOut 0.3s ease 2.7s forwards;
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

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

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

/* === Upgrade modal === */
.pro-features { list-style: none; padding: 0; margin-bottom: 20px; }

.pro-features li {
  padding: 8px 0;
  color: #e2e8f0;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 8px;
}

.pro-features li::before {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #fbbf24;
  flex-shrink: 0;
}

.pro-price {
  font-size: 1.5rem;
  font-weight: 700;
  color: #fbbf24;
  text-align: center;
  margin-bottom: 4px;
}

.pro-price-sub {
  color: #64748b;
  font-size: 0.85rem;
  text-align: center;
  margin-bottom: 20px;
}
