:root {
  --bg: #f6f5f1; --surface: #ffffff; --surface-2: #efede7; --text: #1d1d1b;
  --muted: #6b6a65; --line: #e2dfd7; --accent: #2f6b4f; --accent-ink: #ffffff;
  --today: #fff4d6; --warn: #b54708; --danger: #b42318; --radius: 12px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.05);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151614; --surface: #1e201d; --surface-2: #272a26; --text: #ecebe6;
    --muted: #9c9a93; --line: #33362f; --accent: #6fbf8f; --accent-ink: #0f1a13;
    --today: #33301f; --warn: #f5a35c; --danger: #f97066; --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* header */
.top {
  position: sticky; top: 0; z-index: 5; background: var(--bg);
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 12px max(16px, calc((100% - 1100px) / 2)); border-bottom: 1px solid var(--line);
}
.top h1 { font-size: 18px; margin: 0; letter-spacing: -.01em; }
.tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 3px; border-radius: 10px; }
.tab { border: 0; background: none; padding: 6px 12px; border-radius: 8px; cursor: pointer; color: var(--muted); }
.tab.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); font-weight: 600; }
.badge { background: var(--warn); color: #fff; border-radius: 999px; padding: 0 6px; font-size: 12px; margin-left: 2px; }
.me { margin-left: auto; color: var(--muted); display: flex; gap: 8px; align-items: center; }

main { max-width: 1100px; margin: 0 auto; padding: 16px; }

/* controls */
input, select, textarea {
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; min-width: 0;
}
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
.primary { background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 8px; padding: 7px 14px; cursor: pointer; font-weight: 600; }
.ghost { background: none; border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px; cursor: pointer; }
.icon { background: none; border: 0; font-size: 22px; line-height: 1; width: 34px; height: 34px; border-radius: 8px; cursor: pointer; color: var(--text); }
.icon:hover, .ghost:hover { background: var(--surface-2); }
.del { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 18px; padding: 0 4px; border-radius: 6px; }
.del:hover { color: var(--danger); background: var(--surface-2); }

/* calendar */
.month-bar { display: flex; align-items: center; gap: 6px; margin-bottom: 10px; flex-wrap: wrap; }
.month-bar h2 { margin: 0 4px; font-size: 20px; min-width: 9ch; text-align: center; }
#quick-add { margin-left: auto; }
.cal-head, .grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
.cal-head span { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; padding: 0 6px 4px; }
.day {
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px; min-height: 104px;
  padding: 6px; text-align: left; cursor: pointer; display: flex; flex-direction: column; gap: 3px; overflow: hidden;
}
.day:hover { border-color: var(--accent); }
.day.blank { background: transparent; border-style: dashed; cursor: default; opacity: .5; }
.day.blank:hover { border-color: var(--line); }
.day.today { background: var(--today); }
.day .num { font-size: 13px; font-weight: 600; display: flex; justify-content: space-between; }
.day.today .num span:first-child { color: var(--accent); }
.flag { font-size: 11px; color: var(--warn); font-weight: 600; }
.chip {
  font-size: 12px; line-height: 1.3; padding: 2px 6px; border-radius: 6px; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; background: var(--surface-2); border-left: 3px solid var(--c);
}
.more { font-size: 11px; color: var(--muted); }
.dots { display: none; gap: 3px; flex-wrap: wrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c); display: inline-block; flex: none; }

