:root {
  --bg: #FAFAF8;
  --surface: #FFFFFF;
  --surface-2: #F1EFE8;
  --ink: #1C1C1A;
  --ink-2: #5F5E5A;
  --ink-3: #888780;
  --line: #E6E4DC;
  --line-2: #D3D1C7;

  --elon-green: #0F7A3C;
  --elon-green-dark: #0B5C2D;
  --elon-green-light: #EAF3DE;

  --gold: #BA7517;
  --silver: #5F5E5A;
  --bronze: #993C1D;

  --danger: #A32D2D;
  --info: #185FA5;
  --info-bg: #E6F1FB;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

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

/* Make sure hidden attribute always wins over display: flex/grid/etc */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font-sans);
  font-size: 16px;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

body { min-height: 100vh; min-height: 100dvh; }

.screen { display: none; min-height: 100vh; min-height: 100dvh; }
.screen.active { display: block; }

/* ===== LOGIN ===== */
.login-wrap {
  max-width: 380px;
  margin: 0 auto;
  padding: 80px 24px 24px;
}
.login-brand { text-align: center; margin-bottom: 36px; }
.elon-logo-big { height: 36px; width: auto; color: var(--ink); }
.login-title {
  font-size: 28px;
  font-weight: 500;
  margin: 20px 0 6px;
  letter-spacing: -0.5px;
}
.login-sub { color: var(--ink-2); font-size: 14px; margin: 0; }

.login-form { display: flex; flex-direction: column; gap: 6px; }
.field-label {
  font-size: 12px;
  color: var(--ink-2);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 10px;
  font-weight: 500;
}
.login-form input {
  width: 100%;
  padding: 14px 14px;
  font-size: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--ink);
  font-family: inherit;
  transition: border-color 0.15s;
}
.login-form input:focus {
  outline: none;
  border-color: var(--elon-green);
  box-shadow: 0 0 0 3px rgba(15,122,60,0.15);
}

.primary-btn {
  width: 100%;
  padding: 16px;
  margin-top: 24px;
  font-size: 16px;
  font-weight: 500;
  background: var(--elon-green);
  color: white;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  font-family: inherit;
}
.primary-btn:hover { background: var(--elon-green-dark); }
.primary-btn:active { transform: scale(0.98); }
.primary-btn:disabled { opacity: 0.6; cursor: not-allowed; }

.login-error {
  color: var(--danger);
  font-size: 14px;
  margin: 12px 0 0;
  text-align: center;
}

/* ===== MODAL OVERLAY ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(28, 28, 26, 0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 200;
  animation: fade-in 0.25s ease;
}
.modal-overlay[hidden] { display: none; }
@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}
.modal-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 32px 24px 24px;
  max-width: 360px;
  width: 100%;
  text-align: center;
  box-shadow: var(--shadow-lg);
  animation: pop-in 0.3s cubic-bezier(0.2, 0.8, 0.3, 1.1);
}
@keyframes pop-in {
  from { opacity: 0; transform: scale(0.92) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
.modal-icon {
  font-size: 56px;
  margin-bottom: 18px;
  line-height: 1;
}
.modal-title {
  font-size: 22px;
  font-weight: 500;
  margin: 0 0 12px;
  letter-spacing: -0.3px;
}
.modal-msg {
  font-size: 15px;
  color: var(--ink-2);
  line-height: 1.5;
  margin: 0 0 22px;
}
.modal-msg strong { color: var(--ink); font-weight: 500; }
.modal-help {
  font-size: 12px;
  color: var(--ink-3);
  margin: 14px 0 0;
}

.text-btn {
  width: 100%;
  padding: 10px;
  margin-top: 10px;
  font-size: 14px;
  font-weight: 500;
  background: transparent;
  color: var(--ink-2);
  border: none;
  cursor: pointer;
  font-family: inherit;
  border-radius: var(--radius-md);
  transition: background 0.15s;
}
.text-btn:hover { background: var(--surface-2); color: var(--ink); }
.text-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.login-help {
  font-size: 12px;
  color: var(--ink-3);
  text-align: center;
  margin: 14px 0 0;
  line-height: 1.5;
}

.secondary-btn {
  width: 100%;
  padding: 14px;
  margin-top: 18px;
  font-size: 15px;
  font-weight: 500;
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line-2);
  border-radius: var(--radius-md);
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s;
}
.secondary-btn:hover { background: var(--surface-2); }
.secondary-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Verify state (kept for magic link click prompt) */
.verify-state {
  text-align: center;
  padding: 8px 0;
}
.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--line);
  border-top-color: var(--elon-green);
  border-radius: 50%;
  margin: 0 auto 16px;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
