/* Sentence. Warm paper and cobalt ink; the typography is the brand and the ink line is the mark.
   One accent (cobalt), one radius system (2px, near-square, like a printed rule). */

:root {
  --paper: #F3EFE5;
  --paper-hi: #FAF7EF;
  --paper-lo: #EBE5D6;
  --paper-2: #EBE6D9;
  --paper-3: #FBF8F1;
  --ink: #1C1B17;
  --ink-soft: #5A574D;
  --ink-faint: #66625A;
  --hair: #D6D0C0;
  --accent: #1F3FBF;
  --accent-fill: #1F3FBF;
  --accent-a: #2F52D6;
  --accent-b: #1A38AE;
  --on-accent: #FFFFFF;
  --accent-tint: rgba(31, 63, 191, .10);
  --accent-shadow: 31, 63, 191;
  --danger: #9B2E24;
  --danger-line: rgba(155, 46, 36, .45);
  --shadow: 66, 52, 24;                    /* warm umber: the paper's own shadow */
  --grain-alpha: .10;
  --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 .6 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23g)'/%3E%3C/svg%3E");
  --radius: 2px;
  --serif: "Source Serif 4", Iowan Old Style, Palatino, Georgia, serif;
  --measure: 34rem;
}

body.set-typewriter { --serif: "Courier New", Courier, monospace; }
body.set-manuscript { --paper: #F5EEDC; --paper-hi: #FBF6E8; --paper-lo: #EDE4CF; --paper-2: #EDE4CF; --paper-3: #FCF7EA; --ink: #26211A; }

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #171612;
    --paper-hi: #1D1B15;
    --paper-lo: #12110C;
    --paper-2: #201E18;
    --paper-3: #23211A;
    --ink: #ECE6D6;
    --ink-soft: #B3AC9A;
    --ink-faint: #9A9484;
    --hair: #383528;
    --accent: #9DB3FF;
    --accent-fill: #2E52D9;
    --accent-a: #3A5EE6;
    --accent-b: #2646B8;
    --on-accent: #FFFFFF;
    --accent-tint: rgba(157, 179, 255, .14);
    --accent-shadow: 20, 40, 140;
    --danger: #E08C84;
    --danger-line: rgba(224, 140, 132, .45);
    --shadow: 0, 0, 0;
    --grain-alpha: .07;
    --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 .6 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23g)'/%3E%3C/svg%3E");
  }
  body.set-manuscript { --paper: #1A1811; --paper-hi: #201D14; --paper-lo: #14120B; --paper-2: #23201A; --paper-3: #26231A; --ink: #EFE8D4; }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 17px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: oldstyle-nums;
  overscroll-behavior: none;
}
body {
  background: radial-gradient(140% 90% at 12% -10%, var(--paper-hi) 0%, var(--paper) 48%, var(--paper-lo) 100%);
}
/* paper tooth, on every screen, behind everything */
body::before {
  content: ""; position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background: var(--grain); opacity: var(--grain-alpha);
}
svg.defs { position: absolute; width: 0; height: 0; }

#stage { position: fixed; inset: 0 0 var(--tabh, 0px) 0; }
body.has-tabs { --tabh: calc(60px + var(--sab, 0px)); }

.screen { position: absolute; inset: 0; display: flex; flex-direction: column; }
.screen[hidden] { display: none !important; }

.scroller {
  flex: 1; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch;
  padding: calc(28px + var(--sat, 0px)) 22px 44px;
  max-width: var(--measure); width: 100%; margin: 0 auto;
}
.topbar + .scroller { padding-top: 10px; }

/* --- focus, for anyone on a keyboard --- */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: var(--radius); }
textarea#line:focus-visible, input[type=search]:focus-visible { outline: none; }

/* --- icons: one stroke, round caps --- */
.icon { width: 20px; height: 20px; display: block; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }

