:root {
  --bg: #0f1116;
  --bg-2: #171a21;
  --card: #1c2029;
  --card-2: #232733;
  --border: #2b303c;
  --text: #e8eaf0;
  --muted: #9aa2b1;
  --gold: #d9a441;
  --gold-2: #f2c260;
  --accent: #4f8cff;
  --success: #3fbf7f;
  --danger: #e5644e;
  --radius: 14px;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
  --maxw: 1080px;
}

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

html { scroll-behavior: smooth; }

body {
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  background: radial-gradient(1200px 600px at 50% -200px, #1b2130 0%, var(--bg) 60%);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  line-height: 1.55;
}

a { color: inherit; text-decoration: none; }

/* ===== Header ===== */
.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(15, 17, 22, 0.9);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 12px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand-logo { width: 34px; height: 34px; border-radius: 9px; }
.brand-name {
  font-weight: 800;
  font-size: 1.15rem;
  background: linear-gradient(90deg, var(--gold-2), var(--gold));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  letter-spacing: .3px;
}

/* App-style back button + centered page title (shown on mobile sub-pages) */
.nav-back {
  display: none;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 12px;
  background: var(--card-2);
  color: var(--text);
  font-size: 1.7rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 0 3px;
  transition: background .15s, transform .1s;
}
.nav-back:hover { background: var(--border); }
.nav-back:active { transform: scale(.92); }
.header-title {
  display: none;
  font-weight: 800;
  font-size: 1.05rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 70vw;
}

.main-nav { display: flex; align-items: center; gap: 6px; }
.main-nav a {
  padding: 9px 13px;
  border-radius: 10px;
  color: var(--muted);
  font-weight: 600;
  font-size: .95rem;
  transition: background .15s, color .15s;
}
.main-nav a:hover { color: var(--text); background: var(--card-2); }
.main-nav a.active { color: var(--gold-2); }
.btn-nav {
  background: linear-gradient(90deg, var(--gold), var(--gold-2));
  color: #1a1400 !important;
  font-weight: 800 !important;
}
.btn-nav:hover { filter: brightness(1.05); }

.nav-toggle {
  display: none;
  flex-direction: column;
  gap: 5px;
  background: none;
  border: 0;
  cursor: pointer;
  padding: 8px;
}
.nav-toggle span {
  width: 24px; height: 2px; background: var(--text); border-radius: 2px;
  transition: transform .2s, opacity .2s;
}

/* ===== Ads ===== */
/* Ad containers are empty until JS fills them (AdSense in-app / Adsterra on web),
   so hide them while empty to avoid blank ad space. */
.ad-header:empty, .ad-footer:empty { display: none; }
.adsterra-frame { display: block; border: 0; max-width: 100%; margin: 0 auto; }
.ad-slot {
  position: relative;
  max-width: var(--maxw);
  margin: 0 auto;
  min-height: 90px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-2);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  overflow: hidden;
}
.ad-slot .adsbygoogle { width: 100%; }
.ad-label {
  position: absolute;
  top: 4px; left: 8px;
  font-size: .62rem;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted);
  opacity: .6;
}
.ad-footer { border-bottom: 0; }

/* Login / logout ad interstitial */
.ad-modal {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  background: rgba(0, 0, 0, .72);
  backdrop-filter: blur(4px);
  opacity: 0; transition: opacity .2s;
}
.ad-modal.show { opacity: 1; }
.ad-modal-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 24px;
  width: 100%; max-width: 380px;
  box-shadow: var(--shadow);
  text-align: center;
}
.ad-modal-card h2 { font-size: 1.35rem; margin-bottom: 16px; }
.ad-modal-slot {
  min-height: 200px;
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 16px;
}
.ad-support {
  color: var(--muted);
  font-size: .84rem;
  line-height: 1.55;
  margin-bottom: 18px;
}
.ad-support strong { color: var(--gold-2); }

/* ===== Quiz + points + levels ===== */
.quiz-cta {
  display: flex; align-items: center; gap: 14px;
  margin-top: 20px;
  background: linear-gradient(90deg, rgba(217,164,65,.14), var(--card));
  border: 1px solid var(--gold);
  border-radius: 14px;
  padding: 16px 18px;
  transition: transform .15s;
}
.quiz-cta:hover { transform: translateY(-2px); }
.quiz-cta-icon { font-size: 2rem; }
.quiz-cta-body { flex: 1; }
.quiz-cta-body h3 { font-size: 1.1rem; font-weight: 800; }
.quiz-cta-body p { color: var(--muted); font-size: .9rem; }
.quiz-cta-arrow { font-size: 1.6rem; color: var(--gold-2); }