.verify-msg {
  font-size: 14px;
  color: var(--danger);
  margin: 14px 0 0;
}
.sent-icon {
  font-size: 56px;
  text-align: center;
  margin-bottom: 18px;
  line-height: 1;
}
.sent-title {
  font-size: 22px;
  font-weight: 500;
  margin: 0 0 12px;
  letter-spacing: -0.3px;
  text-align: center;
}
.sent-msg {
  font-size: 15px;
  color: var(--ink-2);
  line-height: 1.5;
  text-align: center;
  margin: 0 0 8px;
}

/* ===== TOP BRAND BAR ===== */
.brand-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand-left { display: flex; align-items: center; gap: 10px; }
.brand-right { display: flex; align-items: center; gap: 10px; }
.elon-logo { height: 22px; width: auto; color: var(--ink); }
.brand-divider { width: 1px; height: 20px; background: var(--line-2); }
.product-name {
  font-size: 16px;
  font-weight: 500;
  letter-spacing: -0.2px;
}

.live-pill {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 500;
  color: var(--elon-green);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--elon-green);
  animation: pulse 1.5s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.85); }
}

.logout-btn {
  background: transparent;
  border: none;
  color: var(--ink-2);
  padding: 6px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
}
.logout-btn:hover { background: var(--surface-2); color: var(--ink); }

/* ===== TAB BAR ===== */
.tab-bar {
  display: flex;
  gap: 4px;
  padding: 8px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 50px;
  z-index: 19;
}
.tab-btn {
  flex: 1;
  padding: 10px;
  font-size: 14px;
  font-weight: 500;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--ink-2);
  font-family: inherit;
  transition: all 0.15s;
}
.tab-btn.active {
  background: var(--surface-2);
  color: var(--ink);
}

/* ===== VIEW ===== */
.view { padding: 16px; padding-bottom: 80px; }
.view.hidden { display: none; }
.view-header {
  font-size: 12px;
  color: var(--ink-2);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
  font-weight: 500;
}

/* ===== MY STATS ===== */
.my-stats {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 18px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}
.my-name { font-size: 17px; font-weight: 500; margin-bottom: 2px; }
.my-ort { font-size: 13px; color: var(--ink-2); margin-bottom: 16px; }
.my-stat-row { display: flex; gap: 18px; align-items: baseline; }
.my-stat { display: flex; align-items: baseline; gap: 8px; }
.my-stat-num { font-size: 32px; font-weight: 500; line-height: 1; letter-spacing: -0.5px; }
.my-stat-label { font-size: 13px; color: var(--ink-2); }
.my-stat-divider { width: 1px; height: 28px; background: var(--line-2); }

/* ===== SOUND TOGGLE ===== */
.sound-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--ink-2);
  margin-bottom: 12px;
  cursor: pointer;
  user-select: none;
}
.sound-toggle input { margin: 0; cursor: pointer; }

