/* ============================================================
   EXPAT COMPASS — Progressive enhancement layer
   Loaded after style.css on every page. Everything here degrades
   gracefully: older browsers simply ignore what they don't know.
   Contents:
     1. Cross-page view transitions
     4. Scroll-driven reveals (+ reduced-motion opt-out)
     5. Micro-interactions (buttons, cards, result pop)
     6. Accessibility: skip link, focus-visible
   ============================================================ */

/* ---------- 1. View transitions (app-like page fades) ---------- */
@view-transition { navigation: auto; }
::view-transition-old(root) { animation: 160ms ease-out both vt-fade-out; }
::view-transition-new(root) { animation: 200ms ease-in  both vt-fade-in; }
@keyframes vt-fade-out { to { opacity: 0; } }
@keyframes vt-fade-in  { from { opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
  ::view-transition-old(root), ::view-transition-new(root) { animation: none; }
}

/* ---------- 4. Scroll reveals ----------
   enhance.js tags candidates with .reveal, then flips .in when they
   enter the viewport. Opacity/transform only — zero layout shift. */
.reveal { opacity: 0; transform: translateY(14px); }
.reveal.in {
  opacity: 1; transform: none;
  transition: opacity .55s ease, transform .55s cubic-bezier(.22,1,.36,1);
  transition-delay: var(--reveal-delay, 0ms);
}
/* If JS never runs, or user prefers stillness, everything is visible */
@media (prefers-reduced-motion: reduce) {
  .reveal { opacity: 1; transform: none; transition: none; }
}
html.no-io .reveal { opacity: 1; transform: none; }

/* ---------- 5. Micro-interactions ---------- */
@media (prefers-reduced-motion: no-preference) {
  .btn { transition: background .15s ease, transform .18s cubic-bezier(.34,1.56,.64,1), border-color .15s ease, box-shadow .18s ease; }
  .btn:hover { transform: translateY(-1px); }
  .btn:active { transform: translateY(0) scale(.97); }
  .btn-primary:hover, .btn-amber:hover { box-shadow: 0 6px 18px rgba(15,61,62,.22); }

  a.calc-card { transition: transform .22s cubic-bezier(.22,1,.36,1), box-shadow .22s ease, border-color .22s ease; }
  a.calc-card:hover { transform: translateY(-4px); }
  a.calc-card:hover .ci { transform: scale(1.07) rotate(-3deg); }
  .calc-card .ci { transition: transform .25s cubic-bezier(.34,1.56,.64,1); }
  a.calc-card .go { transition: gap .18s ease; }
  a.calc-card:hover .go { gap: 10px; }

  /* Result value pop — applied by the count-up animator */
  .num-pop { animation: num-pop .45s cubic-bezier(.22,1,.36,1); }
  @keyframes num-pop { 0% { transform: scale(.96); } 55% { transform: scale(1.025); } 100% { transform: none; } }
}

/* ---------- 6. Accessibility ---------- */
.skip-link {
  position: absolute; left: 16px; top: -48px; z-index: 100;
  background: var(--teal-700); color: #fff; font-weight: 600;
  padding: 10px 18px; border-radius: 0 0 12px 12px;
  transition: top .15s ease;
}
.skip-link:focus { top: 0; text-decoration: none; }

:focus-visible {
  outline: 3px solid var(--teal-500);
  outline-offset: 2px;
  border-radius: 4px;
}
.btn:focus-visible, .choice:focus-visible { outline-offset: 3px; }
input:focus-visible, select:focus-visible { outline: none; } /* keep existing ring */

/* ---------- 7. Tool finder (palette + nav button + wizard) ---------- */
.finder-btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 14px; border-radius: var(--radius-pill);
  border: 1.5px solid var(--line); background: transparent;
  color: var(--ink-faint); font-family: var(--font); font-size: .88rem; font-weight: 500;
  cursor: pointer; transition: border-color .15s ease, color .15s ease;
}
.finder-btn:hover { border-color: var(--teal-500); color: var(--teal-700); }
.finder-btn svg { width: 15px; height: 15px; }
.finder-btn kbd {
  font-family: var(--font); font-size: .7rem; font-weight: 600;
  border: 1px solid var(--line); border-radius: 5px; padding: 1px 5px; color: var(--ink-faint);
}
@media (max-width: 1200px) {
  .finder-btn kbd, .finder-btn span { display: none; }
  .finder-btn { padding: 9px; border-radius: 50%; }
}

