/* Momentos: a notebook page on dotted paper. */

:root {
  color-scheme: light dark;
  --paper: #f6f2e8;
  --card: #fffdf8;
  --card-2: #f9f5ec;
  --ink: #1d2433;
  --ink-soft: #586174;
  --ink-faint: #9aa1ae;
  --line: #ece5d7;
  --line-strong: #d8cfbd;
  --dot: #dcd3c1;
  --accent: #2b4ea2;
  --accent-ink: #ffffff;
  --accent-soft: rgba(43, 78, 162, 0.09);
  --danger: #b42318;
  --ok: #2e7d4f;
  --shadow: 0 1px 2px rgba(40, 32, 16, 0.06), 0 10px 28px -14px rgba(40, 32, 16, 0.22);
  --radius: 14px;

  /* One colour per weekday, Monday first. */
  --wd-0: #3b6fd8;
  --wd-1: #13998a;
  --wd-2: #5b9a2f;
  --wd-3: #c48a00;
  --wd-4: #e0662a;
  --wd-5: #d33d68;
  --wd-6: #8b5cd6;

  /* The mood traffic light. */
  --mood-good: #2f9e5b;
  --mood-okay: #e0ad12;
  --mood-bad: #d8423b;

  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --topbar-h: 64px; /* kept up to date by app.js */
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #14161b;
    --card: #1b1e25;
    --card-2: #21252d;
    --ink: #ebe8e1;
    --ink-soft: #a9afbb;
    --ink-faint: #6c7381;
    --line: #2a2e37;
    --line-strong: #3b404b;
    --dot: #262a32;
    --accent: #8ea8ff;
    --accent-ink: #10131a;
    --accent-soft: rgba(142, 168, 255, 0.12);
    --danger: #ff8a7a;
    --ok: #6fd39b;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 10px 30px -14px rgba(0, 0, 0, 0.6);
    --wd-0: #7fa4ff;
    --wd-1: #4fd1c0;
    --wd-2: #8fcf63;
    --wd-3: #f2c14e;
    --wd-4: #ff9a5c;
    --wd-5: #ff7a9c;
    --wd-6: #b994ff;
    --mood-good: #5fd08b;
    --mood-okay: #f4cd4a;
    --mood-bad: #ff6b63;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--sans);
  line-height: 1.45;
  color: var(--ink);
  background-color: var(--paper);
  background-image: radial-gradient(circle, var(--dot) 1px, transparent 1.4px);
  background-size: 20px 20px;
}

button, input, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* --- Icons and buttons --- */

.icon { display: inline-grid; width: 18px; height: 18px; flex: none; }
.icon svg { width: 100%; height: 100%; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  background: var(--card);
  color: var(--ink);
  font-size: 0.9rem;
  font-weight: 500;
  line-height: 1.2;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, filter 0.15s;
}
.btn:hover { border-color: var(--ink-faint); }
.btn .icon { width: 16px; height: 16px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-soft); }
.btn.ghost:hover { background: var(--accent-soft); color: var(--ink); }
.btn.subtle { background: transparent; }
.btn.subtle:hover { background: var(--accent-soft); border-color: var(--line-strong); }
.btn.small { padding: 4px 10px; font-size: 0.82rem; border-radius: 7px; }
.btn:disabled { opacity: 0.45; cursor: default; filter: none; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, opacity 0.15s;
}
.icon-btn:hover { background: var(--accent-soft); color: var(--ink); }
.icon-btn:disabled { opacity: 0.3; cursor: default; background: transparent; }
.icon-btn.danger:hover { color: var(--danger); background: color-mix(in srgb, var(--danger) 10%, transparent); }