/* --- the mark: one ink line ending in a full stop --- */
.inkline { display: flex; align-items: center; gap: 7px; height: 16px; margin: 12px 0 22px; color: var(--accent); }
.inkline .ink { flex: 1; min-width: 0; height: 12px; display: block; fill: currentColor; transform-origin: left center; }
.inkline .stop {
  flex: none; width: 7px; height: 7px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, rgba(255,255,255,.95) 0, rgba(255,255,255,0) 48%), currentColor;
  box-shadow: 0 1px 2px rgba(var(--accent-shadow), .4);
}
/* the true mark, the launcher icon's line and full stop, wherever it appears at its own proportions */
.mark { display: block; color: var(--accent); fill: currentColor; overflow: visible; filter: drop-shadow(0 1px 1px rgba(var(--accent-shadow), .35)); }
.mark.small { width: 68px; height: 22px; margin: 0 0 10px; }
.mark .ink, .mark .stop { transform-box: fill-box; }
.mark .ink { transform-origin: left center; }
.mark .stop { transform-origin: center; }
@keyframes draw { from { transform: scaleX(0); } to { transform: scaleX(1); } }
@keyframes stamp { from { transform: scale(0); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes restamp { 0% { transform: scale(1.9); opacity: .35; } 100% { transform: scale(1); opacity: 1; } }
.draw .ink { animation: draw .55s cubic-bezier(.2, .8, .2, 1) both; }
.draw .stop { animation: stamp .3s .42s cubic-bezier(.2, 1.4, .4, 1) both; }
.stamp .stop { animation: restamp .4s cubic-bezier(.2, .8, .2, 1) both; }

/* --- type --- */
.date, .stack-head, .count, .running {
  font-size: 11px; letter-spacing: 0.16em; text-transform: uppercase;
  font-variant-numeric: lining-nums tabular-nums; color: var(--ink-soft);
}
.daymark { margin: 0; }
.date { margin: 0; }
.chapter { margin: 4px 0 0; font-size: 13.5px; color: var(--ink-soft); font-style: italic; }
.rule { border: 0; border-top: 1px solid var(--hair); margin: 12px 0 20px; }
.rule.faint { opacity: .7; margin: 30px 0 20px; }

.entry { font-size: 20px; line-height: 1.5; margin: 0; hanging-punctuation: first; overflow-wrap: anywhere; }
.entry.late { font-style: italic; }
.h { font-size: 27px; font-weight: 600; margin: 0 0 22px; letter-spacing: -0.02em; text-wrap: balance; }
.h2 { font-size: 17px; font-weight: 600; margin: 0 0 4px; letter-spacing: -0.005em; }
.minor { font-size: 15px; color: var(--ink-soft); margin: 0 0 12px; text-wrap: pretty; }
.help { font-size: 13.5px; color: var(--ink-faint); margin: 6px 0 0; line-height: 1.45; text-wrap: pretty; }
.empty { color: var(--ink-soft); font-style: italic; margin: 40px auto 0; max-width: 24rem; text-align: center; text-wrap: balance; }
.colophon { margin-top: 28px; }
.colophon p { font-size: 12.5px; color: var(--ink-faint); letter-spacing: .04em; margin: 0; }

/* --- writing --- */
textarea#line {
  width: 100%; border: 0; outline: 0; resize: none; background: transparent;
  font: inherit; font-size: 20px; line-height: 1.5; color: var(--ink);
  padding: 0; min-height: 4.5em; overflow: hidden; overflow-wrap: anywhere; caret-color: var(--accent);
}
textarea#line::placeholder { color: var(--ink-faint); }
textarea#line[disabled] { color: var(--ink-soft); }
.writebar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 14px; min-height: 36px; }
.count { min-height: 1em; }
.count.warn { color: var(--danger); }

.btn {
  font: inherit; font-size: 14px; letter-spacing: .04em;
  background: var(--accent-fill); color: var(--on-accent); border: 1px solid transparent;
  border-radius: var(--radius); padding: 8px 17px; cursor: pointer;
  box-shadow: 0 1px 2px rgba(var(--accent-shadow), .28), 0 8px 18px -8px rgba(var(--accent-shadow), .6);
  transition: transform .12s ease, box-shadow .12s ease, opacity .12s ease, background-color .15s ease;
}
.btn:active { transform: translateY(1px) scale(.985); box-shadow: 0 1px 1px rgba(var(--accent-shadow), .25); }
.btn[disabled] { opacity: .38; box-shadow: none; cursor: default; transform: none; }
.btn.ghost {
  background: var(--paper-3); color: var(--ink); border-color: var(--hair);
  box-shadow: 0 1px 2px rgba(var(--shadow), .10), 0 6px 14px -10px rgba(var(--shadow), .35);
}
.btn.ghost:active { box-shadow: 0 1px 1px rgba(var(--shadow), .10); }
.btn.small { padding: 6px 12px; font-size: 13px; }
.btn.danger { color: var(--danger); border-color: var(--danger-line); }
.filelabel { display: inline-block; }

/* the day, stamped */
@keyframes press { 0% { transform: translateY(-3px); opacity: .25; } 100% { transform: none; opacity: 1; } }
.pressed { animation: press .26s cubic-bezier(.16, 1, .3, 1) both; }

