/* Dubai Map Mastery — dark luxury theme */
:root {
  --bg: #0A0C10;
  --bg-2: #10131A;
  --gold: #D4AF37;
  --gold-2: #E8C96A;
  --text: #F2EFE6;
  --text-dim: rgba(242, 239, 230, 0.6);
  --line: rgba(255, 255, 255, 0.08);
  --blue: #4C8DFF;
  --green: #3FBF7F;
  --red: #E05555;
  --radius: 18px;
  --font-display: "Space Grotesk", sans-serif;
  --font-body: "Inter", sans-serif;
}

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

html, body {
  height: 100%;
  height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  overflow: hidden;
  overscroll-behavior: none;
}

/* Fixed app shell — no page scroll/bounce behind the app */
body { position: fixed; inset: 0; width: 100%; }

/* Touch-first defaults */
button, .mastery-chip, .mode-tab, .nameit-option, .drawer-grabber, #legend-toggle {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.glass {
  background: rgba(16, 19, 26, 0.72);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}

.hidden { display: none !important; }

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

/* ---------- Top HUD ---------- */
#hud {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 10px 20px;
  padding-top: calc(10px + env(safe-area-inset-top, 0px));
  padding-left: calc(20px + env(safe-area-inset-left, 0px));
  padding-right: calc(20px + env(safe-area-inset-right, 0px));
  background: linear-gradient(to bottom, rgba(10, 12, 16, 0.95), rgba(10, 12, 16, 0.75));
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}

.hud-brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  color: var(--gold);
  font-size: 22px;
  text-shadow: 0 0 14px rgba(212, 175, 55, 0.6);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-title { font-family: var(--font-display); font-weight: 600; font-size: 15px; letter-spacing: 0.02em; }
.brand-sub { font-size: 11px; color: var(--text-dim); letter-spacing: 0.14em; text-transform: uppercase; }

#mode-tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.03);
}
.mode-tab {
  padding: 7px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-dim);
  transition: all 0.25s ease;
}
.mode-tab:hover { color: var(--text); }
.mode-tab.active {
  color: #141414;
  background: linear-gradient(135deg, var(--gold-2), var(--gold));
  box-shadow: 0 0 18px rgba(212, 175, 55, 0.35);
}
.tab-short { display: none; }

.hud-progress { flex: 1; max-width: 320px; min-width: 140px; }
.level-info {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  margin-bottom: 5px;
}
#level-name { font-family: var(--font-display); font-weight: 600; color: var(--gold-2); }
#xp-text { color: var(--text-dim); }
.xp-bar {
  height: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  overflow: hidden;
}
#xp-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--gold), var(--gold-2));
  box-shadow: 0 0 10px rgba(212, 175, 55, 0.55);
  transition: width 0.6s cubic-bezier(0.22, 1, 0.36, 1);
}

.hud-stats { display: flex; gap: 18px; }
.stat { display: flex; flex-direction: column; align-items: center; line-height: 1.2; }
.stat-val { font-family: var(--font-display); font-weight: 600; font-size: 15px; color: var(--text); }
.stat-label { font-size: 10px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.1em; }
.stat.big .stat-val { font-size: 28px; color: var(--gold-2); }

.hud-actions { display: flex; gap: 8px; }
.icon-btn {
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-dim);
  font-size: 15px;
  transition: all 0.2s ease;
}
.icon-btn:hover { color: var(--gold-2); border-color: rgba(212, 175, 55, 0.4); }
.icon-btn.danger:hover { color: var(--red); border-color: rgba(224, 85, 85, 0.4); }

/* Mastery ring button (opens the mastery drawer) */
.ring-btn { position: relative; width: 40px; height: 40px; }
.mini-ring { position: absolute; inset: 2px; width: 36px; height: 36px; transform: rotate(-90deg); }
.mini-ring circle { fill: none; stroke-width: 2.5; }
.mini-ring-bg { stroke: rgba(255, 255, 255, 0.12); }
.mini-ring-fg {
  stroke: var(--gold);
  stroke-linecap: round;
  stroke-dasharray: 94.25;
  stroke-dashoffset: 94.25;
  transition: stroke-dashoffset 0.6s cubic-bezier(0.22, 1, 0.36, 1);
  filter: drop-shadow(0 0 3px rgba(212, 175, 55, 0.5));
}
#mini-ring-pct {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display);
  font-size: 8.5px;
  font-weight: 700;
  color: var(--gold-2);
  letter-spacing: -0.02em;
}