/* --- Top bar: year and month --- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  text-decoration: none;
  font-family: var(--serif);
  font-size: 1.35rem;
  font-style: italic;
  font-weight: 600;
}
.brand img { border-radius: 8px; }
.period { flex: 1; min-width: 0; display: flex; align-items: center; justify-content: center; gap: 12px; }
.year-nav { display: flex; align-items: center; }
.year-label {
  min-width: 3.4ch;
  text-align: center;
  font-family: var(--serif);
  font-size: 1.1rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.month-tabs { display: flex; gap: 2px; padding: 2px; overflow-x: auto; scrollbar-width: none; }
.month-tabs::-webkit-scrollbar { display: none; }
.month-tab {
  position: relative;
  padding: 6px 9px 9px;
  border-radius: 8px;
  color: var(--ink-soft);
  text-decoration: none;
  font-size: 0.88rem;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}
.month-tab:hover { background: var(--accent-soft); color: var(--ink); }
.month-tab.now { color: var(--accent); font-weight: 650; }
.month-tab.active { background: var(--ink); color: var(--paper); }
.month-tab.has-entries::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 3px;
  width: 4px;
  height: 4px;
  margin-left: -2px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.6;
}
.top-actions { display: flex; align-items: center; gap: 6px; }
.account {
  max-width: 16ch;
  overflow: hidden;
  margin-left: 4px;
  color: var(--ink-soft);
  font-size: 0.82rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* --- Blocks --- */

.page { max-width: 1180px; margin: 0 auto; padding: 24px 20px 32px; display: grid; gap: 20px; }

.block {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.block-head { display: flex; align-items: center; flex-wrap: wrap; gap: 10px 16px; padding: 16px 20px; }
.block-body { padding: 0 20px 20px; }
.block.collapsed .block-body { display: none; }
.block-actions { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.collapse-btn .icon { transition: transform 0.2s; }
.block.collapsed .collapse-btn .icon { transform: rotate(-90deg); }
.block-meta { margin: 0; color: var(--ink-soft); font-size: 0.88rem; }

h1, h2, h3 { font-family: var(--serif); font-weight: 600; margin: 0; }
h2 { font-size: 1.35rem; }
.month-heading { display: flex; align-items: center; gap: 2px; }
#month-title { margin: 0 6px; font-size: 2rem; line-height: 1.1; letter-spacing: -0.01em; white-space: nowrap; }
#month-title .year { color: var(--ink-faint); font-weight: 400; }

.notice {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 10px;
  margin-bottom: 12px;
  padding: 10px 14px;
  border: 1px dashed var(--line-strong);
  border-radius: 10px;
  background: var(--card-2);
  color: var(--ink-soft);
  font-size: 0.9rem;
}

/* --- The month: one row per day, habit checkboxes on the right --- */

.journal { width: 100%; border-collapse: separate; border-spacing: 0; }
.journal.loading { opacity: 0.5; transition: opacity 0.2s 0.15s; }

.journal thead th {
  position: sticky;
  top: var(--topbar-h);
  z-index: 5;
  padding: 6px 0 8px;
  background: var(--card);
  border-bottom: 2px solid var(--line-strong);
  vertical-align: bottom;
  text-align: left;
  font-weight: 500;
}
.col-hint { color: var(--ink-faint); font-size: 0.82rem; font-style: italic; padding-left: 8px; }

.journal td { padding: 0; border-bottom: 1px solid var(--line); vertical-align: top; }
tr.wd-6 td { border-bottom-color: var(--line-strong); } /* Sundays close the week */

.journal td.num {
  width: 2.75rem;
  padding: 10px 10px 0 4px;
  text-align: right;
  font-family: var(--serif);
  font-size: 1.05rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  box-shadow: inset 3px 0 0 var(--wd);
}
.num-wd { display: none; }
.journal td.wd { width: 3.5rem; padding: 10px 6px 0; }
.chip {
  display: inline-block;
  min-width: 2.6rem;
  padding: 2px 0;
  border-radius: 6px;
  background: color-mix(in srgb, var(--wd) 14%, transparent);
  color: var(--wd);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-align: center;
  text-transform: uppercase;
}
/* The mood traffic light: three dots, the chosen one lit. */
.journal th.mood, .journal td.mood { width: 4.1rem; }
.journal th.mood .col-hint { padding-left: 4px; }
.journal td.mood { padding: 8px 4px 0; }
.mood-light {
  display: inline-flex;
  align-items: center;
  padding: 1px 3px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--ink) 6%, transparent);
}
.mood-dot {
  width: 18px;
  height: 18px;
  padding: 3px; /* a bigger target than the dot itself */
  border: 0;
  border-radius: 50%;
  background: var(--mood);
  background-clip: content-box;
  opacity: 0.22;
  cursor: pointer;
  transition: opacity 0.12s, transform 0.08s;
}
.mood-dot:hover { opacity: 0.6; }
.mood-dot:active { transform: scale(0.85); }
.mood-dot[aria-pressed="true"] { opacity: 1; filter: drop-shadow(0 0 3px var(--mood)); }
.mood-dot.good, .mood-count.good { --mood: var(--mood-good); }
.mood-dot.okay, .mood-count.okay { --mood: var(--mood-okay); }
.mood-dot.bad, .mood-count.bad { --mood: var(--mood-bad); }
.journal tfoot .mood-light { background: none; }
.mood-count { width: 18px; color: var(--mood); font-weight: 700; text-align: center; }

