:root {
  --coral: #d9534f;
  --coral-dark: #b8403c;
  --teal: #1f8a8a;
  --ink: #2b2730;
  --muted: #6e6875;
  --line: #e7e1dc;
  --bg: #faf6f2;
  --card: #fff;
  --chip: #f3ede8;
  --radius: 16px;
  --shadow: 0 1px 2px rgb(0 0 0 / .04), 0 4px 16px rgb(0 0 0 / .05);
  --nav-h: 64px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ink: #f1ecef;
    --muted: #a8a1ad;
    --line: #38323c;
    --bg: #18151a;
    --card: #221e25;
    --chip: #2e2832;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
}
body.logged-in { padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); }
img { max-width: 100%; display: block; }
a { color: var(--teal); }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--teal); outline-offset: 2px; }

/* ---------- top bar / bottom nav ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: center;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; gap: 8px; align-items: center; font-weight: 700; font-size: 1.1rem; color: var(--ink); text-decoration: none; }
.nav {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--card); border-top: 1px solid var(--line);
}
.nav a, .nav button {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font: inherit; font-size: .75rem; color: var(--muted); text-decoration: none;
  background: none; border: 0; cursor: pointer;
}
.nav a span:first-child, .nav button span:first-child { font-size: 1.3rem; }
.nav a.active { color: var(--coral); font-weight: 600; }
.nav a { position: relative; }
.badge-count {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px;
  background: var(--coral); color: #fff; font-size: .72rem; font-weight: 700; line-height: 1;
}
.nav .badge-count { position: absolute; top: 6px; left: calc(50% + 6px); }
@media (min-width: 900px) { .nav .badge-count { position: static; } }

@media (min-width: 900px) {
  body.logged-in { padding-bottom: 0; }
  /* backdrop-filter would trap the fixed mobile nav, so only use it on desktop */
  .topbar { justify-content: space-between; padding: 12px 32px; background: color-mix(in srgb, var(--card) 92%, transparent); backdrop-filter: blur(8px); }
  .nav { position: static; display: flex; gap: 4px; height: auto; padding: 0; background: none; border: 0; }
  .nav a, .nav button { flex-direction: row; gap: 6px; font-size: .95rem; padding: 8px 14px; border-radius: 999px; }
  .nav a span:first-child, .nav button span:first-child { font-size: 1rem; }
  .nav a.active { background: var(--chip); }
  .nav a:hover, .nav button:hover { color: var(--ink); }
}

/* ---------- layout ---------- */
.app { outline: none; }
.page { padding: 16px; max-width: 1200px; margin: 0 auto; }
.page.narrow { max-width: 720px; }
.page-title { font-size: 1.5rem; margin: 8px 0 16px; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; margin-bottom: 14px; box-shadow: var(--shadow);
}
.row-2 { display: grid; gap: 0 14px; }
@media (min-width: 560px) { .row-2 { grid-template-columns: 1fr 1fr; } }
.muted { color: var(--muted); }
.center { text-align: center; }
.hint { color: var(--muted); font-size: .85rem; margin: 4px 0 10px; }
.error { color: var(--coral-dark); margin: 8px 0; min-height: 1em; }
.error:empty { display: none; }
.prewrap { white-space: pre-wrap; }

/* ---------- forms ---------- */
.field { margin-bottom: 14px; }
.field > label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 6px; }
input:not([type=checkbox]):not([type=radio]):not([type=file]), select, textarea {
  width: 100%; font: inherit; color: inherit;
  padding: 11px 12px; min-height: 46px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--teal); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--teal) 25%, transparent); }
