:root {
  --paper: #faf8f3;
  --paper-edge: #ece7dc;
  --ink: #33302b;
  --ink-soft: #6f6a61;
  --ink-faint: #a9a296;
  --rule: #ded7c9;
  --accent: #8d7bb0;
  --danger: #b4544c;
  --radius: 12px;
  --tap: 44px;
  --dot: #ded7c9;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.5 ui-rounded, 'Nunito', 'Avenir Next', 'Segoe UI', system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: contain;
}

body {
  /* Faint dot grid, like the notebook paper. */
  background-image: radial-gradient(var(--dot) 1px, transparent 1px);
  background-size: 22px 22px;
  min-height: 100vh;
  min-height: 100dvh;
}

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

h1, h2, h3 { font-weight: 700; letter-spacing: -0.01em; margin: 0; }

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

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

.bar-inner {
  max-width: 720px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
}

.bar h1 { font-size: 19px; flex: 1; min-width: 0; }
.bar .sub { font-size: 12px; color: var(--ink-soft); font-weight: 500; }

.linkbtn {
  background: none;
  border: 1px solid var(--rule);
  color: var(--ink-soft);
  border-radius: 999px;
  padding: 7px 13px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  min-height: 36px;
  display: inline-flex;
  align-items: center;
}
.linkbtn:active { background: var(--paper-edge); }

/* -------------------------------------------------------------- date picker */

.datebar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 16px 0 8px;
}

.datebar button {
  width: var(--tap);
  height: var(--tap);
  flex: 0 0 auto;
  border-radius: 50%;
  border: 1px solid var(--rule);
  background: #fff;
  font-size: 20px;
  color: var(--ink-soft);
  cursor: pointer;
  display: grid;
  place-items: center;
}
.datebar button:active { background: var(--paper-edge); }
.datebar button:disabled { opacity: 0.35; cursor: default; }

.datefield {
  flex: 1;
  position: relative;
  text-align: center;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: #fff;
  padding: 8px 10px;
  min-height: var(--tap);
  display: grid;
  place-items: center;
}
.datefield .day { font-size: 17px; font-weight: 700; }
.datefield .rel { font-size: 12px; color: var(--ink-soft); }
/* Invisible native date input over the field so the OS picker opens on tap. */
.datefield input[type='date'] {
  position: absolute;
  inset: 0;
  opacity: 0;
  width: 100%;
  height: 100%;
  border: 0;
  cursor: pointer;
}

/* -------------------------------------------------------------- survey card */

