/* ── Reset & Base ─────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --green:   #1a7a4a;
  --gold:    #c8972a;
  --dark:    #0d1b14;
  --card-bg: rgba(255,255,255,0.08);
  --glass:   rgba(13,27,20,0.72);
}

html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--dark);
  color: #fff;
}

/* ── Screens ─────────────────────────────────────── */
.screen {
  position: fixed;
  inset: 0;
  display: none;
  flex-direction: column;
}
.screen.active { display: flex; }

/* ── SCREEN 1 – Loading ──────────────────────────── */
#screen-loading {
  background: radial-gradient(ellipse at 50% 30%, #1a4a2e 0%, #0d1b14 70%);
  align-items: center;
  justify-content: center;
}

.loading-inner {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.kaaba-icon { font-size: 64px; animation: float 3s ease-in-out infinite; }

@keyframes float {
  0%,100% { transform: translateY(0); }
  50%      { transform: translateY(-12px); }
}

h1 {
  font-size: 2rem;
  font-weight: 700;
  background: linear-gradient(135deg, #fff 30%, var(--gold));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.subtitle { color: #a0c4a0; font-size: 0.95rem; }

.spinner {
  width: 44px; height: 44px;
  border: 4px solid rgba(255,255,255,0.15);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
  margin-top: 8px;
}
@keyframes spin { to { transform: rotate(360deg); } }

#loading-msg { color: #a0c4a0; font-size: 0.88rem; }

/* ── SCREEN 2 – Map ──────────────────────────────── */

#map-header {
  background: linear-gradient(135deg, #0d2b1a, #1a4a2e);
  padding: 10px 14px;
  padding-top: calc(10px + env(safe-area-inset-top));
  flex-shrink: 0;
  border-bottom: 1px solid rgba(200,151,42,0.3);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.header-content { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.header-icon { font-size: 24px; flex-shrink: 0; }
#map-header h2 { font-size: 0.92rem; font-weight: 600; color: #fff; }
#map-header p  { font-size: 0.73rem; color: #a0c4a0; margin-top: 1px; line-height: 1.3; }

.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.gps-badge {
  font-size: 0.7rem;
  font-weight: 700;
  border-radius: 20px;
  padding: 4px 8px;
  white-space: nowrap;
}
.acc-good { background: rgba(42,173,104,0.25); color: #2aad68; border: 1px solid #2aad68; }
.acc-ok   { background: rgba(200,151,42,0.25); color: var(--gold); border: 1px solid var(--gold); }
.acc-poor { background: rgba(255,80,80,0.2);   color: #ff5050;    border: 1px solid #ff5050; }

/* Icon-only header buttons */
#btn-compass, #btn-move-pos {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255,255,255,0.1);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.22);
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  flex-shrink: 0;
}
#btn-compass:active, #btn-move-pos:active { transform: scale(0.93); }
#btn-compass.active-mode, #btn-move-pos.active-mode {
  background: rgba(200,151,42,0.3);
  border-color: var(--gold);
  color: var(--gold);
  animation: pulse-btn 1.2s ease-in-out infinite;
}

#map-rotate-wrapper {
  flex: 1;
  overflow: hidden;
  position: relative;
}

#map { width: 100%; height: 100%; z-index: 1; }

#map-footer {
  background: var(--glass);
  backdrop-filter: blur(12px);
  padding: 4px 16px 12px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-top: 1px solid rgba(200,151,42,0.25);
  flex-shrink: 0;
  transition: max-height 0.3s ease, padding 0.3s ease;
  max-height: 280px;
  overflow: hidden;
}
#map-footer.collapsed {
  max-height: 28px;
  padding-top: 0;
  padding-bottom: 0;
  gap: 0;
}
#map-footer.collapsed > *:not(#footer-handle) { opacity: 0; pointer-events: none; }

#footer-handle {
  display: flex;
  justify-content: center;
  padding: 6px 0 2px;
  cursor: pointer;
  touch-action: manipulation;
}
.handle-bar {
  width: 36px;
  height: 4px;
  background: rgba(255,255,255,0.25);
  border-radius: 2px;
}

/* ── Map legend ──────────────────────────────────── */
#map-legend {
  position: fixed;
  bottom: 8px;
  left: 12px;
  z-index: 500;
  display: flex;
  gap: 10px;
  background: var(--glass);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 20px;
  padding: 5px 12px;
  pointer-events: none;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.72rem;
  color: rgba(255,255,255,0.75);
}
.legend-dot {
  width: 10px;
  height: 4px;
  border-radius: 2px;
  display: inline-block;
}
.dot-orange { background: #ff7043; }
.dot-gold   { background: #c8972a; }
.dot-blue   { background: #2196F3; }

/* ── Road draw toolbar ───────────────────────────── */
#road-draw-bar {
  position: absolute;
  top: 68px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 450;
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(13,43,26,0.93);
  border: 1px solid rgba(33,150,243,0.5);
  border-radius: 12px;
  padding: 9px 14px;
  backdrop-filter: blur(10px);
  white-space: nowrap;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}
#road-draw-bar.hidden { display: none; }
#road-draw-bar span   { font-size: 0.82rem; color: rgba(255,255,255,0.8); }
.road-draw-btn {
  padding: 6px 13px;
  border-radius: 8px;
  border: none;
  font-weight: 700;
  font-size: 0.82rem;
  cursor: pointer;
  background: rgba(255,255,255,0.12);
  color: #fff;
}
.road-draw-btn:active { transform: scale(0.96); }
.road-draw-done {
  background: #2196F3;
  color: #fff;
}

/* ── Road bearing tuner (in footer) ─────────────── */
#road-tuner { display: flex; flex-direction: column; gap: 10px; }
#road-tuner.hidden { display: none; }

.tuner-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.tuner-title {
  font-size: 0.78rem;
  color: rgba(255,255,255,0.55);
  font-weight: 600;
}
.tuner-bearing-val {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--gold);
}

.tuner-btns {
  display: flex;
  align-items: center;
  gap: 6px;
  justify-content: center;
}
.tuner-btn {
  padding: 10px 16px;
  background: rgba(200,151,42,0.15);
  color: var(--gold);
  border: 1px solid rgba(200,151,42,0.35);
  border-radius: 9px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  min-width: 52px;
}
.tuner-btn-sm {
  padding: 10px 12px;
  min-width: 44px;
}
.tuner-btn:active { background: rgba(200,151,42,0.35); transform: scale(0.95); }
.tuner-mid-label {
  font-size: 0.68rem;
  color: rgba(255,255,255,0.35);
  min-width: 44px;
  text-align: center;
}
.tuner-footer-row {
  display: flex;
  gap: 8px;
  justify-content: space-between;
}
.tuner-clear-btn {
  padding: 9px 16px;
  background: rgba(255,255,255,0.07);
  color: rgba(255,255,255,0.45);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 9px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  flex: 1;
}
.tuner-clear-btn:active { transform: scale(0.96); }

#compass-preview {
  display: flex;
  justify-content: space-between;
  background: rgba(255,255,255,0.06);
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 0.82rem;
  color: #ccc;
}
#compass-preview strong { color: var(--gold); }