/* ---------- Map ---------- */
#map-wrap { position: fixed; inset: 0; }
#map { position: absolute; inset: 0; background: var(--bg); }

#mode-hint {
  position: absolute;
  bottom: calc(52px + env(safe-area-inset-bottom, 0px)); /* clear of the centered Mastery toggle */
  left: 50%;
  transform: translateX(-50%);
  z-index: 900;
  padding: 9px 18px;
  font-size: 13px;
  color: var(--text-dim);
  border-radius: 999px;
  pointer-events: none;
  white-space: nowrap;
}

/* Tier legend (Explore only) */
#tier-legend {
  position: absolute;
  bottom: 24px;
  left: 16px;
  z-index: 900;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px 14px;
  border-radius: 14px;
  pointer-events: none;
}
.tl-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11.5px;
  color: var(--text-dim);
  letter-spacing: 0.03em;
}
.tl-chip i {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
  box-shadow: 0 0 6px rgba(255, 255, 255, 0.15);
}
.tl-chip i.tl-line {
  width: 16px;
  height: 3px;
  border-radius: 2px;
  background: #CBD5E1;
  box-shadow: none;
}
.tl-chip i.tl-diamond {
  width: 8px;
  height: 8px;
  border-radius: 0;
  background: #E8C96A;
  transform: rotate(45deg);
  box-shadow: none;
}

/* Legend expand button — mobile only (see media query) */
#legend-toggle {
  display: none;
  position: absolute;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  left: 12px;
  z-index: 901;
  padding: 9px 16px;
  border-radius: 999px;
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 600;
  color: var(--gold-2);
  letter-spacing: 0.05em;
}

/* Highway tag on the Locate prompt */
.kind-tag {
  display: inline-block;
  margin-left: 10px;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid rgba(203, 213, 225, 0.45);
  color: #CBD5E1;
  font-family: var(--font-body);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  vertical-align: middle;
}

/* Section headers inside the mastery grid */
.grid-section {
  flex-basis: 100%;
  margin: 12px 0 2px;
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--gold-2);
}

/* MapLibre restyle */
.maplibregl-canvas { outline: none; }
.maplibregl-ctrl-group {
  background: rgba(16, 19, 26, 0.9) !important;
  border: 1px solid var(--line);
  border-radius: 10px !important;
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5) !important;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.maplibregl-ctrl-group button {
  background: transparent !important;
  width: 34px !important;
  height: 34px !important;
}
.maplibregl-ctrl-group button + button { border-top: 1px solid var(--line) !important; }
.maplibregl-ctrl-group button:hover { background: rgba(212, 175, 55, 0.15) !important; }
.maplibregl-ctrl-group button span { filter: invert(0.92) sepia(0.25) saturate(2) hue-rotate(-10deg); }
.maplibregl-ctrl-attrib {
  background: rgba(10, 12, 16, 0.6) !important;
  color: rgba(242, 239, 230, 0.35) !important;
  font-size: 10px !important;
}
.maplibregl-ctrl-attrib a { color: rgba(212, 175, 55, 0.5) !important; }
.maplibregl-ctrl-attrib-button { filter: invert(0.7); }
/* Keep zoom controls clear of the fixed HUD */
.maplibregl-ctrl-top-right { top: 66px; right: 12px; }

