/* ============================================================
   Mobile-first participant UI — clean iOS / Material style
   ============================================================ */

:root {
  --bg: #f6f7fb;
  --card: #ffffff;
  --text: #1c1f2b;
  --muted: #8a90a3;
  --accent: #3b6ef2;
  --accent-soft: rgba(59, 110, 242, 0.14);
  --success: #22c66b;
  --danger: #e5484d;
  --gold: #f5b83d;
  --silver: #b9c0cc;
  --bronze: #cf8753;
  --radius: 12px;
  --shadow: 0 6px 18px rgba(20, 25, 45, 0.12);
  --shadow-sm: 0 2px 8px rgba(20, 25, 45, 0.08);
  --shadow-lg: 0 14px 32px rgba(20, 25, 45, 0.16);
  --tab-h: 64px;
  --maxw: 480px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* The UI is a set of mutually exclusive screens/panels. Some mobile
   browsers let component display rules override the native [hidden] rule,
   so enforce it explicitly for every view. */
[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

button { font: inherit; cursor: pointer; border: none; background: none; }

.language-switch {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, calc((100vw - var(--maxw)) / 2 + 12px));
  z-index: 120;
  display: flex;
  gap: 3px;
  padding: 3px;
  border: 1px solid #dfe4ee;
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(10px);
}
.language-btn {
  min-width: 38px;
  padding: 7px 8px;
  border-radius: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}
.language-btn[aria-pressed="true"] {
  background: var(--accent);
  color: #fff;
}
.language-btn:focus-visible {
  outline: 3px solid var(--accent-soft);
  outline-offset: 1px;
}

/* ---------------- shared ------------- */

.muted { font-size: 13px; color: var(--muted); }

.loader { text-align: center; color: var(--muted); padding: 32px; }
.empty { text-align: center; color: var(--muted); padding: 28px; }

.form-error { color: var(--danger); font-size: 14px; margin-top: 8px; }

.toast {
  position: fixed;
  left: 50%; bottom: calc(var(--tab-h) + 16px);
  transform: translateX(-50%);
  background: var(--text);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 50;
}
.toast.show { opacity: 1; }

/* ---------------- registration screen ------------- */

.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(160deg, #eef1ff 0%, var(--bg) 55%, #eef8ef 100%);
}

.auth-card {
  width: 100%;
  max-width: var(--maxw);
  background: var(--card);
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  padding: 24px;
}

.brand { text-align: center; margin-bottom: 18px; }
.brand-badge { font-size: 40px; margin: 0 auto 6px; }
.brand h1 { margin: 0; font-size: 20px; }
.brand p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field span { font-size: 13px; color: var(--muted); }

input, select {
  width: 100%;
  padding: 13px 14px;
  border: 1.5px solid #dfe4ee;
  border-radius: var(--radius);
  background: #fff;
  font-size: 16px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.consent {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px;
  background: var(--accent-soft);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 14px;
  line-height: 1.35;
}
.consent input { width: 20px; height: 20px; margin: 0; accent-color: var(--accent); }

#register-btn { margin-top: 16px; }

/* ---------------- buttons ------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 13px 22px;
  border-radius: var(--radius);
  font-weight: 600;
  transition: transform 0.08s ease, box-shadow 0.15s ease, opacity 0.2s ease;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-primary { background: var(--accent); color: #fff; box-shadow: var(--shadow-sm); width: 100%; }
.btn-lg { padding: 15px; font-size: 16px; }

/* ---------------- app layout ------------- */

.app { display: block; }

.app-body { max-width: var(--maxw); margin: 0 auto; padding-bottom: calc(var(--tab-h) + 24px); }

.panel { padding: 64px 16px 24px; }
.panel-title { margin: 0 0 2px; font-size: 22px; font-weight: 700; }

/* ---------------- profile tab ------------- */

.profile-header { display: flex; align-items: center; gap: 14px; }

.avatar {
  width: 56px; height: 56px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: linear-gradient(135deg, #4a7bff, #7a5cff);
  color: #fff; font-size: 24px; font-weight: 700;
}

.profile-meta h2 { margin: 0; font-size: 19px; font-weight: 700; }
.profile-meta p { margin: 2px 0 0; color: var(--muted); font-size: 14px; }
.profile-meta .profile-group { font-size: 12px; }

.balance-card {
  margin-top: 18px;
  padding: 22px;
  text-align: center;
  background: linear-gradient(135deg, #3b6ef2, #6a5bff);
  color: #fff;
  border-radius: 18px;
  box-shadow: var(--shadow-lg);
  position: relative;
  overflow: hidden;
}
.balance-label { display: block; font-size: 14px; opacity: 0.85; }
.balance-value {
  font-size: 52px;
  font-weight: 800;
  letter-spacing: 1px;
  transition: color 0.25s ease, transform 0.25s ease;
}
.balance-unit { font-size: 14px; opacity: 0.85; }
.balance-value.flash {
  color: #fff8a8;
  transform: scale(1.08);
  transition: color 0.1s ease;
}

.qr-card {
  margin-top: 16px;
  padding: 18px;
  background: var(--card);
  border-radius: 18px;
  box-shadow: var(--shadow);
  text-align: center;
}
.qr-card h3 { margin: 0 0 4px; font-size: 16px; }
.qr-card .muted { margin: 0 0 12px; }
.qr-box { margin: 0 auto; }

/* ---------------- shop tab ------------- */

.shop-list { display: grid; grid-template-columns: 1fr; gap: 12px; margin-top: 12px; }

.product-card {
  display: flex; align-items: center; gap: 12px;
  width: 100%; color: var(--text); text-align: left;
  padding: 14px 16px;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition: opacity 0.25s ease, transform 0.08s ease;
}
.product-card:active { transform: scale(0.98); }
.product-card.is-unavailable { opacity: 0.55; }
.product-card[data-product-image] { cursor: zoom-in; }
.product-card[data-product-image]:focus-visible {
  outline: 3px solid var(--accent-soft);
  outline-offset: 2px;
}

.product-icon {
  width: 48px; height: 48px;
  display: grid; place-items: center;
  border-radius: var(--radius);
  background: var(--accent-soft);
  font-size: 24px;
  overflow: hidden;
}
.product-photo { width: 100%; height: 100%; object-fit: cover; }

.product-info { flex: 1; min-width: 0; }
.product-info h4 { margin: 0; font-size: 16px; font-weight: 600; }
.product-info p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }

.product-badge { text-align: right; padding: 0 4px; font-weight: 700; color: var(--accent); font-size: 15px; }
.product-badge small { display: block; color: var(--muted); font-size: 12px; }
.product-badge .stock { display: block; color: var(--success); font-size: 12px; }

/* ---------------- product image viewer ------------- */

body.modal-open { overflow: hidden; }

.image-viewer {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 68px 20px 20px;
}
.image-viewer-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10, 12, 20, 0.86);
  backdrop-filter: blur(5px);
}
.image-viewer-card {
  position: relative;
  z-index: 1;
  width: min(100%, 680px);
  max-height: calc(100vh - 40px);
  padding: 46px 12px 14px;
  border-radius: 18px;
  background: #fff;
  box-shadow: var(--shadow-lg);
}
.image-viewer-card img {
  display: block;
  width: 100%;
  max-height: calc(100vh - 135px);
  object-fit: contain;
  border-radius: 12px;
  background: #f1f3f8;
}
.image-viewer-card p {
  margin: 10px 8px 0;
  text-align: center;
  font-weight: 700;
}
.image-viewer-close {
  position: absolute;
  top: 7px;
  right: 9px;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #edf0f6;
  color: var(--text);
  font-size: 30px;
  line-height: 1;
}

/* ---------------- track tasks and leaderboard ------------- */

.track-card { margin-top: 18px; }
.track-card h3 { margin: 0 0 4px; font-size: 17px; }
.track-task-list, .leaderboard-list { display: flex; flex-direction: column; gap: 9px; margin-top: 12px; }
.track-task-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 13px;
  border-radius: 12px;
  background: #f5f7fb;
}
.track-task-item span {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 800;
}
.track-task-item strong { font-size: 14px; }
.leaderboard-row {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
}
.leaderboard-header {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) auto;
  gap: 10px;
  padding: 0 14px 2px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}
