/* Personal Brain — one stylesheet.
   Sizes are in rem so the whole interface reflows when the browser text size
   changes; nothing is pinned in pixels. */

:root {
  --fg: #111;
  --bg: #fff;
  --bg-soft: #f4f6f8;
  --accent: #0b5cad;
  --accent-fg: #fff;
  --muted: #555;
  --border: #ccd2d8;
  --focus: #ffbf00;
  --focus-halo: rgba(0, 0, 0, 0.55);
  --danger: #b00020;
  --ok: #1a7f37;
  --link: #0a58ca;
}

@media (prefers-color-scheme: dark) {
  :root {
    --fg: #f4f4f4;
    --bg: #121212;
    --bg-soft: #1c1f23;
    --accent: #66aaff;
    --accent-fg: #000;
    --muted: #bbb;
    --border: #3a3f45;
    --focus: #ffd23f;
    --focus-halo: rgba(0, 0, 0, 0.75);
    --danger: #ff6b78;
    --ok: #5fd17a;
    --link: #79b8ff;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font: 1.05rem/1.55 system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
}

body {
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  min-height: 100vh;
}

header, nav, main, footer { padding: 1rem 1.25rem; }
body > header, body > nav, body > main, body > footer { min-width: 0; }

main { max-width: 74ch; width: 100%; }

/* A wide list scrolls inside its own box; the page itself never scrolls
   sideways, which is what WCAG reflow asks for. */
.scroll-x { overflow-x: auto; }

h1 { margin: 0 0 0.75rem; font-size: 1.75rem; }
h2 { margin: 1.5rem 0 0.5rem; font-size: 1.25rem; }
h3 { margin: 1rem 0 0.35rem; font-size: 1.05rem; }

a { color: var(--link); }

.brand { margin: 0; font-weight: 700; font-size: 1.4rem; }
.brand a { color: var(--fg); text-decoration: none; }
.tagline { margin: 0.25rem 0 0; color: var(--muted); }

nav {
  background: var(--bg-soft);
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1rem;
}
nav ul { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 0.35rem; }
nav a {
  display: inline-block;
  padding: 0.45rem 0.75rem;
  color: var(--accent);
  text-decoration: none;
  border: 2px solid transparent;
  border-radius: 4px;
}
nav a[aria-current="page"] { background: var(--accent); color: var(--accent-fg); font-weight: 600; }
nav a:hover { text-decoration: underline; }

.user-strip { margin: 0; font-size: 0.95rem; color: var(--muted); }
.user-strip strong { color: var(--fg); }

a:focus, button:focus, input:focus, select:focus, textarea:focus, [tabindex]:focus, summary:focus {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  box-shadow: 0 0 0 6px var(--focus-halo);
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--accent);
  color: var(--accent-fg);
  padding: 0.5rem 0.75rem;
  z-index: 100;
}
.skip-link:focus { left: 0.5rem; top: 0.5rem; }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* Browsers give [hidden] a display:none that any later rule can outrank by
   accident. The !important keeps hidden things genuinely out of the screen
   reader's reach. */
[hidden] { display: none !important; }

footer { border-top: 1px solid var(--border); color: var(--muted); font-size: 0.9rem; }

/* ---------- Blocks ---------- */

.card {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1rem 1.1rem;
  margin: 0.85rem 0;
}
.card > :first-child { margin-top: 0; }
.card > :last-child { margin-bottom: 0; }

.note { color: var(--muted); }
.error { color: var(--danger); font-weight: 600; }
.success { color: var(--ok); font-weight: 600; }
.status-line { margin: 0.5rem 0; min-height: 1.5em; }

/* ---------- Forms ---------- */

/* Every label sits on its own line above its control. A braille display shows
   the focused field's line, so a label sharing that line eats cells the person
   needs for their own text. */
