:root {
  --bg: #0b1c16;
  --card: #12261e;
  --card-2: #183228;
  --ink: #f4efe4;
  --muted: #c7bba6;
  --gold: #e0b85c;
  --gold-2: #f3d48a;
  --teal: #1f8a70;
  --red: #b4232a;
  --green: #1f7a43;
  --rare: #6aa7ff;
  --epic: #c084fc;
  --legendary: #f5c542;
  --common: #d9d3c7;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; width: 100%; height: 100%;
  overflow: hidden; background: var(--bg); color: var(--ink);
  font-family: "Segoe UI", Tahoma, "Noto Naskh Arabic", "Geeza Pro", "Arial", sans-serif;
  user-select: none; touch-action: none;
}
#c { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
.hidden { display: none !important; }

/* HUD */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
.hud-top {
  position: absolute; top: calc(var(--safe-t) + 8px); left: calc(var(--safe-l) + 8px);
  right: calc(var(--safe-r) + 8px);
  display: flex; align-items: flex-start; justify-content: space-between; gap: 8px;
}
.hud-chip {
  background: rgba(8, 20, 16, 0.72); border: 1px solid rgba(224,184,92,0.35);
  border-radius: 999px; padding: 6px 12px; min-width: 64px; text-align: center;
  font-weight: 700; font-size: 15px; backdrop-filter: blur(8px);
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
}
.luban-chip { display: flex; align-items: center; gap: 7px; }
.luban-gem {
  width: 12px; height: 12px; display: inline-block; border-radius: 2px;
  background: linear-gradient(135deg, #ffe9a8, #d28a1a 55%, #8a4b08);
  transform: rotate(45deg);
  box-shadow: 0 0 8px rgba(255, 196, 80, 0.8);
}
.hud-center { text-align: center; flex: 1; }
#kmReadout { font-size: 20px; font-weight: 800; letter-spacing: 0.02em; text-shadow: 0 2px 8px #000; }
#legReadout { font-size: 11px; color: var(--gold-2); opacity: 0.95; text-shadow: 0 1px 4px #000; }

.hud-abilities {
  position: absolute; top: calc(var(--safe-t) + 64px); left: calc(var(--safe-l) + 8px);
  display: flex; flex-direction: column; gap: 8px;
}
.ability {
  background: rgba(8,20,16,0.7); border: 1px solid rgba(255,255,255,0.12);
  border-radius: 14px; padding: 6px 8px; backdrop-filter: blur(8px);
  min-width: 52px; text-align: center; font-size: 10px; color: var(--muted);
}
.ability-ring { position: relative; width: 44px; height: 44px; margin: 0 auto; }
#slashIcon { width: 44px; height: 44px; display: block; }
.charges { display: flex; justify-content: center; gap: 3px; margin-top: 4px; }
.charges i {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--gold); box-shadow: 0 0 6px var(--gold); display: block;
}
.charges i.off { background: #445; box-shadow: none; }

#minimap {
  position: absolute; right: calc(var(--safe-r) + 8px); bottom: calc(var(--safe-b) + 12px);
  width: 96px; height: 124px; border-radius: 12px;
  background: rgba(8,20,16,0.72); border: 1px solid rgba(224,184,92,0.35);
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
}

.banner {
  position: fixed; top: 22%; left: 50%; transform: translateX(-50%) translateY(-12px);
  z-index: 8; pointer-events: none; text-align: center;
  background: linear-gradient(90deg, transparent, rgba(8,20,16,0.82), transparent);
  padding: 10px 36px; opacity: 0; transition: opacity 0.35s, transform 0.35s;
  text-shadow: 0 2px 10px #000; width: min(92vw, 420px);
}
.banner.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.banner .name { font-size: 22px; font-weight: 800; color: var(--gold-2); }
.banner .ar { font-size: 16px; margin-top: 2px; }
.banner .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

.go-flash {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  z-index: 9; pointer-events: none; font-size: 64px; font-weight: 900;
  color: var(--gold-2); text-shadow: 0 4px 24px #000; letter-spacing: 0.08em;
}

