/* ---------------------------------------------------------------------
   Design goals: big touch targets (>=48px, mostly 56-64px), generous
   spacing, strong contrast, and font size that scales from one place
   (--font-scale) so the "A+/A-" controls affect every screen at once.
   ------------------------------------------------------------------- */

:root {
  --font-scale: 1;
  --base-font: 19px;

  --header-h: 64px;
  --footer-h: 76px;
  --radius: 14px;

  --bg: #f6f7f5;
  --surface: #ffffff;
  --text: #1c1c1c;
  --text-muted: #55605a;
  --border: #d8ded9;
  --accent: #2c7a4b;
  --accent-contrast: #ffffff;
  --danger: #b3261e;
  --focus: #0b5fff;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
  --visited-tint: #eaf6ec;
}

:root[data-theme="dark"] {
  --bg: #14181a;
  --surface: #1f2427;
  --text: #f1f3f2;
  --text-muted: #b9c2bd;
  --border: #33393c;
  --accent: #57c07f;
  --accent-contrast: #08210f;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
  --visited-tint: #16261b;
}

:root[data-theme="contrast"] {
  --bg: #000000;
  --surface: #000000;
  --text: #ffffff;
  --text-muted: #ffff00;
  --border: #ffffff;
  --accent: #ffff00;
  --accent-contrast: #000000;
  --focus: #00ffff;
  --shadow: none;
  /* keep the strict black/white/yellow palette in high-contrast mode —
     no separate tint color; the ✓ badge + border alone carry the meaning */
  --visited-tint: transparent;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]):not([data-theme="contrast"]) {
    --bg: #14181a; --surface: #1f2427; --text: #f1f3f2; --text-muted: #b9c2bd;
    --border: #33393c; --accent: #57c07f; --accent-contrast: #08210f;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.5); --visited-tint: #16261b;
  }
}

* { box-sizing: border-box; }

html {
  font-size: calc(var(--base-font) * var(--font-scale));
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}

button {
  font-family: inherit;
  font-size: 1rem;
  cursor: pointer;
}

