:root {
  --bg: #f3f6fa;
  --card: #ffffff;
  --ink: #14212e;
  --muted: #5f6f80;
  --line: #dde4ec;
  --accent: #1f6feb;
  --accent-ink: #ffffff;
  --yes: #2f9e5b;
  --yes-bg: #d7f2e1;
  --maybe: #c98a0b;
  --maybe-bg: #fcefcf;
  --no: #d0463b;
  --no-bg: #f9dbd8;
  --empty: #eef2f6;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 33, 46, 0.06), 0 4px 16px rgba(20, 33, 46, 0.06);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e151c;
    --card: #16202a;
    --ink: #e8eef4;
    --muted: #93a3b4;
    --line: #26333f;
    --accent: #4b8ef5;
    --yes: #48c27a;
    --yes-bg: #1c3a29;
    --maybe: #e2a93a;
    --maybe-bg: #3d3118;
    --no: #ec6a5f;
    --no-bg: #43221f;
    --empty: #1d2934;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 16px/1.45 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}
.wrap { max-width: 980px; margin: 0 auto; padding: 0 16px 64px; }
header.top {
  background: linear-gradient(160deg, #1f4f8f 0%, #2f78c4 55%, #8cc3f0 100%);
  color: #fff;
  padding: 28px 0 56px;
  position: relative;
  overflow: hidden;
}
header.top::after {
  content: '';
  position: absolute; left: 0; right: 0; bottom: -1px; height: 48px;
  background: var(--bg);
  clip-path: polygon(0 100%, 0 60%, 12% 20%, 22% 55%, 34% 5%, 47% 60%, 58% 30%, 70% 70%, 82% 15%, 92% 50%, 100% 25%, 100% 100%);
}
header.top h1 { margin: 0; font-size: 28px; letter-spacing: -0.02em; }
header.top p { margin: 4px 0 0; opacity: 0.9; }
header.top .who { position: absolute; top: 16px; right: 16px; font-size: 14px; opacity: 0.95; }
header.top .who button { background: rgba(255,255,255,0.18); color: #fff; border: 0; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin: 16px 0;
}
.card h2 { margin: 0 0 4px; font-size: 19px; }
.card h3 { margin: 18px 0 8px; font-size: 16px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.hidden { display: none !important; }

button, .btn {
  font: inherit;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  padding: 9px 14px;
  border-radius: 10px;
  cursor: pointer;
}
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.danger { color: var(--no); }
button:disabled { opacity: 0.5; cursor: default; }
input, textarea, select {
  font: inherit;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 11px;
  width: 100%;
}
textarea { min-height: 84px; resize: vertical; }
label { display: block; font-size: 14px; color: var(--muted); margin-bottom: 4px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 600px) { .grid2 { grid-template-columns: 1fr; } }
.pair { display: flex; gap: 8px; align-items: center; }
.pair input { width: 100%; }

/* tabs */
.tabs { display: flex; gap: 6px; margin-top: -36px; position: relative; z-index: 1; }
.tabs button {
  flex: 1;
  border-radius: 12px;
  padding: 12px;
  font-weight: 600;
  box-shadow: var(--shadow);
}
.tabs button.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* brushes */
.brushes { display: flex; gap: 8px; flex-wrap: wrap; position: sticky; top: 0; z-index: 5; background: var(--card); padding: 10px 0; }
.brush { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; }
.brush .sw { width: 14px; height: 14px; border-radius: 4px; display: inline-block; }
.brush.active { outline: 2px solid var(--accent); outline-offset: 1px; }
.sw.yes { background: var(--yes); }
.sw.maybe { background: var(--maybe); }
.sw.no { background: var(--no); }
.sw.clear { background: var(--empty); border: 1px solid var(--line); }
.sw.note { background: transparent; }
.toggle { display: inline-flex; gap: 6px; align-items: center; font-size: 14px; color: var(--muted); cursor: pointer; }
.toggle input { width: auto; }

/* calendar */
.months { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 18px; margin-top: 8px; }
.month h4 { margin: 0 0 6px; text-transform: capitalize; font-size: 15px; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; user-select: none; -webkit-user-select: none; }
.cal .dow { font-size: 12px; color: var(--muted); text-align: center; padding-bottom: 2px; }
.day {
  aspect-ratio: 1 / 1;
  border-radius: 8px;
  background: var(--empty);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 600;
  position: relative;
  cursor: pointer;
  border: 2px solid transparent;
  transition: transform 0.06s;
}
.day:active { transform: scale(0.94); }
.day.out { visibility: hidden; }
.day.off { opacity: 0.25; cursor: default; }
.day.weekend { font-weight: 800; }
.day.yes { background: var(--yes-bg); color: var(--yes); border-color: var(--yes); }
.day.maybe { background: var(--maybe-bg); color: var(--maybe); border-color: var(--maybe); }
.day.no { background: var(--no-bg); color: var(--no); border-color: var(--no); }
.day.anchor { outline: 3px dashed var(--accent); outline-offset: 1px; }
.day .dot { position: absolute; top: 3px; right: 4px; font-size: 10px; }
.day .sub { font-size: 10px; font-weight: 500; line-height: 1; margin-top: 2px; }
.day.sel { outline: 3px solid var(--accent); outline-offset: 1px; }
.day.inwin { box-shadow: inset 0 -4px 0 var(--accent); }

.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--muted); margin-top: 10px; }
.legend span { display: inline-flex; gap: 6px; align-items: center; }

.saved { font-size: 13px; color: var(--muted); min-height: 1.2em; }

/* results */
.lens { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0 12px; }
.lens button.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.win { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin-bottom: 10px; cursor: pointer; }
.win.best { border-color: var(--yes); border-width: 2px; }
.win .head { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.win .dates { font-weight: 700; font-size: 17px; }
.win .score { font-size: 14px; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip { font-size: 13px; padding: 3px 9px; border-radius: 999px; background: var(--empty); }
.chip.yes { background: var(--yes-bg); color: var(--yes); }
.chip.maybe { background: var(--maybe-bg); color: var(--maybe); }
.chip.no { background: var(--no-bg); color: var(--no); }
.why { font-size: 13px; color: var(--muted); margin-top: 6px; }

.heat .day { cursor: pointer; }
.detail { margin-top: 12px; }
.detail ul { list-style: none; padding: 0; margin: 8px 0 0; }
.detail li { padding: 6px 0; border-top: 1px solid var(--line); display: flex; gap: 10px; align-items: baseline; }
.detail li .nm { font-weight: 600; min-width: 90px; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px 6px; border-top: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; border-top: 0; }
.tablewrap { overflow-x: auto; }
.note-cell { white-space: pre-wrap; max-width: 320px; }

.center { text-align: center; }
.join-list { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.err { color: var(--no); font-size: 14px; min-height: 1.2em; margin-top: 6px; }
.banner { background: var(--yes-bg); color: var(--yes); border: 1px solid var(--yes); border-radius: 12px; padding: 12px 14px; font-weight: 600; }

dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); color: var(--ink); max-width: 420px; width: calc(100% - 32px); padding: 18px; }
dialog::backdrop { background: rgba(0,0,0,0.35); }