/* Screens */
.screen {
  position: fixed; inset: 0; z-index: 10; overflow: auto;
  display: flex; align-items: flex-end; justify-content: center;
  padding: calc(var(--safe-t) + 16px) 16px calc(var(--safe-b) + 20px);
  background: linear-gradient(180deg, rgba(6,14,12,0.2) 0%, rgba(6,14,12,0.55) 40%, rgba(6,14,12,0.88) 100%);
}
#title { align-items: center; background: linear-gradient(180deg, rgba(6,14,12,0.35), rgba(6,14,12,0.82)); }
.title-card, .stop-card, .over-card, .cele-card {
  width: min(100%, 440px); background: linear-gradient(180deg, #1a3328, #101f19);
  border: 1px solid rgba(224,184,92,0.35); border-radius: 22px;
  padding: 22px 20px 18px; box-shadow: 0 20px 60px rgba(0,0,0,0.45);
  text-align: center;
}
.flag-bar {
  height: 6px; border-radius: 6px; margin: 0 auto 14px; width: 120px;
  background: linear-gradient(90deg, #b4232a 0 33%, #f4efe4 33% 66%, #1f7a43 66% 100%);
}
h1 { margin: 0; font-size: 42px; letter-spacing: 0.02em; color: var(--gold-2); }
h2 { margin: 0; font-size: 28px; color: var(--gold-2); }
.ar { direction: rtl; font-weight: 600; color: #f0e6d0; margin: 4px 0 0; }
.tagline { color: var(--muted); margin: 10px 0 4px; font-size: 14px; }
.best { color: var(--gold); font-weight: 700; margin: 6px 0 16px; }
.btn {
  display: block; width: 100%; border: 0; border-radius: 14px; padding: 14px 16px;
  font-size: 17px; font-weight: 800; margin: 8px 0; cursor: pointer;
  font-family: inherit;
}
.btn.primary {
  background: linear-gradient(180deg, #f0cc72, #c9922b);
  color: #2a1a06; box-shadow: 0 6px 0 #7a5a16, 0 10px 24px rgba(0,0,0,0.3);
}
.btn.primary:active { transform: translateY(2px); box-shadow: 0 4px 0 #7a5a16; }
.btn.ghost {
  background: transparent; color: var(--ink);
  border: 1px solid rgba(244,239,228,0.25);
}
.btn:disabled { opacity: 0.45; pointer-events: none; }
.btn.small { padding: 8px 10px; font-size: 13px; width: auto; margin: 0; }
.controls-hint {
  margin-top: 14px; text-align: left; color: var(--muted); font-size: 12px; line-height: 1.55;
  background: rgba(0,0,0,0.18); border-radius: 12px; padding: 10px 12px;
}
.controls-hint .desk { opacity: 0.75; margin-top: 4px; }

/* Stop / shop */
#stop { align-items: stretch; }
.stop-card { width: min(100%, 520px); margin: auto; text-align: left; max-height: 100%; overflow: hidden; display: flex; flex-direction: column; }
.stop-head { text-align: center; padding-bottom: 8px; }
.arrived { text-transform: uppercase; letter-spacing: 0.12em; font-size: 11px; color: var(--muted); margin: 0; }
.blurb { color: var(--muted); font-size: 13px; margin: 6px 0; }
.wallet { font-weight: 800; color: var(--gold-2); display: flex; gap: 8px; align-items: center; justify-content: center; }
.tabs { display: flex; gap: 6px; margin: 8px 0; }
.tab {
  flex: 1; border: 1px solid rgba(255,255,255,0.1); background: #0d1c16; color: var(--muted);
  border-radius: 10px; padding: 9px; font-weight: 700; font-family: inherit; cursor: pointer;
}
.tab.on { background: #234636; color: var(--gold-2); border-color: rgba(224,184,92,0.4); }
.panel { overflow: auto; -webkit-overflow-scrolling: touch; flex: 1; max-height: min(58vh, 520px); padding-bottom: 6px; }
.shop-sec { margin: 12px 0 6px; font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--gold); }
.item {
  display: grid; grid-template-columns: 1fr auto; gap: 6px 10px; align-items: center;
  background: #0d1c16; border: 1px solid rgba(255,255,255,0.08);
  border-radius: 14px; padding: 10px 12px; margin: 8px 0;
}
.item .name { font-weight: 800; }
.item .desc { font-size: 12px; color: var(--muted); grid-column: 1 / -1; }
.item .meta { font-size: 11px; }
.rarity { font-size: 10px; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; }
.rarity.common { color: var(--common); }
.rarity.rare { color: var(--rare); }
.rarity.epic { color: var(--epic); }
.rarity.legendary { color: var(--legendary); }
.item.locked { opacity: 0.55; }
.item.equipped { border-color: var(--gold); box-shadow: 0 0 0 1px rgba(224,184,92,0.35); }
#mapCanvas { width: 100%; height: auto; border-radius: 14px; background: #0a1712; display: block; }
.map-meta { text-align: center; margin: 10px 0; }
#mapLegTitle { font-weight: 800; margin: 0; }
#mapLegKm { color: var(--gold-2); margin: 4px 0 0; font-size: 18px; }

.over-stats {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 14px 0;
}
.over-stats div {
  background: #0d1c16; border-radius: 12px; padding: 10px; text-align: center;
}
.over-stats span { display: block; font-size: 11px; color: var(--muted); }
.over-stats b { font-size: 18px; }
.over-where { color: var(--gold-2); font-weight: 700; }
.keep-note { font-size: 12px; color: var(--muted); }

.rotate-hint {
  display: none; position: fixed; inset: 0; z-index: 50;
  background: #0b1c16; color: var(--ink);
  align-items: center; justify-content: center; flex-direction: column; text-align: center;
  padding: 24px;
}
@media (orientation: landscape) and (max-height: 500px) {
  .rotate-hint { display: flex; }
}

.toast-ok { color: #8fe3b0 !important; }
