:root {
  --bg: #FBFBF9;
  --surface: #FFFFFF;
  --surface-2: #F1F1EC;
  --ink: #1A1A1A;
  --ink-2: #3A3A36;
  --muted: #66665F;
  --line: #E2E2DC;
  --accent: #E0482A;
  --accent-ink: #FFFFFF;
  --hl: rgba(255, 214, 10, .45);
  --dot-past: #B9B9B2;
  --dot-future: #E6E6E0;
  --dot-done: #1A1A1A;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 6px 18px rgba(0,0,0,.05);
  --serif: "Newsreader", Georgia, "Times New Roman", serif;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --top-h: 60px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111110; --surface: #1A1A18; --surface-2: #242421; --ink: #EDEDE8; --ink-2: #CFCFC8;
    --muted: #9B9B93; --line: #2E2E2B; --accent: #FF6A45; --accent-ink: #111110;
    --hl: rgba(255, 200, 0, .32); --dot-past: #55554F; --dot-future: #262623; --dot-done: #EDEDE8;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 18px rgba(0,0,0,.3); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111110; --surface: #1A1A18; --surface-2: #242421; --ink: #EDEDE8; --ink-2: #CFCFC8;
  --muted: #9B9B93; --line: #2E2E2B; --accent: #FF6A45; --accent-ink: #111110;
  --hl: rgba(255, 200, 0, .32); --dot-past: #55554F; --dot-future: #262623; --dot-done: #EDEDE8;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 18px rgba(0,0,0,.3); color-scheme: dark;
}

