/* ── ⚙️ Settings: popover (desktop) / bottom sheet (phone) ───────────────────── */
/* The panel anchors to the whole #topbar (sticky, so positioned), not to the button. */

#settings-btn { position: relative; min-height: 32px; }
.mb-dot {
  position: absolute; top: -2px; right: -2px;
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--action-hi); border: 2px solid var(--surface-1);
}
.mb-dot[hidden] { display: none; }

#settings-panel {
  position: absolute; right: 12px; top: calc(100% + 4px);
  z-index: 150;
  width: min(360px, calc(100vw - 24px));
  max-height: calc(100vh - 120px); overflow-y: auto;
  padding: 6px 16px 14px;
  background: var(--surface-1); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: 0 12px 40px color-mix(in srgb, var(--shadow) 55%, transparent);
}
#settings-panel[hidden], #settings-backdrop[hidden] { display: none; }
#settings-backdrop { display: none; }

.set-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 0 2px; }
.set-title { font-size: 14px; font-weight: 800; }
.set-close {
  width: 44px; height: 44px; margin-right: -10px;
  font: inherit; font-size: 16px; color: var(--muted);
  background: transparent; border: 0; border-radius: 10px; cursor: pointer;
}
.set-close:hover { color: var(--text); background: var(--surface-3); }

.set-group { padding: 6px 0 4px; border-top: 1px solid var(--line); }
.set-group:first-of-type { border-top: 0; }
.set-group h3 { margin: 6px 0 2px; font-size: 10px; letter-spacing: 1.5px; text-transform: uppercase; color: var(--muted); }

.set-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; min-height: 44px; padding: 6px 0; }
.set-row[hidden] { display: none; }
.set-text { flex: 1 1 160px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.set-name { font-size: 13px; font-weight: 700; color: var(--text); }
.set-help { font-size: 11px; line-height: 1.4; color: var(--muted); }
.set-note { flex-basis: 100%; margin: 0; font-size: 11px; line-height: 1.4; color: var(--action-lilac); }
.set-note[hidden] { display: none; }

/* Switch: the whole 52×44 button is the touch target, the track is drawn inside */
.set-switch {
  position: relative; flex: none; width: 52px; height: 44px;
  background: transparent; border: 0; cursor: pointer; padding: 0;
}
.set-switch::before {
  content: ''; position: absolute; left: 4px; top: 10px; width: 44px; height: 24px; border-radius: 12px;
  background: var(--surface-sunk); border: 1px solid var(--line); transition: background 0.15s;
}
.set-knob {
  position: absolute; left: 8px; top: 14px; width: 16px; height: 16px; border-radius: 50%;
  background: var(--muted); transition: transform 0.15s, background 0.15s;
}
.set-switch[aria-checked="true"]::before { background: var(--action); border-color: var(--action); }
.set-switch[aria-checked="true"] .set-knob { background: var(--text-strong); transform: translateX(20px); }
.set-switch[hidden] { display: none; }
.set-switch:focus-visible, .set-seg-btn:focus-visible, .set-action:focus-visible, .set-range:focus-visible, #settings-btn:focus-visible, .set-close:focus-visible {
  outline: 2px solid var(--action-lilac); outline-offset: 2px;
}

.set-row-range { flex-wrap: nowrap; }
.set-range { flex: 1; min-width: 0; height: 44px; accent-color: var(--action); cursor: pointer; }
.set-range:disabled { opacity: 0.4; cursor: not-allowed; }
.set-out { width: 3.2em; text-align: right; font-size: 12px; font-weight: 700; color: var(--muted); }

.set-seg { display: flex; flex: none; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.set-seg-btn {
  min-height: 44px; min-width: 52px; padding: 0 12px;
  font: inherit; font-size: 12px; font-weight: 700; color: var(--muted);
  background: transparent; border: 0; border-left: 1px solid var(--line); cursor: pointer;
}
.set-seg-btn:first-child { border-left: 0; }
.set-seg-btn:hover { background: var(--surface-3); color: var(--text); }
.set-seg-btn.active { background: var(--action); color: var(--text-strong); }
/* FR → EN greyed while the card on screen is EN → FR by nature; the reason is printed in #set-dir-note */
.set-seg-btn:disabled, .set-seg-btn:disabled:hover { opacity: 0.4; cursor: not-allowed; background: transparent; color: var(--muted); }
.set-seg-btn.active:disabled { background: var(--action); color: var(--text-strong); }

.set-action {
  flex: none; min-height: 44px; padding: 0 16px;
  font: inherit; font-size: 12px; font-weight: 700; color: var(--text);
  background: transparent; border: 1px solid var(--line); border-radius: 22px; cursor: pointer;
}
.set-action:hover { background: var(--surface-3); }
a.set-action { display: inline-flex; align-items: center; text-decoration: none; }

@media (max-width: 720px) {
  #settings-btn { min-height: 44px; min-width: 44px; }
  #settings-backdrop { display: block; position: fixed; inset: 0; z-index: 240; background: color-mix(in srgb, var(--shadow) 55%, transparent); }
  #settings-backdrop[hidden] { display: none; }
  #settings-panel {
    position: fixed; left: 0; right: 0; bottom: 0; top: auto; z-index: 250;
    width: auto; max-height: 85vh; padding: 6px 18px calc(18px + env(safe-area-inset-bottom));
    border-radius: 18px 18px 0 0; border-bottom: 0;
  }
  #settings-panel::before { /* drag-handle look */
    content: ''; display: block; width: 40px; height: 4px; margin: 6px auto 0; border-radius: 2px; background: var(--line);
  }
}

@media (prefers-reduced-motion: reduce) {
  .set-switch::before, .set-knob { transition: none; }
}

.set-row-dir .set-seg { flex: 1 1 100%; }
.set-row-dir .set-seg-btn { flex: 1; }