.journal td.text { padding: 8px; }
.text-view {
  min-height: 1.5em;
  padding-top: 2px;
  font-family: var(--serif);
  font-size: 1.02rem;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.text-view.empty { color: var(--ink-faint); font-style: italic; }
.journal td.edit { width: 2.75rem; padding: 5px 4px 0; }
.edit-btn { opacity: 0.3; }
tr.day:hover .edit-btn, .edit-btn:focus-visible, tr.editing .edit-btn { opacity: 1; }
tr.editing .edit-btn { color: var(--accent); background: var(--accent-soft); }
@media (hover: none) { .edit-btn { opacity: 0.65; } }

.journal th.habit, .journal td.habit { width: 2.75rem; min-width: 2.75rem; text-align: center; }
.journal .habit.first { border-left: 2px solid var(--line-strong); }
.journal td.habit { padding: 6px 0 4px; }
.habit-name {
  display: inline-block;
  max-height: 8.5rem;
  overflow: hidden;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  white-space: nowrap;
  text-overflow: ellipsis;
  color: var(--ink-soft);
  font-size: 0.8rem;
  font-weight: 650;
  letter-spacing: 0.02em;
}

tr.wd-0 { --wd: var(--wd-0); }
tr.wd-1 { --wd: var(--wd-1); }
tr.wd-2 { --wd: var(--wd-2); }
tr.wd-3 { --wd: var(--wd-3); }
tr.wd-4 { --wd: var(--wd-4); }
tr.wd-5 { --wd: var(--wd-5); }
tr.wd-6 { --wd: var(--wd-6); }
tr.weekend td { background: color-mix(in srgb, var(--wd) 5%, transparent); }
tr.today td { background: var(--accent-soft); }
tr.today td.num { color: var(--accent); }
tr.future td.num { color: var(--ink-faint); }
tr.saving { opacity: 0.6; }
tr.saved td.text { animation: saved 1.6s ease-out; }
@keyframes saved {
  from { background: color-mix(in srgb, var(--ok) 20%, transparent); }
  to { background: transparent; }
}

.check {
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  padding: 0;
  border: 1.5px solid var(--line-strong);
  border-radius: 7px;
  background: var(--card);
  color: transparent;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, transform 0.08s;
}
.check .icon { width: 16px; height: 16px; }
.check .icon path { stroke-width: 2.8; }
.check:hover { border-color: var(--accent); }
.check:active { transform: scale(0.9); }
.check[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

.journal tfoot td { padding: 10px 0 0; border-bottom: 0; color: var(--ink-soft); font-size: 0.8rem; }
.journal tfoot td.foot-label { padding-right: 4px; text-align: right; }
.journal tfoot td.total { color: var(--ink); font-weight: 700; font-variant-numeric: tabular-nums; }

/* --- Editing a day, and the month's background --- */

.editor textarea {
  display: block;
  width: 100%;
  min-height: 2.7em;
  padding: 7px 9px;
  overflow: hidden;
  resize: none;
  border: 1.5px solid var(--accent);
  border-radius: 8px;
  outline: none;
  box-shadow: 0 0 0 4px var(--accent-soft);
  background: var(--card);
  font-family: var(--serif);
  font-size: 1.02rem;
  line-height: 1.45;
}
.editor-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 8px;
  margin-top: 7px;
  color: var(--ink-faint);
  font-size: 0.78rem;
}
.editor-bar .hint { margin-right: auto; }
.counter { font-variant-numeric: tabular-nums; }
.counter.near { color: var(--wd-3); }
.counter.full { color: var(--danger); font-weight: 650; }

.background-text {
  max-width: 78ch;
  margin: 0;
  font-family: var(--serif);
  font-size: 1.06rem;
  line-height: 1.6;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.background-text.empty { color: var(--ink-faint); font-style: italic; }
.background-editor textarea { min-height: 10em; overflow: auto; line-height: 1.6; }

/* --- Settings --- */

dialog.sheet {
  width: 100%;
  max-width: min(620px, calc(100vw - 24px));
  max-height: calc(100vh - 48px);
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
}
dialog.sheet::backdrop { background: rgba(20, 18, 12, 0.38); -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px); }
.sheet-inner {
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 48px);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 24px 60px -20px rgba(0, 0, 0, 0.45);
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px 6px; }
.tabs { display: flex; gap: 4px; padding: 0 20px; border-bottom: 1px solid var(--line); }
.tabs [role="tab"] {
  margin-bottom: -1px;
  padding: 10px 12px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: none;
  color: var(--ink-soft);
  font-weight: 500;
  cursor: pointer;
}
.tabs [role="tab"][aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }
.panel { padding: 16px 20px 20px; overflow-y: auto; }
.panel h3 { margin: 22px 0 4px; font-size: 1.05rem; }
.panel h3:first-child { margin-top: 2px; }
.muted { margin: 0 0 12px; color: var(--ink-soft); font-size: 0.88rem; }
.warning { color: var(--danger); }
.row-buttons { display: flex; flex-wrap: wrap; gap: 8px; }
.sheet-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); }