.skip-link {
  position: absolute; left: -999px; top: 0;
}
.skip-link:focus {
  left: 8px; top: 8px; z-index: 1000;
  background: var(--accent); color: var(--accent-contrast);
  padding: 0.5em 1em; border-radius: 8px;
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

/* ---------------- Header ---------------- */

.app-header {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 0.6rem;
  min-height: var(--header-h);
  padding: 0.4rem 0.6rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
  flex-wrap: wrap;
}

.app-title {
  font-weight: 700;
  font-size: 1.05rem;
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.a11y-controls {
  display: flex; gap: 0.4rem; flex-wrap: wrap; margin-left: auto;
}

.icon-btn {
  display: inline-flex; align-items: center; gap: 0.35rem;
  min-height: 48px; min-width: 48px;
  padding: 0.4rem 0.8rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
}
.icon-btn.small { padding: 0.4rem 0.6rem; font-size: 1.1rem; }
.icon-btn:hover { background: var(--bg); }
.icon-btn .lbl { display: inline; }

@media (max-width: 480px) {
  .icon-btn .lbl { display: none; }
  .icon-btn { padding: 0.5rem; }
}

.update-banner {
  background: #fff3cd; color: #6b5300;
  padding: 0.7rem 1rem; text-align: center; font-weight: 600;
}
:root[data-theme="dark"] .update-banner { background: #4a3d00; color: #ffe89b; }
.update-banner.hidden { display: none; }
.link-btn {
  background: none; border: none; text-decoration: underline;
  font-weight: 700; color: inherit; padding: 0.2rem 0.4rem;
}

/* ---------------- Main / layout ---------------- */

main {
  max-width: 900px;
  margin: 0 auto;
  padding: 1rem 0.8rem 2rem;
  min-height: 60vh;
}

.hidden { display: none !important; }

h1, h2, h3 { line-height: 1.25; }

/* ---------------- Home screen ---------------- */

.continue-card {
  display: flex; align-items: center; gap: 1rem;
  background: var(--surface);
  border: 2px solid var(--accent);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1.2rem;
  width: 100%;
  text-align: left;
}

.continue-card .thumb { flex-shrink: 0; }

.tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
}

.source-tile {
  display: flex; flex-direction: column; align-items: flex-start; gap: 0.4rem;
  padding: 1.1rem 1.2rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  min-height: 100px;
  box-shadow: var(--shadow);
  text-align: left;
  border-left: 8px solid var(--tile-color, var(--accent));
}
.source-tile .name { font-size: 1.15rem; font-weight: 700; }
.source-tile .count { color: var(--text-muted); }

.section-heading {
  margin: 1.6rem 0 0.7rem;
  font-size: 1.1rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* ---------------- List screen ---------------- */

.list-toolbar {
  display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: center;
  margin-bottom: 1rem;
  position: sticky; top: var(--header-h);
  background: var(--bg);
  padding: 0.5rem 0;
  z-index: 10;
}

.list-toolbar input[type="search"],
.list-toolbar select {
  min-height: 48px;
  font-size: 1rem;
  padding: 0.4rem 0.7rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}
.list-toolbar input[type="search"] { flex: 1 1 180px; }

.result-count { color: var(--text-muted); }
.viewed-progress { color: var(--accent); font-weight: 700; margin: -0.3rem 0 0.8rem; }
.filter-note {
  color: var(--text-muted); font-size: 0.95rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 0.6rem 0.9rem; margin-bottom: 1rem;
}

.card-list {
  display: flex; flex-direction: column; gap: 0.7rem;
}

.profile-card {
  display: flex; gap: 0.9rem; align-items: center;
  width: 100%; text-align: left;
  padding: 0.8rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  min-height: 72px;
}
.profile-card:active { background: var(--bg); }

/* Marks a profile already opened before, per matrimony — a background
   tint for quick scanning plus an explicit "✓ Viewed" text badge, so the
   signal never depends on perceiving a subtle color difference alone. */
.profile-card.is-visited {
  background: var(--visited-tint);
  border-color: var(--accent);
}
.visited-badge {
  display: inline-block; font-weight: 700; color: var(--accent);
  white-space: nowrap;
}

/* A profile matched within the last NEW_BADGE_WINDOW_DAYS (build/star_match.py).
   Same gold used for the shortlist button's active state elsewhere in the
   app — reused deliberately as this app's one "special/highlighted" color,
   rather than introducing a second accent color to learn. */
.new-chip {
  display: inline-block; white-space: nowrap;
  background: #ffd76b; color: #3a2c00;
  font-size: 0.78em; font-weight: 800;
  padding: 0.1em 0.55em; border-radius: 999px;
  vertical-align: middle;
}

.thumb {
  width: 64px; height: 64px; border-radius: 50%;
  object-fit: cover; flex-shrink: 0;
  background: var(--accent); color: var(--accent-contrast);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 1.3rem;
  border: 1px solid var(--border);
}
.thumb.large { width: 140px; height: 140px; font-size: 2.4rem; border-radius: 18px; }

.card-body { min-width: 0; flex: 1; }
.card-name { font-weight: 700; font-size: 1.08rem; }
.card-meta { color: var(--text-muted); font-size: 0.95rem; }

.load-more-sentinel { height: 1px; }

.load-more-btn {
  display: block; margin: 1rem auto; min-height: 52px;
  padding: 0.6rem 1.4rem; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font-weight: 700;
}

.empty-state {
  text-align: center; color: var(--text-muted); padding: 2rem 1rem;
}

/* ---------------- Detail screen ---------------- */

.detail-head {
  display: flex; flex-direction: column; gap: 1rem; margin-bottom: 1.2rem;
}

/* Sits above the photo on purpose — so a screenshot of "the photo and
   whatever's right above it" (the natural way someone screenshots a
   profile) always captures the reference number along with the face,
   without needing to scroll up separately to find it. */
.profile-id-banner {
  text-align: center; font-size: 1.15rem;
  background: var(--surface); border: 2px solid var(--accent); border-radius: var(--radius);
  padding: 0.6rem 1rem; word-break: break-word;
}
.profile-id-banner strong { font-size: 1.25em; letter-spacing: 0.02em; }

.detail-info { text-align: center; }
.detail-name { font-size: 1.5rem; font-weight: 800; margin: 0; }
.detail-sub { color: var(--text-muted); font-size: 1.05rem; }
.source-chip {
  display: inline-block; padding: 0.15rem 0.6rem; border-radius: 999px;
  background: var(--accent); color: var(--accent-contrast);
  font-size: 0.85rem; font-weight: 700; margin-top: 0.3rem;
}

/* ---------------- Photo gallery (detail screen) ----------------
   0 photos: initials avatar. 1 photo: plain framed image. 2+ photos: a
   real horizontally-scrollable, scroll-snapping track — works with touch
   swipe and trackpad/mouse-wheel scroll for free, plus big always-visible
   arrow buttons so a mouse-only desktop user (no touch, no trackpad
   gesture) has an equally obvious way to move between photos. Sized as a
   portrait frame (typical headshot aspect) that scales down on small
   phones and stays capped at a sensible size on tablets/desktop since
   it lives inside `main`'s 900px max-width. */

.profile-gallery {
  position: relative;
  width: 100%; max-width: 420px; margin: 0 auto;
}
.profile-gallery-empty { display: flex; justify-content: center; }
.profile-gallery-empty .thumb.large { width: 200px; height: 200px; }

.gallery-single-photo {
  display: block; width: 100%; aspect-ratio: 3 / 4; object-fit: cover;
  border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--surface);
}

.gallery-track {
  display: flex;
  width: 100%; aspect-ratio: 3 / 4;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
}
.gallery-track:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
.gallery-slide {
  flex: 0 0 100%; width: 100%; height: 100%;
  scroll-snap-align: center; scroll-snap-stop: always;
}
.gallery-slide img { width: 100%; height: 100%; object-fit: cover; display: block; }

.gallery-arrow {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 52px; height: 52px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font-size: 1.8rem; line-height: 1; display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow); cursor: pointer;
}
.gallery-arrow-prev { left: -8px; }
.gallery-arrow-next { right: -8px; }
@media (max-width: 480px) {
  /* keep arrows fully on-screen on narrow phones instead of overflowing edge-to-edge */
  .gallery-arrow-prev { left: 4px; }
  .gallery-arrow-next { right: 4px; }
}

.gallery-dots {
  display: flex; justify-content: center; gap: 0.5rem; margin-top: 0.7rem;
}
.gallery-dot {
  width: 14px; height: 14px; border-radius: 50%; padding: 0;
  border: 1px solid var(--border); background: var(--surface);
}
.gallery-dot.active { background: var(--accent); border-color: var(--accent); }

.action-row { display: flex; flex-wrap: wrap; gap: 0.6rem; margin: 1rem 0; }
.action-btn {
  min-height: 52px; padding: 0.6rem 1.1rem; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font-weight: 700; font-size: 1rem; display: inline-flex; align-items: center; gap: 0.5rem;
}
.action-btn.primary { background: var(--accent); color: var(--accent-contrast); border-color: var(--accent); }
.action-btn[aria-pressed="true"] { background: #ffd76b; color: #3a2c00; border-color: #ffd76b; }

.fact-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 0.9rem; margin: 1.2rem 0;
}
.fact {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 0.7rem 0.9rem;
}
.fact .label { color: var(--text-muted); font-size: 0.88rem; text-transform: uppercase; letter-spacing: 0.03em; }
.fact .value { font-size: 1.15rem; font-weight: 600; margin-top: 0.15rem; word-break: break-word; }

.long-fields { display: flex; flex-direction: column; gap: 0.9rem; margin: 1.2rem 0; }
.long-field .label { color: var(--text-muted); font-size: 0.9rem; text-transform: uppercase; }
.long-field .value { font-size: 1.08rem; }

.contact-box {
  background: var(--surface); border: 2px solid var(--accent); border-radius: var(--radius);
  padding: 0.9rem 1rem; margin: 1.2rem 0;
}
.contact-box a.action-btn { text-decoration: none; }

details.more-details {
  margin: 1.4rem 0; border: 1px solid var(--border); border-radius: var(--radius);
  padding: 0.2rem 1rem;
}
details.more-details summary {
  cursor: pointer; padding: 0.8rem 0; font-weight: 700; min-height: 48px;
  display: flex; align-items: center;
}
.raw-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 0.7rem; padding-bottom: 1rem; }
.raw-grid .label { color: var(--text-muted); font-size: 0.85rem; }
.raw-grid .value { font-size: 0.98rem; word-break: break-word; overflow-wrap: anywhere; }

