/* ============================================================
   Daybook design system
   ONE type scale, TWO font families (3 header options, 3 content
   options). Modules never set their own font size or weight —
   they use .h1 .h2 .h3 for headings and .t1 .t2 .t3 for content.
   ============================================================ */

/* ---- font options (system stacks: no downloads, instant paint) ---- */
:root {
  --f-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --f-serif: ui-serif, Georgia, "Times New Roman", serif;
  --f-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --f-grotesk: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

/* 3 header choices */
:root, html[data-header-font="grotesk"] { --font-head: var(--f-grotesk); }
html[data-header-font="serif"] { --font-head: var(--f-serif); }
html[data-header-font="mono"] { --font-head: var(--f-mono); }
/* 3 content choices */
:root, html[data-content-font="sans"] { --font-body: var(--f-sans); }
html[data-content-font="serif"] { --font-body: var(--f-serif); }
html[data-content-font="mono"] { --font-body: var(--f-mono); }

/* ---- colour tokens ---- */
:root {
  --bg: #fbfbfa;
  --surface: #ffffff;
  --surface-2: #f4f4f2;
  --ink: #17181a;
  --ink-2: #5f6368;
  --ink-3: #8b8f95;
  --line: #e6e6e3;
  --line-strong: #d5d5d1;
  --accent: #17181a;
  --accent-ink: #ffffff;
  --danger: #b4372a;
  --ok: #2f7d5b;
  --tint: rgba(23, 24, 26, .045);
  --shadow: 0 1px 2px rgba(20, 20, 20, .05), 0 8px 24px rgba(20, 20, 20, .06);
  --radius: 14px;
  --radius-sm: 10px;
  --gap: 14px;
  --pad: 18px;
  --nav-h: 60px;
  --head-h: 58px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1011;
    --surface: #17181a;
    --surface-2: #1e2022;
    --ink: #f2f3f4;
    --ink-2: #a2a6ac;
    --ink-3: #7b7f85;
    --line: #26282b;
    --line-strong: #34373b;
    --accent: #f2f3f4;
    --accent-ink: #111214;
    --tint: rgba(255, 255, 255, .06);
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 28px rgba(0, 0, 0, .35);
  }
}

/* ============ THE TYPE SCALE — the only sizes that exist ============ */
.h1, .h2, .h3 { font-family: var(--font-head); color: var(--ink); margin: 0; }
.h1 { font-size: clamp(1.55rem, 5vw, 2.05rem); line-height: 1.12; font-weight: 640; letter-spacing: -.025em; }
.h2 { font-size: clamp(.98rem, 4vw, 1.0625rem); line-height: 1.3; font-weight: 600; letter-spacing: -.012em; }
.h3 { font-size: .8125rem; line-height: 1.35; font-weight: 600; letter-spacing: .01em; }

.t1, .t2, .t3 { font-family: var(--font-body); margin: 0; }
.t1 { font-size: .9375rem; line-height: 1.55; font-weight: 400; color: var(--ink); }
.t2 { font-size: .8125rem; line-height: 1.5; font-weight: 400; color: var(--ink-2); }
.t3 { font-size: .6875rem; line-height: 1.4; font-weight: 550; letter-spacing: .07em; text-transform: uppercase; color: var(--ink-3); }