.progress {
  display: flex;
  gap: 4px;
  margin: 14px 0 18px;
}
.progress span {
  height: 4px;
  flex: 1;
  border-radius: 2px;
  background: var(--rule);
  transition: background 0.2s;
}
.progress span.done { background: var(--accent); }
.progress span.current { background: color-mix(in srgb, var(--accent) 55%, #fff); }

.card {
  background: #fff;
  border: 1px solid var(--rule);
  border-radius: 18px;
  padding: 20px 18px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.card .step { font-size: 12px; font-weight: 700; color: var(--ink-faint); text-transform: uppercase; letter-spacing: 0.06em; }
.card h2 { font-size: 24px; margin: 6px 0 4px; }
.card .hint { color: var(--ink-soft); font-size: 14px; margin-bottom: 16px; }

/* ------------------------------------------------------------- option lists */

.options { display: grid; gap: 9px; margin-top: 4px; }

.opt {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: var(--tap);
  padding: 10px 14px;
  border: 1.5px solid var(--rule);
  border-radius: var(--radius);
  background: #fff;
  cursor: pointer;
  font-size: 16px;
  text-align: left;
  font-family: inherit;
  color: inherit;
  width: 100%;
  transition: border-color 0.12s, background 0.12s;
}
.opt:active { transform: scale(0.995); }
.opt.on { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 7%, #fff); }

.swatch {
  width: 26px;
  height: 26px;
  flex: 0 0 auto;
  border-radius: 6px;
  border: 1.5px solid rgba(0, 0, 0, 0.18);
}
.swatch.outline { border-color: var(--ink-soft); }
.swatch.num {
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
  color: rgba(0, 0, 0, 0.5);
}

.opt .label { flex: 1; }
.opt .tick { color: var(--accent); font-weight: 700; opacity: 0; font-size: 18px; }
.opt.on .tick { opacity: 1; }

/* 0–6 scale laid out as a single row */
.scale { display: flex; gap: 6px; margin-top: 8px; }
.scale .opt {
  flex-direction: column;
  gap: 6px;
  padding: 10px 0;
  min-width: 0;
  justify-content: center;
}
.scale .swatch { width: 28px; height: 28px; }
.scale .label { flex: 0; font-weight: 700; font-size: 14px; }
.scale .tick { display: none; }

/* ----------------------------------------------------------- extras / flags */

.extras { margin-top: 14px; padding-top: 14px; border-top: 1px dashed var(--rule); display: grid; gap: 10px; }
.extras.hidden { display: none; }

.stepper { display: flex; align-items: center; gap: 12px; }
.stepper .label { flex: 1; font-size: 15px; }
.stepper button {
  width: 38px; height: 38px;
  border-radius: 50%;
  border: 1px solid var(--rule);
  background: #fff;
  font-size: 20px;
  cursor: pointer;
  color: var(--ink-soft);
}
.stepper output { min-width: 32px; text-align: center; font-weight: 700; font-size: 17px; }

textarea {
  width: 100%;
  min-height: 110px;
  border: 1.5px solid var(--rule);
  border-radius: var(--radius);
  padding: 12px;
  font: inherit;
  resize: vertical;
  background: #fff;
  color: inherit;
}
textarea:focus, .opt:focus-visible, button:focus-visible, input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* ------------------------------------------------------------- bottom nav */

.footbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 20;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--rule);
}
.footbar-inner { max-width: 720px; margin: 0 auto; display: flex; gap: 10px; }

.btn {
  flex: 1;
  min-height: 50px;
  border-radius: var(--radius);
  border: 1px solid var(--rule);
  background: #fff;
  font: inherit;
  font-weight: 700;
  font-size: 16px;
  color: var(--ink);
  cursor: pointer;
}
.btn:active { transform: scale(0.99); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ghost { flex: 0 0 auto; padding: 0 18px; color: var(--ink-soft); }
.btn:disabled { opacity: 0.45; cursor: default; }

/* -------------------------------------------------------------- view grids */

.tracker { margin: 26px 0 34px; }
.tracker > h2 { font-size: 20px; margin-bottom: 2px; }
.tracker > .cap { font-size: 13px; color: var(--ink-soft); margin-bottom: 12px; }

.gridscroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: #fff;
  padding: 10px;
}

table.grid { border-collapse: collapse; font-size: 11px; }
table.grid th, table.grid td { padding: 0; }

table.grid thead th {
  font-weight: 700;
  color: var(--ink-soft);
  font-size: 10px;
  padding: 0 0 5px;
  min-width: 26px;
  text-align: center;
}
table.grid thead th.corner { min-width: 22px; }

table.grid tbody th {
  font-weight: 600;
  color: var(--ink-faint);
  font-size: 10px;
  text-align: right;
  padding-right: 5px;
  min-width: 22px;
}

table.grid td.cell {
  width: 26px;
  height: 22px;
  border: 1px solid #e6ded0;
  background: #fff;
  text-align: center;
  vertical-align: middle;
  font-size: 10px;
  font-weight: 700;
  color: rgba(0, 0, 0, 0.55);
  cursor: pointer;
  position: relative;
}
table.grid td.cell.void { background: repeating-linear-gradient(45deg, #f6f3ec 0 3px, #fff 3px 6px); cursor: default; border-color: #eee6d8; }
table.grid td.cell.today { outline: 2px solid var(--accent); outline-offset: -2px; }
table.grid td.cell.flagged::after {
  content: '';
  position: absolute;
  inset: 2px;
  border: 1.5px solid rgba(0, 0, 0, 0.45);
  border-radius: 2px;
  pointer-events: none;
}
table.grid td.cell.hatch {
  background-image: repeating-linear-gradient(45deg, rgba(0,0,0,0.16) 0 2px, transparent 2px 5px);
}

.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 10px; font-size: 12px; color: var(--ink-soft); }
.legend .item { display: flex; align-items: center; gap: 6px; }
.legend .swatch { width: 15px; height: 15px; border-radius: 4px; border-width: 1px; }

/* Highlights render as ruled lines, like the notebook page. */
.lines { background: #fff; border: 1px solid var(--rule); border-radius: var(--radius); overflow: hidden; }
.lines .line {
  display: flex;
  gap: 10px;
  align-items: baseline;
  padding: 8px 12px;
  border-bottom: 1px solid #f0ebe0;
  min-height: 38px;
  cursor: pointer;
}
.lines .line:last-child { border-bottom: 0; }
.lines .line:nth-child(odd) { background: color-mix(in srgb, var(--accent) 5%, #fff); }
.lines .n { color: var(--ink-faint); font-size: 11px; font-weight: 700; width: 18px; flex: 0 0 auto; text-align: right; }
.lines .txt { flex: 1; font-size: 14px; }
.lines .txt.blank { color: var(--ink-faint); font-style: italic; }

.monthnav { display: flex; align-items: center; gap: 8px; margin: 16px 0 4px; }
.monthnav select {
  flex: 1;
  min-height: var(--tap);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: #fff;
  font: inherit;
  font-weight: 700;
  padding: 0 12px;
  color: inherit;
}

/* ------------------------------------------------------------------ sheets */

.sheet-back {
  position: fixed;
  inset: 0;
  background: rgba(40, 36, 30, 0.35);
  z-index: 40;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.sheet-back[hidden] { display: none; }
.sheet {
  background: var(--paper);
  width: 100%;
  max-width: 720px;
  max-height: 82vh;
  overflow-y: auto;
  border-radius: 18px 18px 0 0;
  padding: 18px 18px calc(20px + env(safe-area-inset-bottom));
  box-shadow: 0 -6px 24px rgba(0, 0, 0, 0.15);
}
.sheet h3 { font-size: 18px; margin-bottom: 2px; }
.sheet .when { font-size: 13px; color: var(--ink-soft); margin-bottom: 14px; }
.sheet dl { margin: 0; display: grid; grid-template-columns: minmax(88px, auto) 1fr; gap: 8px 14px; }
.sheet dt { font-size: 13px; color: var(--ink-soft); font-weight: 600; }
.sheet dd { margin: 0; font-size: 14px; display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.sheet dd .swatch { width: 14px; height: 14px; border-radius: 4px; border-width: 1px; }

/* ------------------------------------------------------------------- login */

.login-wrap {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card { width: 100%; max-width: 360px; }
.login-card h1 { font-size: 28px; margin-bottom: 4px; }
.login-card p.sub { color: var(--ink-soft); font-size: 14px; margin: 0 0 20px; }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 13px; font-weight: 600; color: var(--ink-soft); margin-bottom: 5px; }
.field input {
  width: 100%;
  min-height: var(--tap);
  border: 1.5px solid var(--rule);
  border-radius: var(--radius);
  padding: 0 12px;
  font: inherit;
  background: #fff;
  color: inherit;
}

.msg { font-size: 14px; padding: 10px 12px; border-radius: var(--radius); margin-bottom: 12px; }
.msg.err { background: #fbeceb; color: var(--danger); border: 1px solid #f0d3d0; }
.msg[hidden] { display: none; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(76px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(8px);
  background: var(--ink);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  z-index: 50;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.empty { text-align: center; color: var(--ink-soft); padding: 36px 16px; font-size: 15px; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
