/*
 * The whole design system, in one file. To re-theme a product, change the variables in :root (and the dark block).
 * No inline styles anywhere: the Content-Security-Policy is style-src 'self'.
 * Contrast: text/background pairs below meet WCAG AA (4.5:1) in both schemes.
 */
:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --text: #16181d;
  --text-soft: #4a505c;
  --text-muted: #5f6673;
  --border: #d5d9e0;
  --accent: #3b2f87;
  --accent-text: #ffffff;
  --accent-soft: #ebe8fb;
  --good: #0f6b3a;
  --good-soft: #e3f4ea;
  --warn: #7a4b00;
  --warn-soft: #fdf0d5;
  --bad: #a4161a;
  --bad-soft: #fde8e8;
  --focus: #b3470f;
  --radius: 8px;
  --gap: 16px;
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sidebar: 248px;
  --shadow: 0 1px 2px rgb(0 0 0 / 6%), 0 4px 12px rgb(0 0 0 / 5%);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111318;
    --surface: #1a1d24;
    --surface-2: #232730;
    --text: #eceef2;
    --text-soft: #c1c6d0;
    --text-muted: #a3a9b6;
    --border: #353a46;
    --accent: #c7bdff;
    --accent-text: #17123a;
    --accent-soft: #272148;
    --good: #7fd6a4;
    --good-soft: #17301f;
    --warn: #f1c26b;
    --warn-soft: #33290f;
    --bad: #ff9a9a;
    --bad-soft: #3a1a1b;
    --focus: #ffb37a;
    --shadow: none;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.55 var(--font); }
h1, h2, h3, p, ul, ol, dl, dd, figure { margin: 0; }
h1 { font-size: 1.75rem; line-height: 1.2; }
h2 { font-size: 1.2rem; line-height: 1.3; }
h3 { font-size: 1.05rem; }
ul, ol { padding: 0; list-style: none; }
a { color: var(--accent); text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }
code { font-family: var(--mono); font-size: 0.9em; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
img, svg { max-width: 100%; }

/* One focus style everywhere, never removed. */
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
main:focus { outline: none; }

.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.skip { position: absolute; left: 8px; top: -60px; z-index: 100; background: var(--surface); color: var(--text); padding: 10px 14px; border: 2px solid var(--focus); border-radius: var(--radius); }
.skip:focus { top: 8px; }

.soft { color: var(--text-soft); }
.muted { color: var(--text-muted); }
.small { font-size: 0.875rem; }
.num { font-variant-numeric: tabular-nums; }
.done { text-decoration: line-through; color: var(--text-muted); }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.stack { display: flex; flex-direction: column; gap: var(--gap); }
.row { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.row.end { align-items: flex-end; }
.grow { flex: 1 1 auto; min-width: 0; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: var(--gap); }

/* ---- controls */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 8px 16px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; }
.btn:hover { background: var(--surface-2); }
.btn[disabled] { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.1); }
.btn-danger { background: var(--bad); border-color: var(--bad); color: var(--surface); }
.btn-danger:hover { background: var(--bad); filter: brightness(1.1); }
.btn-small { min-height: 36px; padding: 4px 12px; font-size: 0.9rem; }
.field { display: flex; flex-direction: column; gap: 6px; font-weight: 600; }
.field small { font-weight: 400; }
.input { width: 100%; min-height: 44px; padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); font: inherit; font-weight: 400; }
.input[readonly] { background: var(--surface-2); }
.input-small { min-height: 36px; padding: 4px 8px; width: auto; }
textarea.input { resize: vertical; }

.tag { display: inline-block; padding: 2px 10px; border-radius: 999px; background: var(--surface-2); color: var(--text); font-size: 0.82rem; font-weight: 600; text-transform: capitalize; }
.tag-good { background: var(--good-soft); color: var(--good); }
.badge { display: inline-block; min-width: 22px; margin-left: 8px; padding: 0 6px; border-radius: 999px; background: var(--accent); color: var(--accent-text); font-size: 0.8rem; font-weight: 700; text-align: center; }