.check { display: flex; gap: 10px; align-items: flex-start; margin: 10px 0; font-size: .92rem; }
.check input { width: 20px; height: 20px; margin-top: 2px; flex: none; accent-color: var(--coral); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 46px; padding: 0 20px; border-radius: 999px;
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
  border: 1px solid transparent;
}
.btn.small { min-height: 38px; padding: 0 14px; font-size: .9rem; }
.btn.block { width: 100%; }
.btn.primary { background: var(--coral); color: #fff; }
.btn.primary:hover { background: var(--coral-dark); }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn.link { background: none; color: var(--muted); padding: 0 8px; }
.btn.danger-btn { background: transparent; color: var(--coral-dark); border-color: var(--coral); }
.btn:disabled { opacity: .6; cursor: wait; }
.icon-btn {
  width: 40px; height: 40px; flex: none; border-radius: 50%;
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  font-size: 1.1rem; cursor: pointer;
}

/* chips & tags */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; gap: 6px; align-items: center;
  min-height: 42px; padding: 0 16px; border-radius: 999px;
  font: inherit; color: var(--ink); background: var(--chip); border: 1px solid transparent; cursor: pointer;
}
.chip[aria-pressed=true] { background: color-mix(in srgb, var(--teal) 16%, var(--card)); border-color: var(--teal); font-weight: 600; }
.tags { list-style: none; display: flex; flex-wrap: wrap; gap: 6px; margin: 0; padding: 0; }
.tag { display: inline-flex; align-items: center; gap: 4px; padding: 4px 12px; border-radius: 999px; background: var(--chip); font-size: .9rem; }
.tag-x { border: 0; background: none; color: var(--muted); font-size: 1.1rem; line-height: 1; padding: 0 0 0 4px; cursor: pointer; }
.tag-input {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
  padding: 6px; min-height: 46px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); cursor: text;
}
.tag-input:focus-within { border-color: var(--teal); box-shadow: 0 0 0 3px color-mix(in srgb, var(--teal) 25%, transparent); }
.tag-input input { flex: 1 1 140px; border: 0 !important; box-shadow: none !important; background: none; min-height: 34px; padding: 4px 6px; }

.link-rows { display: grid; gap: 8px; margin-bottom: 10px; }
.link-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; }
.link-row > :first-child { grid-column: 1 / -1; }
@media (min-width: 560px) {
  .link-row { grid-template-columns: 160px 1fr auto; }
  .link-row > :first-child { grid-column: auto; }
}

/* ---------- auth ---------- */
.auth { display: grid; gap: 20px; padding: 24px 16px 40px; max-width: 1040px; margin: 0 auto; }
.hero h1 { font-size: 2rem; margin-top: 14px; }
.hero p { font-size: 1.05rem; color: var(--muted); }
.hero-points { list-style: none; padding: 0; display: grid; gap: 8px; }
.auth-card { max-width: 440px; width: 100%; justify-self: center; }
@media (min-width: 900px) {
  .auth { grid-template-columns: 1.1fr 1fr; align-items: center; min-height: 100vh; }
  .hero h1 { font-size: 2.8rem; }
}

.auth-card.simple { margin: 32px auto; }
.auth-card.simple h1 { font-size: 1.5rem; }
.nudge.verify { background: color-mix(in srgb, var(--teal) 12%, var(--card)); }
.nudge.verify .btn.link { color: var(--teal); text-decoration: underline; padding: 0; min-height: 0; }
.dev-hint { margin: 8px 0 0; font-style: italic; }