.quiz-q { margin-bottom: 22px; }
.quiz-q h3 { font-size: 1.05rem; margin-bottom: 12px; }
.quiz-options { display: flex; flex-direction: column; gap: 8px; }
.quiz-option {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.quiz-option:hover { border-color: var(--gold); }
.quiz-option input { accent-color: var(--gold); width: 18px; height: 18px; }
.quiz-option span { flex: 1; }

.quiz-score {
  background: var(--card);
  border: 1px solid var(--gold);
  border-radius: 16px;
  padding: 24px;
  text-align: center;
  margin-top: 10px;
}
.quiz-score h2 { font-size: 1.5rem; margin-bottom: 8px; }
.quiz-score p { color: var(--muted); margin-bottom: 18px; }
.quiz-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

.level-banner {
  display: flex; align-items: center; gap: 16px;
  background: linear-gradient(90deg, rgba(217,164,65,.16), var(--card));
  border: 1px solid var(--gold);
  border-radius: 16px;
  padding: 18px 20px;
  margin-bottom: 22px;
}
.level-badge {
  flex: 0 0 auto;
  min-width: 64px; height: 64px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--gold-2), var(--gold));
  color: #1a1400; font-weight: 900; font-size: 1.1rem;
  padding: 0 10px;
}
.level-info { flex: 1; }
.level-title { font-weight: 800; margin-bottom: 8px; }
.level-next { color: var(--muted); font-size: .8rem; margin-top: 6px; }

/* ===== Ranked ladder banner ===== */
.rank-banner {
  display: flex; align-items: center; gap: 16px;
  background:
    radial-gradient(120px 120px at 8% 0%, color-mix(in srgb, var(--rank) 24%, transparent), transparent 70%),
    linear-gradient(90deg, color-mix(in srgb, var(--rank) 12%, var(--card)), var(--card));
  border: 1px solid color-mix(in srgb, var(--rank) 55%, var(--border));
  border-radius: 16px;
  padding: 18px 20px;
  margin-bottom: 22px;
}
.rank-badge {
  flex: 0 0 auto;
  width: 66px; height: 66px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  border: 3px solid var(--rank);
  background: radial-gradient(circle at 50% 35%, color-mix(in srgb, var(--rank) 22%, var(--bg-2)), var(--bg-2));
  font-weight: 900; font-size: 1.25rem;
  letter-spacing: .02em;
  box-shadow: 0 0 18px color-mix(in srgb, var(--rank) 40%, transparent);
}
.rank-info { flex: 1; min-width: 0; }
.rank-title { font-weight: 900; font-size: 1.15rem; margin-bottom: 4px; }
.rank-stars { display: flex; align-items: center; gap: 4px; margin-bottom: 8px; }
.rank-stars .star { color: var(--border); font-size: 1rem; line-height: 1; transition: color .2s; }
.rank-stars .star.on { color: var(--rank); text-shadow: 0 0 8px color-mix(in srgb, var(--rank) 60%, transparent); }
.rank-para { font-weight: 800; margin-left: 4px; color: var(--rank); }
.rank-next { color: var(--muted); font-size: .8rem; margin-top: 6px; }
.rank-link {
  display: inline-block;
  margin-top: 8px;
  font-size: .82rem;
  font-weight: 700;
  color: var(--gold-2);
}
.rank-link:hover { text-decoration: underline; }

/* Ranked quiz result accents */
.quiz-score.win h2 { color: var(--success); }
.quiz-score.loss h2 { color: var(--danger); }