.msg { padding: 12px 14px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); }
.msg-warn { background: var(--warn-soft); border-color: var(--warn); color: var(--warn); }
.msg-bad { background: var(--bad-soft); border-color: var(--bad); color: var(--bad); }
.msg-good { background: var(--good-soft); border-color: var(--good); color: var(--good); }
.msg-info { background: var(--accent-soft); border-color: var(--accent); color: var(--text); }
.msg a { color: inherit; font-weight: 600; }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.panel-danger { border-color: var(--bad); }
.panel > h2 { margin-bottom: 4px; }
.empty { text-align: center; padding: 48px 20px; background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius); display: flex; flex-direction: column; align-items: center; gap: 10px; }
.loading { display: flex; align-items: center; gap: 10px; color: var(--text-muted); padding: 24px 0; }
.spinner { width: 18px; height: 18px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } * { scroll-behavior: auto !important; transition: none !important; } }

.list > li { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 12px 0; border-bottom: 1px solid var(--border); }
.list > li:last-child { border-bottom: 0; }
.list > li.is-unread { border-left: 4px solid var(--accent); padding-left: 12px; }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding-top: 16px; }

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table caption { text-align: left; font-weight: 600; padding-bottom: 8px; }
.table th, .table td { text-align: left; padding: 10px 12px 10px 0; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { font-size: 0.85rem; color: var(--text-muted); }
.table .num { text-align: right; }
.table .actions { text-align: right; white-space: nowrap; }
.table .actions .btn { margin-left: 6px; }

.meter-head { display: flex; justify-content: space-between; gap: 12px; font-size: 0.92rem; }
.meter progress { width: 100%; height: 8px; margin-top: 4px; accent-color: var(--accent); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: var(--gap); margin: 12px 0; }
.stats dt { color: var(--text-muted); font-size: 0.85rem; }
.stats dd { font-size: 1.6rem; font-weight: 700; }

/* ---- toasts */
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 50; display: flex; flex-direction: column; gap: 8px; max-width: min(420px, calc(100vw - 32px)); }
.toast { display: flex; align-items: flex-start; gap: 12px; padding: 12px 14px; border-radius: var(--radius); background: var(--text); color: var(--bg); box-shadow: var(--shadow); }
.toast-bad { background: var(--bad); color: var(--surface); }
.toast-close { margin-left: auto; min-width: 28px; min-height: 28px; border: 0; background: transparent; color: inherit; font-size: 1.2rem; line-height: 1; cursor: pointer; }

/* ---- brand */
.lockup { display: inline-flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; }
.lockup small { color: var(--text-muted); font-weight: 400; }
.mark { width: 28px; height: 28px; flex: none; }
.mark rect { fill: var(--accent); }
.mark path { fill: none; stroke: var(--accent-text); stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }

/* ---- signed-in shell */
.shell { display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); min-height: 100vh; }
.topbar { display: none; }
.sidebar { display: flex; flex-direction: column; gap: 20px; padding: 20px 16px; background: var(--surface); border-right: 1px solid var(--border); position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { display: flex; align-items: center; min-height: 44px; padding: 8px 12px; border-radius: var(--radius); color: var(--text); text-decoration: none; font-weight: 500; }
.nav a:hover { background: var(--surface-2); }
.nav a[aria-current='page'] { background: var(--accent-soft); color: var(--text); font-weight: 700; box-shadow: inset 3px 0 0 var(--accent); }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.content { padding: 32px; display: flex; flex-direction: column; gap: 20px; max-width: 1100px; width: 100%; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.page-head p { margin-top: 4px; }
.narrow { max-width: 520px; display: flex; flex-direction: column; gap: var(--gap); }
.plain-page { max-width: 520px; margin: 0 auto; padding: 56px 20px; display: flex; flex-direction: column; gap: var(--gap); }

@media (max-width: 860px) {
  .shell { display: block; }
  .topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
  .sidebar { display: none; position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--border); }
  .sidebar.is-open { display: flex; }
  .sidebar-brand { display: none; }
  .content { padding: 20px 16px 88px; }
  h1 { font-size: 1.45rem; }
  .table .actions { white-space: normal; }
}

/* ---- plans */
.plans { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: var(--gap); }
.plan { display: flex; flex-direction: column; gap: 10px; padding: 20px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.plan.is-current { border: 2px solid var(--accent); }
.price { font-size: 1.9rem; font-weight: 700; line-height: 1.1; }
.price small { font-size: 0.95rem; font-weight: 400; color: var(--text-muted); }
.ticks { display: flex; flex-direction: column; gap: 6px; }
.ticks li { padding-left: 22px; position: relative; }
.ticks li::before { content: ''; position: absolute; left: 2px; top: 0.5em; width: 10px; height: 5px; border-left: 2px solid var(--good); border-bottom: 2px solid var(--good); transform: rotate(-45deg); }
.plan-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; padding-top: 8px; }

/* ---- public pages */
.container { width: 100%; max-width: 1080px; margin: 0 auto; padding: 0 20px; }
main.container { display: flex; flex-direction: column; gap: 48px; padding-top: 48px; padding-bottom: 72px; }
main.container.prose { max-width: 760px; gap: 16px; }
.prose h2 { margin-top: 16px; }
.prose ul { list-style: disc; padding-left: 22px; display: flex; flex-direction: column; gap: 8px; }
.site-head { background: var(--surface); border-bottom: 1px solid var(--border); }
.site-head-in, .site-foot-in { display: flex; align-items: center; justify-content: space-between; gap: 12px 24px; flex-wrap: wrap; padding-top: 12px; padding-bottom: 12px; }
.site-nav { display: flex; align-items: center; gap: 4px 18px; flex-wrap: wrap; }
.site-nav a:not(.btn) { display: inline-flex; align-items: center; min-height: 44px; color: var(--text); }
.site-foot { border-top: 1px solid var(--border); background: var(--surface); color: var(--text-soft); font-size: 0.92rem; }
.hero { display: flex; flex-direction: column; gap: 16px; max-width: 720px; padding: 24px 0; }
.hero h1 { font-size: clamp(1.9rem, 5vw, 3rem); }
.lead { font-size: 1.15rem; color: var(--text-soft); }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: var(--gap); }
.faq { display: flex; flex-direction: column; gap: 18px; }
.faq dt { font-weight: 700; }
.faq dd { color: var(--text-soft); }

/* =====================================================================================================
 * Memory Passport. Mobile first: every rule below is written for a 390 px screen and widened after.
 * ===================================================================================================== */

