/* Letieb Health: the same paper, ink and type as letieb.com
   1. Tokens  2. Base  3. Header  4. Shared pieces  5. Forms and dialogs  6. Views  7. Phones */

/* ---------- 1. Tokens ---------- */
:root {
  --paper: #f7f3ec;
  --paper-2: #efe8dc;
  --ink: #2b2520;
  --ink-soft: #5e554c;
  --ink-faint: #8f8478;
  --line: #ddd3c4;
  --accent: #9a6b3f;
  --accent-ink: #fffdf9;
  --accent-soft: #f0e3d1;
  --card: #fffdf9;
  --danger: #a5463a;
  --danger-soft: #f3dcd6;

  --serif: "Newsreader", Georgia, "Times New Roman", serif;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --radius: 14px;
  --gutter: clamp(16px, 4vw, 40px);
  --max: 860px;
  --tabbar: 0px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #1b1815;
    --paper-2: #24201c;
    --ink: #eee6da;
    --ink-soft: #c2b7a8;
    --ink-faint: #8f8578;
    --line: #3a332c;
    --accent: #d6a874;
    --accent-ink: #1b1815;
    --accent-soft: #3a2e22;
    --card: #221e1a;
    --danger: #e0927a;
    --danger-soft: #3d2620;
  }
}

/* ---------- 2. Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { font-family: var(--serif); font-weight: 500; line-height: 1.15; margin: 0; }
p { margin: 0; }
ul { list-style: none; margin: 0; padding: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }
img { max-width: 100%; display: block; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.icon { display: inline-flex; width: 18px; height: 18px; flex: none; }
.icon svg { width: 100%; height: 100%; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- 3. Header ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px var(--gutter);
  background: color-mix(in srgb, var(--paper) 90%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.wordmark { font-family: var(--serif); font-size: 22px; text-decoration: none; }
.wordmark-app { font-size: 12px; font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase; color: var(--accent); padding-left: 10px; border-left: 1px solid var(--line); }
.nav { margin-left: auto; display: flex; gap: 4px; }
.nav-link { display: inline-flex; align-items: center; gap: 7px; padding: 8px 12px; border-radius: 999px; font-size: 14px; color: var(--ink-soft); text-decoration: none; }
.nav-link:hover { color: var(--ink); background: var(--paper-2); }
.nav-link.is-active { color: var(--ink); background: var(--accent-soft); }
.nav-link .icon { width: 16px; height: 16px; }
body.signed-out .nav { display: none; }

.main { max-width: var(--max); margin: 0 auto; padding: clamp(28px, 5vw, 56px) var(--gutter) calc(64px + var(--tabbar)); }
.loading { padding: 64px 0; text-align: center; color: var(--ink-faint); font-family: var(--serif); font-size: 20px; }

/* ---------- 4. Shared pieces ---------- */
.view { display: flex; flex-direction: column; gap: 20px; animation: rise 0.25s ease; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .view { animation: none; } }

.view-head { margin-bottom: 8px; }
.view-head h1 { font-size: clamp(36px, 6vw, 54px); letter-spacing: -0.01em; margin-top: 6px; }
.view-head-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.lede { margin-top: 10px; font-family: var(--serif); font-size: clamp(18px, 2.2vw, 21px); color: var(--ink-soft); }
.verse { font-style: italic; }
.verse-ref { display: block; margin-top: 4px; font-family: var(--sans); font-style: normal; font-size: 12px; font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase; color: var(--accent); }

.eyebrow, .label { font-size: 12px; font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase; color: var(--accent); }
.label { margin-bottom: 8px; }
.muted { color: var(--ink-faint); font-size: 14px; }
.section-title { font-size: 26px; margin-bottom: 12px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.section-head .section-title { margin-bottom: 0; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.spacer { flex: 1; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: clamp(18px, 3vw, 24px); }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.card-title { font-size: 22px; margin-bottom: 12px; }
.empty { display: flex; flex-direction: column; align-items: flex-start; gap: 14px; color: var(--ink-soft); }
.prompt { font-family: var(--serif); font-size: 20px; color: var(--ink); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  padding: 9px 18px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--card);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
}
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 88%, var(--ink)); }
.btn-quiet { background: transparent; }
.btn-danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--line)); background: transparent; }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn-wide { width: 100%; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; flex: none; border: none; border-radius: 50%; background: transparent; color: var(--ink-faint); cursor: pointer; }
.icon-btn:hover { background: var(--paper-2); color: var(--ink); }
.link-btn { border: none; background: none; padding: 6px; color: var(--accent); font-size: 14px; cursor: pointer; text-decoration: none; }
.link-btn:hover { text-decoration: underline; }
.back-link { align-self: flex-start; display: inline-flex; align-items: center; gap: 6px; color: var(--ink-soft); text-decoration: none; font-size: 14px; }
.back-link:hover { color: var(--accent); }

