:root {
  --bg: #faf7f2;
  --surface: #ffffff;
  --ink: #221d17;
  --muted: #6f675d;
  --line: #e6dfd5;
  --accent: #6d3fd1;
  --accent-ink: #ffffff;
  --mine: #6d3fd1;
  --mine-bg: #efe8fd;
  --person: #0c7468;
  --person-bg: #dff3ef;
  --similar: #a8530a;
  --similar-bg: #fbecd9;
  --theme: #4a5567;
  --theme-bg: #e9edf2;
  --danger: #b3261e;
  --radius: 10px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16141a;
    --surface: #201d26;
    --ink: #efeaf5;
    --muted: #a39cb0;
    --line: #35303f;
    --accent: #a98bf5;
    --accent-ink: #17131f;
    --mine: #b9a1f8;
    --mine-bg: #33264f;
    --person: #6dd3c5;
    --person-bg: #173a36;
    --similar: #f0b168;
    --similar-bg: #43301a;
    --theme: #b3bccb;
    --theme-bg: #2c313b;
    --danger: #f2877f;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}
[hidden] { display: none !important; }
h1, h2, h3, p { margin: 0; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- header ---------- */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 10px max(16px, env(safe-area-inset-left)) 10px max(16px, env(safe-area-inset-right));
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.top h1 { font-size: 1.05rem; letter-spacing: -0.01em; }
#who { font-weight: 400; color: var(--muted); margin-left: 6px; }
#who:empty { display: none; }
.top nav { display: flex; gap: 4px; }
.tab, .seg button, .subtab {
  border: 0; background: none; padding: 8px 12px; border-radius: 999px; color: var(--muted); font-weight: 600; font-size: 0.92rem; min-height: 40px;
}
.tab[aria-current="page"], .seg button[aria-pressed="true"], .subtab[aria-selected="true"] { background: var(--ink); color: var(--bg); }

main { flex: 1; width: 100%; max-width: 1180px; margin: 0 auto; padding: 16px; }

/* ---------- buttons & forms ---------- */
.btn, .primary {
  border: 1px solid var(--line); background: var(--surface); padding: 9px 14px; border-radius: var(--radius); font-weight: 600; min-height: 42px;
}
.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.danger { color: var(--danger); }
.btn:disabled, .primary:disabled { opacity: 0.55; cursor: default; }
.icon-btn {
  border: 1px solid var(--line); background: var(--surface); width: 36px; height: 36px; border-radius: 50%; font-size: 1.15rem; line-height: 1;
  display: inline-grid; place-items: center; flex: none;
}
.icon-btn.on { background: var(--mine-bg); color: var(--mine); border-color: transparent; }
input[type="text"], input[type="email"], input[type="password"], input[type="search"], select {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); min-height: 44px;
}
label { font-weight: 600; font-size: 0.9rem; display: block; margin-bottom: 4px; }
.error { color: var(--danger); font-size: 0.9rem; min-height: 1.3em; }
.muted { color: var(--muted); font-size: 0.9rem; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 18px; }
.stack > * + * { margin-top: 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row > .grow { flex: 1; min-width: 0; }

/* ---------- login ---------- */
.login { flex: 1; display: grid; place-items: center; padding: 24px; }
.login .card { width: min(360px, 100%); display: grid; gap: 10px; }
.login h1 { font-size: 1.3rem; margin-bottom: 8px; }

/* ---------- calendar ---------- */
.cal-bar { position: sticky; top: var(--top-h, 61px); z-index: 4; background: var(--bg); margin: -16px -16px 12px; padding: 12px 16px 10px; border-bottom: 1px solid var(--line); }
.cal-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.cal-head .btn { min-height: 38px; padding: 6px 12px; font-size: 0.92rem; }
.cal-head h2 { font-size: 1.35rem; letter-spacing: -0.02em; margin-right: auto; }
.filters { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.seg { display: inline-flex; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 2px; }
.seg button { min-height: 36px; padding: 6px 12px; }
.icon-btn.reset { color: var(--danger); font-size: 1.2rem; font-weight: 700; }
.check { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; font-size: 0.92rem; margin: 0; min-height: 40px; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
details.services { position: relative; }
details.services summary {
  list-style: none; border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 8px 14px; font-weight: 600; font-size: 0.92rem; cursor: pointer;
}
details.services .menu .check { display: flex; }
details.services summary::-webkit-details-marker { display: none; }
details.services summary::after { content: " ▾"; color: var(--muted); }
details.services summary.active { background: var(--ink); color: var(--bg); border-color: transparent; }
details.services summary.active::after { color: inherit; }
details.services .menu {
  position: absolute; z-index: 4; top: calc(100% + 6px); left: 0; width: 240px; max-height: 320px; overflow: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; box-shadow: 0 8px 24px rgb(0 0 0 / 0.14);
}

.grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; background: var(--line); gap: 1px; }
.dow { background: var(--bg); padding: 6px 8px; font-size: 0.75rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.cell { background: var(--surface); min-height: 128px; padding: 6px; display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.cell.other { background: var(--bg); }
.cell.other .num { opacity: 0.5; }
.cell.past > * { opacity: 0.5; }
.num { font-size: 0.8rem; font-weight: 700; color: var(--muted); align-self: flex-start; padding: 1px 6px; border-radius: 999px; }
.cell.today .num { background: var(--accent); color: var(--accent-ink); }
.chip {
  display: flex; align-items: center; gap: 5px; width: 100%; border: 0; text-align: left; padding: 2px 5px 2px 2px; border-radius: 6px; font-size: 0.78rem; line-height: 1.25;
  background: transparent; color: var(--muted); min-width: 0;
}
.chip img, .chip .ph { width: 18px; height: 27px; border-radius: 3px; object-fit: cover; flex: none; background: var(--line); }
.chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip:hover { background: var(--bg); }
.chip.mine { background: var(--mine-bg); color: var(--mine); font-weight: 700; }
.chip.person { background: var(--person-bg); color: var(--person); font-weight: 600; }
.chip.similar { background: var(--similar-bg); color: var(--similar); font-weight: 600; }
.chip.theme { color: var(--ink); }
.more { border: 0; background: none; color: var(--muted); font-size: 0.75rem; font-weight: 700; text-align: left; padding: 2px 6px; }

/* list (phones, day pop-up) */
.day-title { font-size: 0.82rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin: 18px 0 6px; }
.day-title.today { color: var(--accent); }
.item {
  display: flex; gap: 12px; align-items: center; padding: 8px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); margin-bottom: 6px;
  border-left: 4px solid var(--line);
}
.item.mine { border-left-color: var(--mine); }
.item.person { border-left-color: var(--person); }
.item.similar { border-left-color: var(--similar); }
.item.theme { border-left-color: var(--theme); }
.item img, .item .ph { width: 44px; height: 66px; border-radius: 6px; object-fit: cover; background: var(--line); flex: none; }
.item img.round, .item .ph.round { height: 44px; border-radius: 50%; }
.item .body { flex: 1; min-width: 0; }
.item .name { font-weight: 700; overflow-wrap: anywhere; }
.item .name button { all: unset; cursor: pointer; }
.item .meta { color: var(--muted); font-size: 0.86rem; }
.why { display: inline-block; font-size: 0.78rem; font-weight: 700; padding: 1px 8px; border-radius: 999px; margin: 3px 4px 0 0; }
.why.mine { background: var(--mine-bg); color: var(--mine); }
.why.person { background: var(--person-bg); color: var(--person); }
.why.similar { background: var(--similar-bg); color: var(--similar); }
.why.theme { background: var(--theme-bg); color: var(--theme); }
.empty { text-align: center; color: var(--muted); padding: 40px 16px; }

/* ---------- interests ---------- */
.subtabs { display: flex; gap: 4px; overflow-x: auto; margin-bottom: 14px; padding-bottom: 2px; }
.subtab { white-space: nowrap; }
.search { position: relative; margin-bottom: 14px; }
.results {
  position: absolute; z-index: 4; left: 0; right: 0; top: calc(100% + 4px); background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  max-height: 60vh; overflow: auto; box-shadow: 0 8px 24px rgb(0 0 0 / 0.14);
}
.result { display: flex; gap: 10px; align-items: center; width: 100%; border: 0; background: none; text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.result:last-child { border-bottom: 0; }
.result:hover { background: var(--bg); }
.result img, .result .ph { width: 34px; height: 51px; border-radius: 4px; object-fit: cover; background: var(--line); flex: none; }
.result .ph.none { display: none; }
.item select { width: auto; min-height: 38px; padding: 6px 8px; font-size: 0.88rem; }
.item .next { font-size: 0.88rem; font-weight: 700; color: var(--mine); }
a.plain { color: inherit; text-decoration: none; }
a.plain:hover { text-decoration: underline; }
.suggests { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.why.suggest { border: 0; margin: 0; padding: 6px 12px; font-size: 0.86rem; min-height: 34px; cursor: pointer; }
.why.suggest .from { font-weight: 400; opacity: 0.8; }
.why.suggest:hover { filter: brightness(0.95); }
.group-title { font-size: 1.05rem; font-weight: 700; margin: 22px 0 2px; display: flex; align-items: center; gap: 8px; }
.refresh { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.steps { padding-left: 1.2em; margin: 6px 0 0; }
.steps li { margin-bottom: 4px; }

/* ---------- dialog, toast, footer ---------- */
dialog { border: 1px solid var(--line); border-radius: 16px; padding: 18px; width: min(520px, calc(100vw - 24px)); max-height: 86dvh; background: var(--bg); color: var(--ink); }
dialog::backdrop { background: rgb(0 0 0 / 0.45); }
.dlg-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 10px; }
.dlg-head h3 { font-size: 1.15rem; }
.detail { display: flex; gap: 14px; }
.detail img { width: 110px; height: 165px; border-radius: 8px; object-fit: cover; background: var(--line); flex: none; }
#toast {
  position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-weight: 600; font-size: 0.92rem; transition: 0.2s; max-width: calc(100vw - 32px); z-index: 20;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
.attribution { display: flex; gap: 10px; align-items: center; justify-content: center; flex-wrap: wrap; padding: 18px 16px 24px; color: var(--muted); font-size: 0.75rem; text-align: center; }

@media (max-width: 759px) {
  .top h1 { display: none; }
  .top nav { width: 100%; justify-content: space-between; }
  .cal-head h2 { font-size: 1.2rem; }
  main { padding: 12px; }
  .cal-bar { margin: -12px -12px 8px; padding: 10px 12px 8px; }
  .filters { gap: 6px; }
  .item.with-mode { flex-wrap: wrap; }
  .item.with-mode .body { flex-basis: calc(100% - 110px); }
  .item.with-mode select { order: 5; flex: 1 0 100%; }
  details.services summary { padding: 8px 12px; }
  details.services .menu { position: fixed; left: 12px; right: 12px; width: auto; top: auto; margin-top: 6px; }
  .seg button { padding: 6px 10px; }
}
@media (prefers-reduced-motion: reduce) { #toast { transition: none; } }
