:root {
  --bg: #fbf7f7;
  --surface: #ffffff;
  --surface-2: #f5eef0;
  --border: #e8dde0;
  --text: #2a2126;
  --muted: #7d6f75;
  --accent: #c04f74;
  --accent-soft: #f7e7ec;
  --accent-ink: #8f3455;
  --darcy: #b0447d;
  --james: #3f7292;
  --danger: #b23b3b;
  --shadow: 0 1px 2px rgba(42, 33, 38, .06), 0 8px 24px rgba(42, 33, 38, .05);
  --radius: 14px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171315;
    --surface: #1f1a1e;
    --surface-2: #2a2229;
    --border: #372e35;
    --text: #f0e9ec;
    --muted: #a4949c;
    --accent: #e88bab;
    --accent-soft: #33222a;
    --accent-ink: #f3aac4;
    --darcy: #e58bbd;
    --james: #7fb6d8;
    --danger: #e8807f;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

.wrap {
  max-width: 780px;
  margin: 0 auto;
  padding: 0 16px calc(48px + env(safe-area-inset-bottom));
}

/* ------------------------------------------------------------- header -- */

header.top {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}

.top-inner {
  max-width: 780px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 650;
  font-size: 1.05rem;
  letter-spacing: -.01em;
  margin-right: auto;
  min-width: 0;
}

.brand svg { flex: none; }
.brand span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.whoami {
  font-size: .78rem;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 10px;
  white-space: nowrap;
}

/* ------------------------------------------------------------ controls -- */

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  border: 0;
  background: none;
}

.btn {
  border-radius: 10px;
  padding: 9px 14px;
  font-size: .9rem;
  font-weight: 550;
  border: 1px solid var(--border);
  background: var(--surface);
  transition: background .12s, border-color .12s;
}

.btn:hover { background: var(--surface-2); }

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn.primary:hover { background: var(--accent-ink); border-color: var(--accent-ink); }
.btn.ghost { border-color: transparent; background: none; color: var(--muted); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .5; cursor: default; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  color: var(--muted);
  flex: none;
}

.icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* --------------------------------------------------------------- verse -- */

.verse {
  margin: 16px 0 0;
  padding: 14px 16px;
  border-radius: var(--radius);
  background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 22%, transparent);
}

.verse p {
  margin: 0;
  font-size: .95rem;
  line-height: 1.55;
  font-style: italic;
}

.verse cite {
  display: block;
  margin-top: 6px;
  font-style: normal;
  font-size: .8rem;
  font-weight: 600;
  color: var(--accent-ink);
  letter-spacing: .01em;
}

/* -------------------------------------------------------------- filter -- */

.filter {
  display: flex;
  gap: 4px;
  margin: 16px 0 0;
  padding: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow-x: auto;
  scrollbar-width: none;
}

.filter::-webkit-scrollbar { display: none; }

.filter button {
  flex: 1 1 auto;
  padding: 7px 10px;
  border-radius: 9px;
  font-size: .82rem;
  font-weight: 550;
  color: var(--muted);
  white-space: nowrap;
}

.filter .short { display: none; }

@media (max-width: 520px) {
  .filter .long { display: none; }
  .filter .short { display: inline; }
  .filter button { padding: 7px 4px; }
}

.filter button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0, 0, 0, .08);
}

/* --------------------------------------------------------------- chart -- */

.card {
  margin-top: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.chart-card { padding: 14px 12px 10px; }

.chart-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 0 4px 8px;
}

.chart-title { font-size: .82rem; font-weight: 600; color: var(--muted); }
.chart-total { margin-left: auto; font-size: .82rem; color: var(--muted); }
.chart-total b { color: var(--text); font-weight: 650; }

.chart-holder { position: relative; }
.chart-holder svg { display: block; width: 100%; height: auto; touch-action: pan-y; }

.chart-tip {
  position: absolute;
  pointer-events: none;
  transform: translate(-50%, -100%);
  background: var(--text);
  color: var(--bg);
  font-size: .75rem;
  line-height: 1.35;
  padding: 5px 8px;
  border-radius: 7px;
  white-space: nowrap;
  opacity: 0;
  transition: opacity .1s;
  z-index: 5;
}

.chart-tip.on { opacity: 1; }
.chart-tip b { display: block; font-weight: 600; }

/* ------------------------------------------------------------ arg list -- */

.list-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 26px 0 10px;
}

.list-head h2 {
  margin: 0;
  font-size: .82rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .06em;
}

.arg { padding: 12px 14px; }
.arg + .arg { margin-top: 8px; }

.arg-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.arg-date { font-weight: 600; font-size: .93rem; }

.tod {
  font-size: .72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid var(--border);
}