/* --- screens and lists arrive, quietly --- */
@keyframes viewIn { from { opacity: 0; transform: translateY(6px); } }
.view.enter .scroller, .view.enter .topbar { animation: viewIn .24s ease-out both; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }
.book-entry, .stack-item, .year-row, .cal-month { animation: rise .36s cubic-bezier(.2, .8, .2, 1) both; animation-delay: calc(var(--i, 0) * 26ms); }

/* --- stack: a small pile of postcards from earlier years --- */
.stack-head { margin: 0 0 16px; }
.stack-item {
  margin: 0 0 16px; padding: 14px 16px 15px; border-radius: var(--radius);
  background: var(--paper-3);
  box-shadow: 0 1px 2px rgba(var(--shadow), .12), 0 12px 26px -16px rgba(var(--shadow), .5);
  transform: rotate(-.45deg);
}
.stack-item:nth-child(even) { transform: rotate(.35deg); }
.stack-item .running { display: block; margin: 0 0 6px; padding: 0; border: 0; color: var(--accent); }
.stack-item .entry { font-size: 18px; }

/* --- book --- */
.topbar {
  display: flex; align-items: center; gap: 10px; padding: calc(12px + var(--sat, 0px)) 22px 12px;
  border-bottom: 1px solid var(--hair); max-width: var(--measure); width: 100%; margin: 0 auto;
}
.topbar .date { flex: 1; text-align: center; }
.searchwrap {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; padding: 0 10px;
  background: var(--paper-3); color: var(--ink-faint);
  border: 1px solid var(--hair); border-radius: var(--radius);
  box-shadow: inset 0 1px 2px rgba(var(--shadow), .06);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.searchwrap:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-tint); }
.searchwrap .icon { width: 16px; height: 16px; flex: none; }
.searchwrap[hidden] { display: none !important; }
input[type=search] {
  flex: 1; min-width: 0; font: inherit; font-size: 15px; background: transparent; color: var(--ink);
  border: 0; padding: 8px 0; outline: 0; -webkit-appearance: none; appearance: none;
}
input[type=search]::placeholder { color: var(--ink-faint); }

.running { display: block; margin: 26px 0 12px; padding-bottom: 6px; border-bottom: 1px solid var(--hair); }
.book-entry {
  display: block; width: 100%; text-align: left; background: none; border: 0; padding: 0 0 18px;
  font: inherit; color: inherit; cursor: pointer; transition: opacity .12s ease, transform .12s ease;
}
.book-entry:active { opacity: .6; transform: translateX(2px); }
.book-entry .d { font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-faint); font-variant-numeric: lining-nums tabular-nums; }
.book-entry .entry { font-size: 18px; margin-top: 3px; }

/* --- calendar: written days printed in ink, blank days left as paper --- */
.cal-month { margin-bottom: 26px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; }
.cal-cell {
  aspect-ratio: 1; border-radius: var(--radius); padding: 0; margin: 0;
  background: var(--paper-3); border: 1px solid var(--hair);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .45);
}
.cal-cell.written {
  background: linear-gradient(180deg, var(--accent-a), var(--accent-b)); border-color: transparent; cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .22), 0 1px 2px rgba(var(--accent-shadow), .3);
  transition: transform .12s ease;
}
.cal-cell.written:active { transform: scale(.94); }
.cal-cell.blank { opacity: .55; }
.cal-cell.future { border-style: dotted; background: transparent; box-shadow: none; opacity: .4; }
.cal-cell.today { outline: 2px solid var(--accent); outline-offset: 2px; }