/* ---------- edit ---------- */
.welcome { border-color: var(--coral); }
.photo-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
@media (min-width: 560px) { .photo-grid { grid-template-columns: repeat(4, 1fr); } }
.photo-tile, .photo-add { position: relative; aspect-ratio: 3 / 4; margin: 0; border-radius: 12px; overflow: hidden; }
.photo-tile img { width: 100%; height: 100%; object-fit: cover; }
.photo-tile .badge { position: absolute; top: 6px; left: 6px; background: var(--coral); color: #fff; font-size: .75rem; padding: 2px 8px; border-radius: 999px; }
.photo-actions { position: absolute; bottom: 6px; right: 6px; display: flex; gap: 6px; }
.photo-actions .icon-btn { width: 34px; height: 34px; font-size: .95rem; background: rgb(255 255 255 / .9); color: #222; border: 0; }
.photo-add {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  border: 2px dashed var(--line); background: var(--bg); color: var(--muted); font: inherit; cursor: pointer;
}
.photo-add span { font-size: 2rem; line-height: 1; }
.save-bar {
  position: sticky; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 8px); z-index: 5;
  display: flex; justify-content: flex-end; gap: 10px; margin: 0 0 14px;
  padding: 10px; border-radius: 999px; background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: blur(8px); border: 1px solid var(--line); box-shadow: var(--shadow);
}
@media (min-width: 900px) { .save-bar { bottom: 12px; } }
.danger { border-color: color-mix(in srgb, var(--coral) 40%, var(--line)); }

/* ---------- profile ---------- */
.own-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.own-bar p { margin: 0; }
.back { display: inline-block; margin: 4px 0 12px; text-decoration: none; font-weight: 600; }
.profile-head { padding: 0; overflow: hidden; }
.profile-head > :not(.carousel) { margin-left: 18px; margin-right: 18px; }
.profile-head h1 { margin-top: 14px; font-size: 1.7rem; }
.profile-head .intro { white-space: pre-wrap; margin-bottom: 18px; }
.age { font-weight: 400; color: var(--muted); }
.carousel {
  display: flex; overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none;
  aspect-ratio: 4 / 5; max-height: 70vh; background: var(--chip);
}
.carousel::-webkit-scrollbar { display: none; }
.carousel img { flex: 0 0 100%; width: 100%; height: 100%; object-fit: cover; scroll-snap-align: center; }
.carousel.empty { align-items: center; justify-content: center; aspect-ratio: 16 / 9; }
.landscape-line { display: flex; flex-wrap: wrap; gap: 6px; }
.pill { padding: 4px 12px; border-radius: 999px; background: var(--chip); font-size: .9rem; }
.socials { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 18px 14px; }
.social { padding: 6px 14px; border-radius: 999px; border: 1px solid var(--teal); text-decoration: none; font-size: .9rem; font-weight: 600; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 10px 16px; margin: 0; }
.facts dt { color: var(--muted); font-size: .9rem; padding-top: 3px; }
.facts dd { margin: 0; }
.facts + h3 { margin-top: 18px; }
.link-list { margin: 0; padding-left: 1.2em; }
.link-list li { margin: 4px 0; }

.avatar.placeholder {
  display: flex; align-items: center; justify-content: center;
  width: 100%; height: 100%; font-size: 2.4rem; font-weight: 700; color: #fff;
  background: linear-gradient(135deg, hsl(var(--hue) 60% 60%), hsl(calc(var(--hue) + 50) 55% 45%));
}
.avatar.big { width: 140px; height: 140px; border-radius: 50%; font-size: 3rem; }

/* ---------- search ---------- */
.nudge {
  display: block; padding: 12px 16px; margin-bottom: 14px; border-radius: 12px;
  background: color-mix(in srgb, var(--coral) 12%, var(--card)); color: var(--ink); text-decoration: none;
}
.search-layout { display: grid; gap: 16px; }
@media (min-width: 900px) {
  .search-layout { grid-template-columns: 360px 1fr; align-items: start; }
  .search-layout aside { position: sticky; top: 76px; max-height: calc(100vh - 90px); overflow-y: auto; }
}
.more summary { cursor: pointer; font-weight: 600; color: var(--teal); margin-bottom: 12px; }
.search-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.search-actions .btn.primary { flex: 1 1 100%; }

.results { display: grid; gap: 14px; grid-template-columns: 1fr; }
@media (min-width: 560px) { .results { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1200px) { .results { grid-template-columns: repeat(3, 1fr); } }
.match-card {
  display: flex; flex-direction: column; color: inherit; text-decoration: none;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow);
  transition: transform .15s ease;
}
.match-card:hover { transform: translateY(-2px); }
.match-photo { position: relative; aspect-ratio: 4 / 3; background: var(--chip); }
.match-photo .avatar { width: 100%; height: 100%; object-fit: cover; }
.score {
  position: absolute; top: 10px; right: 10px; padding: 4px 12px; border-radius: 999px;
  background: var(--teal); color: #fff; font-weight: 700; font-size: .9rem;
}
.match-body { padding: 12px 14px 16px; }
.match-body h3 { display: flex; align-items: baseline; gap: 2px; font-size: 1.15rem; margin-bottom: 4px; }
.mini-icons { margin-left: auto; letter-spacing: 2px; }
.dests { margin: 0 0 6px; font-size: .92rem; }
.reasons { margin: 0 0 6px; padding: 0; list-style: none; font-size: .88rem; color: var(--teal); }
.reasons li::before { content: "✓ "; }
.snippet {
  margin: 0; color: var(--muted); font-size: .9rem;
  display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.empty-state { grid-column: 1 / -1; text-align: center; padding: 40px 16px; }

.avatar.small { width: 44px; height: 44px; flex: none; border-radius: 50%; object-fit: cover; font-size: 1rem; }

/* ---------- contact, safety, account ---------- */
.contact .hello-form { margin-top: 4px; }
.contact p { margin-top: 0; }
.safety-actions { display: inline-flex; gap: 4px; }
.safety-actions .btn { color: var(--muted); }
.account-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.people { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.people li { display: flex; align-items: center; gap: 12px; }
.people li span { flex: 1; font-weight: 600; }
.status { display: inline-block; padding: 1px 8px; border-radius: 999px; background: var(--chip); color: var(--muted); font-size: .75rem; font-weight: 600; margin-right: 4px; }
.status.bad { background: var(--coral); color: #fff; }

/* ---------- modal ---------- */
.modal {
  width: min(480px, calc(100% - 24px)); padding: 18px; border: 0; border-radius: var(--radius);
  background: var(--card); color: var(--ink); box-shadow: 0 10px 40px rgb(0 0 0 / .3);
}
.modal::backdrop { background: rgb(20 15 25 / .5); }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.modal-head h2 { margin: 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }

/* ---------- messages ---------- */
.convo-list { display: grid; grid-template-columns: minmax(0, 1fr); margin: 0 -8px; }
.convo {
  min-width: 0;
  display: flex; align-items: center; gap: 12px; padding: 10px 8px; border-radius: 12px;
  color: inherit; text-decoration: none;
}
.convo:hover { background: var(--chip); }
.convo-text { flex: 1; min-width: 0; }
.convo-top { display: flex; align-items: center; gap: 6px; }
.convo-top time { margin-left: auto; color: var(--muted); font-size: .8rem; }
.convo-text p { margin: 2px 0 0; color: var(--muted); font-size: .92rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.convo.unread .convo-text p { color: var(--ink); font-weight: 600; }

.chat { display: flex; flex-direction: column; min-height: calc(100vh - 140px); padding-bottom: 0; }
.chat-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.chat-head .icon-btn { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
.chat-who { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; color: inherit; text-decoration: none; }
.chat-head .safety-actions .btn { padding: 0 6px; }
.safety-tip { margin: 0 0 12px; padding: 10px 14px; border-radius: 12px; background: color-mix(in srgb, var(--teal) 10%, var(--card)); font-size: .85rem; }
.thread { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.bubble { max-width: 82%; padding: 8px 12px 6px; border-radius: 18px; overflow-wrap: anywhere; }
.bubble p { margin: 0; white-space: pre-wrap; }
.bubble time { display: block; text-align: right; font-size: .7rem; opacity: .7; margin-top: 2px; }
.bubble.mine { align-self: flex-end; background: var(--coral); color: #fff; border-bottom-right-radius: 6px; }
.bubble.theirs { align-self: flex-start; background: var(--card); border: 1px solid var(--line); border-bottom-left-radius: 6px; }
.chat-footer {
  position: sticky; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); z-index: 5;
  margin: 12px -16px 0; padding: 10px 16px; background: var(--bg); border-top: 1px solid var(--line);
}
@media (min-width: 900px) { .chat-footer { bottom: 0; margin: 12px 0 0; border-radius: var(--radius) var(--radius) 0 0; } }
.composer { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { min-height: 46px; resize: none; }
.request-box p { margin-top: 0; }

/* ---------- moderation ---------- */
.tabs { display: flex; gap: 6px; margin-bottom: 14px; }
.tabs a { padding: 8px 16px; border-radius: 999px; text-decoration: none; color: var(--muted); background: var(--chip); font-weight: 600; }
.tabs a.active { background: var(--ink); color: var(--bg); }
.report-who { display: flex; gap: 12px; align-items: flex-start; }
.report-who p { margin: 0; font-size: .85rem; }
.report .account-actions { margin-top: 8px; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px); z-index: 50;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  padding: 10px 18px; border-radius: 999px; background: var(--ink); color: var(--bg);
  transition: opacity .2s, transform .2s; max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { background: var(--coral-dark); color: #fff; }
@media (min-width: 900px) { .toast { bottom: 24px; } }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; scroll-behavior: auto !important; } }