.tod[data-tod="morning"]   { background: #fdf1dc; color: #8a6516; border-color: #f2e0bd; }
.tod[data-tod="afternoon"] { background: #e4f2e6; color: #3f6f4b; border-color: #c9e2ce; }
.tod[data-tod="evening"]   { background: #e6e9f7; color: #4a5490; border-color: #cdd3ee; }
.tod[data-tod="late"]      { background: #e9e2f0; color: #61497f; border-color: #d5c9e2; }

@media (prefers-color-scheme: dark) {
  .tod[data-tod="morning"]   { background: #3a2f18; color: #e7c67c; border-color: #4d3f20; }
  .tod[data-tod="afternoon"] { background: #1f3325; color: #96cfa5; border-color: #2c472f; }
  .tod[data-tod="evening"]   { background: #232842; color: #9fabe6; border-color: #333a5c; }
  .tod[data-tod="late"]      { background: #2c2438; color: #bda6dd; border-color: #3d3350; }
}

.arg-actions { margin-left: auto; display: flex; gap: 2px; }

/* Each person is a block of two lines: their scores, then their words directly
   beneath, indented to line up under the tags so the pairing is obvious. */
.side { padding: 9px 0 8px; }
.side + .side { border-top: 1px solid color-mix(in srgb, var(--border) 55%, transparent); }

.side-head {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 26px;
}

.scores {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  min-width: 0;
  padding: 2px 4px;
  margin: -2px -4px;
  border-radius: 8px;
  text-align: left;
}

.scores.is-mine:hover { background: var(--surface-2); }
.side-head .row-actions { margin-left: auto; flex: none; }

.side .persp-wrap { padding-left: 60px; margin-top: 2px; }

.who {
  width: 52px;
  flex: none;
  font-size: .74rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
}

[data-who="darcy"] .who { color: var(--darcy); }
[data-who="james"] .who { color: var(--james); }

.persp {
  margin: 0;
  font-size: .93rem;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 1;
  line-clamp: 1;
  overflow: hidden;
}

.arg.open .persp { -webkit-line-clamp: unset; line-clamp: unset; overflow: visible; }
.persp.empty { color: var(--muted); font-style: italic; }

.persp-wrap { min-width: 0; }
.row-actions { display: flex; gap: 2px; }


.row-edit {
  border-radius: 8px;
  width: 30px;
  height: 26px;
  display: grid;
  place-items: center;
  color: var(--muted);
}

.row-edit:hover { background: var(--surface-2); color: var(--accent); }
.row-edit.is-hidden { color: var(--accent); }

/* Inline with the words rather than above them, so a card still reads as three
   rows: when it was, her side, his side. */
.tag {
  display: inline-block;
  vertical-align: baseline;

  padding: 1px 7px;
  border-radius: 999px;
  font-size: .7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  white-space: nowrap;
  border: 1px solid transparent;
}

.tag.sev[data-sev="minor"]     { background: #e4f2e6; color: #3f6f4b; border-color: #c9e2ce; }
.tag.sev[data-sev="difficult"] { background: #fdf1dc; color: #8a6516; border-color: #f2e0bd; }
.tag.sev[data-sev="serious"]   { background: #fae3e3; color: #a03b3b; border-color: #eecccc; }

.tag.feel {
  background: var(--surface-2);
  color: var(--muted);
  border-color: var(--border);
  font-weight: 600;
}

.tag.private {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--accent-soft);
  color: var(--accent-ink);
  border-color: color-mix(in srgb, var(--accent) 24%, transparent);
}

.tag.none {
  background: none;
  border-color: var(--border);
  border-style: dashed;
  color: var(--muted);
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
  font-size: .72rem;
}

.scores.is-mine:hover .tag.none { border-color: var(--accent); color: var(--accent-ink); }

@media (prefers-color-scheme: dark) {
  .tag.sev[data-sev="minor"]     { background: #1f3325; color: #96cfa5; border-color: #2c472f; }
  .tag.sev[data-sev="difficult"] { background: #3a2f18; color: #e7c67c; border-color: #4d3f20; }
  .tag.sev[data-sev="serious"]   { background: #3b2222; color: #eb9a9a; border-color: #512e2e; }
}

.persp .empty { color: var(--muted); font-style: italic; }

/* A phone has less to spare, so the name column narrows and the words are
   indented less. The expander covers whatever still gets cut. */
@media (max-width: 520px) {
  .who { width: 44px; font-size: .68rem; letter-spacing: .03em; }
  .tag { font-size: .66rem; padding: 1px 6px; letter-spacing: .02em; }
  .row-edit { width: 27px; }
  .arg { padding: 12px 11px; }
  .side .persp-wrap { padding-left: 52px; }
}

.persp.locked {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  color: var(--muted);
  font-style: italic;
}

.persp.locked .until { white-space: nowrap; }
.persp.locked b { font-style: normal; font-weight: 650; color: var(--accent-ink); }

.hide-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-top: 6px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 24%, transparent);
  color: var(--accent-ink);
  font-size: .74rem;
  font-weight: 600;
  line-height: 1.4;
}

.hide-badge b { font-weight: 700; font-variant-numeric: tabular-nums; }
.countdown { font-variant-numeric: tabular-nums; }

.field select {
  width: 100%;
  font: inherit;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

.field select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.dlg-note {
  margin: 0 0 14px;
  font-size: .88rem;
  line-height: 1.5;
  color: var(--muted);
}

.dlg-note.small { margin: -4px 0 0; font-size: .8rem; }

.expand {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 6px;
  border-top: 1px solid color-mix(in srgb, var(--border) 55%, transparent);
  font-size: .78rem;
  font-weight: 600;
  color: var(--accent-ink);
}

.expand:hover { background: var(--surface-2); border-radius: 0 0 8px 8px; }

.editor { grid-column: 2 / -1; }

.editor textarea {
  width: 100%;
  min-height: 92px;
  resize: vertical;
  font: inherit;
  font-size: .93rem;
  padding: 9px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

.editor textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.editor-actions { display: flex; gap: 6px; justify-content: flex-end; margin-top: 8px; }

/* --------------------------------------------------------------- empty -- */

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--muted);
}

.empty-state p { margin: 0 0 4px; }
.empty-state .hint { font-size: .87rem; }

/* -------------------------------------------------------------- dialog -- */

dialog {
  width: min(520px, calc(100vw - 24px));
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  padding: 0;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .25);
}

dialog::backdrop { background: rgba(20, 12, 16, .45); backdrop-filter: blur(2px); }

.dlg-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.dlg-head h2 { margin: 0; font-size: 1rem; font-weight: 650; }
.dlg-body { padding: 16px; max-height: min(68vh, 560px); overflow-y: auto; }

.dlg-foot {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

.field { margin-bottom: 14px; }

.field > label {
  display: block;
  font-size: .78rem;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  margin-bottom: 6px;
}

.field input[type="date"], .field textarea {
  width: 100%;
  font: inherit;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

.field textarea { min-height: 120px; resize: vertical; }
.field input:focus-visible, .field textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.tod-picker { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }

.tod-picker button {
  padding: 9px 4px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  font-size: .82rem;
  font-weight: 550;
}

.sev-picker { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }

.sev-picker button {
  display: grid;
  gap: 2px;
  padding: 9px 6px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  text-align: center;
}

.sev-picker .chip-label { font-size: .85rem; font-weight: 600; }
.sev-picker .chip-hint { font-size: .68rem; line-height: 1.3; color: var(--muted); }
.sev-picker button[aria-pressed="true"] .chip-hint { color: inherit; opacity: .8; }

.feel-picker { display: flex; flex-wrap: wrap; gap: 6px; }

.feel-picker button {
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg);
  font-size: .82rem;
  font-weight: 550;
}

.tod-picker button[aria-pressed="true"],
.sev-picker button[aria-pressed="true"],
.feel-picker button[aria-pressed="true"] {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.sub-field { margin-top: 12px; }

.sub-field > label {
  display: block;
  font-size: .74rem;
  font-weight: 650;
  color: var(--muted);
  margin-bottom: 6px;
}

.form-error { color: var(--danger); font-size: .87rem; margin: 0 0 10px; }

/* --------------------------------------------------------------- setup -- */

.setup {
  max-width: 440px;
  margin: 8vh auto 0;
  padding: 0 20px 40px;
  text-align: center;
}

.setup h1 { font-size: 1.5rem; margin: 18px 0 6px; letter-spacing: -.02em; }
.setup .lead { color: var(--muted); margin: 0 0 22px; font-size: .95rem; }

.who-list { display: grid; gap: 10px; text-align: left; }

.who-list button {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-weight: 600;
  box-shadow: var(--shadow);
}

.who-list button:hover { border-color: var(--accent); background: var(--accent-soft); }

.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: .85rem;
  font-weight: 700;
  color: #fff;
  flex: none;
}

.avatar[data-person="darcy"] { background: var(--darcy); }
.avatar[data-person="james"] { background: var(--james); }

.who-sub { display: block; font-size: .78rem; font-weight: 450; color: var(--muted); }
.setup .warn { margin-top: 22px; font-size: .82rem; color: var(--muted); line-height: 1.5; }

/* ------------------------------------------------------------ settings -- */

.set-block { margin-bottom: 20px; }
.set-block:last-child { margin-bottom: 0; }

.set-block h3 {
  margin: 0 0 8px;
  font-size: .78rem;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
}

.set-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  font-size: .9rem;
}

.set-row + .set-row { margin-top: 6px; }
.set-row .grow { flex: 1; min-width: 0; }
.set-row .sub { display: block; font-size: .78rem; color: var(--muted); }

.set-row .trunc {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.code {
  display: block;
  margin-top: 8px;
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: .76rem;
  overflow-x: auto;
  white-space: pre;
  color: var(--muted);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: .88rem;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s, transform .18s;
  z-index: 60;
  max-width: calc(100vw - 32px);
}

.toast.on { opacity: 1; transform: translate(-50%, 0); }
[hidden] { display: none !important; }

.expand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
}

.ico { display: block; }

/* Thirteen moods should still land in three rows on a phone. Placed at the very
   end so it always wins -- a media query carries no specificity of its own, so
   it only beats the base rule by coming later. */
@media (max-width: 520px) {
  .feel-picker { gap: 5px; }
  .feel-picker button { padding: 7px 8px; font-size: .77rem; }
}