/* ===== Leaderboard ===== */
.leaderboard { display: flex; flex-direction: column; gap: 8px; }
.lb-row {
  display: flex; align-items: center; gap: 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 14px;
}
.lb-row.me { border-color: var(--gold); background: linear-gradient(90deg, rgba(217,164,65,.14), var(--card)); }
.lb-pos { flex: 0 0 auto; width: 34px; text-align: center; font-weight: 800; font-size: 1.05rem; }
.lb-badge {
  flex: 0 0 auto;
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  border: 2px solid var(--muted);
  font-weight: 900; font-size: .85rem;
  background: var(--bg-2);
}
.lb-name { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.3; }
.lb-name strong { font-size: .98rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lb-name span { font-size: .78rem; }
.lb-points { flex: 0 0 auto; font-weight: 900; color: var(--gold-2); font-size: 1.05rem; }
.lb-points span { font-size: .68rem; color: var(--muted); font-weight: 600; margin-left: 3px; }
.lb-sep { margin: 14px 0 6px; color: var(--muted); font-size: .8rem; font-weight: 700; text-align: center; }

/* ===== Main view ===== */
.view {
  flex: 1;
  width: 100%;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 26px 18px 48px;
  outline: none;
}

/* ===== Hero ===== */
.hero {
  text-align: center;
  padding: 40px 18px 30px;
  background: linear-gradient(180deg, var(--card) 0%, transparent 100%);
  border: 1px solid var(--border);
  border-radius: 20px;
  margin-bottom: 30px;
}
.hero h1 { font-size: clamp(1.8rem, 5vw, 2.8rem); font-weight: 900; line-height: 1.1; }
.hero h1 span { color: var(--gold-2); }
.hero p { color: var(--muted); max-width: 620px; margin: 14px auto 0; font-size: 1.05rem; }
.hero-cta { margin-top: 24px; display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 12px 22px;
  border-radius: 12px;
  font-weight: 800;
  font-size: 1rem;
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform .12s, filter .15s, background .15s;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: linear-gradient(90deg, var(--gold), var(--gold-2)); color: #1a1400; }
.btn-primary:hover { filter: brightness(1.06); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn-ghost:hover { background: var(--card-2); }
.btn-danger { background: transparent; border-color: #7f1d1d; color: #f87171; }
.btn-danger:hover { background: rgba(220, 38, 38, 0.12); }
.btn-block { width: 100%; justify-content: center; }

/* ===== Section headers ===== */
.section-head { display: flex; align-items: baseline; justify-content: space-between; margin: 8px 0 18px; }
.section-head h2 { font-size: 1.5rem; font-weight: 800; }
.section-head a { color: var(--gold-2); font-weight: 700; font-size: .92rem; }

/* ===== Course grid ===== */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 18px; }

.course-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: transform .15s, border-color .15s;
}
.course-card:hover { transform: translateY(-3px); border-color: var(--gold); }
.course-thumb {
  height: 120px;
  display: flex; align-items: center; justify-content: center;
  font-size: 2.6rem;
}
.course-body { padding: 16px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.course-tag {
  align-self: flex-start;
  font-size: .7rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase;
  color: var(--gold-2); background: rgba(217,164,65,.12);
  padding: 3px 9px; border-radius: 20px;
}
.course-body h3 { font-size: 1.12rem; font-weight: 800; }
.course-body p { color: var(--muted); font-size: .9rem; flex: 1; }
.course-meta { display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: .82rem; margin-top: 4px; }

.progress-bar { height: 6px; background: var(--card-2); border-radius: 6px; overflow: hidden; }
.progress-fill { height: 100%; background: linear-gradient(90deg, var(--gold), var(--gold-2)); border-radius: 6px; }

/* ===== Course detail ===== */
.breadcrumb { color: var(--muted); font-size: .88rem; margin-bottom: 14px; }
.breadcrumb a { color: var(--gold-2); }
.detail-head {
  display: flex; gap: 20px; align-items: flex-start; flex-wrap: wrap;
  background: var(--card); border: 1px solid var(--border); border-radius: 18px; padding: 22px; margin-bottom: 24px;
}
.detail-icon { font-size: 3rem; }
.detail-head h1 { font-size: 1.8rem; }
.detail-head p { color: var(--muted); margin-top: 8px; }

.lesson-list { display: flex; flex-direction: column; gap: 10px; }
.lesson-item {
  display: flex; align-items: center; gap: 14px;
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  padding: 14px 16px; cursor: pointer; transition: border-color .15s, background .15s;
}
.lesson-item:hover { border-color: var(--gold); background: var(--card-2); }
.lesson-num {
  width: 34px; height: 34px; flex: 0 0 34px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 9px; background: var(--card-2); font-weight: 800; color: var(--gold-2);
}
.lesson-item.done .lesson-num { background: var(--success); color: #06210f; }
.lesson-info { flex: 1; }
.lesson-info h4 { font-size: 1rem; font-weight: 700; }
.lesson-info span { color: var(--muted); font-size: .82rem; }
.lesson-check { color: var(--muted); font-size: 1.2rem; }
.lesson-item.done .lesson-check { color: var(--success); }

/* ===== Lesson reader ===== */
.lesson-reader { background: var(--card); border: 1px solid var(--border); border-radius: 18px; padding: 26px; }
.lesson-reader h1 { font-size: 1.7rem; margin-bottom: 6px; }
.lesson-reader .meta { color: var(--muted); font-size: .88rem; margin-bottom: 20px; }
.lesson-reader h2 { font-size: 1.25rem; margin: 22px 0 8px; color: var(--gold-2); }
.lesson-reader p { margin: 10px 0; color: #d3d7e0; }
.lesson-reader ul { margin: 10px 0 10px 22px; color: #d3d7e0; }
.lesson-reader li { margin: 6px 0; }
.lesson-reader blockquote {
  border-left: 3px solid var(--gold); padding: 8px 16px; margin: 16px 0;
  background: var(--card-2); border-radius: 0 10px 10px 0; color: var(--muted); font-style: italic;
}
.lesson-nav { display: flex; justify-content: space-between; gap: 12px; margin-top: 28px; }

/* ===== Auth / forms ===== */
.auth-wrap { max-width: 420px; margin: 20px auto; }
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 18px; padding: 26px; box-shadow: var(--shadow);
}
.card h1 { font-size: 1.5rem; margin-bottom: 4px; }
.card .sub { color: var(--muted); margin-bottom: 20px; font-size: .92rem; }

.field { margin-bottom: 16px; }
.field label { display: block; font-weight: 700; font-size: .88rem; margin-bottom: 6px; }
.field input {
  width: 100%; padding: 12px 14px;
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: 10px; color: var(--text); font-size: 1rem;
}
.field input:focus { outline: none; border-color: var(--gold); }

.form-msg { font-size: .88rem; margin: 4px 0 14px; min-height: 18px; }
.form-msg.error { color: var(--danger); }
.form-msg.ok { color: var(--success); }

.auth-alt { text-align: center; color: var(--muted); margin-top: 18px; font-size: .92rem; }
.auth-alt a { color: var(--gold-2); font-weight: 700; }

.checkbox-row { display: flex; align-items: flex-start; gap: 9px; margin-bottom: 16px; font-size: .86rem; color: var(--muted); }
.checkbox-row input { margin-top: 3px; }
.checkbox-row a { color: var(--gold-2); }

/* ===== Profile ===== */
.profile-head { display: flex; align-items: center; gap: 18px; margin-bottom: 26px; }
.avatar {
  width: 68px; height: 68px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.8rem; font-weight: 900; color: #1a1400;
  background: linear-gradient(135deg, var(--gold-2), var(--gold));
}
.profile-head h1 { font-size: 1.5rem; }
.profile-head p { color: var(--muted); }
.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 26px; }
.stat {
  background: var(--card); border: 1px solid var(--border); border-radius: 14px;
  padding: 18px; text-align: center;
}
.stat .num { font-size: 1.8rem; font-weight: 900; color: var(--gold-2); }
.stat .lbl { color: var(--muted); font-size: .82rem; }

/* ===== Content pages ===== */
.content-page { background: var(--card); border: 1px solid var(--border); border-radius: 18px; padding: 30px; }
.content-page h1 { font-size: 1.9rem; margin-bottom: 6px; }
.content-page .updated { color: var(--muted); font-size: .85rem; margin-bottom: 22px; }
.content-page h2 { font-size: 1.25rem; margin: 24px 0 8px; color: var(--gold-2); }
.content-page p, .content-page li { color: #d3d7e0; margin: 8px 0; }
.content-page ul { margin-left: 22px; }
.content-page a { color: var(--gold-2); }

/* ===== Footer ===== */
.app-footer { border-top: 1px solid var(--border); background: var(--bg-2); margin-top: 30px; }
.footer-inner {
  max-width: var(--maxw); margin: 0 auto; padding: 24px 18px;
  display: flex; flex-direction: column; align-items: center; gap: 14px; text-align: center;
}
.footer-brand { display: flex; align-items: center; gap: 10px; font-weight: 800; }
.footer-brand .brand-logo { width: 26px; height: 26px; }
.footer-links { display: flex; gap: 18px; flex-wrap: wrap; justify-content: center; }
.footer-links a { color: var(--muted); font-size: .9rem; }
.footer-links a:hover { color: var(--gold-2); }
.copyright { color: var(--muted); font-size: .82rem; }

/* ===== Toast ===== */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--card-2); border: 1px solid var(--border); color: var(--text);
  padding: 12px 20px; border-radius: 12px; box-shadow: var(--shadow);
  opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s; z-index: 100;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ===== Empty / helper ===== */
.notice { color: var(--muted); text-align: center; padding: 30px; }

/* ===== Bottom tab bar (native app navigation) ===== */
.tabbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 60;
  display: none;
  background: rgba(15, 17, 22, 0.97);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom, 0px));
}
.tabbar .tab {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 6px 0;
  color: var(--muted);
  font-size: .62rem;
  font-weight: 600;
  letter-spacing: .01em;
  white-space: nowrap;
  transition: color .15s, transform .1s;
}
.tabbar .tab-ico {
  font-size: 1.24rem;
  line-height: 1;
  filter: grayscale(35%);
  transition: filter .15s, transform .15s;
}
.tabbar .tab.active { color: var(--gold-2); }
.tabbar .tab.active .tab-ico { filter: none; transform: translateY(-1px) scale(1.08); }
.tabbar .tab:active { transform: scale(.94); }

/* ===== Page transition ===== */
@keyframes viewIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: none; }
}
.view.anim { animation: viewIn .28s ease both; }