.btn-primary {
  background: linear-gradient(135deg, var(--green), #2aad68);
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 14px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(26,122,74,0.45);
  transition: transform 0.15s, box-shadow 0.15s;
}
.btn-primary:active { transform: scale(0.97); }

#map-hint { text-align: center; color: #a0c4a0; font-size: 0.85rem; padding: 4px 0; }

/* ── Result panel ────────────────────────────────── */
#result-panel {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#turn-display {
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(255,255,255,0.06);
  border-radius: 14px;
  padding: 12px 16px;
  border: 1px solid rgba(255,255,255,0.1);
}

#turn-arrow {
  font-size: 2rem;
  flex-shrink: 0;
  line-height: 1;
}

#turn-text {
  font-size: 1.05rem;
  font-weight: 600;
  line-height: 1.3;
}
#turn-text strong { font-size: 1.15rem; }

#bearing-row {
  display: flex;
  gap: 6px;
}

.bearing-chip {
  flex: 1;
  background: rgba(255,255,255,0.07);
  border-radius: 10px;
  padding: 7px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  border: 1px solid rgba(255,255,255,0.1);
}
.bearing-chip.chip-gold {
  background: rgba(200,151,42,0.15);
  border-color: rgba(200,151,42,0.35);
}
.chip-label {
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: rgba(255,255,255,0.5);
}
.chip-val {
  font-size: 0.78rem;
  font-weight: 700;
  color: #fff;
}
.chip-gold .chip-val { color: var(--gold); }

