/* Family book club: one stylesheet, "Sticker Book" design (PLAN.md §7).
   Phone first (designed at 390 px), one column up to 520 px, light only. */

/* ------------------------------------------------------------ font (self-hosted, OFL: /fonts/OFL.txt) */

@font-face {
  font-family: "Bricolage Grotesque";
  font-style: normal;
  font-weight: 200 800;
  font-display: swap;
  src: url("/fonts/bricolage-grotesque-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308,
    U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113,
    U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Bricolage Grotesque";
  font-style: normal;
  font-weight: 200 800;
  font-display: swap;
  src: url("/fonts/bricolage-grotesque-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304,
    U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* ------------------------------------------------------------ tokens */

:root {
  --bg: #ffffff;
  --ink: #111111;
  --muted: #555555;
  --soft: #efefef;
  --primary: #ffe14d;
  --danger: #d92d20;
  /* Each reader's own colour; set per element through the CSSOM. Yellow as a neutral default. */
  --me: var(--primary);

  --shadow: 4px 4px 0 var(--ink);
  --shadow-s: 3px 3px 0 var(--ink);
  --shadow-pressed: 2px 2px 0 var(--ink);
  --line: 2px solid var(--ink);

  --font: "Bricolage Grotesque", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue",
    "Noto Sans", "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", Meiryo,
    "PingFang SC", "Microsoft YaHei", "Noto Sans CJK JP", "Noto Sans CJK SC", sans-serif;
  --pad: 20px;
  --tabbar-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);

  color-scheme: light;
}

/* ------------------------------------------------------------ base */

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  background: var(--bg);
}
/* Keep the page still behind an open sheet. */
html:has(dialog[open]) { overflow: hidden; }

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  font-weight: 500;
  line-height: 1.35;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3, p, ul, dl, dd, fieldset { margin: 0; padding: 0; }
ul[role="list"] { list-style: none; }
fieldset { border: 0; min-width: 0; }
legend { padding: 0; }
img { display: block; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--ink); }

:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: 3px;
}
/* Headings and <main> get focus from script only, to guide screen readers. */
[tabindex="-1"]:focus { outline: none; }

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

.skip-link {
  position: absolute;
  left: 16px; top: -100px;
  z-index: 20;
  padding: 10px 18px;
  border: var(--line);
  border-radius: 999px;
  background: var(--primary);
  font-weight: 800;
  text-decoration: none;
}
.skip-link:focus { top: calc(8px + var(--safe-t)); }

.noscript { padding: 24px var(--pad); text-align: center; }

.muted { color: var(--muted); }
.small { font-size: 14px; font-weight: 600; }

/* ------------------------------------------------------------ layout */

.screen {
  max-width: 520px;
  margin: 0 auto;
  padding: calc(26px + var(--safe-t)) max(var(--pad), env(safe-area-inset-right, 0px))
    calc(var(--tabbar-h) + 16px + var(--safe-b) + 40px) max(var(--pad), env(safe-area-inset-left, 0px));
}
.screen:focus { outline: none; }
/* Profile and Me open with a full-bleed header in the reader's colour. */
.screen-hero { padding-top: 0; }
.screen-hero > .back-btn:first-child { margin-top: calc(20px + var(--safe-t)); margin-bottom: 16px; }

.screen-title {
  font-size: 48px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.02em;
  overflow-wrap: anywhere;
}
.screen-head { margin-bottom: 22px; }
.screen-sub { margin-top: 6px; font-size: 14px; font-weight: 700; }

.section { margin-top: 34px; }
.section-title {
  font-size: 24px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.01em;
  margin-bottom: 14px;
}

.lead { margin-top: 10px; color: var(--muted); }
.lead-tight { margin: 0; }
.stack { display: grid; gap: 22px; margin-top: 28px; }

.cards { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }

.empty {
  padding: 18px;
  border: 2px dashed var(--ink);
  border-radius: 24px;
  font-weight: 600;
}
.empty .btn { margin-top: 14px; }

.note { font-size: 13px; font-weight: 600; color: var(--muted); }
.note:empty { display: none; }
.note-center { text-align: center; }
.note-warn {
  padding: 12px 14px;
  border: 2px solid var(--danger);
  border-radius: 14px;
  color: var(--ink);
  font-size: 15px;
}
.section > .btn-block, .section > .note { margin-top: 14px; }