.finder-overlay {
  position: fixed; inset: 0; z-index: 200; display: none;
  background: rgba(15, 40, 38, .45); backdrop-filter: blur(3px);
  padding: 12vh 16px 0;
}
.finder-overlay.open { display: block; animation: finder-fade .18s ease; }
@keyframes finder-fade { from { opacity: 0; } }
.finder {
  max-width: 620px; margin: 0 auto; overflow: hidden;
  background: var(--paper); border: 1px solid var(--line);
  border-radius: var(--radius-lg); box-shadow: 0 24px 80px rgba(0,0,0,.35);
  animation: finder-pop .22s cubic-bezier(.22,1,.36,1);
}
@keyframes finder-pop { from { opacity: 0; transform: translateY(10px) scale(.98); } }
@media (prefers-reduced-motion: reduce) { .finder, .finder-overlay.open { animation: none; } }
.finder-head { display: flex; align-items: center; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.finder-head svg { width: 19px; height: 19px; color: var(--ink-faint); flex: none; }
.finder-head input {
  flex: 1; border: none !important; box-shadow: none !important; padding: 0 !important;
  font-size: 1.05rem; background: transparent !important; color: var(--ink);
}
.finder-head input:focus { outline: none !important; }
.finder-head kbd { font-size: .7rem; color: var(--ink-faint); border: 1px solid var(--line); border-radius: 5px; padding: 2px 6px; }
.finder-list { list-style: none; margin: 0; padding: 8px; max-height: 52vh; overflow-y: auto; }
.finder-list li {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 12px; border-radius: 12px; cursor: pointer;
}
.finder-list li.sel { background: var(--teal-50); }
.finder-list .fr-flag { flex: none; font-size: 1.1rem; }
.finder-list .fr-body { flex: 1; min-width: 0; }
.finder-list .fr-body b { display: block; font-size: .95rem; color: var(--ink); font-weight: 600; }
.finder-list .fr-body small { display: block; font-size: .8rem; color: var(--ink-faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fr-prem {
  flex: none; font-size: .6rem; font-weight: 800; letter-spacing: .06em;
  color: var(--amber-600); border: 1.5px solid var(--amber-500);
  border-radius: var(--radius-pill); padding: 3px 8px;
}
.finder-empty { color: var(--ink-faint); font-size: .92rem; padding: 18px 12px !important; cursor: default !important; }
.finder-foot { display: flex; gap: 18px; padding: 10px 18px; border-top: 1px solid var(--line); font-size: .74rem; color: var(--ink-faint); }

/* Wizard */
.wiz-q { margin-bottom: 26px; }
.wiz-q h3 { display: inline; margin: 0 0 0 10px; font-size: 1.08rem; vertical-align: middle; }
.wiz-num {
  display: inline-grid; place-items: center; vertical-align: middle;
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--teal-700); color: #fff; font-weight: 800; font-size: .88rem;
}
.wiz-chips { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
.wiz-chip {
  text-align: left; cursor: pointer; font-family: var(--font);
  padding: 12px 18px; border: 1.5px solid var(--line); border-radius: var(--radius-sm);
  background: var(--paper); transition: border-color .15s ease, background .15s ease, transform .15s ease;
}
.wiz-chip:hover { border-color: var(--teal-500); transform: translateY(-1px); }
.wiz-chip.active { border-color: var(--teal-600); background: var(--teal-50); }
.wiz-chip b { display: block; font-size: .95rem; color: var(--ink); font-weight: 600; }
.wiz-chip small { display: block; font-size: .78rem; color: var(--ink-faint); margin-top: 2px; }
.wiz-results h3 { font-size: 1.08rem; margin: 4px 0 14px; }
.wiz-recs { display: grid; gap: 12px; }
.wiz-rec {
  display: flex; align-items: center; gap: 14px;
  padding: 16px 18px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--paper); color: inherit;
  transition: border-color .18s ease, transform .18s ease, box-shadow .18s ease;
}
.wiz-rec:hover { text-decoration: none; border-color: var(--teal-500); transform: translateY(-2px); box-shadow: var(--shadow-md); }
.wiz-step {
  flex: none; display: grid; place-items: center;
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--amber-50); color: var(--amber-600); font-weight: 800; font-size: .85rem;
}
.wiz-rec b { display: block; font-size: .97rem; color: var(--ink); font-weight: 600; }
.wiz-rec small { display: block; font-size: .82rem; color: var(--ink-faint); margin-top: 2px; }

/* ---------- 8. Premium gate (js/gate.js) ---------- */
.gate-ribbon {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px;
  margin: 0 0 22px; padding: 12px 18px;
  border: 1.5px solid var(--amber-500); border-radius: var(--radius-sm);
  background: var(--amber-50); font-size: .9rem; color: var(--ink-soft);
}
.gate-ribbon-tag { font-weight: 700; color: var(--amber-600); white-space: nowrap; }
.gate-ribbon a { font-weight: 600; margin-left: auto; white-space: nowrap; }

.gate-locked { filter: blur(5px) saturate(.8); pointer-events: none; user-select: none; }
.gate-overlay { position: relative; z-index: 5; display: grid; place-items: center; margin-bottom: -80px; min-height: 80px; }
.gate-card {
  max-width: 460px; text-align: center; padding: 34px 30px;
  background: var(--paper); border: 1px solid var(--line);
  border-radius: var(--radius-lg); box-shadow: 0 18px 60px rgba(0,0,0,.18);
}
.gate-icon { font-size: 2.2rem; margin-bottom: 10px; }
.gate-card h2 { font-size: 1.3rem; margin-bottom: 8px; }
.gate-card p { font-size: .95rem; }
.gate-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 18px; }