.retap-hint {
  text-align: center;
  font-size: 0.75rem;
  color: rgba(255,255,255,0.35);
}

.hidden { display: none !important; }

/* ── SCREEN 2 – Map ──────────────────────────────── */
#screen-map { background: #111; }
#rotation-controls {
  position: fixed;
  bottom: 140px;
  right: 12px;
  z-index: 500;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

#rotation-controls button {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--glass);
  backdrop-filter: blur(10px);
  color: #fff;
  font-size: 1.1rem;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(0,0,0,0.45);
  transition: background 0.15s, transform 0.1s;
  border: 1px solid rgba(255,255,255,0.18);
  display: flex;
  align-items: center;
  justify-content: center;
}
#rotation-controls button:active { transform: scale(0.92); background: rgba(26,122,74,0.55); }

#btn-rot-reset {
  font-size: 1.25rem !important;
  color: var(--gold) !important;
}

#btn-locate {
  font-size: 1.2rem !important;
  color: #2196F3 !important;
  margin-top: 4px;
}

@keyframes pulse-btn {
  0%, 100% { box-shadow: 0 0 0 0 rgba(200,151,42,0.5); }
  50%       { box-shadow: 0 0 0 6px rgba(200,151,42,0); }
}

#rotation-display {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--glass);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(200,151,42,0.35);
  border-radius: 10px;
  padding: 4px 8px;
  min-width: 42px;
}
#rotation-deg {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--gold);
  line-height: 1;
}
.rot-label {
  font-size: 0.62rem;
  color: rgba(255,255,255,0.5);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ── User location pulse ─────────────────────────── */
/* User location pulse */
.user-dot {
  width: 18px; height: 18px;
  background: #2196F3;
  border: 3px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 0 rgba(33,150,243,0.7);
  animation: pulse-dot 2s ease-out infinite;
}
@keyframes pulse-dot {
  0%   { box-shadow: 0 0 0 0 rgba(33,150,243,0.7); }
  70%  { box-shadow: 0 0 0 12px rgba(33,150,243,0); }
  100% { box-shadow: 0 0 0 0 rgba(33,150,243,0); }
}

/* Direction line on map */
.direction-line { stroke: #ff7043; stroke-width: 3; stroke-dasharray: 8 5; }

/* ── Secondary tool buttons (inside result panel) ────── */
.result-tools {
  display: flex;
  gap: 8px;
}

.tool-btn {
  flex: 1;
  padding: 8px 6px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.15);
  background: rgba(255,255,255,0.07);
  color: rgba(255,255,255,0.7);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
.tool-btn:active { transform: scale(0.96); background: rgba(255,255,255,0.13); }

/* ── Shared camera screen base ───────────────────── */
#screen-camera {
  background: #000;
  overflow: hidden;
}

#sun-video,
#camera-feed {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

#sun-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.hud-btn {
  background: rgba(0,0,0,0.45);
  backdrop-filter: blur(8px);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.22);
  border-radius: 20px;
  padding: 9px 16px;
  font-size: 0.88rem;
  cursor: pointer;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.hud-btn:active { background: rgba(255,255,255,0.15); }

/* ── Camera View screen ───────────────────── */
#cam-top-hud {
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top));
  background: linear-gradient(to bottom, rgba(0,0,0,0.6) 0%, transparent 100%);
  gap: 10px;
}

/* ── Camera View screen ──────────────────────────── */
.hud-badge {
  background: var(--gold);
  color: #000;
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 0.82rem;
  font-weight: 700;
}

#cam-direction-overlay {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  z-index: 10;
  background: rgba(10,20,14,0.8);
  backdrop-filter: blur(12px);
  border-top: 1px solid rgba(200,151,42,0.3);
  padding: 18px 20px;
  padding-bottom: calc(18px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

#cam-turn-arrow {
  font-size: 3rem;
  line-height: 1;
}