/* --- empty states, drawn --- */
.empty-art { margin-top: 30px; text-align: center; }
.empty-art .art { width: 200px; max-width: 70%; height: auto; display: block; margin: 0 auto 4px; overflow: visible; }
.empty-art .empty { margin-top: 6px; }
.art-page { fill: var(--paper-3); stroke: var(--hair); filter: drop-shadow(0 8px 12px rgba(var(--shadow), .18)); }
.art-ink { fill: var(--accent); }
.art-ink circle:last-child { fill: #fff; }
.art-rule { fill: none; stroke: var(--hair); stroke-width: 1.2; stroke-dasharray: 1 3.5; stroke-linecap: round; }
.art-cell { fill: var(--paper-3); stroke: var(--hair); }
.art-cell.on { fill: var(--accent); stroke: none; }

/* --- years --- */
.year-row { padding: 18px 0; border-bottom: 1px solid var(--hair); }
.year-row:last-child { border-bottom: 0; }
.year-row .y { font-size: 11px; letter-spacing: .16em; color: var(--ink-faint); font-variant-numeric: lining-nums tabular-nums; }
.year-row .entry { font-size: 18px; margin-top: 4px; }
.year-row .none { display: flex; align-items: center; gap: 12px; color: var(--ink-faint); font-style: italic; font-size: 16px; margin: 6px 0 0; }
.year-row .none::after { content: ""; flex: 1; border-top: 1px dotted var(--hair); }

/* --- settings --- */
.field { margin-bottom: 22px; }
.field.row { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
label { display: block; font-size: 15px; margin-bottom: 6px; }
input[type=time], select {
  font: inherit; font-size: 15px; background: var(--paper-3); color: var(--ink);
  border: 1px solid var(--hair); border-radius: var(--radius); padding: 7px 10px;
  box-shadow: inset 0 1px 2px rgba(var(--shadow), .06);
}
input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--accent-fill); margin-top: 4px; flex: none; }
.btnrow { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

/* --- onboarding --- */
#onboard { justify-content: space-between; padding: 0; }
.ob-mark { flex: none; width: 210px; height: 68px; margin: calc(54px + var(--sat, 0px)) 30px 0 26px; filter: drop-shadow(0 2px 3px rgba(var(--accent-shadow), .35)); }
.ob-track { flex: 1; display: flex; overflow: hidden; }
.ob-card {
  flex: 0 0 100%; display: flex; flex-direction: column; justify-content: center;
  padding: 0 30px 48px; transition: transform .38s cubic-bezier(.16, 1, .3, 1);
}
.ob-line { font-size: 31px; line-height: 1.2; margin: 0 0 16px; letter-spacing: -0.02em; font-weight: 600; text-wrap: balance; }
.ob-sub { font-size: 16.5px; color: var(--ink-soft); margin: 0; max-width: 26rem; text-wrap: pretty; }
.ob-time { margin: 18px 0 6px; }
.ob-foot { display: flex; align-items: center; justify-content: space-between; padding: 20px 30px calc(34px + var(--sab, 0px)); }
.ob-dots { display: flex; gap: 8px; align-items: center; }
.ob-dot { width: 5px; height: 5px; border-radius: 50%; background: var(--hair); transition: transform .2s ease, background-color .2s ease; }
.ob-dot.on { background: var(--accent); transform: scale(1.5); }

/* --- tabs: a lifted strip of paper --- */
#tabs {
  position: fixed; left: 0; right: 0; bottom: 0; height: calc(60px + var(--tabextra, 0px) + var(--sab, 0px));
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--paper-3);
  box-shadow: 0 -1px 0 var(--hair), 0 -12px 30px -14px rgba(var(--shadow), .35);
  padding-bottom: var(--sab, 0px);
  align-items: start; padding-top: 8px;
}
#tabs[hidden] { display: none !important; }
.tab {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  background: none; border: 0; font: inherit; font-size: 10.5px; letter-spacing: .14em;
  text-transform: uppercase; color: var(--ink-faint); cursor: pointer; padding: 4px 0;
  transition: color .15s ease, transform .12s ease;
}
.tab .icon { width: 22px; height: 22px; }
.tab.is-on { color: var(--accent); }
.tab:active { transform: scale(.94); }

/* --- sheet + toast --- */
.sheet { position: fixed; inset: 0; background: rgba(28, 24, 12, .46); display: flex; align-items: flex-end; z-index: 20; }
.sheet[hidden] { display: none !important; }
@keyframes sheetUp { from { transform: translateY(24px); opacity: 0; } }
.sheet-panel {
  background: var(--paper-3); width: 100%; padding: 22px 22px calc(26px + var(--sab, env(safe-area-inset-bottom)));
  box-shadow: 0 -1px 0 var(--hair), 0 -24px 50px -24px rgba(var(--shadow), .6);
  max-width: var(--measure); margin: 0 auto; animation: sheetUp .26s cubic-bezier(.2, .8, .2, 1) both;
}
.sheet-date { font-size: 11px; letter-spacing: .16em; text-transform: uppercase; color: var(--accent); margin: 0 0 8px; font-variant-numeric: lining-nums tabular-nums; }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 6px); } }
.toast {
  position: fixed; left: 50%; bottom: calc(76px + var(--sab, env(safe-area-inset-bottom))); transform: translateX(-50%);
  background: var(--ink); color: var(--paper); font-size: 14px; padding: 8px 14px; border-radius: var(--radius);
  z-index: 30; max-width: 88vw; text-align: center; box-shadow: 0 6px 18px -6px rgba(var(--shadow), .5);
  animation: toastIn .2s ease-out both;
}
.toast[hidden] { display: none !important; }

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