/* Hover tooltip (Explore mode) */
#map-tooltip {
  position: absolute;
  z-index: 920;
  width: 250px;
  padding: 14px 16px;
  pointer-events: none;
  opacity: 0;
  transform: scale(0.94) translateY(4px);
  transition: opacity 0.18s ease, transform 0.18s cubic-bezier(0.22, 1, 0.36, 1);
  will-change: left, top;
}
#map-tooltip.visible {
  opacity: 1;
  transform: scale(1) translateY(0);
}
/* On touch, the tooltip is tappable (second tap opens the panel) */
#map-tooltip.touch-active { pointer-events: auto; cursor: pointer; }
.tt-name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 16px;
  line-height: 1.25;
  margin-bottom: 4px;
}
.tt-meta { font-size: 11px; color: var(--text-dim); letter-spacing: 0.05em; text-transform: uppercase; margin-bottom: 6px; }
.tt-tier { font-family: var(--font-display); color: var(--gold-2); letter-spacing: 0.18em; font-size: 12px; margin-bottom: 6px; }
.tt-blurb { font-size: 12px; line-height: 1.55; color: var(--text-dim); }

/* Click ripple */
.click-ripple {
  position: absolute;
  width: 20px; height: 20px;
  margin: -10px 0 0 -10px;
  border-radius: 50%;
  border: 2px solid var(--gold-2);
  pointer-events: none;
  animation: ripple 0.7s ease-out forwards;
  z-index: 800;
}
@keyframes ripple {
  from { transform: scale(0.4); opacity: 1; }
  to { transform: scale(4); opacity: 0; }
}

/* ---------- Explore panel ---------- */
#area-panel {
  position: fixed;
  top: 76px;
  right: 20px;
  z-index: 950;
  width: 320px;
  padding: 26px 24px 24px;
}
.panel-close {
  position: absolute;
  top: 12px; right: 14px;
  color: var(--text-dim);
  font-size: 14px;
  transition: color 0.2s;
}
.panel-close:hover { color: var(--text); }
.panel-tier {
  font-family: var(--font-display);
  color: var(--gold-2);
  letter-spacing: 0.2em;
  font-size: 13px;
  margin-bottom: 6px;
}
#panel-name {
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 600;
  line-height: 1.2;
  margin-bottom: 12px;
}
.panel-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.tag {
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-dim);
  letter-spacing: 0.04em;
}
#panel-blurb { font-size: 14px; line-height: 1.6; color: var(--text-dim); margin-bottom: 16px; }
.panel-state { font-size: 12px; margin-bottom: 14px; color: var(--text-dim); }
.panel-state .yes { color: var(--green); }
.panel-state .no { color: rgba(242, 239, 230, 0.35); }

/* ---------- Buttons ---------- */
.btn-gold {
  width: 100%;
  padding: 12px 18px;
  border-radius: 12px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 14px;
  color: #141414;
  background: linear-gradient(135deg, var(--gold-2), var(--gold));
  box-shadow: 0 4px 18px rgba(212, 175, 55, 0.35);
  transition: transform 0.15s ease, box-shadow 0.2s ease;
}
.btn-gold:hover { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(212, 175, 55, 0.5); }
.btn-ghost {
  padding: 12px 18px;
  border-radius: 12px;
  font-weight: 500;
  font-size: 14px;
  color: var(--text-dim);
  border: 1px solid var(--line);
  transition: all 0.2s ease;
}
.btn-ghost:hover { color: var(--text); border-color: rgba(255, 255, 255, 0.2); }
.btn-small { width: auto; padding: 8px 14px; font-size: 12.5px; }
.share-btn { flex: none; margin-left: auto; }

/* ---------- Quiz cards ---------- */
#locate-card, #nameit-card {
  position: fixed;
  top: 76px;
  left: 20px;
  z-index: 950;
  width: 340px;
  padding: 20px;
}
.card-collapse {
  position: absolute;
  top: 8px;
  right: 10px;
  z-index: 2;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  color: var(--text-dim);
  font-size: 15px;
  line-height: 1;
  transition: color 0.2s ease, transform 0.25s ease;
}
.card-collapse:hover { color: var(--gold-2); }
.card-full {
  overflow: hidden;
  max-height: 640px;
  opacity: 1;
  transition: max-height 0.35s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.25s ease;
}
.card-pill {
  display: none;
  align-items: center;
  gap: 12px;
  padding-right: 30px; /* clear of the collapse button */
}
.pill-find {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pill-find strong { color: var(--gold-2); }
.quiz-card.collapsed {
  padding: 11px 16px;
  background: rgba(16, 19, 26, 0.6);
}
.quiz-card.collapsed .card-full { max-height: 0; opacity: 0; }
.quiz-card.collapsed .card-pill { display: flex; }
.quiz-card.collapsed .card-collapse { top: 6px; }
.card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.card-eyebrow {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--gold-2);
  font-weight: 600;
}
#locate-progress { font-size: 12px; color: var(--text-dim); }
.locate-prompt { font-family: var(--font-display); font-size: 19px; font-weight: 500; margin-bottom: 12px; }
.locate-prompt strong { color: var(--gold-2); }
.card-row { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; min-height: 30px; }
.card-row .btn-gold { width: auto; padding: 9px 20px; }
.streak-badge {
  font-size: 13px;
  font-weight: 600;
  color: var(--gold-2);
  text-shadow: 0 0 12px rgba(212, 175, 55, 0.5);
}