.habit-list { display: grid; gap: 6px; margin: 0 0 12px; padding: 0; list-style: none; }
.habit-item { display: flex; align-items: center; gap: 4px; }
.habit-index { width: 1.6rem; color: var(--ink-faint); font-size: 0.8rem; text-align: center; font-variant-numeric: tabular-nums; }
.habit-item input {
  flex: 1;
  min-width: 0;
  margin-right: 4px;
  padding: 8px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--card-2);
}
.habit-item input:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }

.stacked { max-width: 360px; }
.stacked .btn { margin-top: 2px; }

.import-preview { margin-top: 12px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--card-2); }
.import-preview > p { margin: 0 0 4px; font-size: 0.9rem; }
.choices { display: grid; gap: 8px; margin: 10px 0 12px; padding: 0; border: 0; }
.choice {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--card);
  font-size: 0.92rem;
  cursor: pointer;
}
.choice input { margin-top: 3px; accent-color: var(--accent); }
.choice:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.choice small { display: block; margin-top: 2px; color: var(--ink-soft); font-size: 0.82rem; }

.backup-list { display: grid; gap: 3px; margin: 0 0 12px; padding: 0; list-style: none; font-size: 0.85rem; }
.backup-list li { display: flex; justify-content: space-between; gap: 12px; padding: 6px 10px; border-radius: 8px; background: var(--card-2); }
.backup-list .name { font-family: var(--mono); font-size: 0.78rem; overflow-wrap: anywhere; }
.backup-list .when { color: var(--ink-soft); white-space: nowrap; }
.backup-folder { font-family: var(--mono); font-size: 0.8rem; color: var(--ink); overflow-wrap: anywhere; }

/* --- Messages --- */