#cam-turn-text {
  font-size: 1.4rem;
  font-weight: 700;
  text-align: center;
}
#cam-turn-text b { font-size: 1.6rem; }

#cam-bearings {
  font-size: 0.75rem;
  color: rgba(255,255,255,0.45);
  margin-top: 2px;
}

/* Aim panel */
#cam-aim-panel, #cam-result-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 100%;
}
#cam-aim-panel.hidden, #cam-result-panel.hidden { display: none; }

#cam-compass-val {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--gold);
  letter-spacing: 0.03em;
}

.cam-aim-hint {
  font-size: 0.85rem;
  color: rgba(255,255,255,0.6);
  margin: 0;
  text-align: center;
}

#btn-facing-wall {
  margin-top: 4px;
  padding: 13px 28px;
  background: var(--gold);
  color: #0d2b1a;
  border: none;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 0.01em;
  box-shadow: 0 3px 12px rgba(200,151,42,0.4);
}
#btn-facing-wall:active { transform: scale(0.97); }

.cam-reaim-btn {
  margin-top: 6px;
  padding: 9px 22px;
  background: rgba(255,255,255,0.12);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.25);
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}
.cam-reaim-btn:active { transform: scale(0.97); }

/* ── AR Kaaba marker ────────────────────────────── */
#cam-kaaba-marker {
  position: absolute;
  top: 38%;
  transform: translate(-50%, -50%);
  z-index: 15;
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: none;
  transition: left 0.5s cubic-bezier(0.34, 1.4, 0.64, 1);
}
#cam-kaaba-marker.hidden { display: none; }

.cam-kaaba-icon {
  font-size: 3.2rem;
  line-height: 1;
  filter:
    drop-shadow(0 0 10px rgba(200,151,42,1))
    drop-shadow(0 0 28px rgba(200,151,42,0.7));
  animation: kaaba-pulse 1.8s ease-in-out infinite;
}
@keyframes kaaba-pulse {
  0%,100% { filter: drop-shadow(0 0 10px rgba(200,151,42,1)) drop-shadow(0 0 28px rgba(200,151,42,0.7)); }
  50%      { filter: drop-shadow(0 0 18px rgba(200,151,42,1)) drop-shadow(0 0 50px rgba(200,151,42,0.9)); }
}

.cam-kaaba-beam {
  width: 2px;
  height: 90px;
  background: linear-gradient(to bottom, rgba(200,151,42,0.9) 0%, transparent 100%);
}

.cam-kaaba-deg-label {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--gold);
  background: rgba(0,0,0,0.65);
  padding: 3px 9px;
  border-radius: 8px;
  border: 1px solid rgba(200,151,42,0.5);
  white-space: nowrap;
  margin-top: 4px;
}

/* Centre crosshair */
#cam-crosshair {
  position: absolute;
  top: 38%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 14;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
}
#cam-crosshair.hidden { display: none; }
.crosshair-h {
  width: 44px; height: 2px;
  background: rgba(255,255,255,0.45);
  position: absolute;
  top: 50%; transform: translateY(-50%);
}
.crosshair-v {
  width: 2px; height: 44px;
  background: rgba(255,255,255,0.45);
  position: absolute;
  left: 50%; transform: translateX(-50%);
}
.crosshair-label {
  position: absolute;
  top: 28px;
  font-size: 0.7rem;
  color: rgba(255,255,255,0.55);
  white-space: nowrap;
  background: rgba(0,0,0,0.4);
  padding: 2px 6px;
  border-radius: 6px;
}

/* Edge out-of-frame arrows */
.cam-edge-arrow {
  position: absolute;
  top: 38%;
  transform: translateY(-50%);
  z-index: 16;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--gold);
  background: rgba(0,0,0,0.6);
  border: 1px solid rgba(200,151,42,0.6);
  padding: 8px 10px;
  border-radius: 10px;
  pointer-events: none;
  animation: edge-pulse 1.2s ease-in-out infinite;
  display: flex;
  align-items: center;
  gap: 4px;
}
.cam-edge-arrow.hidden { display: none; }
#cam-edge-left  { left: 10px; }
#cam-edge-right { right: 10px; }
@keyframes edge-pulse {
  0%,100% { opacity: 1; }
  50%      { opacity: 0.45; }
}