/* ===== Responsive ===== */
@media (max-width: 760px) {
  .nav-toggle { display: none; }
  .main-nav { display: none; }
  .tabbar { display: flex; }
  body { padding-bottom: 66px; }

  /* App-style header: back button + centered title on sub-pages */
  body[data-nav="sub"] .header-inner { position: relative; justify-content: center; }
  body[data-nav="sub"] .nav-back { display: inline-flex; position: absolute; left: 12px; }
  body[data-nav="sub"] .header-title { display: block; }
  body[data-nav="sub"] .brand { display: none; }
}

/* ===== Quiz Arena ===== */
.arena-promo {
  display: flex; align-items: center; gap: 14px;
  margin: 4px 0 22px;
  padding: 16px 18px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: linear-gradient(120deg, rgba(111,123,224,.22), rgba(242,194,96,.12));
  color: var(--text);
}
.arena-promo:hover { border-color: var(--gold); }
.arena-promo-ico { font-size: 2rem; flex: 0 0 auto; }
.arena-promo-body { flex: 1; display: flex; flex-direction: column; line-height: 1.35; min-width: 0; }
.arena-promo-body strong { font-size: 1.05rem; }
.arena-promo-body span { color: var(--muted); font-size: .86rem; }
.arena-promo-go { flex: 0 0 auto; font-weight: 800; color: var(--gold-2); }