/* ------------------------------------------------------------ icons */

.icon {
  width: 20px; height: 20px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.icon-plus { color: var(--primary); stroke-width: 3.2; }

/* ------------------------------------------------------------ buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 48px;
  padding: 0 22px;
  border: var(--line);
  border-radius: 999px;
  background: var(--bg);
  color: var(--ink);
  font-size: 17px;
  font-weight: 800;
  line-height: 1.1;
  text-align: center;
  text-decoration: none;
  touch-action: manipulation;
}
.btn:disabled { opacity: .5; cursor: default; }
.btn-block { display: flex; width: 100%; }
.btn-sm { min-height: 44px; padding: 0 16px; font-size: 15px; }
.btn-lg { min-height: 60px; font-size: 20px; }
.btn-xl { min-height: 60px; font-size: 19px; }

/* The main action on a screen: black pill with a yellow plus. */
.btn-ink { background: var(--ink); color: #fff; }
.btn-ink:active:not(:disabled) { background: #2a2a2a; }

/* The main action in a form: a raised yellow pill. */
.btn-primary { background: var(--primary); box-shadow: var(--shadow); }

.btn-outline:active:not(:disabled) { background: var(--soft); }

/* Destructive actions are outlined in red, never filled. */
.btn-danger,
.btn-primary.btn-danger {
  background: var(--bg);
  border-color: var(--danger);
  color: var(--danger);
  box-shadow: none;
}

/* Raised things sink 2 px and lose half their shadow when pressed. */
.btn-primary:not(.btn-danger):active:not(:disabled),
.round-btn:not(.round-btn-flat):active,
.member-card.is-read:active,
.tile[aria-pressed="true"]:active {
  transform: translate(2px, 2px);
  box-shadow: var(--shadow-pressed);
}

.round-btn {
  display: inline-grid;
  place-items: center;
  width: 44px; height: 44px;
  flex: none;
  padding: 0;
  border: var(--line);
  border-radius: 50%;
  background: var(--bg);
  color: var(--ink);
  box-shadow: var(--shadow-s);
  text-decoration: none;
}
.round-btn .icon { width: 18px; height: 18px; }
.round-btn:disabled { opacity: .5; }
.round-btn-flat { box-shadow: none; }
.round-btn-flat:active { background: var(--soft); }
.round-btn-danger { border-color: var(--danger); color: var(--danger); }

.pill-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 16px 0 10px;
  border: var(--line);
  border-radius: 999px;
  background: var(--bg);
  font-size: 15px;
  font-weight: 800;
  justify-self: start;
}
.pill-back .icon { width: 18px; height: 18px; }
.pill-back:active { background: var(--soft); }

/* ------------------------------------------------------------ tab bar: floating black pill */

.tabbar {
  position: fixed;
  left: 0; right: 0;
  bottom: calc(16px + var(--safe-b));
  z-index: 10;
  width: calc(min(100%, 520px) - 2 * var(--pad));
  margin: 0 auto;
}
.tabbar-list {
  display: flex;
  height: var(--tabbar-h);
  padding: 7px;
  border-radius: 32px;
  background: var(--ink);
  list-style: none;
}
.tabbar-list li { flex: 1; display: flex; }
.tab {
  flex: 1;
  display: grid;
  place-items: center;
  border-radius: 25px;
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  text-decoration: none;
}
.tab[aria-current="page"] { background: var(--primary); color: var(--ink); font-weight: 800; }
.tab:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }

/* ------------------------------------------------------------ avatars and covers */

.avatar {
  flex: none;
  border: var(--line);
  border-radius: 50%;
  object-fit: cover;
  background: var(--soft);
}
.avatar-xs { width: 26px; height: 26px; border-width: 1.5px; }
.avatar-s { width: 32px; height: 32px; }
.avatar-m { width: 44px; height: 44px; }
.avatar-l { width: 56px; height: 56px; }
.avatar-xl { width: 84px; height: 84px; box-shadow: var(--shadow); }
.avatar-xxl { width: 112px; height: 112px; box-shadow: var(--shadow); }
.avatar-missing { display: inline-grid; place-items: center; font-weight: 800; }

.cover {
  flex: none;
  border: var(--line);
  border-radius: 6px;
  object-fit: cover;
  background: var(--soft);
}
.cover-xs { width: 34px; height: 48px; font-size: 18px; }
.cover-s { width: 40px; height: 58px; font-size: 20px; }
.cover-m { width: 52px; height: 74px; font-size: 26px; border-radius: 8px; }
.cover-l { width: 96px; height: 140px; font-size: 44px; border-radius: 10px; }
/* Letter tile; --h (hue) comes from the title. Light enough for ink on top. */
.cover-tile {
  display: inline-grid;
  place-items: center;
  background: hsl(var(--h, 50) 85% 74%);
  color: var(--ink);
  font-weight: 800;
  line-height: 1;
  user-select: none;
}

/* Progress bar, filled in the reader's colour. Width from --p. */
.progress { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.bar {
  flex: 1;
  height: 14px;
  border: var(--line);
  border-radius: 999px;
  background: var(--bg);
  overflow: hidden;
}
.bar-fill { display: block; height: 100%; width: var(--p, 0%); background: var(--me); border-right: var(--line); }
.progress-label { font-size: 12px; font-weight: 700; white-space: nowrap; font-variant-numeric: tabular-nums; }
p.progress-label { margin-top: 6px; }

/* Big outlined numbers. The font is a variable font whose glyphs are built from overlapping
   shapes, so a plain text stroke also draws the hidden joins inside each digit (a line across
   the 8, the 4, the 1). Painting the stroke first and the fill on top hides them; only the
   outer half of the stroke shows, so the widths here are twice the visible outline.
   The hard shadow is a drop-shadow filter, not text-shadow: with the stroke painted first,
   browsers draw a text-shadow between the stroke and the fill, on top of the outline. */
.big-num {
  display: block;
  font-size: 52px;
  font-weight: 800;
  line-height: .9;
  letter-spacing: 0.03em; /* the outline now sits wholly outside each digit, so they need air */
  color: #fff;
  -webkit-text-stroke: 4px var(--ink);
  paint-order: stroke fill;
  filter: drop-shadow(3px 3px 0 var(--ink));
}
.big-num-xl {
  font-size: 104px;
  -webkit-text-stroke-width: 6px;
  filter: drop-shadow(5px 5px 0 var(--ink));
  letter-spacing: 0.02em;
}

.book-text { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.book-title { font-size: 17px; font-weight: 800; line-height: 1.15; overflow-wrap: anywhere; }
.book-meta { font-size: 13px; font-weight: 600; color: var(--muted); overflow-wrap: anywhere; }

/* ------------------------------------------------------------ Family */

.family-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.week-sticker {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 14px;
  border: var(--line);
  border-radius: 16px;
  background: var(--primary);
  box-shadow: var(--shadow-s);
  transform: rotate(4deg);
  text-align: center;
}
.week-num { font-size: 20px; font-weight: 800; line-height: 1; white-space: nowrap; }
.week-label { margin-top: 2px; font-size: 12px; font-weight: 600; }

.family-head + .btn { margin-top: 22px; }
.member-cards { margin-top: 22px; }

.member-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px;
  border: var(--line);
  border-radius: 24px;
  color: var(--ink);
  text-decoration: none;
}
.member-card.is-read { background: var(--me); box-shadow: var(--shadow); }
.member-card.is-not { background: var(--bg); border-style: dashed; }
.member-card.is-not:active { background: var(--soft); }
.member-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
}
.member-name { font-size: 22px; font-weight: 800; line-height: 1; overflow-wrap: anywhere; }
.member-book {
  max-width: 100%;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.streak-chip {
  padding: 3px 10px;
  border: 1.5px solid var(--ink);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}
.is-read .streak-chip { background: var(--ink); color: #fff; }
.member-today { flex: none; text-align: right; }
.big-label { display: block; margin-top: 6px; font-size: 12px; font-weight: 700; }
.notyet-chip {
  flex: none;
  padding: 8px 12px;
  border: var(--line);
  border-radius: 14px;
  background: var(--me);
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}

/* ------------------------------------------------------------ Books */

.screen-head + .btn { margin-bottom: 22px; }
.book-row {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 14px;
  align-items: start;
  padding: 14px;
  border: var(--line);
  border-radius: 24px;
}
.readers { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.reader {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  padding: 2px 10px 2px 2px;
  border: var(--line);
  border-radius: 999px;
  font-size: 13px;
  font-weight: 800;
}
.reader-now { background: var(--me); }
.reader-done { background: var(--bg); }
.reader-status { font-weight: 500; }
.reader-status::before { content: "· "; }

/* ------------------------------------------------------------ Profile and Me */

.hero {
  margin: 0 calc(-1 * var(--pad));
  padding: calc(20px + var(--safe-t)) var(--pad) 50px;
  background: var(--me);
  border-bottom: var(--line);
}
.hero-who { display: flex; align-items: center; gap: 16px; }
.back-btn + .hero-who { margin-top: 12px; }
.hero-name { min-width: 0; display: flex; flex-direction: column; align-items: flex-start; }
.hero-name .screen-title { font-size: clamp(34px, 11vw, 48px); }
.hero-sub { margin-top: 4px; font-size: 14px; font-weight: 700; overflow-wrap: anywhere; }
.hero-btn { margin-top: 10px; }
.hero-streak { display: flex; align-items: baseline; gap: 12px; margin-top: 16px; }
.hero-streak-label { font-size: 22px; font-weight: 800; line-height: 1.05; }

/* On wide screens the header is a block of its own. */
@media (min-width: 521px) {
  .hero { border: var(--line); border-top: 0; border-radius: 0 0 28px 28px; }
}

/* Three stat stickers overlapping the header. */
.stickers {
  position: relative;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: -30px;
}
.stat-sticker {
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 12px 10px 12px 12px;
  border: var(--line);
  border-radius: 18px;
  background: var(--bg);
  box-shadow: var(--shadow);
}
.sticker-label { font-size: 12px; font-weight: 700; }
.sticker-num {
  margin-top: 2px;
  font-size: clamp(17px, 5.6vw, 24px);
  font-weight: 800;
  line-height: 1.05;
  letter-spacing: -0.02em;
  white-space: nowrap;
}
.me-action { margin-top: 24px; }

.book-card { padding: 16px; border: var(--line); border-radius: 24px; }
.book-card-main { display: grid; grid-template-columns: auto 1fr; gap: 14px; align-items: start; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.actions .btn-danger { margin-left: auto; }

/* Calendar: weeks across, Monday to Sunday down, in strengths of the reader's colour. */
.calendar { padding: 16px; border: var(--line); border-radius: 24px; }
.cal-grid {
  display: grid;
  grid-auto-flow: column;
  grid-template-rows: repeat(7, auto);
  grid-template-columns: auto;
  grid-auto-columns: minmax(0, 1fr);
  gap: 6px;
  align-items: center;
}
.cal-day { padding-right: 4px; font-size: 12px; font-weight: 700; line-height: 1; }
.cal-cell {
  display: block;
  aspect-ratio: 1;
  border-radius: 10px;
  background: var(--soft);
}
/* Strength runs from a clear tint, through the reader's colour, to its richer partner.
   Nothing is mixed with black or grey, so busy days get brighter, not duller. */
.cal-cell[data-level="1"], .cal-key[data-level="1"] { background: color-mix(in srgb, var(--me) 45%, #fff); }
.cal-cell[data-level="2"], .cal-key[data-level="2"] { background: var(--me); }
.cal-cell[data-level="3"], .cal-key[data-level="3"] { background: color-mix(in srgb, var(--me) 45%, var(--me-deep, var(--me))); }
.cal-cell[data-level="4"], .cal-key[data-level="4"] { background: var(--me-deep, var(--me)); }
.cal-today { border: var(--line); box-shadow: 2px 2px 0 var(--ink); }
.cal-future { background: transparent; border: 2px dashed #cfcfcf; }
.cal-picked { outline: 2px solid var(--ink); outline-offset: 2px; }
.cal-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  margin-top: 14px;
  font-size: 12px;
  font-weight: 700;
}
.cal-key { width: 16px; height: 16px; border-radius: 6px; }
.cal-caption { margin-top: 8px; font-size: 13px; font-weight: 600; color: var(--muted); }

/* Finished shelf: covers as tilted stickers. */
.shelf { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px 14px; }
.shelf-item { display: flex; align-items: center; gap: 12px; min-width: 0; }
.shelf-item .cover { box-shadow: var(--shadow-s); transform: rotate(-4deg); }
.shelf-item:nth-child(even) .cover { transform: rotate(3deg); }
.shelf-item .book-title { font-size: 16px; }
.shelf-item .book-meta { font-size: 12px; color: var(--ink); }

.stat-list { padding: 0 18px; border: var(--line); border-radius: 24px; }
.stat {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 16px;
  padding: 14px 0;
}
.stat + .stat { border-top: 2px solid var(--soft); }
.stat dt { font-size: 15px; font-weight: 600; }
.stat dd { font-size: 17px; font-weight: 800; text-align: right; font-variant-numeric: tabular-nums; }

.log-list { padding: 0 10px 0 16px; border: var(--line); border-radius: 24px; }
.log-item { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 0; }
.log-item + .log-item { border-top: 2px solid var(--soft); }
.log-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.log-main { display: flex; align-items: baseline; flex-wrap: wrap; gap: 0 8px; }
.log-main strong { font-size: 20px; font-weight: 800; }
.log-day { font-size: 15px; font-weight: 700; }
.log-actions { display: flex; gap: 8px; flex: none; }

.device-list { display: grid; gap: 10px; }
.device-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  width: 100%;
  min-height: 60px;
  padding: 12px 18px;
  border: var(--line);
  border-radius: 18px;
  background: var(--bg);
  text-align: left;
}
.device-btn:active { background: var(--soft); }
.device-title { font-size: 17px; font-weight: 800; }
.device-sub { font-size: 13px; font-weight: 600; color: var(--muted); }
.device-danger { border-color: var(--danger); }
.device-danger .device-title { color: var(--danger); }

/* ------------------------------------------------------------ gate (lock, picker, I'm new) */

.gate {
  min-height: 100dvh;
  display: flex;
  padding: calc(28px + var(--safe-t)) var(--pad) calc(28px + var(--safe-b));
}
.gate-inner { width: 100%; max-width: 440px; margin: auto; }
.gate-top .gate-inner { margin-top: 12px; }
.gate-mark {
  display: grid;
  place-items: center;
  width: 64px; height: 64px;
  margin-bottom: 24px;
  border: var(--line);
  border-radius: 18px;
  background: var(--primary);
  box-shadow: var(--shadow);
  transform: rotate(-4deg);
}
.gate-mark .icon { width: 32px; height: 32px; }
.gate .pill-back { margin-bottom: 18px; }

.picker {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-top: 28px;
}
.picker-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 100%;
  height: 100%;
  padding: 18px 10px 16px;
  border: var(--line);
  border-radius: 24px;
  background: var(--me);
}
.picker-item:active { background: color-mix(in srgb, var(--me) 85%, #000); }
.picker-item .avatar { width: 88px; height: 88px; background: var(--bg); }
.picker-name {
  max-width: 100%;
  font-size: 22px;
  font-weight: 800;
  line-height: 1.05;
  text-align: center;
  overflow-wrap: anywhere;
}
.picker-new { background: var(--bg); border-style: dashed; }
.picker-new:active { background: var(--soft); }
.picker-plus {
  display: grid;
  place-items: center;
  width: 88px; height: 88px;
  border: var(--line);
  border-radius: 50%;
  background: var(--primary);
}
.picker-plus .icon { width: 36px; height: 36px; stroke-width: 3.2; }

/* Big preview of the chosen picture (I'm new, change picture). */
.new-preview, .avatar-preview-row { display: flex; align-items: center; gap: 18px; }
.preview-avatar { flex: none; display: block; }
.preview-text { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.preview-name { font-size: 22px; font-weight: 800; line-height: 1.05; overflow-wrap: anywhere; }
.preview-label { font-size: 14px; font-weight: 700; color: var(--muted); }

/* The submit button stays reachable below a long avatar list. */
.sticky-submit {
  position: sticky;
  bottom: calc(16px + var(--safe-b));
  z-index: 2;
  display: grid;
  gap: 8px;
}
.sticky-submit .form-error { padding: 8px 12px; border-radius: 12px; background: var(--bg); margin: 0; }

/* Avatar picker: two labelled groups, selected one raised on yellow. */
.avatar-sets { display: grid; gap: 6px; }
.avatar-set-label {
  position: sticky;
  top: 0;
  z-index: 1;
  margin-top: 10px;
  padding: 8px 0;
  background: var(--bg);
  /* Covers the scroller's top padding, so avatars don't peek out above the stuck label. */
  box-shadow: 0 -16px 0 0 var(--bg);
  font-size: 14px;
  font-weight: 800;
}
.avatar-set-label:first-child { margin-top: 0; }
.avatar-set-count { color: var(--muted); font-weight: 600; }
.avatar-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(58px, 1fr));
  gap: 10px;
  margin-top: 4px;
}
.avatar-choice {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  padding: 4px;
  border: 2px solid transparent;
  border-radius: 50%;
  cursor: pointer;
}
.avatar-choice .avatar { width: 100%; height: auto; aspect-ratio: 1; }
.avatar-choice:active { background: var(--soft); }
.avatar-choice:has(input:checked) { background: var(--primary); border-color: var(--ink); box-shadow: var(--shadow-s); }
.avatar-choice:has(input:focus-visible) { outline: 3px solid var(--ink); outline-offset: 3px; }

/* ------------------------------------------------------------ forms */

.field { display: grid; gap: 8px; min-width: 0; }
.label { font-size: 14px; font-weight: 800; }
.label-optional { font-weight: 600; color: var(--muted); }
.hint { font-size: 13px; font-weight: 500; color: var(--muted); }
.field-error, .form-error { font-size: 14px; font-weight: 700; color: var(--danger); }
.form-error { margin-bottom: 12px; }
.static-value { font-size: 17px; font-weight: 800; }

.input {
  width: 100%;
  min-height: 52px;
  padding: 0 16px;
  border: var(--line);
  border-radius: 14px;
  background: var(--bg);
  font-size: 17px; /* ≥ 16 px so iOS doesn't zoom */
  font-weight: 600;
  appearance: none;
}
.input:focus { outline: 3px solid var(--ink); outline-offset: 2px; }
.input[aria-invalid="true"] { border-color: var(--danger); }
.input::placeholder { color: var(--muted); opacity: .75; font-weight: 500; }
.input-center { text-align: center; }
.input-lg { min-height: 60px; font-size: 20px; font-weight: 700; }

.search { position: relative; }
.search-icon { position: absolute; left: 16px; top: 50%; margin-top: -10px; pointer-events: none; }
.input-search { min-height: 56px; padding-left: 48px; }
.input-search::-webkit-search-decoration { appearance: none; }
.input-search::-webkit-search-cancel-button {
  appearance: none;
  width: 22px; height: 22px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Ccircle cx='12' cy='12' r='10' fill='%23111111'/%3E%3Cpath d='M8.5 8.5l7 7M15.5 8.5l-7 7' stroke='%23ffffff' stroke-width='2.6' stroke-linecap='round'/%3E%3C/svg%3E") center / 22px no-repeat;
  cursor: pointer;
}

/* "I finished the book". */
.check {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  font-size: 16px;
  font-weight: 800;
  cursor: pointer;
}
.check[hidden] { display: none; }
.check-input { position: absolute; opacity: 0; width: 26px; height: 26px; margin: 0; }
.check-box {
  display: grid;
  place-items: center;
  width: 28px; height: 28px;
  flex: none;
  border: var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: transparent;
}
.check-box .icon { width: 18px; height: 18px; stroke-width: 3.2; }
.check-input:checked + .check-box { background: var(--ink); color: #fff; }
.check-input:focus-visible + .check-box { outline: 3px solid var(--ink); outline-offset: 3px; }

/* ------------------------------------------------------------ log sheet */

.minutes-group { display: grid; gap: 14px; }
.big-minutes { display: flex; align-items: baseline; justify-content: center; gap: 10px; }
/* The minutes field drawn as a giant outlined number. Width follows the digits (--digits, set by
   sheets.mjs). A text field clips whatever is drawn outside its box, so the padding has to hold
   the outline on every side plus the coloured drop shadow on the right and bottom, and there is
   no negative letter-spacing (it would pull the box in under the last digit). */
.big-input {
  --size: clamp(112px, 38vw, 150px);
  width: calc(var(--digits, 1) * 0.66em + 0.24em);
  min-width: 0;
  height: 1.14em;
  padding: 0.03em 0.15em 0.09em 0.09em;
  border: 0;
  border-bottom: 3px solid transparent;
  background: transparent;
  font-size: var(--size);
  font-weight: 800;
  line-height: 1;
  letter-spacing: 0.05em;
  text-align: center;
  color: #fff;
  caret-color: var(--ink);
  -webkit-text-stroke: 6px var(--ink);
  paint-order: stroke fill;
  filter: drop-shadow(6px 6px 0 var(--me));
  border-radius: 0;
}
.big-minutes.is-long .big-input { --size: clamp(88px, 28vw, 118px); }
/* Where supported, size the field to its exact text instead of the digit estimate. */
@supports (field-sizing: content) {
  .big-input { field-sizing: content; width: auto; min-width: 0.9em; }
}
.big-input::placeholder { color: #fff; opacity: 1; }
.big-input:focus { outline: none; border-bottom-color: var(--ink); }
.big-input[aria-invalid="true"] { border-bottom-color: var(--danger); }
.big-unit { font-size: 24px; font-weight: 800; }
.minutes-group > .field-error { text-align: center; }

.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.tile {
  height: 62px;
  border: var(--line);
  border-radius: 18px;
  background: var(--bg);
  font-size: 24px;
  font-weight: 800;
  touch-action: manipulation;
}
.tile:active { background: var(--soft); }
.tile[aria-pressed="true"] { background: var(--primary); box-shadow: var(--shadow); }

.book-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(148px, 1fr)); gap: 10px; }
.book-tile {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  min-height: 72px;
  padding: 10px;
  border: var(--line);
  border-radius: 18px;
  background: var(--bg);
  cursor: pointer;
}
.book-tile.is-on, .book-tile:has(.tile-radio:checked) { background: var(--me); box-shadow: var(--shadow); }
.book-tile:has(.tile-radio:focus-visible) { outline: 3px solid var(--ink); outline-offset: 3px; }
.tile-radio { position: absolute; opacity: 0; width: 1px; height: 1px; margin: 0; pointer-events: none; }
.book-tile-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.book-tile-title {
  font-size: 16px;
  font-weight: 800;
  line-height: 1.1;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
}
.book-tile-meta { font-size: 12px; font-weight: 600; }

.stepper-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; }
.stepper { display: flex; align-items: center; gap: 8px; }
.step-btn {
  display: grid;
  place-items: center;
  width: 44px; height: 44px;
  padding: 0;
  border: var(--line);
  border-radius: 14px;
  background: var(--bg);
}
.step-btn:active { background: var(--soft); }
.step-btn .icon { width: 18px; height: 18px; }
.stepper-input {
  width: 76px; height: 44px;
  padding: 0 4px;
  border: var(--line);
  border-radius: 14px;
  background: var(--bg);
  font-size: 20px;
  font-weight: 800;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.stepper-input:focus { outline: 3px solid var(--ink); outline-offset: 2px; }
.stepper-input[aria-invalid="true"] { border-color: var(--danger); }

.day-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.day-more:not([hidden]) { display: contents; }
.day-chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 44px;
  min-width: 44px;
  padding: 0 16px;
  border: var(--line);
  border-radius: 22px;
  background: var(--bg);
  font-size: 15px;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
}
.day-chip:has(.tile-radio:checked) { background: var(--ink); color: #fff; font-weight: 800; }
.day-chip:has(.tile-radio:focus-visible) { outline: 3px solid var(--ink); outline-offset: 3px; }
.day-toggle { padding: 0 14px; font-weight: 800; }

/* ------------------------------------------------------------ bottom sheets */

/* On phones the sheet is pinned to the bottom edge. --kb is the height of the on-screen
   keyboard (iOS) and --vvh the visible height, both kept current by app.js. */
dialog.sheet {
  position: fixed;
  inset: auto 0 var(--kb, 0px) 0;
  width: 100%;
  max-width: 520px;
  max-height: calc(var(--vvh, 100dvh) - 16px - var(--safe-t));
  margin: 0 auto;
  padding: 0;
  border: var(--line);
  border-bottom: 0;
  border-radius: 28px 28px 0 0;
  background: var(--bg);
  color: var(--ink);
  overflow: hidden;
}
dialog.sheet[open] {
  display: flex;
  flex-direction: column;
  animation: sheet-up 200ms cubic-bezier(.2, .8, .2, 1);
}
dialog.sheet::backdrop { background: rgb(17 17 17 / .45); }
/* Search-style sheets keep one height while results come and go. */
dialog.sheet-tall { height: calc(var(--vvh, 100dvh) - 40px - var(--safe-t)); }

@keyframes sheet-up { from { transform: translateY(100%); } }
@keyframes sheet-in { from { transform: translateY(16px); opacity: 0; } }

.sheet-form { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.sheet-head {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 24px var(--pad) 4px;
  flex: none;
}
/* Grab handle. Decorative. */
.sheet-head::before {
  content: "";
  position: absolute;
  top: 8px; left: 50%;
  width: 40px; height: 5px;
  margin-left: -20px;
  border-radius: 3px;
  background: var(--ink);
}
.sheet-title {
  flex: 1;
  min-width: 0;
  font-size: 32px;
  font-weight: 800;
  line-height: 1.02;
  letter-spacing: -0.02em;
  overflow-wrap: anywhere;
}
.sheet-log .sheet-title { font-size: clamp(28px, 9vw, 36px); }
.sheet-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 14px var(--pad) 24px;
  display: grid;
  align-content: start;
  gap: 22px;
}
/* The primary button stays in view below the scrolling content, even with the keyboard up. */
.sheet-foot {
  flex: none;
  padding: 12px var(--pad) calc(16px + var(--safe-b));
  border-top: 2px solid var(--soft);
  background: var(--bg);
}
.sheet-foot[hidden] { display: none; }
.sheet-foot .btn { min-height: 64px; font-size: 21px; }
.sheet-foot .form-error { margin-bottom: 10px; }

/* Wide screens: a centred card instead of a bottom sheet. */
@media (min-width: 640px) and (min-height: 560px) {
  dialog.sheet {
    inset: 0;
    margin: auto;
    height: fit-content;
    max-height: min(780px, calc(100dvh - 64px));
    border-bottom: var(--line);
    border-radius: 28px;
    box-shadow: 8px 8px 0 var(--ink);
  }
  dialog.sheet[open] { animation-name: sheet-in; }
  dialog.sheet-tall { height: min(700px, calc(100dvh - 64px)); }
  .sheet-head::before { display: none; }
  .sheet-foot { padding-bottom: 18px; }
}

/* ------------------------------------------------------------ start a book */

.results { display: grid; gap: 14px; }
.group-title { font-size: 14px; font-weight: 800; margin-bottom: -4px; }
.result-list { display: grid; gap: 10px; }
.result {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto;
  column-gap: 12px;
  row-gap: 4px;
  align-items: center;
  width: 100%;
  min-height: 80px;
  padding: 10px 12px 10px 10px;
  border: var(--line);
  border-radius: 18px;
  background: var(--bg);
  text-align: left;
}
.result > .cover { grid-row: 1 / span 2; }
.result > .book-text { align-self: end; }
.result .book-title { font-size: 16px; }
.result-who { grid-column: 2; align-self: start; font-size: 12px; font-weight: 800; }
.result-who.result-muted { font-weight: 600; color: var(--muted); }
.result:active:not(:disabled) { background: var(--soft); }
.result:disabled { cursor: default; border-style: dashed; }
.result:disabled .cover { opacity: .6; }

.by-hand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding-top: 16px;
  border-top: 2px solid var(--soft);
  font-weight: 700;
}

.confirm-book { display: flex; gap: 16px; align-items: flex-start; }
.confirm-text { display: grid; gap: 4px; min-width: 0; }
.confirm-title { font-size: 26px; font-weight: 800; line-height: 1.05; overflow-wrap: anywhere; }
.confirm-text .muted { font-weight: 600; }

/* ------------------------------------------------------------ small screens and motion */

@media (max-width: 359px) {
  :root { --pad: 16px; }
  .screen-title { font-size: 44px; }
  .big-num { font-size: 44px; }
  .big-num-xl { font-size: 88px; }
  .member-card { gap: 10px; padding: 12px; }
  .stat-sticker { padding: 10px 8px; }
  .cal-grid { gap: 4px; }
  .cal-cell { border-radius: 7px; }
  .tiles { gap: 8px; }
  .day-chip { padding: 0 12px; }
  .picker-item .avatar, .picker-plus { width: 72px; height: 72px; }
  .avatar-grid { grid-template-columns: repeat(auto-fill, minmax(52px, 1fr)); gap: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .btn-primary:active, .round-btn:active, .member-card.is-read:active,
  .tile[aria-pressed="true"]:active { transform: none !important; }
}