.form-field { margin: 0.9rem 0; }
.form-field > label { display: block; margin-bottom: 0.25rem; font-weight: 600; }
.form-field > input[type="text"],
.form-field > input[type="password"],
.form-field > input[type="search"],
.form-field > input[type="number"],
.form-field > input[type="date"],
.form-field > input[type="url"],
.form-field > select,
.form-field > textarea {
  width: 100%;
  max-width: 46rem;
  padding: 0.5rem 0.6rem;
  font-size: 1rem;
  font-family: inherit;
  line-height: 1.5;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
}
.form-field > textarea { resize: vertical; min-height: 6rem; }
.form-field .field-hint { display: block; margin-top: 0.2rem; color: var(--muted); font-size: 0.92rem; font-weight: 400; }

label.check-row { display: flex; gap: 0.5rem; align-items: flex-start; font-weight: 400; }
label.check-row input { margin-top: 0.3rem; width: 1.1rem; height: 1.1rem; flex: 0 0 auto; }

fieldset {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.5rem 0.9rem 0.9rem;
  margin: 1rem 0;
}
legend { font-weight: 600; padding: 0 0.3rem; }
label.radio-row { display: flex; gap: 0.5rem; align-items: center; margin: 0.3rem 0; font-weight: 400; }
label.radio-row input { width: 1.1rem; height: 1.1rem; flex: 0 0 auto; }

button, .button {
  font: inherit;
  padding: 0.5rem 0.9rem;
  border: 1px solid var(--accent);
  border-radius: 4px;
  background: var(--accent);
  color: var(--accent-fg);
  cursor: pointer;
}
button.secondary, .button.secondary { background: transparent; color: var(--accent); }
button.danger { background: transparent; color: var(--danger); border-color: var(--danger); }
button[disabled] { opacity: 0.55; cursor: not-allowed; }
.actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 1rem 0; }

/* ---------- Lists of items ---------- */

.item-list { list-style: none; padding: 0; margin: 0.5rem 0; }
.item-list > li {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.7rem 0.9rem;
  margin: 0.5rem 0;
  background: var(--bg-soft);
}
.item-list h3 { margin: 0 0 0.2rem; font-size: 1.05rem; }
.item-list h3 a { text-decoration: none; }
.item-list h3 a:hover { text-decoration: underline; }
.item-meta { margin: 0.15rem 0; color: var(--muted); font-size: 0.92rem; }
.item-snippet { margin: 0.3rem 0 0; }

.pill {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.85rem;
  background: var(--bg);
}

.stat-list { list-style: none; padding: 0; margin: 0.5rem 0; display: flex; flex-wrap: wrap; gap: 0.5rem 1.5rem; }
.stat-list strong { font-size: 1.3rem; display: block; }

dl.kv { margin: 0.5rem 0; }
dl.kv dt { font-weight: 600; margin-top: 0.6rem; }
dl.kv dd { margin: 0.1rem 0 0; }

.answer { white-space: pre-wrap; }

/* ---------- Meme maker ---------- */

.meme-preview {
  display: block;
  max-width: 100%;
  height: auto;
  border: 1px solid var(--border);
  border-radius: 4px;
  margin: 0.5rem 0;
  background: var(--bg-soft);
}
.meme-readback {
  border-left: 4px solid var(--accent);
  padding: 0.5rem 0 0.5rem 0.8rem;
  margin: 0.75rem 0;
}
.meme-readback p { margin: 0.25rem 0; }

.gallery { list-style: none; padding: 0; margin: 0.5rem 0; }
.gallery > li {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.8rem 0.9rem;
  margin: 0.6rem 0;
  background: var(--bg-soft);
}
.gallery img { max-width: min(100%, 22rem); height: auto; display: block; margin: 0.4rem 0; border: 1px solid var(--border); }

/* ---------- Misc ---------- */

.busy { color: var(--muted); font-style: italic; }
.tag-links { list-style: none; padding: 0; margin: 0.3rem 0; display: flex; flex-wrap: wrap; gap: 0.4rem; }
.tag-links a { text-decoration: none; }
.chooser { display: flex; flex-wrap: wrap; gap: 0.5rem 1rem; align-items: flex-end; }
.chooser .form-field { margin: 0.4rem 0; }
.offline-note { border: 2px solid var(--danger); border-radius: 6px; padding: 0.6rem 0.9rem; margin: 0.75rem 0; }