/* Mode select */
.arena-note {
  background: rgba(79,176,224,.12);
  border: 1px solid rgba(79,176,224,.35);
  border-radius: 12px;
  padding: 12px 14px;
  color: var(--text);
  font-size: .86rem;
  line-height: 1.45;
  margin: 4px 0 16px;
}
.arena-modes { display: flex; flex-direction: column; gap: 12px; margin-top: 8px; }
.arena-mode {
  display: flex; align-items: center; gap: 14px; text-align: left;
  padding: 16px; border-radius: 14px;
  border: 1px solid var(--border);
  border-left: 4px solid var(--am, var(--gold));
  background: var(--card);
  color: var(--text); cursor: pointer;
  transition: transform .12s, border-color .15s, background .15s;
}
.arena-mode:hover { background: var(--card-2); transform: translateY(-2px); }
.arena-mode:active { transform: scale(.98); }
.arena-mode-ico { font-size: 1.9rem; flex: 0 0 auto; }
.arena-mode-body { flex: 1; display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.arena-mode-body strong { font-size: 1.05rem; display: flex; align-items: center; gap: 8px; }
.arena-mode-body small { color: var(--muted); font-size: .84rem; }
.arena-mode-meta { color: var(--am, var(--gold-2)); font-size: .78rem; font-weight: 700; margin-top: 2px; }
.arena-ranked {
  font-style: normal; font-size: .62rem; font-weight: 800; letter-spacing: .08em;
  padding: 2px 6px; border-radius: 6px; background: var(--gold); color: #1a1305;
}
.arena-mode-go { flex: 0 0 auto; font-size: 1.4rem; color: var(--muted); }

/* Small buttons + friends list */
.btn-sm { padding: 6px 10px; font-size: .8rem; }
.friend-add { display: flex; gap: 8px; margin: 6px 0 18px; }
.friend-add input {
  flex: 1 1 auto; padding: 11px 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--card); color: inherit; font-size: .95rem;
}
.friend-list { margin-top: 6px; }
.friend-row {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 12px;
  background: var(--card); margin-bottom: 8px;
}
.friend-badge {
  flex: 0 0 auto; width: 38px; height: 38px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 900; font-size: .8rem; border: 2px solid var(--border);
}
.friend-name { flex: 1 1 auto; font-weight: 700; display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.friend-name small { font-weight: 600; color: var(--muted); font-size: .74rem; }
.friend-acts { flex: 0 0 auto; display: flex; gap: 6px; }
.arena-choice .arena-mode { cursor: pointer; }

/* Matchmaking / searching */
.arena-search { text-align: center; padding: 30px 10px; }
.arena-spinner {
  width: 64px; height: 64px; margin: 0 auto 20px;
  border-radius: 50%;
  border: 5px solid var(--border);
  border-top-color: var(--am, var(--gold-2));
  animation: arenaSpin 0.9s linear infinite;
}
@keyframes arenaSpin { to { transform: rotate(360deg); } }
.arena-search-timer { font-size: 1.6rem; font-weight: 900; color: var(--gold-2); margin: 6px 0 14px; font-variant-numeric: tabular-nums; }
.arena-search-teams { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 18px 0 22px; }
.arena-chip {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 12px 6px 8px; border-radius: 999px;
  background: var(--card); border: 1px solid var(--border);
  font-size: .85rem; font-weight: 600;
  animation: viewIn .3s ease both;
}
.arena-chip.you { border-color: var(--gold); background: rgba(217,164,65,.14); }
.arena-chip-badge {
  width: 26px; height: 26px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  border: 2px solid var(--muted); font-size: .68rem; font-weight: 900;
}

/* Battle HUD */
.arena-battle { --am: var(--gold-2); }
.arena-hud {
  position: sticky; top: 0; z-index: 5;
  background: var(--bg-2);
  border: 1px solid var(--border); border-radius: 14px;
  padding: 12px 14px; margin-bottom: 16px;
}
.arena-hud-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.arena-mode-tag { font-size: .74rem; font-weight: 800; color: var(--am); letter-spacing: .03em; }
.arena-timer { font-size: 1.05rem; font-weight: 900; font-variant-numeric: tabular-nums; }
.arena-score { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.arena-side { display: flex; flex-direction: column; align-items: center; flex: 1; }
.arena-side span { font-size: 2rem; font-weight: 900; line-height: 1; }
.arena-side small { color: var(--muted); font-size: .72rem; margin-top: 2px; }
.arena-side.you span { color: var(--success); }
.arena-side.foe span { color: var(--danger); }
.arena-vs { font-size: .8rem; font-weight: 800; color: var(--muted); white-space: nowrap; }
.arena-bars { display: flex; flex-direction: column; gap: 5px; margin-top: 10px; }
.arena-bar { height: 7px; border-radius: 4px; background: var(--border); overflow: hidden; }
.arena-bar-fill { height: 100%; width: 0; border-radius: 4px; transition: width .4s ease; }
.arena-bar-fill.you { background: var(--success); }
.arena-bar-fill.foe { background: var(--danger); }

/* Battle question */
.arena-question {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 14px; padding: 18px; margin-bottom: 16px;
}
.arena-q-head { font-size: .78rem; font-weight: 800; color: var(--gold-2); margin-bottom: 8px; }
.arena-question h3 { margin: 0 0 14px; font-size: 1.12rem; line-height: 1.4; }
.arena-options { display: flex; flex-direction: column; gap: 10px; }
.arena-opt {
  text-align: left; padding: 13px 15px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--bg-2); color: var(--text);
  font-size: .95rem; cursor: pointer;
  transition: background .12s, border-color .12s, transform .1s;
}
.arena-opt:hover:not(:disabled) { border-color: var(--gold); background: var(--card-2); }
.arena-opt:active:not(:disabled) { transform: scale(.98); }
.arena-opt:disabled { cursor: default; opacity: .95; }
.arena-opt.correct { border-color: var(--success); background: rgba(63,191,127,.16); color: var(--success); font-weight: 700; }
.arena-opt.wrong { border-color: var(--danger); background: rgba(229,100,78,.16); color: var(--danger); }

/* Battle roster */
.arena-roster { margin-top: 4px; border: 1px solid var(--border); border-radius: 12px; background: var(--card); }
.arena-roster summary { cursor: pointer; padding: 12px 16px; font-weight: 700; color: var(--muted); }
.arena-roster-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; padding: 4px 16px 16px; }
.arena-roster-grid h4 { margin: 0 0 8px; font-size: .82rem; color: var(--muted); }
.arena-pl { display: flex; align-items: center; gap: 8px; padding: 5px 0; font-size: .84rem; }
.arena-pl.you { font-weight: 700; }
.arena-pl-badge {
  width: 24px; height: 24px; border-radius: 50%; flex: 0 0 auto;
  display: inline-flex; align-items: center; justify-content: center;
  border: 2px solid var(--muted); font-size: .62rem; font-weight: 900;
}
.arena-pl-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.arena-pl-score { font-weight: 900; color: var(--gold-2); }