/* ---- cover themes: the same six pairs as THEMES in src/shared/journal.ts (text on cover is at least 7:1) */
.theme-indigo { --cover: #1b1f4b; --cover-2: #3b2f87; --cover-ink: #f4f3ff; --cover-accent: #ffc857; }
.theme-ember { --cover: #4a1410; --cover-2: #8a2f14; --cover-ink: #fff4ec; --cover-accent: #ffd166; }
.theme-forest { --cover: #0f3326; --cover-2: #1f5a3d; --cover-ink: #effaf3; --cover-accent: #f6c667; }
.theme-ocean { --cover: #0b2f4a; --cover-2: #12597a; --cover-ink: #eef8ff; --cover-accent: #ffb86b; }
.theme-plum { --cover: #3a1242; --cover-2: #6b1f5c; --cover-ink: #fdf1fb; --cover-accent: #ffd27d; }
.theme-slate { --cover: #1d232b; --cover-2: #3a4452; --cover-ink: #f2f5f8; --cover-accent: #9ad1ff; }

.btn-big { min-height: 52px; padding: 12px 22px; font-size: 1.05rem; }
.check { display: flex; align-items: flex-start; gap: 10px; min-height: 44px; padding: 8px 0; font-weight: 500; cursor: pointer; }
.check input { width: 22px; height: 22px; margin: 2px 0 0; flex: none; accent-color: var(--accent); }
.plain-list { list-style: disc; padding-left: 22px; display: flex; flex-direction: column; gap: 8px; color: var(--text-soft); max-width: 760px; }
.source { font-size: 0.9rem; }

/* ---- chips: a radio group drawn as large tap targets */
.chips { border: 0; padding: 0; margin: 0; min-width: 0; }
.chips legend { font-weight: 600; padding: 0; margin-bottom: 6px; }
.chips-row { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { position: relative; display: inline-flex; align-items: center; min-height: 44px; padding: 8px 14px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); font-weight: 500; cursor: pointer; }
.chip input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.chip.is-on { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 700; }
.chip:has(input:focus-visible) { outline: 3px solid var(--focus); outline-offset: 2px; }
.chips-theme .chip { padding-left: 38px; }
.chips-theme .chip::before { content: ''; position: absolute; left: 10px; width: 20px; height: 20px; border-radius: 50%; background: linear-gradient(135deg, var(--cover), var(--cover-2)); border: 2px solid var(--surface); box-shadow: 0 0 0 1px var(--border); }

/* ---- journal tiles and covers */
.journal-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: var(--gap); }
.journal-tile { display: flex; flex-direction: column; height: 100%; border-radius: var(--radius); overflow: hidden; background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); color: var(--text); text-decoration: none; }
.journal-tile:hover { border-color: var(--accent); }
.journal-tile-cover { position: relative; display: flex; align-items: flex-end; min-height: 132px; padding: 14px; background: linear-gradient(135deg, var(--cover), var(--cover-2)); color: var(--cover-ink); }
.journal-tile-cover img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0.45; }
.journal-tile-title { position: relative; font-size: 1.2rem; font-weight: 800; line-height: 1.2; overflow-wrap: anywhere; }
.journal-tile-meta { display: flex; flex-direction: column; gap: 6px; padding: 12px 14px 14px; font-size: 0.92rem; color: var(--text-soft); }
.journal-cover { padding: 28px 20px; border-radius: var(--radius); background: linear-gradient(135deg, var(--cover), var(--cover-2)); color: var(--cover-ink); display: flex; flex-direction: column; gap: 6px; }
.journal-cover h1, .journal-cover-title { font-size: clamp(1.5rem, 6vw, 2.2rem); font-weight: 800; line-height: 1.15; overflow-wrap: anywhere; }
.journal-cover-eyebrow { color: var(--cover-accent); font-size: 0.82rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; }
.first-days { display: flex; flex-direction: column; gap: 2px; }

/* ---- timeline */
.quick { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px; }
.quick .field { flex: 1 1 220px; }
.timeline-tools { display: flex; flex-direction: column; gap: var(--gap); }
.day { display: flex; flex-direction: column; gap: 10px; }
.day-head { display: flex; align-items: baseline; gap: 10px; padding-bottom: 6px; border-bottom: 2px solid var(--border); font-size: 1rem; }
.day-n { font-size: 1.15rem; font-weight: 800; }
.memory-list { display: flex; flex-direction: column; gap: 12px; }
.memory-list > li { display: flex; flex-direction: column; gap: 10px; }
.memory { display: flex; flex-direction: column; gap: 8px; padding: 14px 16px; background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--accent); border-radius: var(--radius); }
.memory h3, .memory-title { font-size: 1.08rem; font-weight: 700; overflow-wrap: anywhere; }
.memory-head { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.memory-note { white-space: pre-wrap; overflow-wrap: anywhere; color: var(--text-soft); }
.memory-images { display: grid; gap: 6px; grid-template-columns: 1fr; }
.memory-images.n2 { grid-template-columns: 1fr 1fr; }
.memory-images.n3 { grid-template-columns: 1fr 1fr 1fr; }
.memory-images img { display: block; width: 100%; height: auto; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 6px; background: var(--surface-2); }
.memory-images.n1 img { aspect-ratio: auto; max-height: 420px; object-fit: contain; }
.memory-actions { padding-top: 4px; }
.kind-first { background: var(--warn-soft); color: var(--warn); }
.kind-milestone { background: var(--accent-soft); color: var(--text); }
.kind-funny { background: var(--good-soft); color: var(--good); }
.spoiler > summary { display: flex; align-items: center; min-height: 44px; padding: 8px 12px; border: 1px dashed var(--border); border-radius: var(--radius); background: var(--surface-2); font-weight: 600; cursor: pointer; }
.spoiler[open] > summary { margin-bottom: 8px; }
.spoiler > * + * { margin-top: 8px; }
.fab { display: none; }

/* ---- add memory */
.composer .pick-btn { width: 100%; border-style: dashed; border-width: 2px; }
.picks { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 10px; }
.pick { display: flex; flex-direction: column; gap: 6px; }
.pick img, .pick-wait { display: flex; align-items: center; justify-content: center; width: 100%; aspect-ratio: 16 / 10; object-fit: cover; border-radius: 6px; background: var(--surface-2); }
.pick.is-error span[role='alert'] { color: var(--bad); }
.input.is-sample { font-style: italic; color: var(--text-muted); border-style: dashed; }
.save-bar { position: sticky; bottom: 0; padding: 12px 0; background: linear-gradient(to top, var(--bg) 70%, transparent); }
.save-bar .btn { width: 100%; }

/* ---- share cards, public-page picker */
.card-preview { display: block; width: 100%; height: auto; max-width: 420px; border-radius: var(--radius); background: var(--surface-2); border: 1px solid var(--border); }
.card-preview.card-story { max-width: 260px; }
.card-preview.card-wide { max-width: 560px; }
.pick-list { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; margin: 0; min-width: 0; }
.pick-list legend { font-weight: 600; padding: 0 6px; }
.pick-list ul { max-height: 360px; overflow-y: auto; }
.pick-list li + li { border-top: 1px solid var(--border); }

/* ---- landing example */
.example { display: flex; flex-direction: column; gap: var(--gap); padding: 16px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); max-width: 760px; }

/* ---- public journal page (/p/<slug>), written by the server */
.pub-cover { padding: 44px 0 36px; background: linear-gradient(135deg, var(--cover), var(--cover-2)); color: var(--cover-ink); }
.pub-cover .container { display: flex; flex-direction: column; gap: 8px; }
.pub-cover h1 { font-size: clamp(1.7rem, 7vw, 2.8rem); font-weight: 800; overflow-wrap: anywhere; }
.pub-eyebrow { color: var(--cover-accent); font-size: 0.82rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; }
.pub-alias { font-size: 1.1rem; font-weight: 600; }
.pub-count { opacity: 0.85; }
main.container.pub-main { max-width: 760px; gap: 28px; padding-top: 28px; }
.pub-day { display: flex; flex-direction: column; gap: 12px; }
.pub-day h2 { padding-bottom: 6px; border-bottom: 2px solid var(--border); }
.pub-list { display: flex; flex-direction: column; gap: 12px; }
.pub-memory { display: flex; flex-direction: column; gap: 8px; padding: 14px 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.pub-memory h3 { overflow-wrap: anywhere; }
.pub-note { color: var(--text-soft); overflow-wrap: anywhere; }
.pub-images { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 6px; }
.pub-images img { display: block; width: 100%; height: auto; border-radius: 6px; background: var(--surface-2); }

@media (max-width: 860px) {
  /* The one action that matters on a phone is always under the thumb. */
  .fab { display: inline-flex; position: fixed; right: 16px; bottom: 16px; z-index: 30; min-height: 56px; padding: 12px 22px; border-radius: 999px; box-shadow: 0 6px 20px rgb(0 0 0 / 28%); }
  .toasts { bottom: 84px; }
  .page-head .row { width: 100%; }
  .page-head .row .btn { flex: 1 1 auto; }
  .memory-images.n3 { grid-template-columns: 1fr 1fr; }
}