.toasts {
  position: fixed;
  left: 50%;
  bottom: 20px;
  z-index: 100;
  display: grid;
  gap: 8px;
  width: max-content;
  max-width: calc(100vw - 32px);
  transform: translateX(-50%);
  pointer-events: none;
}
.toast {
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--ink);
  color: var(--paper);
  box-shadow: var(--shadow);
  font-size: 0.9rem;
  animation: toast-in 0.2s ease-out;
  transition: opacity 0.3s;
}
.toast.error { background: var(--danger); color: #fff; }
.toast.leaving { opacity: 0; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

.page-foot { padding: 0 0 28px; color: var(--ink-faint); font-size: 0.8rem; text-align: center; }

/* --- Login and registration --- */

.auth-page { display: grid; place-items: center; padding: 32px 16px; }
.auth { width: 100%; max-width: 380px; }
.auth-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  font-family: var(--serif);
  font-size: 1.9rem;
  font-style: italic;
  font-weight: 600;
}
.auth-brand img { border-radius: 9px; }
.auth-tagline {
  margin: 6px 0 22px;
  color: var(--ink-soft);
  font-family: var(--serif);
  font-style: italic;
  text-align: center;
}
/* The weekday colours, as a small signature under the tagline. */
.auth-tagline::after {
  content: "";
  display: block;
  width: 98px;
  height: 6px;
  margin: 12px auto 0;
  border-radius: 3px;
  background: linear-gradient(90deg,
    var(--wd-0) 0 14.28%, var(--wd-1) 0 28.57%, var(--wd-2) 0 42.85%, var(--wd-3) 0 57.14%,
    var(--wd-4) 0 71.42%, var(--wd-5) 0 85.71%, var(--wd-6) 0);
}
.auth-card {
  padding: 26px 26px 22px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
}
.auth-card h1 { margin: 0 0 18px; font-size: 1.55rem; }
.field { display: grid; gap: 6px; margin-bottom: 14px; color: var(--ink-soft); font-size: 0.88rem; font-weight: 500; }
.field small { color: var(--ink-faint); font-weight: 400; }
.field input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  background: var(--card-2);
  color: var(--ink);
  font-size: 1rem;
}
.field input:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
.btn.wide { width: 100%; justify-content: center; margin-top: 6px; padding: 11px 14px; font-size: 0.95rem; }
.form-error { margin: 2px 0 10px; color: var(--danger); font-size: 0.88rem; }
.auth-note {
  margin: -6px 0 16px;
  padding: 10px 12px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--ok) 12%, transparent);
  color: var(--ok);
  font-size: 0.9rem;
}
.auth-fineprint { margin: 16px 0 0; color: var(--ink-faint); font-size: 0.8rem; text-align: center; }
.auth-note.neutral { background: var(--accent-soft); color: var(--ink-soft); }
.auth-text { margin: 0 0 12px; color: var(--ink-soft); font-size: 0.92rem; }
.recovery-key {
  margin: 16px 0 12px;
  padding: 14px 12px;
  border: 1px dashed var(--line-strong);
  border-radius: 10px;
  background: var(--card-2);
  font-family: var(--mono);
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-align: center;
  overflow-wrap: anywhere;
  user-select: all;
}
.row-buttons.centered { justify-content: center; }
.check-line {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 16px 0 8px;
  font-size: 0.92rem;
  cursor: pointer;
}
.check-line input { width: 18px; height: 18px; accent-color: var(--accent); }
.auth-switch { margin: 18px 0 0; color: var(--ink-soft); font-size: 0.92rem; text-align: center; }
.auth-switch a { color: var(--accent); font-weight: 600; text-decoration: none; }
.auth-switch a:hover { text-decoration: underline; }

/* --- Smaller screens --- */

@media (max-width: 960px) {
  .topbar-inner { flex-wrap: wrap; gap: 6px 12px; padding: 8px 16px; }
  .period { order: 3; flex-basis: 100%; justify-content: flex-start; }
  .top-actions { margin-left: auto; }
}

@media (max-width: 640px) {
  .page { padding: 14px 8px 24px; gap: 14px; }
  .block-head { padding: 12px 12px; gap: 6px 10px; }
  .block-body { padding: 0 6px 14px; }
  #month-title { font-size: 1.5rem; margin: 0 2px; }
  .btn-label { display: none; }
  .account { display: none; }
  .btn.subtle { padding: 7px 8px; }

  /* Many habit columns scroll sideways (the sticky header gives way to that). */
  .table-wrap { overflow-x: auto; }
  .journal thead th { position: static; }
  /* The weekday moves under the day number, to leave room for the text. */
  .journal .wd { display: none; }
  .journal td.num { width: 2.4rem; padding: 8px 6px 0 2px; font-size: 0.95rem; text-align: center; }
  .num-wd {
    display: block;
    margin-top: 1px;
    color: var(--wd);
    font-family: var(--sans);
    font-size: 0.58rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
  }
  .journal th.mood, .journal td.mood { width: 1.5rem; }
  .journal th.mood .col-hint { display: none; }
  .journal td.mood { padding: 6px 2px 0; }
  .mood-light { flex-direction: column; padding: 2px 1px; } /* upright, like a real one */
  .mood-dot { width: 16px; height: 16px; }
  .mood-count { width: 16px; }
  .journal td.text { min-width: 7.5rem; padding: 7px 4px; }
  .text-view { font-size: 0.96rem; }
  .journal td.edit { width: 2rem; padding: 4px 0 0; }
  .journal th.habit, .journal td.habit { width: 2rem; min-width: 2rem; }
  .check { width: 24px; height: 24px; }
  .editor-bar .hint { display: none; }
  .col-hint { display: none; }
}
