/*
 * The app's stylesheet. The token block is the site's, verbatim
 * (docs/WEBSITE.md section 11.2: the app adopts the tokens), and
 * tokens.test.ts fails when the two drift. Everything under "App" is
 * the app's own: one column, the title screen, the live region.
 *
 * The two families are served from this origin, as on the site, from the
 * repository's one copy in `fonts/` (#324). Never from anyone else's.
 */

/* The two families, served from this origin and from nowhere else
   (#324, docs/WEBSITE.md section 13.4). woff2, the latin subset, four
   files and 88,484 bytes; the licences and the provenance are in
   `fonts/README.md`. `swap` so the page renders at once in the fallback
   and changes to these when they arrive: nothing waits on a font. */

@font-face {
  font-family: "Lora";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("lora-regular.woff2") format("woff2");
}
@font-face {
  font-family: "Lora";
  font-style: italic;
  font-weight: 400;
  font-display: swap;
  src: url("lora-italic.woff2") format("woff2");
}
@font-face {
  font-family: "Cormorant Garamond";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("cormorant-regular.woff2") format("woff2");
}
@font-face {
  font-family: "Cormorant Garamond";
  font-style: italic;
  font-weight: 400;
  font-display: swap;
  src: url("cormorant-italic.woff2") format("woff2");
}

:root {
  color-scheme: light dark;

  /* Colour: light. Accent is a stroke and a label colour, never a fill. */
  --bg: #f3f2f2;
  --ink: #201f1d;
  --surface: #f8f4f4;
  --muted: #605d5d;
  --soft: #444141;
  --accent: #b68235;
  --accent-strong: #7d5411;
  --accent-wash: #fff3e4;
  --hairline: color-mix(in srgb, var(--ink) 16%, transparent);

  /* Type. Named families, system fallbacks, nothing fetched. */
  --font-body: "Lora", Georgia, "Times New Roman", serif;
  --font-heading: "Cormorant Garamond", Georgia, "Times New Roman", serif;
  --text-s: 0.8125rem; /* small caps, citations, table headers */
  --text-secondary: 0.9375rem; /* help, notes beside a thing, the gloss */
  --text-m: 1.125rem;
  --text-l: 1.375rem;
  --text-xl: 1.75rem;
  --text-xxl: 2.25rem;
  --leading-body: 1.7;
  --leading-tight: 1.2;
  --tracking-label: 0.16em;

  /* Measure and space. One column; the measure is set in the body font. */
  --measure: 62ch;
  --gutter: 1rem;
  --s1: 0.25rem;
  --s2: 0.5rem;
  --s3: 1rem;
  --s4: 1.5rem;
  --s5: 2rem;
  --s6: 3rem;
  --s7: 4rem;

  /* Controls. 44px is the smallest target the design record allows. */
  --target: 2.75rem;
  --focus: var(--accent-strong);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1b1a;
    --ink: #ebe7e1;
    --surface: #262422;
    --muted: #b3ada5;
    --soft: #cdc7bf;
    --accent: #c9975a;
    --accent-strong: #e0b77e;
    --accent-wash: #2e2519;
    --hairline: color-mix(in srgb, var(--ink) 20%, transparent);
  }
}

/* App */

*, *::before, *::after { box-sizing: border-box; }

html {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 100%;
  line-height: var(--leading-body);
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-size: var(--text-m);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
}

main {
  width: 100%;
  max-width: calc(var(--measure) + 2 * var(--gutter));
  margin: 0 auto;
  padding: var(--s5) var(--gutter) var(--s7);
  flex: 1;
}
main:focus { outline: none; }

.skip {
  position: absolute;
  left: var(--gutter);
  top: -100%;
  padding: var(--s2) var(--s3);
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--accent-strong);
  z-index: 1;
}
.skip:focus { top: var(--s2); }

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 3px;
}

a {
  color: var(--accent-strong);
  text-decoration: underline;
  text-decoration-thickness: from-font;
  text-underline-offset: 0.15em;
}
a:hover { text-decoration-thickness: 2px; }

h1, h2, h3 {
  font-family: var(--font-heading);
  font-weight: 400;
  line-height: var(--leading-tight);
  margin: var(--s6) 0 var(--s3);
}
h1 { font-size: var(--text-xxl); margin-top: 0; }
h2 { font-size: var(--text-xl); }
h1:focus { outline: none; }

p { margin: 0 0 var(--s3); }

button {
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--accent-strong);
  border-radius: 2px;
  min-height: var(--target);
  min-width: var(--target);
  padding: var(--s2) var(--s4);
  cursor: pointer;
}
button:hover { background: var(--accent-wash); }

