/* Layout: a day sheet. Date bar on top, tasks + habits in the left column, the evening page and comments on the right; stacks on phones. */
:root {
  --bg: #eef2ef;
  --paper: #fbfcfb;
  --fg: #1c2622;
  --muted: #5d6b65;
  --line: #d5ddd8;
  --accent: #2c6a55;
  --accent-soft: #dcebe4;
  --mark: #d99a1e;
  --mark-soft: #f6e6c4;
  --danger: #b0413e;
  --f-display: "Bricolage Grotesque", "Segoe UI", system-ui, sans-serif;
  --f-body: "Atkinson Hyperlegible", "Segoe UI", system-ui, sans-serif;
  --f-mono: "JetBrains Mono", ui-monospace, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121816; --paper: #1a221f; --fg: #e3ebe7; --muted: #94a59d; --line: #2c3833;
    --accent: #6cc4a3; --accent-soft: #1f3a31; --mark: #e8b44a; --mark-soft: #3a3020; --danger: #e07a76;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg); color: var(--fg);
  font-family: var(--f-body); font-size: 16px; line-height: 1.5;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: calc(20px + env(safe-area-inset-top, 0px)) calc(48px + env(safe-area-inset-bottom, 0px));
}
.wrap { max-width: 1120px; margin: 0 auto; display: grid; gap: 20px; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.muted { color: var(--muted); }

/* Header */
header { display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: 12px 24px; }
.head-right { display: grid; gap: 10px; justify-items: end; }
@media (max-width: 520px) { .head-right { justify-items: start; } }
.brand { font-family: var(--f-mono); font-size: 12px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.whoami { text-transform: none; letter-spacing: 0; margin-left: 6px; }
h1 { font-family: var(--f-display); font-weight: 700; font-size: clamp(30px, 5vw, 46px); line-height: 1.05; margin: 4px 0 0; text-wrap: balance; letter-spacing: -0.01em; }
h1 .sub { display: block; font-weight: 500; font-size: .45em; color: var(--muted); letter-spacing: 0; margin-top: 6px; }
.daynav { display: flex; align-items: center; gap: 6px; }
.daynav button { border: 1px solid var(--line); background: var(--paper); border-radius: 999px; height: 38px; min-width: 38px; padding: 0 14px; }
.daynav button:hover { border-color: var(--accent); }
.daynav .today-btn[aria-pressed="true"] { background: var(--accent); color: var(--paper); border-color: var(--accent); }
.tally { display: flex; flex-wrap: wrap; gap: 8px; font-family: var(--f-mono); font-size: 13px; font-variant-numeric: tabular-nums; }
.tally span { background: var(--paper); border: 1px solid var(--line); border-radius: 999px; padding: 4px 12px; }
.tally b { color: var(--accent); font-weight: 600; }
.mode-note { font-size: 13px; color: var(--muted); }

/* Columns */
.cols { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; align-items: start; }
@media (max-width: 820px) { .cols { grid-template-columns: minmax(0, 1fr); } }
.stack { display: grid; gap: 20px; min-width: 0; }
section.sheet { background: var(--paper); border: 1px solid var(--line); border-radius: 14px; padding: 18px 20px 20px; min-width: 0; }
.sheet-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
h2 { font-family: var(--f-display); font-weight: 700; font-size: 21px; margin: 0; }
.sheet-head .meta { font-family: var(--f-mono); font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.linkish { background: none; border: 0; padding: 2px 4px; color: var(--accent); font-size: 14px; }
.linkish.small { font-family: var(--f-mono); font-size: 12px; letter-spacing: 0; text-transform: none; }
.linkish:hover { text-decoration: underline; }

/* To-dos */
.add-row { display: flex; gap: 8px; }
#habitForm { margin-top: 12px; }
.add-row input { flex: 1; min-width: 0; border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: 9px 12px; }
.add-row input:focus { border-color: var(--accent); outline: none; }
.add-row button, .primary { border: 0; background: var(--accent); color: var(--paper); border-radius: 10px; padding: 0 16px; font-weight: 700; }
ul.todos { list-style: none; margin: 12px 0 0; padding: 0; display: grid; }
ul.todos li { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: start; gap: 10px; padding: 9px 2px; border-top: 1px dashed var(--line); }
ul.todos li:first-child { border-top: 0; }
ul.todos li.empty { display: block; }
.check { width: 22px; height: 22px; border-radius: 6px; border: 2px solid var(--muted); background: transparent; padding: 0; display: grid; place-items: center; margin-top: 1px; }
.check svg { width: 14px; height: 14px; opacity: 0; }
li.done .check { background: var(--accent); border-color: var(--accent); }
li.done .check svg { opacity: 1; }
.todo-text { overflow-wrap: anywhere; }
li.done .todo-text { color: var(--muted); text-decoration: line-through; text-decoration-color: var(--muted); }
.carried { display: inline-block; font-family: var(--f-mono); font-size: 11px; color: var(--mark); background: var(--mark-soft); border-radius: 4px; padding: 0 6px; margin-left: 6px; vertical-align: 2px; }
.x { background: none; border: 0; color: var(--muted); padding: 0 4px; font-size: 18px; line-height: 1; opacity: .55; }
.x:hover, .x:focus-visible { color: var(--danger); opacity: 1; }
.empty { color: var(--muted); font-size: 14px; padding: 10px 0 2px; }

/* Habits */
.habit-grid { display: grid; gap: 4px; margin-top: 4px; overflow-x: auto; }
.hrow { display: grid; grid-template-columns: minmax(0, 1fr) repeat(7, 30px) 54px; align-items: center; gap: 4px; min-width: 360px; }
.hrow.headrow { font-family: var(--f-mono); font-size: 11px; color: var(--muted); text-align: center; }
.hrow.headrow .sel { color: var(--fg); font-weight: 600; }
.hname { display: flex; align-items: center; gap: 6px; min-width: 0; }
.hname span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--line); background: transparent; padding: 0; justify-self: center; }
.dot:not(:disabled):hover { border-color: var(--mark); }
.dot.on { background: var(--mark); border-color: var(--mark); }
.dot.sel { box-shadow: 0 0 0 2px var(--paper), 0 0 0 4px var(--accent-soft); }
.dot.future { opacity: .25; pointer-events: none; }
.streak { font-family: var(--f-mono); font-size: 12px; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.streak.hot { color: var(--mark); font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chips:empty { display: none; }
.chip { border: 1px dashed var(--line); background: transparent; border-radius: 999px; padding: 4px 12px; font-size: 14px; color: var(--muted); }
.chip:hover { border-color: var(--accent); color: var(--accent); }
.rm { background: none; border: 1px solid var(--line); border-radius: 6px; font-size: 12px; padding: 0 6px; color: var(--muted); flex: none; }
.rm.arm { color: var(--paper); background: var(--danger); border-color: var(--danger); }

/* Journal */
.mood { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; margin-bottom: 16px; }
.mood button { border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: 8px 4px 6px; display: grid; justify-items: center; gap: 4px; font-size: 13px; }
.mood .bars { display: flex; gap: 2px; align-items: end; height: 16px; }
.mood .bars i { width: 4px; border-radius: 2px; background: var(--line); }
.mood button[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); }
.mood button[aria-pressed="true"] .bars i.f { background: var(--accent); }
.field { display: grid; gap: 4px; margin-bottom: 14px; }
.field.last { margin-bottom: 0; }
.field label { font-family: var(--f-mono); font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.field textarea, .field input { width: 100%; border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: 10px 12px; line-height: 1.55; }
.field textarea { resize: vertical; min-height: 74px; }
.field textarea.tall { min-height: 150px; }
.field textarea:focus, .field input:focus { outline: none; border-color: var(--accent); }
.save-state { font-family: var(--f-mono); font-size: 12px; color: var(--muted); min-height: 1.5em; }

/* Comments */
.comments { display: grid; margin-bottom: 12px; }
.cmt { display: grid; grid-template-columns: 28px minmax(0, 1fr) auto; gap: 10px; padding: 10px 0; border-top: 1px dashed var(--line); }
.cmt:first-child { border-top: 0; padding-top: 2px; }
.avatar { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 13px; color: var(--paper); background: var(--accent); }
.avatar.other { background: var(--mark); color: var(--fg); }
.cmt .who { font-weight: 700; font-size: 14px; }
.cmt .when { font-family: var(--f-mono); font-size: 11px; color: var(--muted); margin-left: 8px; font-variant-numeric: tabular-nums; }
.cmt .body { overflow-wrap: anywhere; white-space: pre-wrap; }

/* History */
.history { display: grid; grid-template-columns: repeat(14, minmax(0, 1fr)); gap: 4px; }
.hcell { border: 1px solid var(--line); background: var(--bg); border-radius: 8px; padding: 6px 0 4px; display: grid; justify-items: center; gap: 3px; font-family: var(--f-mono); font-size: 10px; color: var(--muted); }
.hcell.sel { border-color: var(--accent); color: var(--fg); }
.hcell .m { width: 10px; height: 10px; border-radius: 50%; background: var(--line); }
.hcell .m.l1 { background: var(--danger); }
.hcell .m.l2 { background: var(--mark); opacity: .55; }
.hcell .m.l3 { background: var(--mark); }
.hcell .m.l4 { background: var(--accent); opacity: .6; }
.hcell .m.l5 { background: var(--accent); }
.hcell .wr { width: 6px; height: 3px; border-radius: 2px; background: transparent; }
.hcell .wr.has { background: var(--fg); opacity: .5; }
@media (max-width: 520px) { .history { grid-template-columns: repeat(7, minmax(0, 1fr)); } }
.legend { font-size: 12px; color: var(--muted); margin-top: 8px; }

/* Read-only view for people with the shared password */
.ro .owner-only, .ro .todos .x { display: none !important; }
.ro .check, .ro .mood button { cursor: default; }

/* Sign in */
.login { min-height: 80vh; display: grid; place-items: center; }
.login-card { width: 100%; max-width: 400px; background: var(--paper); border: 1px solid var(--line); border-radius: 14px; padding: 24px; display: grid; gap: 4px; }
.login-card h1 { font-size: 32px; margin-bottom: 4px; }
.login-card p { margin: 0 0 12px; font-size: 14px; }
.login-card .primary { height: 44px; margin-top: 4px; }
.form-error { color: var(--danger); font-size: 14px; margin-top: 8px; }

.toast { position: fixed; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); background: var(--fg); color: var(--bg); padding: 8px 16px; border-radius: 999px; font-size: 14px; z-index: 20; max-width: calc(100% - 32px); }
@media (prefers-reduced-motion: no-preference) {
  .dot, .check, .mood button { transition: background .15s, border-color .15s; }
}