.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { padding: 7px 14px; border-radius: 999px; border: 1px solid var(--line); background: transparent; color: var(--ink-soft); font-size: 14px; white-space: nowrap; cursor: pointer; }
.chip:hover { border-color: var(--accent); }
.chip.is-active { background: var(--ink); border-color: var(--ink); color: var(--paper); }

.avatar { flex: none; display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; overflow: hidden; background: var(--accent-soft); color: var(--accent); font-family: var(--serif); }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-xs { width: 22px; height: 22px; font-size: 12px; }
.avatar-md { width: 40px; height: 40px; font-size: 20px; }
.avatar-lg { width: 72px; height: 72px; font-size: 34px; }
.avatar-xl { width: 120px; height: 120px; font-size: 56px; }

.person-chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px 3px 4px; border: 1px solid var(--line); border-radius: 999px; font-size: 13px; color: var(--ink-soft); text-decoration: none; }
a.person-chip:hover { border-color: var(--accent); color: var(--ink); }
.people-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }

.toast { position: fixed; left: 50%; bottom: calc(24px + var(--tabbar)); z-index: 50; max-width: calc(100vw - 32px); padding: 12px 18px; border-radius: 999px; background: var(--ink); color: var(--paper); font-size: 14px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s; }
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }
.toast[data-kind="error"] { background: var(--danger); color: #fff; }

/* ---------- 5. Forms and dialogs ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; min-width: 0; }
.field-label { font-size: 13px; font-weight: 500; color: var(--ink-soft); }
.field-hint { font-size: 13px; color: var(--ink-faint); }
.field-error { min-height: 20px; margin-bottom: 8px; font-size: 14px; color: var(--danger); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.field input:not([type="checkbox"]), .field select, .field textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--paper);
  font-size: 16px; /* 16px keeps iPhone from zooming in */
}
.field textarea { resize: vertical; line-height: 1.5; }
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.picks { display: flex; flex-wrap: wrap; gap: 8px; }
.pick { display: inline-flex; align-items: center; gap: 7px; padding: 6px 12px 6px 8px; border: 1px solid var(--line); border-radius: 999px; font-size: 14px; cursor: pointer; }
.pick:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.pick input { width: 16px; height: 16px; accent-color: var(--accent); }

