:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --hover: #f1f3f4;
  --line: #dadce0;
  --text: #202124;
  --muted: #5f6368;
  --faint: #80868b;
  --accent: #1a73e8;
  --accent-soft: #e8f0fe;
  --fight: #d93025;
  --fight-soft: #fce8e6;
  --ok: #188038;
  --shadow: 0 1px 3px rgba(60, 64, 67, .3), 0 4px 8px 3px rgba(60, 64, 67, .15);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1f1f1f;
    --surface: #2d2e30;
    --hover: #35363a;
    --line: #3c4043;
    --text: #e8eaed;
    --muted: #9aa0a6;
    --faint: #80868b;
    --accent: #8ab4f8;
    --accent-soft: #1e3a5f;
    --fight: #f28b82;
    --fight-soft: #4a2321;
    --ok: #81c995;
    --shadow: 0 1px 3px rgba(0, 0, 0, .5), 0 4px 8px 3px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1f1f1f; --surface: #2d2e30; --hover: #35363a; --line: #3c4043; --text: #e8eaed;
  --muted: #9aa0a6; --faint: #80868b; --accent: #8ab4f8; --accent-soft: #1e3a5f;
  --fight: #f28b82; --fight-soft: #4a2321; --ok: #81c995; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 400 14px/1.43 "Google Sans Text", Roboto, system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
input, textarea { font: inherit; color: inherit; }
svg { width: 24px; height: 24px; fill: currentColor; flex: none; }
.muted { color: var(--muted); }
.error { color: var(--fight); margin: 0; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 16px;
  padding: 8px 16px; background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.brand { font: 400 22px/1 "Google Sans", Roboto, sans-serif; margin: 0 8px 0 0; }
.tabs { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.tabs a {
  text-decoration: none;
  padding: 10px 14px; border-radius: 20px; color: var(--muted); font-weight: 500; white-space: nowrap;
}
.tabs a:hover { background: var(--hover); }
.tabs a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%;
  display: inline-grid; place-items: center; color: var(--muted);
}
.icon-btn:hover { background: var(--hover); }
.icon-btn:focus:not(:focus-visible) { outline: none; }
.editor-top .icon-btn:focus { outline: none; }
.editor-top .icon-btn:focus-visible { box-shadow: 0 0 0 2px var(--accent); }
.icon-btn svg { width: 20px; height: 20px; }

.view { max-width: 720px; margin: 0 auto; padding: 16px 16px 80px; }
#view-calendar { max-width: 1000px; }

.list-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin: 4px 0 8px; }
.list-head h2, .cal-head h2 { font: 400 22px/1.3 "Google Sans", Roboto, sans-serif; margin: 0; }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 18px; overflow: hidden; }
.seg button { padding: 6px 14px; color: var(--muted); font-weight: 500; font-size: 13px; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--accent-soft); color: var(--accent); }

.btn { padding: 8px 20px; border-radius: 20px; font-weight: 500; }
.btn-primary { background: var(--accent); color: var(--bg); }
.btn-outline { border: 1px solid var(--line); color: var(--text); }
.btn-outline:hover { background: var(--hover); }

/* ---------- Google-Tasks style rows ---------- */
.add-row {
  display: flex; align-items: center; gap: 16px; width: 100%;
  padding: 12px 8px; color: var(--accent); font-size: 16px; text-align: left; border-radius: 8px;
}
.add-row:hover { background: var(--hover); }
.add-icon { width: 24px; height: 24px; }

.items { list-style: none; margin: 0; padding: 0; }
.item { border-radius: 8px; }
.row {
  display: flex; align-items: flex-start; gap: 16px;
  padding: 10px 8px; border-radius: 8px; cursor: pointer;
}
.row:hover { background: var(--hover); }
.row .body { flex: 1; min-width: 0; }
.row .title { font-size: 16px; line-height: 24px; word-wrap: break-word; }
.row .notes { color: var(--muted); font-size: 14px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  border: 1px solid var(--line); border-radius: 8px; padding: 1px 8px;
  font-size: 12px; line-height: 20px; color: var(--muted);
}
.chip.fight { border-color: transparent; background: var(--fight-soft); color: var(--fight); font-weight: 500; }
.chip.ok { color: var(--ok); }
.done .title { text-decoration: line-through; color: var(--muted); }

.sub { margin-left: 40px; }
.sub .row { padding: 6px 8px; }
.sub .title { font-size: 14px; line-height: 22px; }