.leaderboard-header span:last-child { text-align: right; }
.leaderboard-row.is-top-ten { border-left: 4px solid var(--accent); }
.leaderboard-row.is-podium { background: linear-gradient(135deg, #fff8dc, #fff); }
.leaderboard-row.podium-1 { border-left-color: #e1aa15; }
.leaderboard-row.podium-2 { border-left-color: #98a1b3; }
.leaderboard-row.podium-3 { border-left-color: #b97845; }
.leaderboard-rank { color: var(--muted); font-size: 15px; font-weight: 900; text-align: center; }
.leaderboard-name { min-width: 0; overflow-wrap: anywhere; font-size: 14px; }
.leaderboard-points { color: var(--accent); font-size: 13px; font-weight: 800; white-space: nowrap; }

/* ---------------- history tab ------------- */

.history-list { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }

.history-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.history-kind { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 50%; }
.history-kind.accrual { background: var(--accent-soft); }
.history-kind.purchase { background: rgba(229, 72, 77, 0.12); }

.history-body { flex: 1; min-width: 0; }
.history-body h4 { margin: 0; font-size: 15px; font-weight: 600; }
.history-body p { margin: 2px 0 0; color: var(--muted); font-size: 12px; }

.history-change { font-weight: 800; }
.history-change.plus { color: var(--success); }
.history-change.minus { color: var(--danger); }

/* ---------------- tab bar ------------- */

.tab-bar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: var(--tab-h);
  display: flex;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(14px);
  border-top: 1px solid #e8ebf3;
  box-shadow: 0 4px 18px rgba(20, 25, 45, 0.08);
}

.tab-btn {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px;
  color: var(--muted);
  transition: color 0.15s ease, transform 0.06s ease;
  position: relative;
}
.tab-btn:active { transform: scale(0.94); }
.tab-icon { font-size: 19px; }
.tab-label { min-width: 0; font-size: 10px; font-weight: 600; white-space: nowrap; }
.tab-btn.is-active { color: var(--accent); }
.tab-btn.is-active .tab-icon { transform: translateY(-1px) scale(1.08); }
.tab-btn.is-active::before {
  content: "";
  position: absolute;
  top: 4px; width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--accent);
}

@media (min-width: 520px) {
  body { background: #eef1f8; }
}

/* ---------------- choice / login extras ---------------- */

.btn-outline {
  margin-top: 12px;
  width: 100%;
  background: transparent;
  color: var(--accent);
  border: 2px solid var(--accent);
}

.btn-ghost { background: transparent; color: var(--muted); }
.btn-sm { padding: 8px 14px; font-size: 13px; border-radius: 10px; }

.link-back {
  display: inline-flex;
  align-items: center;
  background: transparent;
  color: var(--accent);
  font-weight: 600;
  font-size: 15px;
  padding: 6px 0;
  margin-bottom: 6px;
}

.seg {
  display: flex;
  gap: 4px;
  background: #eef1f8;
  border-radius: var(--radius);
  padding: 4px;
  margin-bottom: 16px;
}
.seg-btn {
  flex: 1;
  padding: 10px;
  border-radius: 10px;
  font-weight: 600;
  color: var(--muted);
  transition: background 0.15s ease, color 0.15s ease;
}
.seg-btn.is-active { background: #fff; color: var(--accent); box-shadow: var(--shadow-sm); }

.profile-header .btn-ghost { margin-left: auto; white-space: nowrap; }