/* ---------------- Detail footer nav ---------------- */

.detail-nav {
  position: sticky; bottom: 0; z-index: 40;
  display: flex; gap: 0.5rem; padding: 0.6rem;
  background: var(--surface); border-top: 1px solid var(--border);
  box-shadow: 0 -1px 3px rgba(0, 0, 0, 0.12);
}
.nav-btn {
  flex: 1; min-height: 56px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--accent); color: var(--accent-contrast);
  font-weight: 800; font-size: 1.05rem;
  display: flex; align-items: center; justify-content: center; gap: 0.4rem;
}
.nav-btn.secondary { background: var(--surface); color: var(--text); flex: 0 0 auto; padding: 0 1.1rem; }

/* ---------------- Sheet / modal ---------------- */

.sheet, .pin-gate {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0, 0, 0, 0.55);
  display: flex; align-items: flex-end; justify-content: center;
}
.pin-gate { align-items: center; background: var(--bg); }

.sheet-panel {
  background: var(--surface); color: var(--text);
  width: 100%; max-width: 640px;
  border-radius: 18px 18px 0 0;
  padding: 1.2rem; max-height: 85vh; overflow-y: auto;
}
.sheet-panel h2 { margin-top: 0; }

.pin-panel {
  background: var(--surface); color: var(--text);
  border-radius: var(--radius); padding: 1.6rem; text-align: center;
  width: 92%; max-width: 380px;
}
.pin-dots { font-size: 2rem; letter-spacing: 0.4rem; min-height: 2.4rem; margin: 0.6rem 0; }
.pin-keypad {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.6rem; margin-top: 0.8rem;
}
.pin-key {
  min-height: 60px; font-size: 1.4rem; border-radius: 12px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text); font-weight: 700;
}
.pin-error { color: var(--danger); min-height: 1.4rem; font-weight: 700; }

/* ---------------- Footer / misc ---------------- */

.build-note {
  text-align: center; color: var(--text-muted); font-size: 0.85rem; margin-top: 2rem;
}

@media (prefers-reduced-motion: no-preference) {
  .sheet-panel, .continue-card, .profile-card { transition: transform 0.15s ease, opacity 0.15s ease; }
}