* { box-sizing: border-box; }
/* A permanent scrollbar gutter: switching views never shifts the page sideways. */
html { scrollbar-gutter: stable; overflow-y: scroll; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink); font-family: var(--sans);
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(80px + env(safe-area-inset-bottom));
}
button { font: inherit; color: inherit; }
button:focus-visible, a:focus-visible, textarea:focus-visible, input:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.wrap { max-width: 680px; margin: 0 auto; padding: 0 22px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Top bar */
.top {
  position: sticky; top: 0; z-index: 20; background: var(--bg);
  border-bottom: 1px solid var(--line); padding-top: env(safe-area-inset-top);
}
.top .wrap { display: flex; align-items: center; gap: 6px; height: var(--top-h); max-width: 1320px; }
.brand { font-family: var(--serif); font-style: italic; font-size: 24px; margin-right: auto; text-decoration: none; color: var(--ink); }
.top-tabs { display: none; gap: 4px; margin-right: auto; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 22px; border: none; background: transparent; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer; color: var(--ink);
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn:disabled { opacity: .35; cursor: default; background: transparent; }

/* Bottom nav (phone) */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: var(--bg);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.tabs .wrap { display: flex; justify-content: space-around; height: 64px; align-items: center; }
.tab {
  display: flex; flex-direction: column; align-items: center; gap: 3px; min-width: 64px; min-height: 48px;
  justify-content: center; text-decoration: none; color: var(--muted); font-size: 11px; font-weight: 500; border-radius: 12px;
}
.tab svg { width: 22px; height: 22px; }
.tab[aria-current="page"] { color: var(--ink); }
.tab[aria-current="page"] svg { color: var(--accent); }

.view { display: none; }
.view.on { display: block; }

/* ---------- Day ---------- */
.day-grid { display: block; }
.side { display: none; }
.meta { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: 22px 0 14px; min-height: 44px; }
.meta .date { font-size: 13px; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-2); font-weight: 500; }
.daynav { display: flex; gap: 2px; }
.day-title { font-family: var(--serif); font-weight: 500; font-size: clamp(34px, 8vw, 46px); line-height: 1.06; letter-spacing: -.01em; margin: 0 0 20px; }

.toolbar {
  position: sticky; top: calc(var(--top-h) + 1px + env(safe-area-inset-top)); z-index: 15; display: flex; gap: 4px; align-items: center;
  height: 52px; padding: 0 6px; margin: 0 -6px 22px; background: var(--surface-2); border-radius: 16px;
  overflow-x: auto; overflow-y: hidden; scrollbar-width: none;
}
.toolbar::-webkit-scrollbar { display: none; }
.tool {
  flex-shrink: 0; height: 40px; padding: 0 12px; border-radius: 11px; border: none; background: transparent;
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer; font-size: 13px; font-weight: 500; color: var(--muted);
}
.tool svg { width: 18px; height: 18px; flex-shrink: 0; }
.tool[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.tool:disabled { opacity: .35; cursor: default; }
.tool-sep { width: 1px; height: 24px; background: var(--line); flex-shrink: 0; margin: 0 2px; }
/* The context slot keeps a fixed width so the toolbar never changes size between tools. */
.ctx { flex-shrink: 0; width: 100px; height: 40px; position: relative; }
.ctx > * { position: absolute; inset: 0; display: flex; align-items: center; gap: 8px; visibility: hidden; }
.ctx > .show { visibility: visible; }
.swatch { width: 26px; height: 26px; border-radius: 13px; border: 2px solid transparent; flex-shrink: 0; cursor: pointer; padding: 0; outline-offset: 1px; }
.swatch[aria-pressed="true"] { border-color: var(--ink); box-shadow: inset 0 0 0 2px var(--surface-2); }
.ctx .tool { padding: 0 10px; }

.apply-pill {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(88px + env(safe-area-inset-bottom)); z-index: 40;
  border: none; border-radius: 24px; min-height: 48px; padding: 0 22px; background: var(--ink); color: var(--bg);
  font-weight: 600; font-size: 15px; box-shadow: var(--shadow); cursor: pointer; visibility: hidden;
}
.apply-pill.show { visibility: visible; }

.text { position: relative; }
.text.inking { user-select: none; -webkit-user-select: none; }
.text canvas { position: absolute; left: 0; top: 0; pointer-events: none; z-index: 2; }
.text.inking canvas { pointer-events: auto; touch-action: none; cursor: crosshair; }
.text.erasing canvas { cursor: cell; }
.quote { font-family: var(--serif); font-style: italic; font-size: 23px; line-height: 1.45; color: var(--ink-2); margin: 0 0 10px; }
.source { font-size: 13px; color: var(--muted); margin: 0 0 22px; }
.thought p { font-family: var(--serif); font-size: 19px; line-height: 1.65; margin: 0 0 18px; color: var(--ink); }
/* Folding: the height glides open, calm and unhurried. */
.collapse { display: grid; grid-template-rows: 0fr; opacity: 0; transition: grid-template-rows .6s cubic-bezier(.22,.61,.36,1), opacity .5s ease; }
.collapse.open { grid-template-rows: 1fr; opacity: 1; }
.collapse > .inner { overflow: hidden; min-height: 0; }
.collapse.instant { transition: none; }
@media (prefers-reduced-motion: reduce) { .collapse { transition: none; } }
mark.h { background: var(--hl); color: inherit; border-radius: 2px; padding: 0 1px; }
.x { text-decoration: line-through; text-decoration-color: var(--accent); text-decoration-thickness: 2px; color: var(--muted); }

.fold {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; width: 100%; min-height: 52px;
  padding: 0 16px; margin: 0 0 18px; border: 1px solid var(--line); border-radius: 14px; background: transparent;
  cursor: pointer; font-size: 15px; font-weight: 500; color: var(--ink); text-align: left;
}
.fold:hover { background: var(--surface-2); }
.fold .sub { color: var(--muted); font-weight: 400; font-size: 13px; margin-left: 6px; }
.fold svg { width: 18px; height: 18px; transition: transform .6s cubic-bezier(.22,.61,.36,1); flex-shrink: 0; }
.fold[aria-expanded="true"] svg { transform: rotate(180deg); }
@media (prefers-reduced-motion: reduce) { .fold svg { transition: none; } }
.fold.small { min-height: 44px; border: none; padding: 0; margin: 10px 0 0; font-size: 14px; color: var(--muted); justify-content: flex-start; }
.fold.small:hover { background: none; color: var(--ink); }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 18px 20px 20px; margin: 0 0 16px; }
.card h2 { font-size: 12px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); font-weight: 600; margin: 0; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; min-height: 44px; margin: -6px -8px 4px 0; }
.exercise { font-family: var(--serif); font-size: 21px; line-height: 1.4; margin: 0; }
.exercise-long { font-size: 15px; line-height: 1.55; color: var(--ink-2); margin: 8px 0 0; }
.star[aria-pressed="true"] { color: var(--accent); }
.star[aria-pressed="true"] svg { fill: currentColor; }