/* round checkbox */
.check {
  position: relative; flex: none;
  width: 20px; height: 20px; margin: 2px; border-radius: 50%;
  border: 2px solid var(--muted); display: inline-block; cursor: pointer;
}
.check::after {
  content: ""; position: absolute; left: 5px; top: 1.5px; width: 5px; height: 10px;
  border: solid var(--accent); border-width: 0 2px 2px 0; transform: rotate(45deg); opacity: 0;
}
.check:hover::after { opacity: .7; }
.check.on { background: var(--accent); border-color: var(--accent); }
.check.on::after { border-color: var(--bg); opacity: 1; }
.check.ghost { opacity: .5; pointer-events: none; }
.sub .check { width: 18px; height: 18px; margin: 2px; }
.sub .check::after { left: 4.5px; top: 1px; width: 4px; height: 9px; }

.check-input { position: absolute; opacity: 0; pointer-events: none; }
.check-row { display: flex; align-items: center; gap: 12px; cursor: pointer; padding: 6px 0; position: relative; }
.check-input:checked + .check { background: var(--accent); border-color: var(--accent); }
.check-input:checked + .check::after { border-color: var(--bg); opacity: 1; }
.check-input:focus-visible + .check { outline: 2px solid var(--accent); outline-offset: 2px; }

.quick-add { display: flex; align-items: center; gap: 16px; padding: 8px; }
.quick-add input {
  flex: 1; border: 0; border-bottom: 2px solid var(--accent); background: transparent;
  font-size: 16px; padding: 6px 0; outline: none;
}

.empty { color: var(--muted); padding: 32px 8px; text-align: center; }

.completed { margin-top: 12px; }
.completed summary {
  list-style: none; display: flex; align-items: center; gap: 12px;
  padding: 12px 8px; cursor: pointer; font-weight: 500; border-radius: 8px;
}
.completed summary::-webkit-details-marker { display: none; }
.completed summary:hover { background: var(--hover); }
.completed .chev { width: 20px; height: 20px; transition: transform .15s; color: var(--muted); }
.completed[open] .chev { transform: rotate(90deg); }

/* ---------- editor dialog ---------- */
.editor {
  border: 0; padding: 0; border-radius: 16px; width: min(520px, calc(100vw - 32px));
  max-height: calc(100dvh - 48px); background: var(--surface); color: var(--text); box-shadow: var(--shadow);
}
.editor::backdrop { background: rgba(32, 33, 36, .45); }
.editor-inner { padding: 8px 20px 24px; }
.editor-top { display: flex; align-items: center; margin: 0 -12px 4px; }
.spacer { flex: 1; }
.ed-title {
  width: 100%; border: 0; background: transparent; outline: none;
  font: 400 22px/1.3 "Google Sans", Roboto, sans-serif; padding: 6px 0; border-bottom: 2px solid transparent;
}
.ed-title:focus { border-bottom-color: var(--accent); }
.ed-row { display: flex; align-items: flex-start; gap: 14px; padding: 8px 0; }
.ed-ico { width: 20px; height: 20px; color: var(--muted); margin-top: 8px; }
.ed-row textarea, .ed-row input, .fight-fields > input {
  flex: 1; border: 0; background: var(--hover); border-radius: 8px; padding: 8px 12px; outline: none; resize: vertical;
}
.fight-fields > input { width: 100%; margin-top: 8px; }
.ed-row textarea:focus, .ed-row input:focus, .fight-fields > input:focus { box-shadow: inset 0 0 0 2px var(--accent); }
.ed-section { border-top: 1px solid var(--line); margin-top: 12px; padding-top: 12px; }
.field-label { font-weight: 500; margin: 12px 0 8px; }
.ed-section > .field-label:first-child { margin-top: 0; }

.switch-row { display: flex; align-items: center; justify-content: space-between; cursor: pointer; font-weight: 500; }
.switch {
  appearance: none; width: 36px; height: 14px; border-radius: 7px; background: var(--line);
  position: relative; cursor: pointer; margin: 8px 4px;
}
.switch::before {
  content: ""; position: absolute; top: -3px; left: -4px; width: 20px; height: 20px; border-radius: 50%;
  background: var(--surface); box-shadow: 0 1px 3px rgba(0,0,0,.4); transition: transform .15s, background .15s;
}
.switch:checked { background: color-mix(in srgb, var(--fight) 45%, transparent); }
.switch:checked::before { transform: translateX(24px); background: var(--fight); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button {
  border: 1px solid var(--line); border-radius: 8px; padding: 4px 10px; font-size: 13px; color: var(--muted);
}
.chips button:hover { background: var(--hover); }
.chips button.on { background: var(--fight-soft); color: var(--fight); border-color: transparent; font-weight: 500; }

.intensity { display: flex; gap: 6px; }
.intensity button {
  width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line); color: var(--muted); font-weight: 500;
}
.intensity button.on { background: var(--fight); border-color: var(--fight); color: var(--surface); }
.intensity button.lit { background: var(--fight-soft); color: var(--fight); border-color: transparent; }