/* ===== SELL BUTTON ===== */
.sell-btn {
  width: 100%;
  padding: 24px;
  background: var(--elon-green);
  color: white;
  border: none;
  border-radius: var(--radius-lg);
  font-size: 19px;
  font-weight: 500;
  cursor: pointer;
  margin-bottom: 10px;
  transition: background 0.15s, transform 0.1s;
  font-family: inherit;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  box-shadow: 0 2px 8px rgba(15,122,60,0.25);
}
.sell-btn:hover { background: var(--elon-green-dark); }
.sell-btn:active { transform: scale(0.98); }
.sell-btn:disabled { opacity: 0.6; cursor: not-allowed; }
.sell-btn-emoji { font-size: 22px; }

.undo-btn {
  width: 100%;
  padding: 11px;
  background: transparent;
  color: var(--ink-2);
  border: 1px solid var(--line-2);
  border-radius: var(--radius-md);
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: inherit;
  transition: background 0.15s;
}
.undo-btn:hover:not(:disabled) { background: var(--surface-2); }
.undo-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.undo-timer {
  font-variant-numeric: tabular-nums;
  color: var(--ink-3);
  font-size: 13px;
}

/* ===== SECTIONS ===== */
.section { margin-top: 24px; }
.section-title {
  font-size: 13px;
  font-weight: 500;
  margin: 0 0 10px;
  color: var(--ink-2);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ===== LIVE-FEED STRIP ===== */
.latest-strip {
  background: var(--info-bg);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  margin-bottom: 14px;
  font-size: 14px;
  color: var(--info);
  display: flex;
  align-items: center;
  gap: 10px;
}
.pulse-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--elon-green);
  animation: pulse 1.5s ease-in-out infinite;
  flex-shrink: 0;
}

/* ===== STAT CARDS ===== */
.stat-row { display: flex; gap: 10px; margin-bottom: 14px; }
.stat-card {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 12px 14px;
}
.stat-label {
  font-size: 11px;
  color: var(--ink-2);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
  font-weight: 500;
}
.stat-value { font-size: 26px; font-weight: 500; letter-spacing: -0.5px; }

/* ===== LEADERBOARD ===== */
.leader-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
  transition: background 0.15s;
}
.leader-row:last-child { border-bottom: none; }
.leader-row.me {
  background: var(--elon-green-light);
  margin: 0 -10px;
  padding: 11px 10px;
  border-radius: var(--radius-md);
  border-bottom: none;
}
.leader-row.flash {
  animation: flash-row 1.2s ease;
}
@keyframes flash-row {
  0% { background: rgba(15,122,60,0.25); }
  100% { background: transparent; }
}
.leader-row.me.flash {
  animation: flash-row-me 1.2s ease;
}
@keyframes flash-row-me {
  0% { background: rgba(15,122,60,0.4); }
  100% { background: var(--elon-green-light); }
}
.rank {
  width: 26px;
  font-size: 14px;
  font-weight: 500;
  color: var(--ink-3);
  text-align: center;
}
.rank.gold { color: var(--gold); }
.rank.silver { color: var(--silver); }
.rank.bronze { color: var(--bronze); }
.leader-info { flex: 1; min-width: 0; }
.leader-name { font-size: 15px; font-weight: 500; }
.leader-ort { font-size: 12px; color: var(--ink-2); }
.leader-count {
  font-size: 17px;
  font-weight: 500;
  min-width: 30px;
  text-align: right;
}

/* ===== MINI PODIUM (sell view) ===== */
#mini-podium { display: flex; flex-direction: column; gap: 4px; }

