/* ==========================================================================
   Kirjakerho — calm, editorial, warm. One accent, three text tones, and
   everything sized from a scale. Dark-first but light-mode correct.

   Contrast: every text/background pairing below is >= WCAG 2.2 AA (4.5:1).
   Browser default link blue/purple is overridden globally — on the dark theme
   it measures ~1.9:1.
   ========================================================================== */

:root {
  /* Type scale (1.25 major third), 17px base for comfortable long-form reading */
  --step--1: 0.875rem;
  --step-0:  1.0625rem;
  --step-1:  1.25rem;
  --step-2:  1.5rem;
  --step-3:  1.875rem;

  /* Spacing scale — every margin/padding comes from here */
  --s1: 0.25rem;
  --s2: 0.5rem;
  --s3: 0.75rem;
  --s4: 1rem;
  --s5: 1.5rem;
  --s6: 2rem;
  --s7: 3rem;

  --radius: 0.85rem;
  --radius-sm: 0.5rem;
  --pill: 999px;
  --measure: 44rem;

  /* Light theme */
  --bg: #f7f4ee;
  --surface: #ffffff;
  --text: #1f1c17;      /* ~16:1 */
  --muted: #5a544a;     /* ~7:1  */
  --border: #e4ddcf;
  --accent: #4f6343;    /* used as a fill */
  --link: #43563a;      /* ~7.5:1 */
  --on-accent: #ffffff;
  --shadow: 0 1px 2px rgba(31, 28, 23, .06), 0 6px 16px rgba(31, 28, 23, .05);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16140f;
    --surface: #201d17;   /* lifted off the bg so cards actually read as cards */
    --text: #f2ede3;      /* ~15:1 */
    --muted: #b8b0a2;     /* ~8.6:1 */
    --border: #38332a;
    --accent: #a8c090;
    --link: #b3ca9c;      /* ~9:1  */
    --on-accent: #14120d; /* dark ON the light accent — never white */
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 18px rgba(0, 0, 0, .3);
  }
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: var(--step-0)/1.65 "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.wrap { width: 100%; max-width: var(--measure); margin: 0 auto; padding: 0 var(--s4); }

/* Links: one colour, including :visited. Component classes below re-declare
   :visited where they paint their own colour — otherwise a:visited (0,1,1)
   silently outranks a bare class (0,1,0) and repaints the text. */
a { color: var(--link); text-underline-offset: 2px; text-decoration-thickness: 1px; }
a:visited { color: var(--link); }
a:hover { text-decoration-thickness: 2px; }

:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; border-radius: 2px; }

.skip-link {
  position: absolute; left: -999px;
  background: var(--accent); color: var(--on-accent);
  padding: var(--s2) var(--s4); border-radius: 0 0 var(--radius-sm) 0;
}
.skip-link:focus { left: 0; top: 0; z-index: 20; }

/* ── Header ─────────────────────────────────────────────────────────────── */
.site-header { background: var(--surface); border-bottom: 1px solid var(--border); }
.header-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--s4); padding: var(--s4) 0;
}
.brand { font-size: var(--step-1); font-weight: 700; letter-spacing: -0.01em; }
.header-actions { display: flex; align-items: center; gap: var(--s4); }
.header-actions a,
.header-actions a:visited,
.header-actions .linklike {
  color: var(--muted); text-decoration: none;
  font-size: var(--step--1); font-weight: 600;
}
.header-actions a:hover, .header-actions .linklike:hover {
  color: var(--text); text-decoration: underline;
}
.logout-form { margin: 0; }

/* ── Primary nav (top bar, all sizes) ───────────────────────────────────── */
.primary-nav { background: var(--surface); border-bottom: 1px solid var(--border); }
.nav-inner { display: flex; gap: var(--s1); }
.primary-nav a, .primary-nav a:visited {
  display: inline-flex; align-items: center; gap: var(--s2);
  padding: var(--s3) var(--s3) calc(var(--s3) - 2px);
  color: var(--muted); text-decoration: none;
  font-size: var(--step--1); font-weight: 600;
  border-bottom: 2px solid transparent;
}
.primary-nav a:hover { color: var(--text); }
.primary-nav a[aria-current="page"] { color: var(--text); border-bottom-color: var(--accent); }
.primary-nav a[aria-disabled="true"] { opacity: .45; pointer-events: none; }
/* Icons inherit currentColor so they can never render as coloured emoji. */
.nav-icon { display: inline-flex; }
.nav-icon svg { width: 1.1rem; height: 1.1rem; display: block; }

