/**
 * FindMyQibla — tool styles (fmq-tool.css)
 * Brand v4: navy instrument (#101C2D) on any page, ivory text, gold reserved
 * for the Qibla pointer + key numerals on dark, emerald actions.
 * Every selector is prefixed .fmq- — zero leakage into the theme.
 * Mobile-first: 320 / 390 / 768 / 1024 / 1440.
 */

/* ---------- tokens (scoped, not :root) ---------- */
.fmq-tool {
  /* Clear sticky site headers on anchor jumps (QA: tabs hidden under header). */
  scroll-margin-top: 88px;
/* Mobile QA: the theme header shrinks to 56px under 640px — keep in sync. */
@media (max-width:640px){
  .fmq-tool{scroll-margin-top:76px}
}
  --fmq-navy: #101C2D;
  --fmq-navy-2: #18293D;
  --fmq-ivory: #F8F6F0;
  --fmq-ivory-dim: rgba(248, 246, 240, 0.72);
  --fmq-ivory-faint: rgba(248, 246, 240, 0.45);
  --fmq-gold: #D5A62D;
  --fmq-emerald: #086C69;
  --fmq-emerald-dark: #075653;
  --fmq-white: #FFFFFF;
  --fmq-line: rgba(248, 246, 240, 0.16);
  --fmq-radius: 16px;
}

/* ---------- tool shell ---------- */
.fmq-tool {
  background: var(--fmq-navy);
  color: var(--fmq-ivory);
  border-radius: 20px;
  padding: 20px 16px;
  max-width: 1080px;
  margin-inline: auto;
  font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.55;
  box-sizing: border-box;
  overflow-wrap: break-word;
  /* Phone QA: hard containment — nothing inside the card may ever bleed past
     its rounded border, even if a child miscalculates its width. */
  overflow: clip;
}
.fmq-tool *,
.fmq-tool *::before,
.fmq-tool *::after { box-sizing: border-box; }

.fmq-tool--light {
  background: var(--fmq-ivory);
  color: #192B34;
  border: 1px solid #E4DFD3;
  --fmq-ivory-dim: rgba(25, 43, 52, 0.78);
  --fmq-ivory-faint: rgba(25, 43, 52, 0.5);
  --fmq-line: rgba(16, 28, 45, 0.14);
}

.fmq-tool h2, .fmq-tool h3 {
  color: inherit;
  line-height: 1.3;
  margin: 0 0 12px;
}
.fmq-tool h2 { font-size: 24px; }
.fmq-tool h3 { font-size: 18px; }
.fmq-tool p { margin: 0 0 12px; }
.fmq-tool button { font: inherit; }

/* Visible focus everywhere inside the tool. Gold on the dark instrument,
   emerald on the light variant (gold fails contrast on ivory). */
.fmq-tool :focus-visible {
  outline: 3px solid var(--fmq-gold);
  outline-offset: 2px;
  border-radius: 6px;
}
.fmq-tool--light :focus-visible { outline-color: var(--fmq-emerald); }

/* ---------- layout ---------- */
.fmq-tool-grid { display: grid; gap: 24px; }
/* Phone QA: grid items default to min-width:auto, which lets wide children
   (tabs, buttons) force the whole tool wider than the viewport. Force shrink. */
.fmq-tool-grid > *{min-width:0}
@media (min-width: 900px) {
  .fmq-tool-grid { grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); align-items: start; }
  .fmq-tool { padding: 32px; }
}

/* ---------- compass ---------- */
.fmq-compass-wrap { width:100%; max-width: 360px; margin-inline: auto; }
/* Mobile QA + user: the compass column's buttons had inconsistent alignment
   (centered dial, full-width actions, left-aligned help link). Center the
   whole column with consistent rhythm, capped at the dial width. */
.fmq-compass-col{display:flex;flex-direction:column;align-items:center}
/* Desktop QA: the single "Enable live compass" button must be centered over the
   Compass dial/Arrow segmented controls — use flex centering, not width:100%
   (which defeats align-items:center by filling the whole row). */
.fmq-compass-col .fmq-actions{display:flex;justify-content:center;width:100%;max-width:360px}
.fmq-compass-col .fmq-actions .fmq-btn{width:auto;min-width:200px}
.fmq-compass-col .fmq-view-switch{width:100%;max-width:360px;margin-inline:auto}
.fmq-compass-col .fmq-reset-link{text-align:center}
.fmq-compass-wrap svg { width: 100%; height: auto; display: block; }