.feedback {
  margin-top: 10px;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.5;
  border: 1px solid var(--line);
}
.feedback.perfect { border-color: rgba(212, 175, 55, 0.5); background: rgba(212, 175, 55, 0.1); color: var(--gold-2); }
.feedback.close { border-color: rgba(76, 141, 255, 0.5); background: rgba(76, 141, 255, 0.1); color: #9CC2FF; }
.feedback.warm { border-color: rgba(63, 191, 127, 0.45); background: rgba(63, 191, 127, 0.08); color: #8FDDB4; }
.feedback.miss { border-color: rgba(224, 85, 85, 0.5); background: rgba(224, 85, 85, 0.1); color: #F0A0A0; }
.feedback.skip { border-color: rgba(242, 239, 230, 0.25); background: rgba(242, 239, 230, 0.05); color: var(--text-dim); }

#nameit-options { display: flex; flex-direction: column; gap: 8px; margin-top: 6px; }
.nameit-option {
  padding: 11px 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  font-size: 14px;
  text-align: left;
  color: var(--text);
  transition: all 0.18s ease;
}
.nameit-option:hover:not(:disabled) { border-color: rgba(212, 175, 55, 0.5); background: rgba(212, 175, 55, 0.08); transform: translateX(3px); }
.nameit-option.correct { border-color: var(--green); background: rgba(63, 191, 127, 0.15); color: #8FDDB4; }
.nameit-option.wrong { border-color: var(--red); background: rgba(224, 85, 85, 0.12); color: #F0A0A0; }
.nameit-option:disabled { cursor: default; opacity: 0.75; }

/* ---------- Mastery drawer ---------- */
/* Grabber handle — mobile only (see media query) */
.drawer-grabber { display: none; }
/* Drawer stats row — mobile only (HUD stats hide on small screens) */
.drawer-stats { display: none; }
#mastery-drawer {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 930;
  max-height: 46vh;
  padding: 18px 24px 24px;
  border-radius: 20px 20px 0 0;
  border-bottom: none;
  overflow-y: auto;
  transform: translateY(calc(100% + 2px));
  transition: transform 0.45s cubic-bezier(0.22, 1, 0.36, 1);
}
#mastery-drawer.open { transform: translateY(0); }
#mastery-drawer::-webkit-scrollbar { width: 6px; }
#mastery-drawer::-webkit-scrollbar-thumb { background: rgba(212, 175, 55, 0.3); border-radius: 3px; }
.drawer-head { display: flex; align-items: center; gap: 24px; margin-bottom: 16px; }
.ring-wrap { position: relative; width: 80px; height: 80px; flex: none; }
.ring { width: 80px; height: 80px; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 6; }
.ring-bg { stroke: rgba(255, 255, 255, 0.07); }
.ring-fg {
  stroke: url(#ring-grad), var(--gold);
  stroke: var(--gold);
  stroke-linecap: round;
  stroke-dasharray: 213.6;
  stroke-dashoffset: 213.6;
  transition: stroke-dashoffset 0.8s cubic-bezier(0.22, 1, 0.36, 1);
  filter: drop-shadow(0 0 5px rgba(212, 175, 55, 0.6));
}
.ring-text {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  line-height: 1.1;
}
.ring-text span { font-family: var(--font-display); font-weight: 700; font-size: 17px; color: var(--gold-2); }
.ring-text small { font-size: 9px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.1em; }
.legend { display: flex; flex-wrap: wrap; gap: 8px 18px; font-size: 12px; color: var(--text-dim); }
.legend span { display: flex; align-items: center; gap: 6px; }
.chip-dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.chip-dot.undiscovered { background: rgba(255, 255, 255, 0.12); }
.chip-dot.discovered { background: var(--blue); }
.chip-dot.located { background: var(--gold); }
.chip-dot.mastered { background: var(--green); }

#mastery-grid { display: flex; flex-wrap: wrap; gap: 7px; }
.mastery-chip {
  font-size: 12px;
  padding: 5px 11px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--text-dim);
  background: rgba(255, 255, 255, 0.04);
  transition: all 0.2s ease;
}
.mastery-chip:hover { transform: translateY(-2px); border-color: rgba(255, 255, 255, 0.25); }
.mastery-chip.discovered { border-color: rgba(76, 141, 255, 0.55); background: rgba(76, 141, 255, 0.14); color: #9CC2FF; }
.mastery-chip.located { border-color: rgba(212, 175, 55, 0.55); background: rgba(212, 175, 55, 0.12); color: var(--gold-2); }
.mastery-chip.mastered { border-color: rgba(63, 191, 127, 0.55); background: rgba(63, 191, 127, 0.13); color: #8FDDB4; }

/* ---------- Modals ---------- */
.modal-overlay {
  position: fixed; inset: 0;
  z-index: 1200;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(6, 8, 12, 0.7);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  padding: 20px;
}
/* onboarding & celebration stack above results/share modals, below toasts */
#onboarding, #celebration { z-index: 1210; }
.modal {
  width: 100%;
  max-width: 480px;
  max-height: 86vh;
  max-height: 86dvh;
  overflow-y: auto;
  padding: 32px 30px;
}
.modal h2 { font-family: var(--font-display); font-size: 24px; margin-bottom: 14px; }
.modal p { font-size: 14.5px; line-height: 1.65; color: var(--text-dim); }
.modal p strong, .modal p em { color: var(--text); font-style: normal; }
.modal-actions { display: flex; gap: 10px; margin-top: 22px; }
.modal-actions .btn-gold { flex: 1; }
.modal-actions .btn-ghost { flex: 1; }

.results-summary { display: flex; justify-content: space-around; margin: 18px 0; }
#results-list { list-style: none; max-height: 220px; overflow-y: auto; }
#results-list li {
  display: flex;
  justify-content: space-between;
  padding: 8px 4px;
  font-size: 13px;
  border-bottom: 1px solid var(--line);
  color: var(--text-dim);
}
#results-list li .r-name { color: var(--text); }
#results-list li .r-perfect { color: var(--gold-2); }
#results-list li .r-close { color: #9CC2FF; }
#results-list li .r-warm { color: #8FDDB4; }
#results-list li .r-miss { color: #F0A0A0; }
#results-list li .r-skip { color: rgba(242, 239, 230, 0.4); }

/* Share modal */
.share-modal { max-width: 520px; }
#share-preview-img {
  width: 100%;
  border-radius: 12px;
  border: 1px solid var(--line);
  display: block;
  margin: 6px 0 4px;
}

/* Onboarding */
.onboarding-modal { max-width: 440px; text-align: center; }
.ob-dots { display: flex; justify-content: center; gap: 8px; margin-bottom: 22px; }
.ob-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  transition: all 0.3s ease;
}
.ob-dot.active { background: var(--gold); box-shadow: 0 0 10px rgba(212, 175, 55, 0.7); width: 22px; border-radius: 999px; }
.ob-step h2 { margin-bottom: 14px; }
.ob-step p strong { color: var(--gold-2); }

/* ---------- Confetti & toasts ---------- */
#confetti-canvas {
  position: fixed; inset: 0;
  z-index: 1300;
  pointer-events: none;
}
#toast-layer {
  position: fixed;
  bottom: 90px;
  right: 28px;
  z-index: 1250;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  pointer-events: none;
}
.xp-toast {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 17px;
  color: var(--gold-2);
  text-shadow: 0 0 14px rgba(212, 175, 55, 0.6);
  background: rgba(16, 19, 26, 0.85);
  border: 1px solid rgba(212, 175, 55, 0.4);
  padding: 8px 16px;
  border-radius: 999px;
}

/* ---------- Responsive: phones & tablets ---------- */
@media (max-width: 900px) {
  /* --- Top HUD: clean two-row wrap --- */
  #hud { flex-wrap: wrap; gap: 8px 10px; padding: 8px 12px;
    padding-top: calc(8px + env(safe-area-inset-top, 0px));
    padding-left: calc(12px + env(safe-area-inset-left, 0px));
    padding-right: calc(12px + env(safe-area-inset-right, 0px)); }
  .hud-stats { display: none; }
  .maplibregl-ctrl-top-right { top: calc(104px + env(safe-area-inset-top, 0px)); right: 10px; }
  .brand-sub { display: none; }
  .brand-title { font-size: 13px; }
  .hud-progress { order: 3; flex-basis: 100%; max-width: none; }
  .tab-long { display: none; }
  .tab-short { display: inline; }
  .mode-tab { min-height: 44px; padding: 10px 14px; display: inline-flex; align-items: center; font-size: 12.5px; }
  .icon-btn { width: 44px; height: 44px; font-size: 17px; }

  /* --- Quiz cards: docked bottom, thumb-reachable, above safe-area --- */
  #locate-card, #nameit-card {
    top: auto;
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    left: 12px;
    right: 12px;
    width: auto;
    padding: 16px;
  }
  #nameit-options { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
  .nameit-option { min-height: 52px; display: flex; align-items: center; font-size: 13.5px; }
  #locate-skip, .btn-small { min-height: 44px; padding: 10px 16px; font-size: 13px; }
  #locate-next { min-height: 44px; }

  /* --- Legend: collapsed behind a floating button --- */
  #legend-toggle { display: block; }
  #tier-legend { display: none; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); left: 12px; padding: 12px 14px; }
  #tier-legend.open { display: flex; }

  /* --- Side panel: bottom sheet, ≤45dvh, safe-area aware --- */
  #area-panel {
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    max-height: 45dvh;
    overflow-y: auto;
    border-radius: 20px 20px 0 0;
    padding-bottom: calc(30px + env(safe-area-inset-bottom, 0px));
  }
  .panel-close { width: 44px; height: 44px; top: 4px; right: 8px; font-size: 16px; }

  /* --- Mastery drawer: grabber, pinned head, roomier chips --- */
  #mastery-drawer {
    max-height: 60dvh;
    padding: 8px 16px 24px;
    padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  }
  .drawer-grabber {
    display: block;
    width: 44px;
    height: 5px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.22);
    margin: 2px auto 10px;
    touch-action: none;
  }
  .drawer-head {
    position: sticky;
    top: -8px;
    z-index: 2;
    background: rgba(16, 19, 26, 0.92);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    flex-wrap: wrap;
    gap: 12px;
    padding: 8px 0 10px;
    margin-bottom: 10px;
  }
  .drawer-stats { display: flex; gap: 18px; }
  .share-btn { margin-left: 0; flex-basis: 100%; min-height: 44px; }
  .mastery-chip { padding: 9px 14px; font-size: 12.5px; min-height: 38px; }

  #mode-hint { display: none; }

  /* --- Modals: fit viewport, internal scroll --- */
  .modal { padding: 24px 20px; max-height: 92dvh; overflow-y: auto; }
  .modal-actions { flex-wrap: wrap; }
  .modal-actions .btn-gold, .modal-actions .btn-ghost { flex: 1 1 100%; min-height: 48px; }

  /* --- Toasts: top, under the HUD — never under bottom-docked UI --- */
  #toast-layer {
    bottom: auto;
    top: calc(110px + env(safe-area-inset-top, 0px));
    right: 14px;
  }
}

/* ---------- Landscape phones / very short viewports ---------- */
@media (max-height: 520px) and (orientation: landscape) {
  .modal { max-height: 94dvh; }
  #mastery-drawer { max-height: 82dvh; }
  #area-panel { max-height: 78dvh; }
  #locate-card, #nameit-card { max-width: 480px; }
  #mode-hint { display: none; }
}