.add-sub { display: flex; align-items: center; gap: 14px; margin-left: 8px; padding: 4px 8px; }
.add-sub .plus { width: 18px; text-align: center; color: var(--accent); font-size: 20px; line-height: 1; }
.add-sub input { flex: 1; border: 0; background: transparent; outline: none; padding: 6px 0; border-bottom: 1px solid transparent; }
.add-sub input:focus { border-bottom-color: var(--accent); }
#ed-decisions { margin-left: 0; }
.dec-edit { flex: 1; border: 0; background: transparent; outline: none; padding: 0; line-height: 22px; }
.done .dec-edit { text-decoration: line-through; color: var(--muted); }
.x { opacity: 0; width: 28px; height: 28px; border-radius: 50%; color: var(--muted); display: grid; place-items: center; }
.x svg { width: 16px; height: 16px; }
.row:hover .x, .x:focus-visible { opacity: 1; }
.x:hover { background: var(--line); }
@media (hover: none) { .x { opacity: .6; } }

/* ---------- calendar ---------- */
.cal-head { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; margin-bottom: 4px; }
.cal-head h2 { margin-left: 8px; flex: 1; }
.cal-legend { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; }
.dot-talk { background: var(--accent); }
.dot-fight { background: var(--fight); margin-left: 8px; }
.cal-summary { margin: 4px 0 12px; }
.cal-grid {
  display: grid; grid-template-columns: repeat(7, minmax(0, 1fr));
  border-top: 1px solid var(--line); border-left: 1px solid var(--line);
}
.cal-dow { padding: 6px; font-size: 11px; font-weight: 500; color: var(--muted); text-align: center; text-transform: uppercase; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.cal-cell {
  min-height: 96px; padding: 4px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line);
  text-align: left; display: flex; flex-direction: column; gap: 2px; min-width: 0;
}
.cal-cell:hover { background: var(--hover); }
.cal-cell.out { color: var(--faint); }
.cal-cell.out .cal-n { opacity: .5; }
.cal-cell.sel { box-shadow: inset 0 0 0 2px var(--accent); }
.cal-cell.f1 { background: color-mix(in srgb, var(--fight-soft) 50%, transparent); }
.cal-cell.f2 { background: var(--fight-soft); }
.cal-n { font-size: 12px; font-weight: 500; width: 24px; height: 24px; display: grid; place-items: center; border-radius: 50%; align-self: center; }
.cal-cell.today .cal-n { background: var(--accent); color: var(--bg); }
.ev {
  font-size: 11px; line-height: 18px; padding: 0 6px; border-radius: 4px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  background: var(--accent-soft); color: var(--accent);
}
.ev.fight { background: var(--fight); color: var(--surface); }
.ev.more { background: none; color: var(--muted); }
.dots { display: none; gap: 3px; justify-content: center; flex-wrap: wrap; }
.cal-day { margin-top: 20px; }
.cal-day h3 { font: 500 16px/1.4 "Google Sans", Roboto, sans-serif; margin: 0 0 4px; }

@media (max-width: 640px) {
  .topbar { gap: 8px; padding: 8px 12px; }
  .brand { display: none; }
  .cal-cell { min-height: 54px; align-items: center; }
  .cal-cell .ev { display: none; }
  .cal-cell .dots { display: flex; }
  .cal-legend { width: 100%; margin-top: 4px; }
  .editor {
    width: 100vw; max-width: 100vw; margin: auto 0 0; border-radius: 16px 16px 0 0; max-height: 92dvh;
  }
}