.sheet { width: min(560px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); padding: 0; border: 1px solid var(--line); border-radius: 18px; background: var(--card); color: var(--ink); box-shadow: 0 24px 64px -24px rgb(0 0 0 / 0.45); }
.sheet::backdrop { background: rgb(27 24 21 / 0.45); backdrop-filter: blur(3px); }
.sheet-body { padding: 22px 24px 24px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.sheet-head h2 { font-size: 26px; }
.sheet-actions { display: flex; align-items: center; gap: 10px; margin-top: 8px; }

.photo-strip { display: flex; flex-wrap: wrap; gap: 8px; }
.photo-thumb { position: relative; width: 84px; height: 84px; border-radius: 10px; overflow: hidden; background: var(--paper-2); }
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; }
.photo-remove { position: absolute; top: 4px; right: 4px; display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px; border: none; border-radius: 50%; background: rgb(27 24 21 / 0.7); color: #fff; cursor: pointer; }
.photo-remove .icon { width: 14px; height: 14px; }
.photo-add { display: inline-flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; width: 84px; height: 84px; border: 1px dashed var(--line); border-radius: 10px; background: transparent; color: var(--ink-soft); font-size: 13px; cursor: pointer; }
.photo-add:hover { border-color: var(--accent); color: var(--accent); }

.lightbox { max-width: 96vw; max-height: 96dvh; padding: 0; border: none; background: transparent; }
.lightbox::backdrop { background: rgb(15 13 11 / 0.9); }
.lightbox img { max-width: 96vw; max-height: 96dvh; border-radius: 8px; cursor: zoom-out; }

/* ---------- 6. Views ---------- */

/* The door */
.signin { max-width: 400px; margin: clamp(24px, 8vh, 80px) auto 0; display: flex; flex-direction: column; }
.signin h1 { font-size: 44px; margin: 4px 0 6px; }
.signin-intro { margin-bottom: 22px; font-family: var(--serif); font-size: 18px; color: var(--ink-soft); }
.signin .link-btn { margin-top: 14px; align-self: center; }

/* Today */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-2 .card { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }
.grid-2 .card .card-title { margin-bottom: 4px; }
.grid-2 .card .btn { margin-top: auto; }
.grid-2 .card .bar-track { width: 100%; }
.big-number { font-family: var(--serif); font-size: 52px; line-height: 1; }
.big-number span { font-family: var(--sans); font-size: 16px; color: var(--ink-faint); }
.bar-track { display: block; height: 6px; border-radius: 999px; background: var(--paper-2); overflow: hidden; }
.bar-fill { display: block; height: 100%; border-radius: inherit; background: var(--accent); transition: width 0.4s ease; }
.streak-number { display: flex; align-items: center; gap: 10px; color: var(--accent); }
.streak-number .icon { width: 30px; height: 30px; }
.streak-number span:last-child { font-family: var(--serif); font-size: 52px; line-height: 1; color: var(--ink); }
.streak-text { font-family: var(--serif); font-size: 19px; color: var(--ink-soft); }
.next-title { font-family: var(--serif); font-size: 26px; line-height: 1.2; }
.is-overdue { color: var(--danger); }

/* Charts */
.chart { position: relative; display: flex; align-items: stretch; gap: 10px; height: 150px; }
.chart.is-dense { gap: 4px; }
.chart-col { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.chart-slot { flex: 1; width: 100%; max-width: 40px; display: flex; align-items: flex-end; }
.chart-bar { width: 100%; border-radius: 4px 4px 2px 2px; background: color-mix(in srgb, var(--accent) 45%, var(--paper-2)); }
.chart-bar.is-met, .chart-col.is-now .chart-bar:not(.is-empty) { background: var(--accent); }
.chart-bar.is-empty { height: 3px !important; background: var(--line); border-radius: 2px; }
.chart-label { height: 14px; font-size: 11px; line-height: 14px; color: var(--ink-faint); white-space: nowrap; }
.chart-col.is-now .chart-label { color: var(--accent); font-weight: 600; }
.chart-goal { position: absolute; left: 0; right: 0; border-top: 1px dashed var(--ink-faint); opacity: 0.6; pointer-events: none; }
.line-chart { position: relative; height: 160px; margin: 6px 0 4px; }
.line-chart svg { width: 100%; height: 100%; overflow: visible; }
.line-chart path { fill: none; stroke: var(--accent); stroke-width: 2; vector-effect: non-scaling-stroke; stroke-linejoin: round; stroke-linecap: round; }
.line-dot { position: absolute; width: 10px; height: 10px; margin: -5px 0 0 -5px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 3px var(--card); }
.line-max, .line-min { position: absolute; left: 0; font-size: 11px; color: var(--ink-faint); background: var(--card); padding-right: 6px; }
.line-max { top: 0; }
.line-min { bottom: 0; }
.line-axis { display: flex; justify-content: space-between; font-size: 12px; color: var(--ink-faint); }

/* Lists of entries */
.rows { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.rows li + li { border-top: 1px solid var(--line); }
.row { width: 100%; display: flex; align-items: center; gap: 14px; padding: 14px 18px; border: none; background: none; text-align: left; }
button.row { cursor: pointer; }
button.row:hover { background: color-mix(in srgb, var(--paper-2) 50%, transparent); }
.rows li:first-child .row { border-radius: var(--radius) var(--radius) 0 0; }
.rows li:last-child .row { border-radius: 0 0 var(--radius) var(--radius); }
.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.row-title { font-weight: 500; }
.row-value { flex: none; font-family: var(--serif); font-size: 20px; }
.row-note { font-family: var(--serif); font-size: 17px; color: var(--ink-soft); white-space: pre-wrap; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.pair { display: flex; align-items: center; gap: 8px; }
.pair span { color: var(--ink-faint); }
.check { display: flex; align-items: flex-start; gap: 10px; cursor: pointer; }
.check input { width: 18px; height: 18px; margin-top: 2px; accent-color: var(--accent); flex: none; }
.check > span { display: flex; flex-direction: column; gap: 2px; }

/* Settings */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; display: flex; flex-direction: column; gap: 2px; }
.stat-value { font-family: var(--serif); font-size: 30px; line-height: 1.1; }
.stat-label { font-size: 13px; color: var(--ink-faint); }
.card > .muted { margin-bottom: 14px; }
.sign-out { align-self: flex-start; }

/* ---------- 7. Phones: the menu becomes a tab bar at the bottom ---------- */
@media (max-width: 720px) {
  :root { --tabbar: calc(64px + env(safe-area-inset-bottom)); }
  /* No blur on the header here: it would pin the fixed tab bar to the header instead of the screen */
  .site-header { padding-top: 12px; padding-bottom: 12px; background: var(--paper); backdrop-filter: none; -webkit-backdrop-filter: none; }
  .nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; gap: 0; padding: 6px 6px env(safe-area-inset-bottom); background: var(--paper); border-top: 1px solid var(--line); }
  .nav-link { flex: 1; flex-direction: column; gap: 3px; padding: 6px 0 8px; border-radius: 12px; font-size: 11px; }
  .nav-link .icon { width: 22px; height: 22px; }
  .nav-link.is-active { background: transparent; color: var(--accent); }

  .field-row { grid-template-columns: 1fr; gap: 0; }
  .stats { grid-template-columns: 1fr 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
  .sheet { width: 100vw; max-width: none; max-height: 92dvh; margin: auto 0 0; border-radius: 18px 18px 0 0; border-bottom: none; }
  .sheet-body { padding-bottom: calc(24px + env(safe-area-inset-bottom)); }
  .sheet-actions { flex-wrap: wrap; }
}