/* Result */
.arena-result { text-align: center; padding: 24px 12px; }
.arena-result h1 { font-size: 2rem; margin-bottom: 8px; }
.arena-result.win h1 { color: var(--success); }
.arena-result.loss h1 { color: var(--danger); }
.arena-result.draw h1 { color: var(--gold-2); }
.arena-result-score { font-size: 2.4rem; font-weight: 900; margin: 6px 0 4px; font-variant-numeric: tabular-nums; }
.arena-result-score span:first-child { color: var(--success); }
.arena-result-score span:last-child { color: var(--danger); }

@media (max-width: 760px) {
  .arena-roster-grid { grid-template-columns: 1fr; gap: 10px; }
}

/* ===== Leaderboard tier headings + live badge ===== */
.lb-tier {
  display: flex; align-items: center; gap: 8px;
  margin: 18px 0 6px;
  font-weight: 800; font-size: .82rem; letter-spacing: .04em;
  text-transform: uppercase; color: var(--tier, var(--muted));
}
.lb-tier:first-child { margin-top: 2px; }
.lb-tier-badge {
  flex: 0 0 auto; width: 24px; height: 24px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%; border: 2px solid var(--muted);
  font-weight: 900; font-size: .72rem;
}
.lb-tier-name { flex: 1 1 auto; }
.lb-tier-count {
  flex: 0 0 auto; font-size: .68rem; font-weight: 700;
  color: var(--muted); text-transform: none; letter-spacing: 0;
  border: 1px solid var(--border); border-radius: 999px; padding: 2px 9px;
}
.lb-empty {
  color: var(--muted); font-size: .82rem;
  padding: 8px 12px 12px; border-left: 2px dashed var(--border); margin-left: 11px;
}
.lb-live {
  display: inline-flex; align-items: center;
  color: var(--success); font-weight: 700; white-space: nowrap;
  animation: lbPulse 1.6s ease-in-out infinite;
}
@keyframes lbPulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }

/* ===== Fit-all-devices safeguards ===== */
/* Never let anything sit hidden behind the fixed bottom tab bar. */
@media (max-width: 760px) {
  .view { padding-bottom: 90px; }
  /* Keep the three small stats side-by-side so the Arena record fits cleanly. */
  .stat-row { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .stat { padding: 12px 6px; }
  .stat .num { font-size: 1.3rem; }
  .stat .lbl { font-size: .66rem; }
}
/* Very small phones */
@media (max-width: 380px) {
  .lb-row { gap: 8px; padding: 9px 10px; }
  .lb-badge { width: 34px; height: 34px; font-size: .74rem; }
  .lb-name strong { font-size: .9rem; }
  .lb-points { font-size: .95rem; }
  .tabbar .tab-label { font-size: .58rem; }
}
/* Large screens: give the stats room and cap super-wide reading width. */
@media (min-width: 1100px) {
  .view { padding-left: 24px; padding-right: 24px; }
}