/* ---------- insights ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin: 8px 0 24px; }
.stat { border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
.stat .v { font: 400 28px/1.2 "Google Sans", Roboto, sans-serif; font-variant-numeric: tabular-nums; }
.stat .l { color: var(--muted); font-size: 13px; }
.panel { border: 1px solid var(--line); border-radius: 12px; padding: 16px; margin-bottom: 16px; }
.panel h3 { font: 500 15px/1.4 "Google Sans", Roboto, sans-serif; margin: 0 0 12px; }
.bars { display: grid; grid-template-columns: minmax(80px, max-content) 1fr auto; gap: 8px 12px; align-items: center; }
.bar-label { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-track { height: 10px; border-radius: 5px; background: var(--hover); overflow: hidden; }
.bar-fill { height: 100%; border-radius: 5px; background: var(--fight); }
.bar-val { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.cols { display: flex; align-items: flex-end; gap: 6px; height: 120px; }
.col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; min-width: 0; }
.col .bar { width: 100%; max-width: 32px; border-radius: 4px 4px 0 0; background: var(--fight); min-height: 2px; }
.col .bar.zero { background: var(--line); }
.col span { font-size: 11px; color: var(--muted); }
.col b { font-size: 11px; font-weight: 500; color: var(--muted); }

/* ---------- login & toast ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(360px, 100%); display: flex; flex-direction: column; gap: 14px; text-align: center; }
.login-card h1 { font: 400 32px/1.2 "Google Sans", Roboto, sans-serif; margin: 0; }
.login-card p { margin: 0; }
.login-card input { border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; background: transparent; outline: none; font-size: 16px; }
.login-card input:focus { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.login-card .btn { padding: 12px; }

.toast {
  position: fixed; left: 16px; bottom: 16px; z-index: 20;
  background: #323232; color: #fff; padding: 12px 20px; border-radius: 6px; box-shadow: var(--shadow);
  max-width: calc(100vw - 32px);
}

/* ---------- do's & don'ts ---------- */
.lede { margin: 0 0 16px; }
#view-prefs { max-width: 1100px; }
.pref-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
@media (max-width: 720px) { .pref-cols { grid-template-columns: 1fr; } }
.pref-col { min-width: 0; }
.pref-head { display: flex; align-items: center; gap: 10px; font: 500 16px/1.4 "Google Sans", Roboto, sans-serif; margin: 0 0 4px; padding: 0 8px; }
.pref-head .muted { font-weight: 400; font-size: 14px; }
.kind-ico { width: 22px; height: 22px; flex: none; margin: 1px; }
.kind-ico.do { color: var(--ok); }
.kind-ico.dont { color: var(--fight); }
.sub .kind-ico { width: 20px; height: 20px; }
.pref-add { margin: 0 0 4px; padding: 6px 8px; }
.pref-add .plus { width: 22px; }
.chip.who { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.chip.link { cursor: pointer; }
.chip.link:hover { background: var(--hover); }
.empty-col { color: var(--muted); padding: 12px 8px 12px 46px; font-size: 13px; }
.seg-sm button { padding: 3px 10px; font-size: 12px; }
#ed-pref-kind button[data-kind="do"].on { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
#ed-pref-kind button[data-kind="dont"].on, #pe-kind button[data-kind="dont"].on { background: var(--fight-soft); color: var(--fight); }
#pe-kind button[data-kind="do"].on { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
#pe-kind { margin: 4px 0 8px; }
.add-sub:has(#ed-pref-kind) { margin-left: 0; gap: 10px; }
.who-chips button.on { background: var(--accent-soft); color: var(--accent); }
.plain-input {
  width: 100%; border: 0; background: var(--hover); border-radius: 8px; padding: 8px 12px; outline: none; margin-top: 8px;
}
.plain-input:focus { box-shadow: inset 0 0 0 2px var(--accent); }
select.plain-input { margin-top: 0; }
#ed-prefs { margin-left: 0; }

/* do's & don'ts: husband / wife sides */
.sides { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
.sides:has(.side[hidden]) { grid-template-columns: 1fr; max-width: 720px; }
@media (max-width: 760px) { .sides { grid-template-columns: 1fr; } }
.side { border: 1px solid var(--line); border-radius: 16px; padding: 12px 8px 8px; min-width: 0; }
.side-head {
  display: flex; align-items: center; gap: 8px; margin: 0 8px 8px;
  font: 400 20px/1.3 "Google Sans", Roboto, sans-serif;
}
.side-count { font-size: 12px; font-weight: 500; color: var(--muted); background: var(--hover); border-radius: 10px; padding: 0 8px; line-height: 20px; }
.side-count:empty { display: none; }
.side-block + .side-block { border-top: 1px solid var(--line); margin-top: 8px; padding-top: 12px; }
.side .pref-head { font-size: 15px; }
.side .empty-col { padding: 4px 8px 8px 46px; }
.add-sub:has(#ed-pref-kind) { flex-wrap: wrap; }
.add-sub:has(#ed-pref-kind) input { flex: 1 1 220px; }
#ed-pref-who button.on, #pe-who button.on { background: var(--accent-soft); color: var(--accent); }
#pe-who { margin-bottom: 4px; }