/* ============ reset ============ */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; overflow: hidden; }
html { overscroll-behavior: none; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button, input, textarea, select { font-family: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; border-radius: 6px; }

/* ============ shell ============ */
#app { height: 100dvh; display: grid; grid-template-rows: auto 1fr auto; }
@media (min-width: 720px) { #app { grid-template-rows: auto 1fr; } }

.topbar {
  height: calc(var(--head-h) + var(--safe-t));
  padding: var(--safe-t) var(--pad) 0;
  display: flex; align-items: center; gap: 12px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in oklab, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  position: relative; z-index: 20;
}
.topbar .brand { font-family: var(--font-head); font-weight: 650; font-size: .95rem; letter-spacing: -.02em; }
.topbar .spacer { flex: 1; }
.topbar .title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.avatar {
  width: 32px; height: 32px; border-radius: 50%; flex: 0 0 auto;
  display: grid; place-items: center;
  background: var(--surface-2); border: 1px solid var(--line);
  font-size: .72rem; font-weight: 600; text-transform: uppercase; color: var(--ink-2);
}

main { overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; overscroll-behavior-y: contain; }
.view { padding: 20px var(--pad) calc(28px + var(--safe-b)); max-width: 820px; margin: 0 auto; width: 100%; }

/* bottom tab bar (phone) */
.tabbar {
  height: calc(var(--nav-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  display: flex; align-items: stretch;
  border-top: 1px solid var(--line);
  background: var(--surface);
}
.tabbar button {
  flex: 1 1 0; min-width: 0; display: grid; place-items: center; gap: 3px;
  padding: 8px 2px 6px; color: var(--ink-3); transition: color .15s;
}
.tabbar button .lbl { font-size: .625rem; letter-spacing: .01em; font-weight: 500; }
.tabbar button[aria-current="page"] { color: var(--ink); }
.tabbar button[aria-current="page"] .lbl { font-weight: 620; }

/* sidebar (tablet/desktop) */
.sidenav { display: none; }
@media (min-width: 720px) {
  .tabbar { display: none; }
  #app { grid-template-columns: auto 1fr; grid-template-rows: auto 1fr; }
  .topbar { grid-column: 1 / -1; }
  .sidenav {
    display: flex; flex-direction: column; gap: 4px;
    padding: 16px 10px; border-right: 1px solid var(--line);
    background: var(--bg); width: 76px;
  }
  .sidenav button {
    display: grid; place-items: center; gap: 5px; padding: 11px 4px;
    border-radius: var(--radius-sm); color: var(--ink-3);
  }
  .sidenav button .lbl { font-size: .625rem; font-weight: 500; }
  .sidenav button[aria-current="page"] { background: var(--tint); color: var(--ink); }
  .sidenav .foot { margin-top: auto; }
}
@media (min-width: 1100px) {
  .sidenav { width: 224px; padding: 20px 14px; }
  .sidenav button {
    display: flex; align-items: center; gap: 11px; justify-content: flex-start;
    padding: 10px 12px; font-size: .875rem;
  }
  .sidenav button .lbl { font-size: .8125rem; font-weight: 500; }
}

/* ============ components ============ */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px;
}
.card + .card, .stack > * + * { margin-top: var(--gap); }
.row { display: flex; align-items: center; gap: 12px; }
.between { justify-content: space-between; }
.muted { color: var(--ink-2); }
.dim { color: var(--ink-3); }
.section-head { display: flex; align-items: baseline; justify-content: space-between; margin: 26px 0 10px; }
.section-head:first-child { margin-top: 4px; }
.divide > * + * { border-top: 1px solid var(--line); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 38px; padding: 0 15px; border-radius: 999px;
  border: 1px solid var(--line-strong); background: var(--surface);
  color: var(--ink); font-size: .8125rem; font-weight: 550;
  transition: transform .08s, background .15s, border-color .15s;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn.sm { height: 30px; padding: 0 11px; font-size: .75rem; }
.btn.wide { width: 100%; }
.btn.icon { width: 36px; height: 36px; padding: 0; border-radius: 50%; }

.field, textarea.field, select.field {
  width: 100%; min-height: 42px; padding: 10px 12px;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  font-size: 16px; /* 16px keeps iOS from zooming on focus */
}
@media (min-width: 720px) { .field, textarea.field, select.field { font-size: .9375rem; } }
textarea.field { min-height: 96px; resize: vertical; line-height: 1.5; }
.field::placeholder { color: var(--ink-3); }
label.lab { display: block; margin-bottom: 6px; }

.check {
  width: 22px; height: 22px; flex: 0 0 auto; border-radius: 50%;
  border: 1.5px solid var(--line-strong); display: grid; place-items: center;
  background: var(--surface); transition: background .15s, border-color .15s;
}
.check[aria-checked="true"] { background: var(--accent); border-color: var(--accent); }
.check svg { opacity: 0; color: var(--accent-ink); }
.check[aria-checked="true"] svg { opacity: 1; }

.item-row { display: flex; align-items: flex-start; gap: 12px; padding: 12px 0; }
.item-row .body { flex: 1; min-width: 0; }
.item-row.done .body .t1 { color: var(--ink-3); text-decoration: line-through; }
.item-row .meta { display: flex; gap: 8px; align-items: center; margin-top: 3px; flex-wrap: wrap; }

.pill {
  font-size: .6875rem; padding: 2px 8px; border-radius: 999px;
  background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line);
  white-space: nowrap;
}
.pill.warn { color: var(--danger); border-color: color-mix(in oklab, var(--danger) 30%, var(--line)); }

.empty { padding: 34px 8px; text-align: center; color: var(--ink-3); }

/* ---------- month grid ---------- */
.month { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.month .dow { text-align: center; padding: 6px 0 8px; }
.month .day {
  aspect-ratio: 1 / 1.05; border-radius: 10px; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 3px; position: relative;
  font-size: .8125rem; color: var(--ink);
}
.month .day.out { color: var(--ink-3); opacity: .45; }
.month .day.sel { background: var(--accent); color: var(--accent-ink); }
.month .day.today:not(.sel) { background: var(--tint); font-weight: 650; }
.month .dot { width: 4px; height: 4px; border-radius: 50%; background: currentColor; opacity: .55; }
.month .day .dots { display: flex; gap: 3px; height: 4px; }

/* wide layouts: square cells on a phone, fixed rows where the columns are wide */
@media (min-width: 720px) {
  .month { gap: 4px; }
  .month .day { aspect-ratio: auto; height: 54px; border-radius: 12px; }
  .month .day:hover:not(.sel) { background: var(--tint); }
  .month .dow { padding: 10px 0; }
}

/* ---------- sheet / dialog ---------- */
.scrim {
  position: fixed; inset: 0; background: rgba(10, 10, 12, .38);
  display: none; z-index: 50; backdrop-filter: blur(2px);
}
.scrim.open { display: block; }
.sheet {
  position: fixed; z-index: 51; left: 0; right: 0; bottom: 0;
  background: var(--surface); border-radius: 20px 20px 0 0;
  padding: 8px var(--pad) calc(20px + var(--safe-b));
  max-height: 88dvh; overflow-y: auto; display: none;
  box-shadow: 0 -8px 40px rgba(0, 0, 0, .18);
  animation: sheet-in .18s ease-out;
}
.sheet.open { display: block; }
.sheet .grip { width: 36px; height: 4px; border-radius: 2px; background: var(--line-strong); margin: 6px auto 14px; }
.sheet .sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.sheet .form-stack { display: flex; flex-direction: column; gap: 14px; }
@keyframes sheet-in { from { transform: translateY(14px); opacity: .5; } to { transform: none; opacity: 1; } }

@media (min-width: 720px) {
  .sheet {
    left: 50%; right: auto; bottom: auto; top: 50%;
    transform: translate(-50%, -50%); width: 460px; border-radius: 18px;
    padding: 20px; max-height: 84dvh; animation: none;
  }
  .sheet .grip { display: none; }
}

/* ---------- settings ---------- */
.opt-group { display: flex; gap: 8px; flex-wrap: wrap; }
.opt {
  padding: 8px 14px; border-radius: 999px; border: 1px solid var(--line-strong);
  font-size: .8125rem; background: var(--surface); color: var(--ink-2);
}
.opt[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.toggle {
  width: 44px; height: 26px; border-radius: 999px; background: var(--line-strong);
  position: relative; transition: background .18s; flex: 0 0 auto;
}
.toggle::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px;
  border-radius: 50%; background: #fff; transition: transform .18s;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .25);
}
.toggle[aria-checked="true"] { background: var(--ink); }
.toggle[aria-checked="true"]::after { transform: translateX(18px); }

/* ---------- auth ---------- */
.auth { height: 100dvh; display: grid; place-items: center; padding: 24px; overflow-y: auto; }
.auth-card { width: 100%; max-width: 360px; }
.auth-card .field { margin-bottom: 10px; }
.switcher { display: flex; gap: 6px; background: var(--surface-2); padding: 4px; border-radius: 999px; margin-bottom: 20px; }
.switcher button { flex: 1; height: 32px; border-radius: 999px; font-size: .8125rem; color: var(--ink-2); }
.switcher button[aria-pressed="true"] { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: var(--shadow); }
.err { color: var(--danger); min-height: 18px; }

/* ---------- notes ---------- */
.note-grid { display: grid; gap: 10px; grid-template-columns: 1fr; }
@media (min-width: 560px) { .note-grid { grid-template-columns: 1fr 1fr; } }
.note-card { text-align: left; padding: 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.note-card .snip { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; margin-top: 6px; }
.editor { display: flex; flex-direction: column; gap: 10px; height: 100%; }
.editor textarea { flex: 1; min-height: 40dvh; border: 0; background: transparent; padding: 0; font-size: 16px; }
.editor input { border: 0; background: transparent; padding: 0; }
.auto-hint { opacity: 0; transition: opacity .3s; }
.auto-hint.on { opacity: 1; }

/* ---------- misc ---------- */
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.stack-tight > * + * { margin-top: 8px; }
.skeleton { height: 12px; border-radius: 6px; background: var(--tint); }
[hidden] { display: none !important; }