.fmq-compass-status {
  font-size: 14px;
  color: var(--fmq-ivory-dim);
  text-align: center;
  margin: 12px 0 0;
  min-height: 44px;
  /* Phone QA: long status text was clipped on narrow screens — force wrap. */
  max-width: 100%;
  overflow-wrap: anywhere;
}
.fmq-compass-status--live { color: var(--fmq-ivory); }
.fmq-compass-status--live::before {
  content: "";
  display: inline-block;
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--fmq-gold);
  margin-inline-end: 8px;
}

.fmq-view-switch {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-top: 12px;
}
.fmq-seg {
  min-height: 44px;
  padding: 10px 18px;
  border-radius: 999px;
  border: 1px solid var(--fmq-line);
  background: transparent;
  color: var(--fmq-ivory-dim);
  cursor: pointer;
}
.fmq-tool--light .fmq-seg { color: rgba(25,43,52,.78); }
.fmq-seg--active {
  background: var(--fmq-emerald);
  border-color: var(--fmq-emerald);
  color: #fff;
  font-weight: 600;
}

/* ---------- buttons ---------- */
.fmq-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 48px;
  padding: 12px 22px;
  border-radius: 999px; /* pill: matches the theme's button language (QA r2) */
  border: 1px solid transparent;
  background: var(--fmq-emerald);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
  width: 100%;
}
.fmq-btn:hover { background: var(--fmq-emerald-dark); }
.fmq-btn:disabled { opacity: 0.55; cursor: wait; }
.fmq-btn--gold { background: var(--fmq-gold); color: var(--fmq-navy); }
.fmq-btn--gold:hover { background: #C2951F; }
.fmq-btn--ghost {
  background: transparent;
  border-color: var(--fmq-line);
  color: var(--fmq-ivory);
  font-weight: 500;
}
.fmq-tool--light .fmq-btn--ghost { color: #192B34; }
.fmq-btn--ghost:hover { border-color: var(--fmq-ivory-faint); background: rgba(248,246,240,.06); }
.fmq-btn--inline { width: auto; }
.fmq-actions { display: grid; gap: 10px; margin-top: 16px; }
@media (min-width: 560px) {
  .fmq-actions { grid-template-columns: 1fr 1fr; }
}

/* ---------- tabs ---------- */
.fmq-tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--fmq-line);
  margin-bottom: 20px;
  overflow-x: auto;
}
.fmq-tab {
  flex: 1 1 0;
  min-width: 0; /* allow shrinking below content size on narrow phones */
  min-height: 48px;
  padding: 12px 8px;
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  color: var(--fmq-ivory-dim);
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.fmq-tab--active { color: var(--fmq-gold); border-bottom-color: var(--fmq-gold); }
/* Hover feedback on tabs + segmented controls (QA r2: only active was styled). */
.fmq-tab:not(.fmq-tab--active):hover { color: var(--fmq-ivory); background: rgba(248,246,240,.06); }
.fmq-seg:not(.fmq-seg--active):hover { border-color: var(--fmq-ivory-faint); color: var(--fmq-ivory); background: rgba(248,246,240,.05); }
.fmq-tool--light .fmq-tab:not(.fmq-tab--active):hover { color: #192B34; background: rgba(16,28,45,.05); }
.fmq-tool--light .fmq-seg:not(.fmq-seg--active):hover { border-color: rgba(16,28,45,.35); color: #192B34; background: rgba(16,28,45,.05); }
.fmq-tool--light .fmq-tab { color: rgba(25,43,52,.7); }
.fmq-tool--light .fmq-tab--active { color: var(--fmq-emerald); border-bottom-color: var(--fmq-emerald); }
.fmq-panel { padding: 4px 2px 8px; }

/* ---------- forms ---------- */
.fmq-label {
  display: block;
  font-weight: 600;
  font-size: 15px;
  margin-bottom: 8px;
}
.fmq-input, .fmq-select {
  width: 100%;
  min-height: 48px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--fmq-line);
  background: var(--fmq-navy-2);
  color: var(--fmq-ivory);
  font-size: 16px; /* 16px+ stops iOS zoom on focus */
}
.fmq-tool--light .fmq-input {
  background: #fff;
  color: #192B34;
  border-color: rgba(16,28,45,.2);
}
.fmq-input::placeholder { color: var(--fmq-ivory-faint); }
.fmq-coords-row { display: grid; gap: 12px; }
@media (min-width: 560px) { .fmq-coords-row { grid-template-columns: 1fr 1fr; } }
.fmq-hint { font-size: 14px; color: var(--fmq-ivory-dim); margin-top: 8px; }
.fmq-error {
  font-size: 14px;
  color: #F2B8B5;
  background: rgba(178, 44, 38, 0.22);
  border: 1px solid rgba(242, 184, 181, 0.4);
  border-radius: 10px;
  padding: 10px 12px;
  margin-top: 10px;
}
.fmq-tool--light .fmq-error { color: #8C1D18; background: #FDECEA; border-color: #F5C6C2; }
.fmq-status { font-size: 14px; color: var(--fmq-ivory-dim); margin-top: 10px; min-height: 22px; }
.fmq-status--pending { color: var(--fmq-ivory); }
.fmq-status--error { color: #F2B8B5; }
.fmq-tool--light .fmq-status--error { color: #8C1D18; }

/* city autocomplete */
.fmq-city-wrap { position: relative; }
.fmq-city-list {
  list-style: none;
  margin: 6px 0 0;
  padding: 6px;
  position: absolute;
  inset-inline: 0;
  top: 100%;
  z-index: 20;
  background: var(--fmq-navy-2);
  border: 1px solid var(--fmq-line);
  border-radius: 12px;
  max-height: 264px;
  overflow-y: auto;
}
.fmq-tool--light .fmq-city-list { background: #fff; border-color: rgba(16,28,45,.18); }
.fmq-city-option {
  padding: 12px;
  min-height: 44px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--fmq-ivory);
}
.fmq-tool--light .fmq-city-option { color: #192B34; }
.fmq-city-option--active, .fmq-city-option:hover {
  background: var(--fmq-emerald);
  color: #fff;
}

/* ---------- results ---------- */
.fmq-results { margin-top: 8px; }
/* Success feedback: brief gold pulse on the cards when a bearing computes. */
@keyframes fmq-result-flash {
  0% { box-shadow: 0 0 0 0 rgba(213,166,45,.55); }
  100% { box-shadow: 0 0 0 16px rgba(213,166,45,0); }
}
.fmq-results--flash .fmq-result-card { animation: fmq-result-flash .9s ease-out; }
.fmq-result-cards {
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr 1fr;
  margin: 16px 0;
}
/* Mobile QA: at 320–360px each card is ~126–150px wide but "4793.8 km"
   at 34px needs ~170px — stack to one column under 480px. */
@media (max-width:480px){
  .fmq-result-cards{grid-template-columns:1fr}
}
/* Mobile QA: shorten tab labels on phones so the row never needs to
   scroll sideways ("Use My Location" → "Location", etc.). */
.fmq-tab-label-short{display:none}
@media (max-width:480px){
  .fmq-tab-label-full{display:none}
  .fmq-tab-label-short{display:inline}
  .fmq-tab{padding-left:4px;padding-right:4px;overflow:hidden;text-overflow:ellipsis}
}
.fmq-result-card {
  background: var(--fmq-navy-2);
  border: 1px solid var(--fmq-line);
  border-radius: var(--fmq-radius);
  padding: 16px 14px;
  text-align: center;
}
.fmq-tool--light .fmq-result-card { background: #fff; }
.fmq-result-label {
  display: block;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--fmq-ivory-dim);
  margin-bottom: 6px;
}
.fmq-result-num {
  display: block;
  font-size: 34px;
  font-weight: 700;
  color: var(--fmq-gold); /* gold numerals on navy: ~8.1:1, AA pass */
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
}
.fmq-tool--light .fmq-result-num { color: var(--fmq-emerald); } /* gold fails on ivory — emerald instead */
.fmq-result-sub { display: block; font-size: 14px; color: var(--fmq-ivory-dim); margin-top: 4px; }
.fmq-result-place { font-size: 17px; font-weight: 600; }
.fmq-result-coords { font-size: 14px; color: var(--fmq-ivory-dim); font-variant-numeric: tabular-nums; }
.fmq-result-note {
  border-inline-start: 3px solid var(--fmq-gold);
  padding-inline-start: 12px;
  font-size: 15px;
  margin: 16px 0;
}
.fmq-copy-msg { font-size: 14px; color: var(--fmq-ivory-dim); margin-top: 8px; min-height: 22px; }
.fmq-copy-msg--error { color: #F2B8B5; }

/* aligned ("Facing Qibla") — restrained: gold ring + badge, never fake */
.fmq-aligned-badge {
  display: none;
  text-align: center;
  font-weight: 700;
  color: var(--fmq-navy);
  background: var(--fmq-gold);
  border-radius: 999px;
  padding: 10px 18px;
  margin: 12px auto 0;
  max-width: max-content;
}
.fmq-tool--aligned .fmq-aligned-badge { display: block; }
.fmq-tool--aligned .fmq-compass-wrap svg {
  filter: drop-shadow(0 0 18px rgba(213, 166, 45, 0.35));
}

/* Inline spinner for the GPS button while locating (QA r2). */
.fmq-spinner {
  display: inline-block;
  flex: none;
  width: 1em; height: 1em;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: fmq-spin .7s linear infinite;
}
@keyframes fmq-spin { to { transform: rotate(360deg); } }

/* ---------- share ---------- */
.fmq-share { display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.fmq-share a {
  flex: 1 1 0;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--fmq-line);
  border-radius: 999px;
  color: var(--fmq-ivory);
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
  padding: 10px 8px;
  white-space: nowrap;
}
.fmq-share a:hover { border-color: var(--fmq-gold); color: var(--fmq-gold); }

/* ---------- settings ---------- */
.fmq-settings { margin-top: 24px; border-top: 1px solid var(--fmq-line); padding-top: 20px; }
.fmq-settings summary {
  min-height: 44px;
  cursor: pointer;
  font-weight: 600;
  font-size: 16px;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.fmq-settings summary::-webkit-details-marker { display: none; }
/* Chevron indicator on the Settings toggle — rotates open/closed (QA r2:
   it looked like a static label). */
.fmq-settings summary::after {
  content: "";
  flex: none;
  width: 10px; height: 10px;
  margin-inline-start: 12px;
  border-right: 2px solid var(--fmq-gold);
  border-bottom: 2px solid var(--fmq-gold);
  transform: rotate(45deg);
  transition: transform .2s ease;
}
.fmq-settings[open] summary::after { transform: rotate(225deg); }
.fmq-setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 0;
  border-top: 1px solid var(--fmq-line);
  min-height: 56px;
}
.fmq-setting-row .fmq-setting-label { font-size: 15px; }
.fmq-setting-row .fmq-setting-desc { display: block; font-size: 13px; color: var(--fmq-ivory-dim); font-weight: 400; }
.fmq-switch { position: relative; width: 56px; height: 32px; flex: none; }
.fmq-switch input {
  position: absolute; inset: 0;
  opacity: 0; margin: 0; cursor: pointer;
  width: 56px; height: 32px;
}
.fmq-switch-track {
  position: absolute; inset: 0;
  border-radius: 999px;
  background: rgba(248,246,240,.22);
  transition: background 0.2s;
  pointer-events: none;
}
.fmq-switch-thumb {
  position: absolute; top: 4px; inset-inline-start: 4px;
  width: 24px; height: 24px; border-radius: 50%;
  background: #fff;
  transition: transform 0.2s;
  pointer-events: none;
}
.fmq-switch input:checked + .fmq-switch-track { background: var(--fmq-emerald); }
.fmq-switch input:checked + .fmq-switch-track .fmq-switch-thumb { transform: translateX(24px); }
[dir="rtl"] .fmq-switch input:checked + .fmq-switch-track .fmq-switch-thumb { transform: translateX(-24px); }
.fmq-switch input:focus-visible ~ .fmq-switch-track { outline: 3px solid var(--fmq-gold); outline-offset: 2px; }

/* Idle dial: dimmed until a real bearing exists (needle hidden by JS). */
.fmq-compass--idle .fmq-svg-dial,
.fmq-compass--idle .fmq-svg-arrow { opacity: .55; }

/* ---------- guide ---------- */
.fmq-guide {
  margin-top: 20px;
  border: 1px solid var(--fmq-line);
  border-radius: var(--fmq-radius);
  padding: 16px;
  background: rgba(248,246,240,.04);
}
.fmq-tool--light .fmq-guide { background: rgba(16,28,45,.04); }
.fmq-guide ol { margin: 8px 0 12px; padding-inline-start: 22px; }
.fmq-guide li { margin-bottom: 8px; font-size: 15px; }

/* Small "Show guide" link offered after the guide is dismissed (QA r2). */
.fmq-guide-reopen-link {
  background: none;
  border: none;
  padding: 8px 4px;
  margin-top: 4px;
  color: var(--fmq-ivory-dim);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
  font-size: 14px;
  min-height: 44px;
}
.fmq-guide-reopen-link:hover { color: var(--fmq-gold); }

/* ---------- calibrate ---------- */
.fmq-calibrate-panel {
  border: 1px solid var(--fmq-line);
  border-radius: var(--fmq-radius);
  padding: 16px;
  margin-top: 12px;
  font-size: 15px;
}
.fmq-calibrate-panel ol { margin: 8px 0; padding-inline-start: 22px; }
.fmq-calibrate-panel li { margin-bottom: 8px; }
.fmq-calibrate-warn, .fmq-calibrate-note {
  font-size: 14px;
  color: var(--fmq-ivory-dim);
  border-top: 1px solid var(--fmq-line);
  padding-top: 10px;
  margin-top: 10px;
}

/* ---------- map ---------- */
.fmq-map-wrap { margin-top: 20px; }
.fmq-leaflet { height: 320px; border-radius: var(--fmq-radius); z-index: 0; }
.fmq-leaflet .fmq-marker-dot {
  display: block; width: 18px; height: 18px; border-radius: 50%;
  background: var(--fmq-emerald); border: 3px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,.4);
}
.fmq-leaflet .fmq-marker-diamond {
  display: block; width: 16px; height: 16px;
  background: var(--fmq-gold);
  border: 2px solid var(--fmq-navy);
  transform: rotate(45deg);
  box-shadow: 0 1px 4px rgba(0,0,0,.4);
}
.fmq-map-readout { font-size: 14px; color: var(--fmq-ivory-dim); margin-top: 10px; font-variant-numeric: tabular-nums; }
.fmq-map-fallback, .fmq-map-note {
  font-size: 15px;
  border: 1px solid var(--fmq-line);
  border-radius: var(--fmq-radius);
  padding: 14px;
  margin-top: 12px;
}

/* ---------- misc ---------- */
.fmq-divider { border: none; border-top: 1px solid var(--fmq-line); margin: 20px 0; }
.fmq-reset-link {
  background: none; border: none; padding: 12px 0;
  color: var(--fmq-ivory-dim); text-decoration: underline;
  cursor: pointer; font-size: 15px; min-height: 44px;
}
.fmq-reset-link:hover { color: var(--fmq-ivory); }
/* Chevron on the compass-help toggle, rotating with aria-expanded. */
.fmq-reset-link[data-fmq="calibrate"]::after {
  content: "";
  display: inline-block;
  width: 8px; height: 8px;
  margin-inline-start: 8px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
  transition: transform .2s ease;
  vertical-align: 2px;
}
.fmq-reset-link[data-fmq="calibrate"][aria-expanded="true"]::after { transform: rotate(225deg); }
.fmq-eyebrow {
  font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--fmq-gold); font-weight: 700; margin-bottom: 8px;
}
.fmq-tool--light .fmq-eyebrow { color: var(--fmq-emerald); }

/* Screen-reader only */
.fmq-sr {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* No horizontal scroll, ever */
.fmq-tool img, .fmq-tool svg, .fmq-tool iframe { max-width: 100%; }

/* ---------- breakpoints ---------- */
@media (min-width: 390px) {
  .fmq-tool { padding: 24px 20px; }
}
@media (min-width: 768px) {
  .fmq-tool h2 { font-size: 28px; }
  .fmq-result-num { font-size: 40px; }
  .fmq-leaflet { height: 400px; }
}
@media (min-width: 1024px) {
  .fmq-tool-grid { gap: 32px; }
}
@media (min-width: 1440px) {
  .fmq-tool { max-width: 1140px; }
}

/* Reduced motion: kill transitions */
@media (prefers-reduced-motion: reduce) {
  .fmq-tool *, .fmq-tool *::before, .fmq-tool *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