/* ── Typography ─────────────────────────────────────────────────────────── */
h1 { font-size: var(--step-3); line-height: 1.15; letter-spacing: -0.02em; margin: var(--s6) 0 var(--s3); }
h2 { font-size: var(--step-1); line-height: 1.3; margin: 0 0 var(--s2); }
p { margin: var(--s3) 0; }
p:last-child { margin-bottom: 0; }
.muted { color: var(--muted); }
.small { font-size: var(--step--1); }  /* floor — smaller text stops being readable */
.error { color: #b3261e; }
@media (prefers-color-scheme: dark) { .error { color: #f2b8b5; } }

/* ── Cards ──────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: var(--s5);
  margin: var(--s4) 0; box-shadow: var(--shadow);
}
.card-title { font-size: var(--step-0); font-weight: 700; margin: 0 0 var(--s2); }
.empty-state p { margin: var(--s2) 0; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s3); }

.messages { list-style: none; padding: 0; margin: 0 0 var(--s4); }
.messages li {
  padding: var(--s3) var(--s4); border-radius: var(--radius-sm);
  background: var(--surface); border: 1px solid var(--border); margin-bottom: var(--s2);
}

/* ── Secondary nav (tabs) ───────────────────────────────────────────────── */
.subnav {
  display: flex; gap: var(--s5); margin: 0 0 var(--s5);
  border-bottom: 1px solid var(--border);
}
.subnav a, .subnav a:visited {
  padding: var(--s2) 0; margin-bottom: -1px;
  color: var(--muted); text-decoration: none;
  font-size: var(--step--1); font-weight: 600;
  border-bottom: 2px solid transparent;
}
.subnav a:hover { color: var(--text); }
.subnav a[aria-current="page"] { color: var(--text); border-bottom-color: var(--accent); }

/* ── Buttons ────────────────────────────────────────────────────────────── */
/* :visited is declared explicitly — without it a:visited repaints the label
   in the accent colour, on the accent background. Invisible text. */
.btn, .btn:visited {
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--accent); color: var(--on-accent);
  text-decoration: none; border: none; border-radius: var(--radius-sm);
  padding: var(--s3) var(--s5); cursor: pointer;
  font: inherit; font-size: var(--step--1); font-weight: 700; letter-spacing: .01em;
}
.btn:hover { filter: brightness(1.08); }
.btn.danger, .btn.danger:visited { background: #a3231b; color: #fff; }
@media (prefers-color-scheme: dark) { .btn.danger, .btn.danger:visited { background: #d4685f; color: #14120d; } }

.linklike {
  background: none; border: none; color: var(--link); cursor: pointer;
  font: inherit; font-size: var(--step--1); padding: 0;
  text-decoration: underline; text-underline-offset: 2px;
}
.linklike:hover { text-decoration-thickness: 2px; }

/* ── Forms ──────────────────────────────────────────────────────────────── */
.stack { display: flex; flex-direction: column; gap: var(--s4); }
.stack label { display: flex; flex-direction: column; gap: var(--s1); }
.stack label > span:first-child { font-size: var(--step--1); font-weight: 600; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: var(--s2); }
label.check > span:first-child { order: 2; }

input[type="text"], input[type="password"], input[type="email"], input[type="url"],
input[type="search"], input[type="date"], input[type="datetime-local"], textarea, select {
  width: 100%; padding: var(--s3); font: inherit; font-size: var(--step-0);
  color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
}
textarea { resize: vertical; }

/* ── Badges / pills ─────────────────────────────────────────────────────── */
.badge {
  display: inline-block; flex: 0 0 auto; white-space: nowrap;  /* never wrap into a lozenge */
  font-size: 0.7rem; text-transform: uppercase; letter-spacing: .06em; font-weight: 700;
  padding: .18rem .5rem; border-radius: var(--pill);
  border: 1px solid var(--border); color: var(--muted);
}
.badge.shared { color: var(--link); border-color: var(--accent); }
.badges { display: inline-flex; flex-wrap: wrap; gap: var(--s1); }
.danger-link, .danger-link:visited { color: #a3231b; }
@media (prefers-color-scheme: dark) { .danger-link, .danger-link:visited { color: #e8918a; } }
.member-card .card-title a { text-decoration: none; }
.member-card .card-title a:hover { text-decoration: underline; }

/* ── Book covers ────────────────────────────────────────────────────────── */
.cover, .cover-placeholder {
  flex: 0 0 auto; width: 4rem; height: 6rem;
  border-radius: var(--radius-sm); box-shadow: var(--shadow);
}
.cover { object-fit: cover; background: var(--border); }
.cover-placeholder {
  display: flex; align-items: center; justify-content: center;
  background: var(--accent); color: var(--on-accent);
  font-size: var(--step-2); font-weight: 700;
}

/* ── Active book card ───────────────────────────────────────────────────── */
.book-card { display: flex; gap: var(--s4); align-items: center; }
.book-meta { min-width: 0; }
.book-title { font-size: var(--step-1); line-height: 1.25; margin: 0 0 var(--s1); }

/* ── One-tap controls (reading status, RSVP, preferences) ───────────────── */
.status-control { display: flex; flex-wrap: wrap; gap: var(--s2); }
.status-btn {
  cursor: pointer; font: inherit; font-size: var(--step--1); font-weight: 600;
  padding: var(--s2) var(--s4); border-radius: var(--pill);
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
}
.status-btn:hover { border-color: var(--accent); }
.status-btn.is-current {
  background: var(--accent); color: var(--on-accent);
  border-color: var(--accent); font-weight: 700;
}

/* ── Lists (members, history, plan, summary) ────────────────────────────── */
.member-list, .history, .option-list { list-style: none; margin: 0; padding: 0; }
.member-list li, .history li {
  display: flex; align-items: center; gap: var(--s2);
  padding: var(--s3) 0; border-bottom: 1px solid var(--border);
}
.member-list li:last-child, .history li:last-child { border-bottom: none; }
.member-name { flex: 1; }
.history li > span:first-child { flex: 1; }

.plan { margin: 0; padding-left: 1.1rem; }
.plan li { padding: var(--s1) 0; }
.plan li.is-current { font-weight: 700; }

.summary { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: var(--s2) var(--s5); }
.summary .count { font-weight: 700; color: var(--link); }

.row-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s4); margin-top: var(--s3); }
.inline-form { display: inline; margin: 0; }
.spaced-top { margin-top: var(--s3); }

.handover { display: grid; grid-template-columns: auto 1fr; gap: var(--s1) var(--s4); margin: var(--s4) 0; }
.handover dt { color: var(--muted); font-size: var(--step--1); }
.handover dd { margin: 0; }
.handover code {
  font-size: var(--step-0); background: var(--bg); padding: .1rem .4rem;
  border-radius: var(--radius-sm); border: 1px solid var(--border);
}

/* ── Meetings ───────────────────────────────────────────────────────────── */
.option, .option-list li {
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: var(--s3) var(--s4); margin: 0 0 var(--s3);
}
.option.best, .option-list li.best { border-color: var(--accent); }
.option legend { padding: 0 var(--s1); font-weight: 600; }
.radio { display: inline-flex; align-items: center; gap: var(--s1); margin-right: var(--s4); font-size: var(--step--1); }
.meeting-when { font-size: var(--step-1); }

/* ── Meeting prep + spoilers ────────────────────────────────────────────── */
.prep-item { padding: var(--s4) 0; border-bottom: 1px solid var(--border); }
.prep-item:last-child { border-bottom: none; padding-bottom: 0; }
.prep-item.hidden-item { opacity: .6; }
.spoiler {
  background: var(--bg); border: 1px dashed var(--border);
  border-radius: var(--radius-sm); padding: var(--s3) var(--s4);
}
.spoiler summary { cursor: pointer; color: var(--muted); font-size: var(--step--1); font-weight: 600; }
.spoiler[open] summary { margin-bottom: var(--s2); }

/* ── Reading list ───────────────────────────────────────────────────────── */
/* Cover sits on the right and stretches to the full height of the card, so tall
   and short cards both look intentional. */
.suggestion-body { display: flex; gap: var(--s5); align-items: stretch; }
.suggestion-meta { min-width: 0; flex: 1; }
.cover-side {
  width: 7rem; align-self: stretch; height: auto;
  object-fit: cover; object-position: center top;
}
.cover-placeholder.cover-side { min-height: 9rem; }
.suggestion .prefs { display: flex; flex-wrap: wrap; gap: var(--s1) var(--s5); margin: var(--s3) 0; }
.facts { display: flex; flex-wrap: wrap; gap: var(--s1) var(--s4); }

@media (max-width: 34rem) {
  .cover-side { width: 4.5rem; }
  .suggestion-body { gap: var(--s4); }
}

/* ── Archive ────────────────────────────────────────────────────────────── */
.archive-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(13rem, 1fr)); gap: var(--s4); }
.archive-card, .archive-card:visited {
  display: flex; gap: var(--s3); align-items: center;
  text-decoration: none; color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: var(--s3); background: var(--surface); box-shadow: var(--shadow);
}
.archive-card:hover { border-color: var(--accent); }
.archive-card .cover, .archive-card .cover-placeholder { width: 3rem; height: 4.5rem; font-size: var(--step-1); }

/* ── Notifications ──────────────────────────────────────────────────────── */
.note { padding: var(--s3) 0; border-bottom: 1px solid var(--border); }
.note:last-child { border-bottom: none; }
.note.unread { font-weight: 700; }

/* ── 2FA QR ─────────────────────────────────────────────────────────────── */
.qr { width: 200px; max-width: 60vw; margin: var(--s4) 0; }
.qr svg { width: 100%; height: auto; background: #fff; padding: var(--s2); border-radius: var(--radius-sm); }

.whatsapp { text-align: center; margin: var(--s5) 0; }

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