/* The title screen: the name, one line, Begin. Centred, and it is the only centred screen. */
.title {
  min-height: 70vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  gap: var(--s4);
}
.title .mark {
  width: 6rem;
  height: 6rem;
  border: 1px solid var(--accent);
  display: grid;
  place-items: center;
  font-family: var(--font-heading);
  font-size: 3.5rem;
}
.title h1 { margin: 0; }
.title p { color: var(--soft); margin: 0; }
/* The Beta disclosure (#357): read, not centred, on the title screen and on Privacy. */
.beta { text-align: left; max-width: 34rem; border-left: 2px solid var(--accent); padding: 0 0 0 var(--s3); }
.beta h2 { margin: 0 0 var(--s2); }
.title .beta p { color: var(--ink); margin: 0 0 var(--s2); }

/* The live region: read by screen readers, out of the way for everyone else. */
.status {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

@media (prefers-reduced-motion: no-preference) {
  .title { animation: settle 400ms ease-out; }
  @keyframes settle { from { opacity: 0; } to { opacity: 1; } }
}

/* Forms */

label { display: block; margin: var(--s3) 0 var(--s1); }
input[type="text"], input[type="password"], input[type="search"], textarea {
  display: block;
  width: 100%;
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--muted);
  border-radius: 2px;
  padding: var(--s2) var(--s3);
  min-height: var(--target);
}
textarea { line-height: var(--leading-body); resize: vertical; }
input[type="file"] { display: block; margin: var(--s2) 0; min-height: var(--target); }
input[type="checkbox"] { width: 1.25rem; height: 1.25rem; margin: 0 var(--s2) 0 0; vertical-align: middle; }
.check label { display: inline; margin: 0; }
.check .help { display: block; }
.help { color: var(--muted); font-size: var(--text-secondary); margin: var(--s1) 0 0; }
.error { color: var(--accent-strong); min-height: 1.5em; margin: var(--s2) 0; }
.note { color: var(--soft); }
.pattern { margin: var(--s5) 0; padding: var(--s3); border-left: 2px solid var(--muted); }
.label { font-size: var(--text-s); letter-spacing: var(--tracking-label); text-transform: uppercase; color: var(--accent-strong); margin: var(--s4) 0 var(--s1); }
.prompt { font-family: var(--font-heading); font-size: var(--text-l); margin: var(--s4) 0 var(--s2); }
.row { display: flex; flex-wrap: wrap; gap: var(--s3); align-items: center; margin: var(--s4) 0; }
.row a { min-height: var(--target); display: inline-flex; align-items: center; }
.bar { position: sticky; bottom: 0; background: var(--bg); padding: var(--s2) 0; margin-bottom: 0; }
button.quiet { background: transparent; border-color: var(--muted); }
button.danger { border-color: var(--accent-strong); color: var(--accent-strong); }
.text-button {
  background: none;
  border: none;
  padding: var(--s2) 0;
  min-height: var(--target);
  color: var(--accent-strong);
  text-decoration: underline;
  text-underline-offset: 0.15em;
}
.text-button:hover { background: none; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.step { color: var(--muted); font-size: var(--text-s); }
.secret-row { display: flex; gap: var(--s2); align-items: stretch; }
.secret-row input { flex: 1; }
.secret-row .reveal { padding: 0 var(--s3); }
.start-again { margin-top: var(--s6); }
.text { white-space: pre-wrap; }
.phrase { columns: 2; font-family: var(--font-heading); font-size: var(--text-l); padding-left: var(--s5); }
.phrase li { break-inside: avoid; padding: var(--s1) 0; }

/* The Marcus plate: margin note, a matted panel (design/SCREENS.md §3). */
.plate {
  margin: var(--s5) 0;
  border: 1px solid var(--hairline);
  background: var(--surface);
  padding: 6px;
}
.plate > * { margin-left: var(--s3); margin-right: var(--s3); }
.plate > .label:first-child { margin-top: var(--s3); }
.plate-quote { margin: var(--s2) var(--s3); border: 1px solid var(--hairline); padding: var(--s3); }
.plate-quote blockquote { margin: 0; font-size: 1.0625rem; }
.plate-quote blockquote p { margin: 0 0 var(--s2); }
.plate-quote figcaption { margin-top: var(--s1); font-size: var(--text-s); color: var(--soft); }
/* <cite> is the citation, as on the site; the browser's italic is not wanted. */
.plate-quote figcaption cite, .print-view .print-passage figcaption cite { font-style: normal; }
.plate-quote figcaption a { display: inline-flex; align-items: center; min-height: var(--target); }
.plate .gloss { color: var(--soft); font-size: var(--text-secondary); }
.plate .question { font-size: 1.625rem; margin: var(--s2) var(--s3) var(--s3); }
.hairline { border: 0; border-top: 1px solid var(--hairline); margin: var(--s3) 0; }

/* Chips: 44px targets and a 3:1 border (WCAG 2.2 1.4.11). */
.chips { display: flex; flex-wrap: wrap; gap: var(--s2); margin: var(--s2) 0; }
.chip {
  min-height: var(--target);
  padding: var(--s1) var(--s3);
  border: 1px solid var(--soft);
  border-radius: 999px;
  background: var(--surface);
  font-size: var(--text-secondary);
}
.chip[aria-pressed="true"] { border-color: var(--accent-strong); background: var(--accent-wash); }
.declined, .safety, .failed { margin: var(--s5) 0; padding: var(--s3); border-left: 2px solid var(--accent); }
.safety ul { padding-left: var(--s4); }
.engine-line { color: var(--muted); font-size: var(--text-secondary); }

/* Journal */
.entries { list-style: none; padding: 0; margin: 0; }
.entries li { border-top: 1px solid var(--hairline); }
.entry-link { display: grid; grid-template-columns: 3rem 1fr; gap: 0 var(--s2); padding: var(--s3) 0; text-decoration: none; color: var(--ink); min-height: var(--target); }
.entry-link .day { grid-row: 1 / span 3; font-family: var(--font-heading); font-size: var(--text-xl); color: var(--soft); }
.entry-link .entry-title { font-weight: 500; }
.entry-link .excerpt, .entry-link .reflected { color: var(--muted); font-size: var(--text-secondary); }
.entry-link:hover .entry-title { text-decoration: underline; }
.empty { color: var(--muted); }
.month h2 { font-size: var(--text-l); margin-top: var(--s5); }
.rows { list-style: none; padding: 0; }
.rows li { display: flex; justify-content: space-between; gap: var(--s3); padding: var(--s2) 0; border-top: 1px solid var(--hairline); }
.row-state { color: var(--soft); text-align: right; font-size: var(--text-secondary); }
.outputs { list-style: none; padding: 0; }
.outputs li { padding: var(--s3) 0; border-top: 1px solid var(--hairline); }
.picture p { font-size: var(--text-m); }
.themes { color: var(--muted); font-size: var(--text-secondary); }

/* The tabs: Today · Journal · Me. Hidden while the title, onboarding or unlock screens show. */
.tabs {
  position: sticky;
  bottom: 0;
  display: flex;
  justify-content: space-around;
  background: var(--surface);
  border-top: 1px solid var(--hairline);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs[hidden] { display: none; }
.tabs a { flex: 1; text-align: center; padding: var(--s2) 0; min-height: var(--target); display: inline-flex; align-items: center; justify-content: center; text-decoration: none; color: var(--soft); font-size: var(--text-s); }
.tabs a[aria-current="page"] { color: var(--accent-strong); border-top: 2px solid var(--accent-strong); margin-top: -1px; }

/* The print view (#142): on screen a plain reading view; on paper, pages. */
.button-link { display: inline-flex; align-items: center; min-height: var(--target); padding: var(--s2) var(--s4); border: 1px solid var(--accent-strong); border-radius: 2px; text-decoration: none; color: var(--ink); background: var(--surface); }
.print-view .print-entry { margin-top: var(--s6); }
.print-view .print-passage { margin: var(--s3) 0; padding-left: var(--s3); border-left: 2px solid var(--accent); }
.print-view .print-passage blockquote { margin: 0; }
.print-view .print-passage figcaption { font-size: var(--text-s); color: var(--soft); }
.print-view .gloss { color: var(--soft); font-size: var(--text-s); }
.print-view .question { font-family: var(--font-heading); font-size: var(--text-l); }
.print-view .action { padding-left: var(--s3); }
.print-foot { margin-top: var(--s6); color: var(--muted); font-size: var(--text-s); }

@page { margin: 2cm; }
@media print {
  html { background: #fff; color: #000; }
  body { display: block; font-size: 11pt; }
  main { max-width: none; padding: 0; }
  .tabs, .skip, .status, .no-print { display: none !important; }
  .print-view .print-entry { break-before: page; margin-top: 0; }
  .print-view .print-passage { break-inside: avoid; border-left-color: #000; }
  .print-view h1, .print-view h2 { break-after: avoid; }
  .print-view .gloss, .print-view .print-passage figcaption, .print-foot { color: #333; }
  a { color: inherit; text-decoration: none; }
}

/* Beta feedback (#358): the report is shown whole, as it would leave. */
.useful { margin: var(--s4) 0; }
.feedback fieldset { border: 0; padding: 0; margin: 0 0 var(--s3); }
.feedback .choice { display: flex; align-items: center; gap: var(--s2); min-height: 44px; }
.report { white-space: pre-wrap; overflow-wrap: anywhere; padding: var(--s3); border: 1px solid var(--muted); font-size: 0.9em; }
