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

:root {
  --bg-dark:     #0d0d1a;
  --bg-card:     #16213e;
  --bg-inner:    #1a1a2e;
  --gold:        #c9a84c;
  --gold-light:  #f0d080;
  --gold-dark:   #8a6a20;
  --green:       #2ecc71;
  --red:         #e74c3c;
  --text:        #e8e0d0;
  --text-muted:  #8a8a9a;
  --needle-top:  #c9a84c;
  --needle-bot:  #2c3e50;
  --shadow:      0 4px 24px rgba(0,0,0,0.5);
  --radius:      16px;
}

/* ===========================
   Base
   =========================== */
html, body {
  height: 100%;
  background: var(--bg-dark);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

.app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px 16px 32px;
  gap: 16px;
  max-width: 420px;
  margin: 0 auto;
}

/* ===========================
   Header
   =========================== */
.header {
  text-align: center;
  padding-top: env(safe-area-inset-top, 8px);
}

.header-icon {
  font-size: 2rem;
  margin-bottom: 4px;
  color: var(--gold);
}

.header h1 {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--gold-light);
}

.subtitle {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ===========================
   Status Bar
   =========================== */
.status-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-card);
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 0.8rem;
  color: var(--text-muted);
  width: 100%;
  justify-content: center;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: background 0.4s;
  flex-shrink: 0;
}

.status-dot.active { background: var(--green); box-shadow: 0 0 6px var(--green); }
.status-dot.error  { background: var(--red);   box-shadow: 0 0 6px var(--red); }
.status-dot.warn   { background: var(--gold);  box-shadow: 0 0 6px var(--gold); }

/* ===========================
   Compass
   =========================== */
.compass-container {
  position: relative;
  width: min(300px, 78vw);
  height: min(300px, 78vw);
  flex-shrink: 0;
  margin: 8px 0;
}

/* Outer ring — rotates opposite to device heading */
.compass-outer {
  position: absolute;
  inset: 0;
  transition: transform 0.15s ease-out;
}

.compass-ring {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  border: 3px solid var(--gold-dark);
  background: radial-gradient(circle at 50% 50%, #1e1e38, #0d0d1a);
  box-shadow: var(--shadow), inset 0 0 40px rgba(0,0,0,0.6), 0 0 0 1px rgba(201,168,76,0.15);
  position: relative;
}

/* Cardinal directions */
.dir {
  position: absolute;
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--gold-light);
  transform: translate(-50%, -50%);
}
.dir.n { top: 8%;  left: 50%; color: var(--red); }
.dir.s { top: 92%; left: 50%; }
.dir.e { top: 50%; left: 92%; }
.dir.w { top: 50%; left: 8%;  }

/* Tick marks via SVG-less approach */
.tick-marks {
  position: absolute;
  inset: 0;
  border-radius: 50%;
}