.sub { margin: 22px 0 8px; font-size: 14px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.tally { display: grid; gap: 8px; }
.tally-row { display: grid; grid-template-columns: 110px 1fr 36px; align-items: center; gap: 10px; }
.tally-row .who { display: flex; gap: 8px; align-items: center; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.bar { height: 10px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--c); border-radius: 999px; }
.tally-row .n { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }

/* cards & lists */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.card h3 { margin: 0 0 10px; font-size: 16px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row input { flex: 1; }
.list { list-style: none; margin: 0 0 10px; padding: 0; }
.list li { display: flex; align-items: center; gap: 8px; padding: 7px 2px; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.list li .grow { flex: 1; overflow-wrap: anywhere; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.hint { color: var(--muted); font-size: 14px; }
.empty { color: var(--muted); font-size: 14px; padding: 6px 2px; }

/* notes */
.note-form { display: grid; gap: 10px; margin-bottom: 16px; }
.note-form textarea { resize: vertical; width: 100%; }
.note-form .row { justify-content: space-between; }
.note-form label { color: var(--muted); display: flex; gap: 8px; align-items: center; }
.notes { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.note { position: relative; display: flex; flex-direction: column; gap: 8px; border-top: 4px solid var(--c, var(--line)); }
.note .body { white-space: pre-wrap; overflow-wrap: anywhere; }
.note .meta { display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: 12px; margin-top: auto; }
.note .meta .when { margin-left: auto; }
.note.done { opacity: .55; }
.note.done .body { text-decoration: line-through; }
.due { font-size: 12px; font-weight: 600; color: var(--muted); }
.due.soon { color: var(--warn); }
.due.late { color: var(--danger); }
.note input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--accent); }

/* dialog */
dialog { border: 1px solid var(--line); border-radius: 14px; padding: 16px; width: min(440px, calc(100vw - 32px)); background: var(--surface); color: var(--text); }
dialog::backdrop { background: rgba(0,0,0,.35); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.dlg-head h3 { margin: 0; }
.log-form { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; }

/* login / logout */
.login-body { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { width: min(360px, 100%); display: grid; gap: 12px; }
.login h1 { margin: 0; font-size: 22px; }
.login .hint { margin: 0; }
.login .primary { padding: 9px 14px; }
.login-error { margin: 0; color: var(--danger); font-size: 14px; font-weight: 600; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.logout { margin: 0; }
.logout button { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 6px 4px; font-size: 14px; }
.logout button:hover { color: var(--text); text-decoration: underline; }

/* weather */
.wx-now { display: grid; grid-template-columns: auto 1fr; gap: 6px 20px; align-items: center; }
.wx-icon { font-size: 64px; line-height: 1; grid-row: span 2; }
.wx-temp { font-size: 44px; font-weight: 700; letter-spacing: -.02em; line-height: 1; }
.wx-temp small { font-size: 16px; font-weight: 500; color: var(--muted); margin-left: 8px; letter-spacing: 0; }
.wx-desc { color: var(--muted); }
.wx-stats { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 8px; margin-top: 10px; }
.wx-stat { background: var(--surface-2); border-radius: 10px; padding: 8px 10px; }
.wx-stat b { display: block; font-size: 17px; }
.wx-stat span { font-size: 12px; color: var(--muted); }
.wx-stale { grid-column: 1 / -1; color: var(--warn); font-size: 13px; }
.wx-hours { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; scroll-snap-type: x mandatory; }
.wx-hour { flex: none; width: 64px; scroll-snap-align: start; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 8px 4px; text-align: center; display: grid; gap: 2px; }
.wx-hour .t { font-size: 12px; color: var(--muted); }
.wx-hour .i { font-size: 22px; }
.wx-hour .v { font-weight: 600; }
.wx-hour .p { font-size: 11px; color: #2e86ab; min-height: 1em; }
.wx-days { padding: 4px 14px; }
.wx-day { display: grid; grid-template-columns: 76px 28px 44px 36px 1fr 36px; gap: 10px; align-items: center; padding: 9px 0; border-bottom: 1px solid var(--line); }
.wx-day:last-child { border-bottom: 0; }
.wx-day .d { font-weight: 600; }
.wx-day .i { font-size: 20px; text-align: center; }
.wx-day .p { font-size: 12px; color: #2e86ab; text-align: right; }
.wx-day .lo { color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }
.wx-day .hi { font-weight: 600; font-variant-numeric: tabular-nums; }
.wx-range { position: relative; height: 6px; background: var(--surface-2); border-radius: 999px; }
.wx-range i { position: absolute; top: 0; bottom: 0; border-radius: 999px; background: linear-gradient(90deg, #2e86ab, #f0a202); }
.wx-credit a { color: var(--muted); }
@media (max-width: 680px) {
  .wx-day { grid-template-columns: 56px 24px 34px 30px 1fr 30px; gap: 6px; }
  .wx-icon { font-size: 48px; }
  .wx-temp { font-size: 36px; }
}

.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 9px 14px; border-radius: 10px; font-size: 14px; z-index: 20; }

/* phones */
@media (max-width: 680px) {
  .top { gap: 10px; }
  .me { margin-left: 0; flex: 1; }
  .me select { flex: 1; }
  .cal-head, .grid { gap: 3px; }
  .cal-head span { padding: 0; text-align: center; font-size: 11px; }
  .day { min-height: 58px; padding: 4px; border-radius: 8px; }
  .day .chip, .day .more { display: none; }
  .day .dots { display: flex; }
  .flag { font-size: 0; }
  .flag::after { content: "●"; font-size: 9px; }
  #quick-add { width: 100%; margin-left: 0; order: 9; }
  .two-col { grid-template-columns: 1fr; }
  .log-form { grid-template-columns: 1fr 1fr; }
  .log-form .primary { grid-column: span 2; }
  .tally-row { grid-template-columns: 90px 1fr 30px; }
}
