/*
 * Qibla finder widget. The dial, its N/E/S/W labels and the readout pill come
 * from /style.css (.compass, .compass-circle, .dir, .degree-display); this file
 * adds the destination marker, the facing pointer, the facts and the form.
 */

.qibla {
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ---------- destination switch (two radio buttons drawn as pills) ---------- */

.qibla-target {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-bottom: 16px;
}

.qibla-target__option {
  position: relative;
}

.qibla-target__option input {
  position: absolute;
  inset: 0;
  opacity: 0;
  margin: 0;
  cursor: pointer;
}

.qibla-target__option span {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding-inline: 18px;
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.85);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  color: var(--ink);
  font-size: 15px;
  font-weight: 500;
  user-select: none;
  -webkit-user-select: none;
}

.qibla-target__option input:checked + span {
  background: var(--ink);
  color: #fff;
}

.qibla-target__option input:focus-visible + span {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* ---------- dial ---------- */

.qibla .qibla-start {
  margin-bottom: 20px;
}

.qibla-dial {
  position: relative;
  padding-top: 16px;
}

/* Fixed pointer above the dial: "this is the way you are facing". */
.qibla-pointer {
  position: absolute;
  top: 0;
  left: 50%;
  z-index: 2;
  width: 0;
  height: 0;
  margin-left: -11px;
  border-left: 11px solid transparent;
  border-right: 11px solid transparent;
  border-top: 16px solid var(--ink);
  transition: border-top-color 0.2s ease;
}

.qibla.is-aligned .qibla-pointer {
  border-top-color: var(--accent);
}

/* The destination marker: a full-size overlay rotated to the bearing, like the
   cardinal labels, with its dot in the white rim just outside the letters. */
.compass > .compass-circle > .qibla-marker {
  position: absolute;
  inset: 0;
  transform: rotate(var(--bearing, 0deg));
  pointer-events: none;
}

.compass > .compass-circle > .qibla-marker[hidden] {
  display: none;
}

.qibla-marker__dot {
  position: absolute;
  top: -2.8%;
  left: 50%;
  width: 16px;
  height: 16px;
  margin: -8px 0 0 -8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 2px #fff, 0 1px 5px rgba(0, 0, 0, 0.35);
}

/* ---------- readout, status, facts ---------- */

/* .degree-display sets display:flex, which would override the hidden attribute. */
.qibla .qibla-readout[hidden] {
  display: none;
}

.qibla .qibla-readout {
  max-width: min(340px, 92vw);
  white-space: normal;
  line-height: 1.3;
  transition: background-color 0.2s ease;
}

.qibla.is-aligned .qibla-readout {
  background: var(--accent);
}

.qibla-status {
  min-height: 1.5em;
  max-width: 340px;
  margin: 12px auto 0;
  text-align: center;
  color: var(--ink-soft);
  font-size: 14px;
  line-height: 1.5;
}

.qibla-facts {
  width: min(360px, 100%);
  margin: 16px 0 0;
  padding: 2px 16px;
  box-sizing: border-box;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  font-size: 14px;
}

.qibla-fact {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}

.qibla-fact:first-child,
.qibla-fact--continued {
  border-top: 0;
}

.qibla-fact--continued {
  padding-top: 0;
}

.qibla-fact dt {
  color: var(--ink-soft);
}

.qibla-fact dd {
  margin: 0;
  text-align: end;
  color: var(--ink);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.qibla-fact small {
  font-size: 12px;
  font-weight: 400;
  color: var(--ink-soft);
}

.qibla-accuracy,
.qibla-hint {
  max-width: 300px;
  margin: 12px auto 0;
  text-align: center;
  color: var(--ink-soft);
  font-size: 14px;
  line-height: 1.5;
}

/* ---------- "set your location" form ---------- */

.qibla-manual {
  width: min(360px, 100%);
  margin: 24px 0 0;
  padding: 16px;
  box-sizing: border-box;
  display: grid;
  gap: 12px;
  border-radius: 16px;
  background: var(--surface);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.05);
  text-align: start;
}

.qibla-manual__title {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  color: var(--ink);
}

.qibla-field {
  display: grid;
  gap: 4px;
  font-size: 13px;
  color: var(--ink-soft);
}

.qibla-field input,
.qibla-field select {
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  box-sizing: border-box;
  border: 1px solid #cbd5e0;
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-size: 16px; /* below 16px, iOS Safari zooms the page on focus */
}

.qibla-coords {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.qibla-button {
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid #cbd5e0;
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--ink);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  touch-action: manipulation;
}

.qibla-button--primary {
  border-color: var(--ink-soft);
  background: var(--ink-soft);
  color: #fff;
}

.qibla-button:focus-visible,
.qibla-field input:focus-visible,
.qibla-field select:focus-visible,
.qibla .qibla-start:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  .qibla-pointer,
  .qibla .qibla-readout {
    transition: none;
  }
}