/* Inner compass (fixed) */
.compass-inner {
  position: absolute;
  inset: 14%;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, #22223a, #0d0d1a);
  box-shadow: inset 0 2px 12px rgba(0,0,0,0.8), 0 0 0 2px rgba(201,168,76,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Needle wrapper — rotates to Qibla direction */
.needle-wrapper {
  position: absolute;
  width: 100%;
  height: 100%;
  transition: transform 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.needle {
  position: absolute;
  bottom: 50%;
  left: 50%;
  transform: translateX(-50%);
  width: 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
  transform-origin: center bottom;
}

.needle-top {
  width: 28px;
  height: calc(50% - 18px);
  /* Height relative to inner circle */
  height: min(90px, 22vw);
  background: linear-gradient(to bottom, var(--gold), var(--gold-dark));
  clip-path: polygon(50% 0%, 100% 100%, 50% 85%, 0% 100%);
  border-radius: 2px 2px 0 0;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 6px;
  position: relative;
}

.kaaba-icon {
  font-size: 1.1rem;
  margin-top: 4px;
  filter: drop-shadow(0 0 4px rgba(255,255,255,0.3));
}

.needle-bottom {
  width: 20px;
  height: min(55px, 14vw);
  background: linear-gradient(to top, #2c3e50, #3d4f6a);
  clip-path: polygon(50% 100%, 100% 0%, 50% 15%, 0% 0%);
}

/* Center dot */
.center-dot {
  position: absolute;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: radial-gradient(circle, var(--gold-light), var(--gold-dark));
  box-shadow: 0 0 8px var(--gold);
  z-index: 10;
}

/* ===========================
   Info Panel
   =========================== */
.info-panel {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  width: 100%;
}

.info-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 14px 8px;
  text-align: center;
  border: 1px solid rgba(201,168,76,0.1);
  box-shadow: var(--shadow);
  transition: border-color 0.3s;
}

.info-card.active {
  border-color: rgba(201,168,76,0.4);
}

.info-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.info-value {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--gold-light);
  font-variant-numeric: tabular-nums;
}

.info-sub {
  font-size: 0.62rem;
  color: var(--text-muted);
  margin-top: 3px;
}

/* ===========================
   Location Info
   =========================== */
.location-info {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: center;
  background: var(--bg-card);
  padding: 8px 16px;
  border-radius: 20px;
  width: 100%;
}

/* ===========================
   Accuracy Bar
   =========================== */
.accuracy-bar {
  width: 100%;
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.accuracy-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.accuracy-track {
  height: 6px;
  background: #2a2a3e;
  border-radius: 3px;
  overflow: hidden;
}

.accuracy-fill {
  height: 100%;
  border-radius: 3px;
  background: linear-gradient(to right, var(--red), var(--gold), var(--green));
  width: 0%;
  transition: width 0.5s;
}

.accuracy-text {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-align: right;
}

/* ===========================
   Permission Section
   =========================== */
.permission-section {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.permission-note {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ===========================
   Buttons
   =========================== */
.btn-primary {
  background: linear-gradient(135deg, var(--gold), var(--gold-dark));
  color: #1a1206;
  font-weight: 700;
  font-size: 0.9rem;
  padding: 14px 28px;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(201,168,76,0.4);
  transition: transform 0.1s, box-shadow 0.1s;
  -webkit-tap-highlight-color: transparent;
}

.btn-primary:active {
  transform: scale(0.97);
  box-shadow: 0 2px 8px rgba(201,168,76,0.3);
}

.btn-secondary {
  background: transparent;
  color: var(--gold);
  font-weight: 600;
  font-size: 0.85rem;
  padding: 10px 24px;
  border: 1px solid var(--gold-dark);
  border-radius: 10px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

/* ===========================
   Alert Overlay
   =========================== */
.alert-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(4px);
}

.alert-box {
  background: var(--bg-card);
  border: 1px solid rgba(201,168,76,0.3);
  border-radius: 20px;
  padding: 28px 24px;
  text-align: center;
  max-width: 300px;
  margin: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: var(--shadow);
}

.alert-icon { font-size: 2rem; }
.alert-box p { font-size: 0.9rem; color: var(--text-muted); line-height: 1.5; }

/* ===========================
   Animations
   =========================== */
@keyframes pulse-glow {
  0%, 100% { box-shadow: 0 0 6px var(--green); }
  50%       { box-shadow: 0 0 14px var(--green); }
}

.status-dot.active {
  animation: pulse-glow 2s infinite;
}

@keyframes spin-in {
  from { transform: rotate(-180deg) scale(0.5); opacity: 0; }
  to   { transform: rotate(0deg) scale(1); opacity: 1; }
}

.compass-container {
  animation: spin-in 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

/* ===========================
   Responsive tweaks
   =========================== */
@media (max-height: 700px) {
  .app { gap: 10px; }
  .compass-container { width: min(240px, 65vw); height: min(240px, 65vw); }
  .info-card { padding: 10px 6px; }
  .info-value { font-size: 1.15rem; }
}

@media (prefers-color-scheme: light) {
  /* Keep dark for this app — compass looks better dark */
}