/* ===== FEED ITEMS ===== */
.feed-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 0;
  font-size: 14px;
  border-bottom: 1px solid var(--line);
}
.feed-item:last-child { border-bottom: none; }
.feed-time {
  font-size: 12px;
  color: var(--ink-3);
  min-width: 42px;
  font-variant-numeric: tabular-nums;
}
.feed-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--elon-green);
  flex-shrink: 0;
}
.feed-text { flex: 1; }
.feed-item.fresh { animation: slide-in 0.5s ease; }
@keyframes slide-in {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===== IN-APP BANNER NOTIFICATION ===== */
.inapp-banner {
  position: fixed;
  top: 8px;
  left: 8px;
  right: 8px;
  max-width: 400px;
  margin: 0 auto;
  background: #1A1A1A;
  color: white;
  border-radius: var(--radius-md);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  transform: translateY(-160px);
  transition: transform 0.4s cubic-bezier(0.2, 0.8, 0.3, 1);
  z-index: 100;
  box-shadow: var(--shadow-lg);
}
.inapp-banner.show { transform: translateY(0); }
.banner-icon {
  width: 38px;
  height: 38px;
  border-radius: 9px;
  background: var(--elon-green);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: white;
}
.banner-content { flex: 1; min-width: 0; }
.banner-title { font-size: 13px; font-weight: 500; margin-bottom: 3px; }
.banner-msg { font-size: 14px; opacity: 0.92; line-height: 1.35; }
.banner-rank {
  display: inline-block;
  background: rgba(255,255,255,0.15);
  padding: 2px 9px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 500;
  margin-top: 6px;
}

/* ===== AVATARS ===== */
.kc-avatar {
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-2);
}
.kc-avatar img {
  display: block;
  border-radius: 50%;
}
.kc-avatar-initials {
  color: white;
  font-weight: 500;
  letter-spacing: 0.5px;
  font-family: var(--font-sans);
}

/* Profilbild-header i Min vy */
.my-stats-head {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 16px;
}
.my-stats-head-text { flex: 1; min-width: 0; }
.my-avatar-btn {
  position: relative;
  border: none;
  background: none;
  padding: 0;
  cursor: pointer;
  flex-shrink: 0;
  border-radius: 50%;
}
.my-avatar-btn .kc-avatar {
  width: 56px;
  height: 56px;
  border: 2px solid var(--line);
}
.my-avatar-edit {
  position: absolute;
  bottom: -2px;
  right: -2px;
  background: var(--elon-green);
  border-radius: 50%;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  border: 2px solid var(--surface);
}
.avatar-uploading {
  opacity: 0.5;
  pointer-events: none;
}
.avatar-hint {
  margin-top: 5px;
  background: none;
  border: none;
  padding: 0;
  color: var(--elon-green);
  font-size: 12px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  display: inline-block;
}
.avatar-hint:hover { text-decoration: underline; }

/* ===== UPDATE BANNER ===== */
.update-banner {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: #1C1C1A;
  color: white;
  padding: 12px 16px 12px 18px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.18);
  z-index: 1000;
  animation: update-slide-up 0.4s cubic-bezier(0.2, 0.8, 0.3, 1);
  max-width: 90vw;
}
@keyframes update-slide-up {
  from { opacity: 0; transform: translate(-50%, 20px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}
.update-banner button {
  background: var(--elon-green);
  color: white;
  border: none;
  padding: 7px 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  flex-shrink: 0;
}
.update-banner button:hover { background: var(--elon-green-dark); }

/* ===== CONNECTION STATUS ===== */
.conn-status {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: #1A1A1A;
  color: white;
  font-size: 12px;
  padding: 8px 14px;
  border-radius: 20px;
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 50;
  box-shadow: var(--shadow-md);
}
.conn-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #EF9F27;
  animation: pulse 1s infinite;
}

/* ===== TOAST ===== */
.toast {
  position: fixed;
  top: 100px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--elon-green);
  color: white;
  padding: 12px 22px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 500;
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  pointer-events: none;
  z-index: 90;
  white-space: nowrap;
  box-shadow: var(--shadow-md);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ===== CONFETTI ===== */
.confetti-container {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 80;
}
.confetti-piece {
  position: absolute;
  width: 9px;
  height: 9px;
  border-radius: 2px;
}

/* ===== EMPTY STATE ===== */
.empty-state {
  padding: 20px 12px;
  text-align: center;
  color: var(--ink-3);
  font-size: 13px;
}

/* Small phones */
@media (max-width: 360px) {
  .my-stat-num { font-size: 28px; }
  .sell-btn { padding: 20px; font-size: 17px; }
  .product-name { font-size: 15px; }
}
