/*
 * Controls shared by the tool widgets (all but the Qibla finder, which predates
 * them and keeps its own copies in qibla.css): panels and form fields, buttons,
 * option pills, the list of facts, the status line, and the dial's pointer and
 * markers. Logical properties throughout, so right-to-left pages need nothing.
 * The dial itself, its N/E/S/W labels and the readout pill are in /style.css.
 */

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

/* ---------- buttons, pills, fields ---------- */

.tool-widget > .floating-btn {
  margin-bottom: 20px;
}

.tool-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;
}

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

.tool-button--small {
  min-height: 36px;
  padding: 0 10px;
  font-size: 13px;
}

.tool-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 16px;
}

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

.tool-pill {
  position: relative;
}

.tool-pill input {
  position: absolute;
  inset: 0;
  opacity: 0;
  margin: 0;
  cursor: pointer;
}

.tool-pill 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;
}

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

.tool-panel {
  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;
}

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

.tool-panel__note {
  margin: 0;
  font-size: 13px;
  line-height: 1.45;
  color: var(--ink-soft);
}

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

.tool-field input,
.tool-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 */
}

.tool-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.tool-output {
  min-height: 1.4em;
  margin: 0;
  color: var(--ink);
  font-size: 15px;
  font-weight: 600;
  line-height: 1.4;
}

/* ---------- status line, facts ---------- */

.tool-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;
}

.tool-note {
  max-width: 320px;
  margin: 12px auto 0;
  text-align: center;
  color: var(--ink-soft);
  font-size: 14px;
  line-height: 1.5;
}

.tool-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;
}

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

.tool-fact:first-child {
  border-top: 0;
}

.tool-fact dt {
  flex: 0 1 auto;
  color: var(--ink-soft);
}

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

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

/* ---------- dial: fixed pointer and markers ---------- */

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

/* "This is the way you are facing", above the turning dial. */
.tool-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;
}

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

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

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

.tool-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);
}

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

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

.is-aligned .degree-display {
  background: var(--accent);
}

/* ---------- focus ---------- */

.tool-button:focus-visible,
.tool-field input:focus-visible,
.tool-field select:focus-visible,
.tool-widget .floating-btn:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

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

@media (prefers-reduced-motion: reduce) {
  .tool-pointer,
  .tool-widget .degree-display {
    transition: none;
  }
}