.q { margin: 0 0 18px; }
.q:last-child { margin-bottom: 0; }
.q label { display: block; font-family: var(--serif); font-size: 19px; line-height: 1.35; margin-bottom: 10px; }
.q .tag { display: block; font-family: var(--sans); font-size: 12px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); font-weight: 600; margin-bottom: 6px; }
textarea {
  display: block; width: 100%; height: 112px; resize: vertical; border: 1px solid var(--line); border-radius: 14px; background: var(--bg);
  color: var(--ink); font: inherit; font-size: 16px; line-height: 1.55; padding: 12px 14px;
}
.more-q { border-top: 1px solid var(--line); margin-top: 14px; padding-top: 18px; }
.saved-hint { font-size: 12px; color: var(--muted); height: 16px; margin-top: 8px; text-align: right; }

/* ---------- Year ---------- */
.h1 { font-family: var(--serif); font-weight: 500; font-size: 36px; margin: 28px 0 6px; }
.lead { color: var(--muted); margin: 0 0 22px; font-size: 15px; line-height: 1.5; min-height: 45px; }
.dots { display: grid; grid-template-columns: repeat(19, minmax(0, 1fr)); gap: 5px; margin-bottom: 18px; }
@media (min-width: 560px) { #dots { grid-template-columns: repeat(31, minmax(0, 1fr)); } }
.dot { aspect-ratio: 1; border-radius: 50%; border: none; padding: 0; background: var(--dot-future); cursor: pointer; position: relative; }
.dot.past { background: var(--dot-past); }
.dot.done { background: var(--dot-done); }
.dot.today { background: var(--accent); }
.dot.sel { box-shadow: 0 0 0 2px var(--bg), 0 0 0 3.5px var(--ink); }
.dot.bm::after { content: ""; position: absolute; inset: 30%; border-radius: 50%; background: var(--accent); }
.dot.today.bm::after { background: var(--accent-ink); }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12px; color: var(--muted); margin-bottom: 22px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 50%; display: inline-block; position: relative; }
input[type=range] { width: 100%; accent-color: var(--accent); height: 44px; }
.preview { display: flex; flex-direction: column; gap: 8px; margin: 10px 0 18px; min-height: 150px; }
.preview .d { font-size: 13px; color: var(--accent); font-weight: 600; letter-spacing: .04em; }
.preview .t { font-family: var(--serif); font-size: 30px; line-height: 1.1; }
.preview .m { font-family: var(--serif); font-style: italic; color: var(--muted); font-size: 18px; line-height: 1.4; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn {
  min-height: 48px; padding: 0 22px; border-radius: 24px; border: 1px solid var(--ink); background: transparent; color: var(--ink);
  font-size: 15px; font-weight: 500; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none;
}
.btn.primary { background: var(--ink); color: var(--bg); }
.btn svg { width: 18px; height: 18px; }

/* ---------- Lists ---------- */
.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.item { display: block; text-decoration: none; color: inherit; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 16px 18px; }
.item:hover { border-color: var(--muted); }
.item .d { font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.item .t { font-family: var(--serif); font-size: 18px; line-height: 1.45; margin-top: 6px; }
.empty { color: var(--muted); font-family: var(--serif); font-style: italic; font-size: 18px; padding: 18px 0; }
.section-h { font-size: 12px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); font-weight: 600; margin: 30px 0 12px; }

/* ---------- Settings ---------- */
.seg { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 14px; max-width: 420px; }
.seg button { flex: 1; min-height: 42px; border: none; border-radius: 10px; background: transparent; color: var(--muted); font-weight: 500; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.check { display: flex; gap: 10px; align-items: center; min-height: 44px; font-size: 15px; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }
.note { font-size: 14px; color: var(--muted); line-height: 1.55; max-width: 560px; }
[hidden] { display: none !important; }
.field {
  flex: 1; min-width: 0; min-height: 48px; padding: 0 16px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font: inherit; font-size: 15px;
}
.field:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.field[readonly] { color: var(--muted); font-size: 13px; }
.link-row { display: flex; gap: 10px; max-width: 560px; margin: 0; }
.link-box { margin-top: 14px; max-width: 560px; }
.qr { margin-top: 14px; width: 168px; padding: 12px; background: #FFFFFF; border-radius: 14px; }
.qr:empty { display: none; }
.qr svg { display: block; width: 100%; height: auto; }
.field-error { color: var(--accent); font-size: 14px; min-height: 0; margin: 6px 0 0; }
.field-error:empty { display: none; }
.people { list-style: none; margin: 18px 0 0; padding: 0; max-width: 560px; border-top: 1px solid var(--line); }
.people li { display: flex; align-items: center; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.people .who { flex: 1; min-width: 160px; }
.people .who b { font-weight: 500; display: block; }
.people .who span { font-size: 13px; color: var(--muted); }
.people .btn { min-height: 38px; padding: 0 14px; font-size: 14px; }
.toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 12px 18px; border-radius: 14px; font-size: 14px; opacity: 0; pointer-events: none;
  transition: opacity .2s; z-index: 50; white-space: nowrap;
}
.toast.show { opacity: 1; }

/* ---------- Desktop ---------- */
@media (min-width: 1024px) {
  body { padding-bottom: 40px; }
  .tabs { display: none; }
  .top-tabs { display: flex; }
  .brand { margin-right: 36px; }
  .top-tab {
    display: inline-flex; align-items: center; gap: 8px; height: 40px; padding: 0 14px; border-radius: 12px;
    text-decoration: none; color: var(--muted); font-size: 14px; font-weight: 500;
  }
  .top-tab svg { width: 18px; height: 18px; }
  .top-tab:hover { background: var(--surface-2); color: var(--ink); }
  .top-tab[aria-current="page"] { background: var(--surface-2); color: var(--ink); }
  .top-tab[aria-current="page"] svg { color: var(--accent); }
  .toast, .apply-pill { bottom: 32px; }

  .day-grid { display: grid; grid-template-columns: 200px minmax(0, 1fr) 340px; gap: 48px; align-items: start; }
  .side { position: sticky; top: calc(var(--top-h) + 1px + env(safe-area-inset-top)); }
  .side { display: block; padding-top: 30px; }
  .main { max-width: 660px; }
  .panel { padding-top: 30px; }
  .side .label { font-size: 12px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); font-weight: 600; margin: 0 0 12px; }
  .side .dots { grid-template-columns: repeat(14, minmax(0, 1fr)); gap: 4px; margin-bottom: 14px; }
  .side .month { font-family: var(--serif); font-size: 22px; margin: 0 0 4px; }
  .side .sub { font-size: 13px; color: var(--muted); margin: 0 0 22px; line-height: 1.5; }
  .side .links { display: flex; flex-direction: column; gap: 2px; margin-top: 6px; }
  .side .links a { display: flex; align-items: center; min-height: 40px; padding: 0 10px; margin: 0 -10px; border-radius: 10px; color: var(--ink-2); text-decoration: none; font-size: 14px; }
  .side .links a:hover { background: var(--surface-2); }
  .meta { margin-top: 30px; }
  .day-title { font-size: 52px; }
  .tool { padding: 0 9px; }
  .view > .wrap { max-width: 1320px; padding: 0 32px; }
  #view-year .wrap > *, #view-saved .wrap > *, #view-export .wrap > *, #view-settings .wrap > * { max-width: 920px; }
  .h1 { margin-top: 30px; }
  .list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ---------- Hent ---------- */
.formats { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; margin: 0 0 14px; }
.formats button {
  min-height: 64px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); cursor: pointer;
  display: flex; flex-direction: column; align-items: flex-start; justify-content: center; gap: 2px; padding: 8px 12px; text-align: left;
}
.formats b { font-size: 14px; font-weight: 600; }
.formats span { font-size: 11.5px; color: var(--muted); }
.formats button[aria-checked="true"] { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }
@media (max-width: 620px) {
  .formats { display: flex; overflow-x: auto; scrollbar-width: none; margin: 0 -22px 14px; padding: 0 22px; }
  .formats::-webkit-scrollbar { display: none; }
  .formats button { flex: 0 0 auto; min-width: 104px; }
}
.export-opts { display: flex; flex-wrap: wrap; gap: 0 22px; margin-bottom: 10px; }
.preview-box { border: 1px solid var(--line); border-radius: 18px; overflow: hidden; background: var(--surface-2); }
.preview-cap { margin: 0; padding: 10px 14px; font-size: 12px; color: var(--muted); border-bottom: 1px solid var(--line); height: 38px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.preview-box iframe { display: block; width: 100%; height: 520px; border: 0; background: #FFF; }
@media (min-width: 1024px) { .preview-box iframe { height: 640px; } }
.tabs .tab { min-width: 56px; }

/* Icon-only tools */
.tool.icon { width: 44px; padding: 0; justify-content: center; }
.tool.icon svg { width: 20px; height: 20px; }
.font-pick { display: flex; align-items: center; gap: 10px; min-height: 44px; font-size: 15px; }
.font-pick select { min-height: 40px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--ink); font: inherit; font-size: 14px; padding: 0 10px; }
.font-pick.off { visibility: hidden; }

/* ---------- Moleskine paper for the exercise and the questions; dark tobacco paper in the dark theme ---------- */
:root { --paper: #F2E8D5; --paper-line: #E2D5BC; --paper-ink: #3B2E22; --paper-muted: #76624C; --paper-field: #FAF5EA; --paper-field-line: #DCCDB1; --paper-hover: rgba(59,46,34,.07); --paper-star: #A8432A; --paper-hint: #9C8A73; --paper-scheme: light; --paper-shadow: 0 1px 2px rgba(59,46,34,.06), 0 10px 26px rgba(59,46,34,.08); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --paper: #2A231C; --paper-line: #3A3027; --paper-ink: #E9DFCB; --paper-muted: #A8977F; --paper-field: #211B15; --paper-field-line: #3A3027; --paper-hover: rgba(233,223,203,.08); --paper-star: #E07A5A; --paper-hint: #7F705D; --paper-scheme: dark; --paper-shadow: 0 1px 2px rgba(0,0,0,.3), 0 10px 26px rgba(0,0,0,.25); }
}
:root[data-theme="dark"] { --paper: #2A231C; --paper-line: #3A3027; --paper-ink: #E9DFCB; --paper-muted: #A8977F; --paper-field: #211B15; --paper-field-line: #3A3027; --paper-hover: rgba(233,223,203,.08); --paper-star: #E07A5A; --paper-hint: #7F705D; --paper-scheme: dark; --paper-shadow: 0 1px 2px rgba(0,0,0,.3), 0 10px 26px rgba(0,0,0,.25); }
.card { background: var(--paper); border-color: var(--paper-line); color: var(--paper-ink); box-shadow: var(--paper-shadow); }
.card h2, .card .q .tag, .card .saved-hint { color: var(--paper-muted); }
.card .exercise, .card .q label { color: var(--paper-ink); }
.card .exercise-long { color: var(--paper-muted); }
.card .icon-btn { color: var(--paper-ink); }
.card .icon-btn:hover { background: var(--paper-hover); }
.card .star[aria-pressed="true"] { color: var(--paper-star); }
.card .fold.small { color: var(--paper-muted); }
.card .fold.small:hover { color: var(--paper-ink); }
.card .more-q { border-top-color: var(--paper-field-line); }
.card textarea { background: var(--paper-field); border-color: var(--paper-field-line); color: var(--paper-ink); color-scheme: var(--paper-scheme); }
.card textarea::placeholder { color: var(--paper-hint); }
.card textarea:focus-visible { outline-color: var(--paper-star); }
