/* Den · project layer on the MEK design system
   A family's chat, first: the family's group and 1-to-1s, reactions, photos, replies, who's seen it; a parent can post
   a chore as a quiet card. Consumer work on the Slate app themes (slate-light, slate-dark only). Colour is meaning:
   the accent is the action, one a view (Send in a thread; the unread tags on the list); earned is --good. Linked last.

   Deviations (on purpose, lab stage; promote at two):
   - The page never scrolls: html overflow hidden, each view scrolls inside (scrollbar.css's opt-out for a page that
     fills the window, DESIGN.md "Scrollbar").
   - The box to write in is 44px (the chat part's --chat-press at --press-min), not the field's 34: a child's thumb.
   - A phone's sides are 12px (MEK: 8 to 12), not the page gutter's 16.
   - A chat's info sheet is no wider than the column.
   - Reactions have no frame (MEK): ink alone, mine the strongest.
   - Reading sizes of 18 and 15 (MEK), between Dosage's 12px steps and so smoothed: --den-say, --den-small.
   - Faces are pixel people (lib/portrait.js) or coloured patterns, in DawnBringer 32 as Anchorites' are: art, so their
     colours are the pictures' own; a 96 face on Me (.avatar.xl); the pattern colours are raw DB32 values here, as art.
   - People's names in a chat each have a softened palette colour (MEK): the status colours meaning a person here.
   - The + and Send are icon buttons at 44 (--press-min), not the system's 36: a thumb's. The list's search field is 44 too.
   - The thread is the system's chat part (2.46.0, board t74), on its dials: mine in the accent, the thread on the
     surface, theirs on the page's ground with the hover edge, Den's reading sizes and presses (1. Aliases).
   - A message's menu (reactions, commands, who read it) is the part's (mekChat.menu, board t97), fed from app.js.
   - Photos and quest cards as a message's body (a photo alone is bare), a message that didn't go with Try again, and
     "Seen by" are the part's too (2.55.0, board t94). Den's own on top: swipe to reply, people's names in their
     colours, a reaction chip's tip (ui/chat.js), and a quest card at the thread's full width (below).
   - The box to write in and its reply strip are the part's (.chat-compose), with Den's + (a photo, or a flyout of
     Photo and Quest) beside it and "Editing" in the strip while a message is changed. The list row and the head are
     still Den's own (the part's .chat-row and .chat-head are next).
   - The flyout's Photo and Quest cards draw the 15px icons at 4× (60px, the cards' picture size): there are no medium
     image and scroll icons yet (proposed to the system).
   - MEK chose common messenger looks over the system's defaults, on purpose: my bubbles in the accent (so a thread has
     more than one accent thing: Send and mine), with their ink the accent box's --100; faces as an initial on one of three
     neutral grounds (not identicons); a big "Chats" title with search; `undo` as Reply's mark (no reply icon yet).
   - A quest card's row drops the quests part's count column (a chore has no count), so its grid is restated, and its
     name is the body's 16 (the part's 14 is small for a child). Both want a dial in the part. */

/* ---------- 1. Aliases ----------
   The quests part's dials, so its colours keep the App theme's meanings: a done quest is a success, what it's worth
   is plain ink (not the action's colour). On every themed area, as the part declares them. */
:root, [data-theme] {
  --quest-done: var(--good);
  --quest-reward: var(--text-strong);
  /* The chat part's dials (MEK's choices, Deviations above): mine in the accent with the accent box's ink; the thread
     on the surface, a step off the page's ground, theirs on the page's own; Den's reading sizes; a thumb's presses. */
  --chat-mine-fill: var(--accent);
  --chat-mine-edge: var(--accent);
  --chat-mine-ink: var(--100);
  --chat-ground: var(--surface);
  --chat-theirs-fill: var(--bg);
  --chat-say: var(--den-say);
  --chat-say-line: var(--den-say-line);
  --chat-small: var(--den-small);
  --chat-press: var(--den-press);
}

/* ---------- 2. Project tokens ---------- */
:root {
  --den-w: 560px;                      /* the column, at desk width too: it's a phone app */
  --den-top: var(--space-12);          /* the top bar */
  /* Den's reading sizes (MEK: readability first; Dosage reads smaller than a system face at the same size, and
     children read it): between the face's 12px steps, so smoothed, not crisp. A Deviation from the type scale. */
  --den-say: 18px;                     /* a message's words, a quest's name, the box to write in, a chat's and a row's name */
  --den-say-line: 24px;                /* their line: a third again, room between lines of a long message */
  --den-small: 15px;                   /* names over messages, quotes, a row's last line, the head's second line */
  --den-name: var(--text-lg);          /* a person's name where it's the point (Who's using Den?, Me): 24, crisp */
  --den-press: var(--press-min);       /* every control a finger presses: 44 */
  --den-photo: 240px;                  /* a photo in the thread, on its long edge */
  --den-gutter: var(--page-gutter);    /* the page's sides */
}
@media (max-width: 640px) {   /* --bp-phone: a phone's width is the thread's, so the sides stay thin (MEK: 8 to 12) */
  :root { --den-gutter: var(--space-3); }
}

/* ---------- 3. Project components ---------- */

/* A chat's ground is a step off the page's (200), so the bubbles on the page's own (100) stand off it a little:
   easier on the eyes (MEK). The box to write in sits on 100 as well. */
html[data-den-view="chat"], html[data-den-view="chat"] body { background-color: var(--chat-ground); }
html[data-den-view="chat"] .chat-compose .field { background-color: var(--bg); border-color: var(--line-hover); }
/* On that ground the page's own (100) is only a shade off (1.05:1), so what sits on it is told apart by its edge:
   600 (--line-hover), 2:1 or more in both Slates, not the line's 400 (1.2:1). */
html[data-den-view="chat"] { --chat-theirs-edge: var(--line-hover); }

/* The app: the top bar and the view, in the window's height. */
html { overflow: hidden; scrollbar-gutter: auto; }
.den { display: grid; grid-template-rows: auto minmax(0, 1fr); height: 100dvh; max-width: var(--den-w); margin-inline: auto;
  padding-inline: max(var(--den-gutter), env(safe-area-inset-left)) max(var(--den-gutter), env(safe-area-inset-right)); box-sizing: border-box; }
.den-top { display: flex; align-items: center; justify-content: space-between; height: var(--den-top); padding-top: env(safe-area-inset-top); }
.den-name { color: var(--text-strong); text-decoration: none; }
.den-top-me { display: inline-flex; text-decoration: none; }
.den-top-me[hidden] { display: none; }
.den-main { display: grid; min-height: 0; outline: none; }
.den-view { display: grid; align-content: start; gap: var(--space-6); min-height: 0;
  padding-bottom: max(var(--space-4), env(safe-area-inset-bottom)); }   /* each is a .scroller: room for focus rings at its sides */
.den-view[hidden] { display: none; }

/* Who's using Den? The family as big buttons. */
.den-who { align-content: center; justify-items: start; }
.den-who-list { display: grid; gap: var(--space-2); width: 100%; margin: 0; padding: 0; list-style: none; }
.den-who-btn { display: flex; align-items: center; gap: var(--space-4); width: 100%; min-height: var(--space-16); justify-content: flex-start;
  font-size: var(--den-name); }
.den-who-btn .t-note { margin-inline-start: auto; }

/* The chats list: a row a chat (after Meknegement's .chat-row): its face, its name and when, its last line and how
   many unread (the list's one accent). Hover fills it with the surface. */
.den-chats { gap: var(--space-3); }
.den-list-title { margin: var(--space-2) 0 0; color: var(--text-strong); outline: none; }
.den-search { gap: var(--space-2); height: var(--den-press); color: var(--text-muted); }
.den-search input { font-size: var(--den-say); }
.den-list[hidden] { display: none; }
.den-list-label { padding: var(--space-3) var(--space-3) var(--space-1); }
.den-row-mark { flex: none; display: inline-flex; color: var(--text-muted); }
.den-row-draft { color: var(--text-strong); }
.den-list { display: grid; gap: var(--space-1); margin: 0; padding: 0; list-style: none; }
.den-row { --edge: var(--bg); --edge-to: var(--surface); --fill-to: var(--surface); --ink: var(--text); --ink-to: var(--text-strong);
  display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: var(--space-3); padding: var(--space-3);
  color: var(--ink); text-decoration: none; }
.den-row-text { display: grid; gap: var(--space-1); min-width: 0; }
.den-row-top, .den-row-bottom { display: flex; align-items: baseline; gap: var(--space-2); min-width: 0; }
.den-row-name { flex: 1 1 auto; font-size: var(--den-say); }
.den-row.unread .den-row-name { color: var(--text-strong); }
.den-row-time { flex: none; font: var(--text-crisp) var(--font-mono); color: var(--text-muted); }
.den-row-last { flex: 1 1 auto; font-size: var(--den-small); color: var(--text-muted); }
.den-row.unread .den-row-last { color: var(--text); }
.den-row-bottom .tag { flex: none; }
.den-row-skel { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: var(--space-3); padding: var(--space-3); }

/* A chat, as chat apps have it: its head in the top bar (back, its face, its name, who's in it, a rule under it), the
   thread full width with the newest at the foot (a short thread sits on the box to write in), and the box pinned
   under it. */
.den-top-home, .den-top-chat { display: flex; align-items: center; gap: var(--space-3); width: 100%; min-width: 0; }
.den-top-home { justify-content: space-between; }
.den-top-home[hidden], .den-top-chat[hidden] { display: none; }
.den-top:has(> .den-top-chat:not([hidden])) { border-bottom: var(--stroke) solid var(--line); }
.den-top-chat .den-back { --ink: var(--text-soft); --ink-to: var(--text-strong); display: inline-flex; align-items: center; justify-content: center;
  flex: none; width: var(--den-press); height: var(--den-press); margin-inline-start: calc(-1 * var(--space-3)); }   /* a plain arrow, no box: hover is ink only */
.den-top-chat .den-back .icon { width: var(--icon-text); height: var(--icon-text); }
.den-head-face { flex: none; display: inline-flex; }
.den-head-text { display: grid; min-width: 0; flex: 1 1 auto; min-height: var(--den-press); align-content: center; padding: 0; border: 0;
  background: none; color: inherit; font: inherit; text-align: start; cursor: pointer; }   /* its name opens the chat's info */
.den-head-name { font: var(--den-say)/var(--leading) var(--font-ui); color: var(--text-strong); }
.den-head-sub { font-size: var(--den-small); color: var(--text-muted); }
.den-head-sub.blank { visibility: hidden; }
.den-chat { overflow: clip; overflow-clip-margin: var(--scroll-room); grid-template-rows: minmax(0, 1fr); padding-bottom: 0; }
.den-card { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; min-height: 0; }   /* the pinned strip (when there is one), the thread, the box */
.den-card > .den-pinned { grid-row: 1; }
.den-card > .chat-pane { grid-row: 2; }
.den-card > .den-compose { grid-row: 3; }
.den-flow > :first-child { margin-top: auto; }   /* the newest at the foot: a short thread sits on the box to write in */

/* The box to write in (the chat part's .chat-compose), pinned under the thread with a rule over it: the reply strip
   over it when answering or editing one message, then the +, the field and Send (icon buttons at a thumb's 44). */
.den-compose { padding-block: var(--space-2) max(var(--space-2), env(safe-area-inset-bottom)); border-top: var(--stroke) solid var(--line); }
.den-icon-btn[hidden], .den-add[hidden] { display: none; }
.den-icon-btn { flex: none; width: var(--den-press); height: var(--den-press); padding: 0; align-items: center; justify-content: center; }
.den-icon-btn:is(:active:not(:disabled), .pushed) { padding: 1px 0 0; }   /* pushed: down a pixel, as the core's is */
.den-add { flex: none; }
.den-add .flyout-art { width: 60px; height: 60px; }   /* Deviation: a 15px icon at 4×, the cards' 60px picture (no medium icon yet) */

/* Swipe to reply: the bubble springs back over a beat; Reply's mark shows at the left once it's far enough. */
.den-flow .msg { position: relative; }
.den-flow .msg > .msg-bubble { z-index: 1; }   /* over Reply's mark, which comes out from behind it */
.den-flow .msg-bubble[tabindex] { touch-action: pan-y; -webkit-touch-callout: none; user-select: none; cursor: pointer; }   /* the hold opens its actions, not the phone's own menu */
.den-spring { transition: translate var(--dur-beat) var(--ease-frames-2); }
.den-swipe-mark { position: absolute; color: var(--text-muted); opacity: 0; pointer-events: none; }   /* placed and shown by ui/gestures.js */
.den-swipe-mark.on { color: var(--text-strong); }
@media (prefers-reduced-motion: reduce) { .den-spring { transition: none; } }

/* Typing: the head's second line says who, its dots stepping (still under reduced motion). */
.den-head-sub.typing::after { content: "..."; display: inline-block; clip-path: inset(0 100% 0 0); animation: den-dots calc(4 * var(--dur-beat)) steps(4, jump-none) infinite; }
@keyframes den-dots { to { clip-path: inset(0 0 0 0); } }
@media (prefers-reduced-motion: reduce) { .den-head-sub.typing::after { animation: none; clip-path: none; } }

/* A photo: its long edge at --den-photo, its room kept from its stored size before it loads. Alone (no quote over it)
   it's the part's bare bubble. */
.den-photo { position: relative; display: grid; place-items: center; width: var(--den-photo); max-width: 100%; padding: 0; border: 0;
  background-color: transparent; color: var(--text-muted); cursor: zoom-in; }
.den-photo[data-tall] { width: auto; height: var(--den-photo); max-height: var(--den-photo); }
.den-photo > img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.den-photo > img:not([src]) { visibility: hidden; }
.den-photo:disabled { cursor: auto; gap: var(--space-1); }

/* The reaction bar's buttons (the reactions under a message are the part's): no frame (MEK), ink alone. */
.den-react { --ink: var(--text-muted); --ink-to: var(--text-strong); display: inline-flex; align-items: center; justify-content: center;
  width: var(--den-press); height: var(--den-press); }
.den-react.on { --ink: var(--text-strong); }
.den-react .icon { width: var(--icon-text); height: var(--icon-text); }


/* A photo large (the loupe part). */
.den-loupe-img { display: block; max-width: 100%; height: auto; }
.den-loupe .loupe-subject { max-width: min(640px, 100%); }
.den-loupe-actions { flex-wrap: wrap; }
.den-loupe-actions .btn { min-height: var(--den-press); }

/* A quest card in the thread (the part's .msg.card: theirs' colours whoever posted it, not a message to act on), at
   the full width, on its own: Den's override. */
.msg.card:has(.den-qcard) { align-self: stretch; width: 100%; max-width: none; }
.msg.card:has(.den-qcard) > .msg-bubble { justify-self: stretch; }

/* A quest card: who it's for and who posted it, the quest (the quests part), and its one action in a foot that keeps
   its height whatever it holds (a button, "Waiting for Mum or Dad", "Done"). */
.den-qcard { display: grid; gap: var(--space-2); width: 100%; }
.den-qcard-for { font-size: var(--den-small); color: var(--text-muted); }
.den-qcard .quests { max-width: none; }
.den-qcard .quest { grid-template-columns: 16px minmax(0, 1fr) auto; }   /* the part's box column, less the count's */
.den-qcard .quest-count:empty { display: none; }
.den-qcard .quest-name { font-size: var(--den-say); line-height: var(--den-say-line); }
.den-qcard .quest:last-child { border-bottom: 0; }
.den-qcard-foot { display: flex; align-items: center; justify-content: flex-end; gap: var(--space-3); min-height: var(--den-press); }
.den-qcard-foot .btn { min-height: var(--den-press); }
.den-qcard-foot .t-note { margin-inline-end: auto; min-width: 0; font-size: var(--text-md); line-height: var(--leading); }
.den-qcard-foot .den-done { color: var(--good); }
.quest[data-waiting]:not([data-done]) .quest-box { --edge: var(--text-soft); --edge-to: var(--text-soft); }

/* Me. */
.den-me { padding-top: var(--space-4); }
.den-me-who { display: flex; align-items: center; gap: var(--space-4); font-size: var(--den-name); color: var(--text-strong); }

/* The new quest sheet. */
.den-nq-recent { min-height: var(--den-press); }
.den-nq-error { min-height: var(--space-6); margin: 0; }

.avatar.den-av-family { --avatar-ground: var(--400); color: var(--1000); }   /* a group: a house, not a letter (its form tells it, not a colour) */
.avatar.den-av-family .icon { width: var(--icon-text); height: var(--icon-text); }
.avatar.den-av-family.lg .icon { width: 30px; height: 30px; }

/* A chat's info: who's in it (a row each), its photos in threes, my pin and mute. No wider than the column. */
@media (min-width: 641px) { .den-info { width: min(var(--den-w), 100% - 2 * var(--dialog-inset)); } }   /* (on a phone it's a bottom sheet, the window's width) */
.den-info-photos > .note { grid-column: 1 / -1; margin: 0; }
.den-info-people { display: grid; gap: var(--space-1); margin: 0; padding: 0; list-style: none; }
.den-info-people > li { display: flex; align-items: center; gap: var(--space-3); min-height: var(--den-press); font-size: var(--den-say); }
.den-info-people .t-note { margin-inline-start: auto; }
.den-info-photos { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--space-1); }
.den-info-photo { position: relative; aspect-ratio: 1; padding: 0; border: 0; background-color: transparent; cursor: zoom-in; }
.den-info-photo > img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.den-info-photo > img:not([src]) { visibility: hidden; }

/* Names in a chat, so who's who reads at a glance (MEK): five of the palette's colours (info, good, warn, accent, bad),
   each softened 70/30 with the text so none shouts, 6.5:1 or more on the chat's ground in both Slates; given round the
   family in its order (ui/dom.js). A Deviation: in an App theme these colours mean a status, here they mean a person. */
:root, [data-theme] {
  --den-name-0: color-mix(in srgb, var(--info) 70%, var(--text));
  --den-name-1: color-mix(in srgb, var(--good) 70%, var(--text));
  --den-name-2: color-mix(in srgb, var(--warn) 70%, var(--text));
  --den-name-3: color-mix(in srgb, var(--accent) 70%, var(--text));
  --den-name-4: color-mix(in srgb, var(--bad) 70%, var(--text));
}
.den-name-0 { color: var(--den-name-0); }
.den-name-1 { color: var(--den-name-1); }
.den-name-2 { color: var(--den-name-2); }
.den-name-3 { color: var(--den-name-3); }
.den-name-4 { color: var(--den-name-4); }

/* Faces: a little pixel person (12 × 12, so 2× at 24 and 32, 4× at 48, 8× at 96) or a pattern; the picture's own
   colours are its content, like a photo's, never the theme's. A person sits on the avatar's ground, edge to edge. */
.avatar.den-face { --avatar-ground: var(--line); }
.avatar.den-face > img { width: 24px; height: 24px; image-rendering: pixelated; object-fit: contain; }
.avatar.den-face.lg > img { width: 48px; height: 48px; }
.avatar.den-face.sm > img { width: 24px; height: 24px; }
.avatar.den-face-photo > img { width: 100%; height: 100%; image-rendering: auto; object-fit: cover; }   /* a photo: smoothed, filling the face */
.avatar.xl { --av: 96px; --av-cell: 16px; }   /* Me's: a Deviation, the avatar part has no 96 */
.avatar.den-face.xl > img { width: 96px; height: 96px; }
/* A pattern's colour, one of eight round the family (never a status colour), 3:1 or more on the ground in each Slate. */
.avatar[data-hue="0"] { --avatar-ink: #306082; } .avatar[data-hue="1"] { --avatar-ink: #37946e; }
.avatar[data-hue="2"] { --avatar-ink: #8f563b; } .avatar[data-hue="3"] { --avatar-ink: #76428a; }
.avatar[data-hue="4"] { --avatar-ink: #ac3232; } .avatar[data-hue="5"] { --avatar-ink: #4b692f; }
.avatar[data-hue="6"] { --avatar-ink: #3f3f74; } .avatar[data-hue="7"] { --avatar-ink: #8a6f30; }
[data-theme="slate-dark"] .avatar[data-hue="0"] { --avatar-ink: #639bff; } [data-theme="slate-dark"] .avatar[data-hue="1"] { --avatar-ink: #99e550; }
[data-theme="slate-dark"] .avatar[data-hue="2"] { --avatar-ink: #df7126; } [data-theme="slate-dark"] .avatar[data-hue="3"] { --avatar-ink: #d77bba; }
[data-theme="slate-dark"] .avatar[data-hue="4"] { --avatar-ink: #d95763; } [data-theme="slate-dark"] .avatar[data-hue="5"] { --avatar-ink: #6abe30; }
[data-theme="slate-dark"] .avatar[data-hue="6"] { --avatar-ink: #5fcde4; } [data-theme="slate-dark"] .avatar[data-hue="7"] { --avatar-ink: #fbf236; }
.avatar.den-face[data-identicon] { --avatar-ground: var(--surface); }
.den-me-face .cluster { margin-top: var(--space-2); }

/* A reply's quote a step back from the message that answers it, so the new words read first. Solid colour, never
   opacity: it would blend the pixel type's edges. On mine it is 15% towards the fill, the most the accent allows at AA
   (4.8 light, 5.2 dark); on theirs the muted ink. A Deviation (the chat part's .msg-quote has no dim): to promote. */
.msg-bubble { --chat-quote-ink: var(--text-muted); }
.msg.mine > .msg-bubble { --chat-quote-ink: color-mix(in srgb, var(--chat-mine-ink) 85%, var(--chat-mine-fill)); }
.msg-quote { color: var(--chat-quote-ink); }

/* Naming someone: the people who match what's been written after "@", a list of presses, each with the person's face, over the box (ui/mention-pick.js). */
.den-mentions { display: grid; gap: var(--space-1); padding-bottom: var(--space-2); }
.den-mentions[hidden] { display: none; }
.den-mentions .btn { justify-content: flex-start; gap: var(--space-3); min-height: var(--den-press); text-align: start; }
.den-mentions .t-note { margin-inline-start: auto; }

/* The pinned strip over the thread: the chat part's reply strip as a press, with the pin's mark and a count. */
.den-pinned { grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; inline-size: 100%; min-height: var(--den-press);
  padding-block: var(--space-1); background: none; border-block: 0; border-inline-end: 0; color: inherit; font: inherit; text-align: start; cursor: pointer; }
.den-pinned[hidden] { display: none; }

/* The chat's wallpaper (a Deviation, MEK's choice): the library's one-tone four-circle-flower motif, tiled as bricks at 2× (96×136px: two rows, the
   second half a tile along, each motif with room round it (one art pixel above and below, eight each side), img/wallpaper-tile.png, made from the motif's PNG; whole-number, pixel-true) in the quietest motif tone, behind the thread only. The head and the box stay flat, and the
   bubbles are opaque, so nothing under a word. */
html[data-den-view="chat"] .chat-pane { position: relative; isolation: isolate; background-color: var(--chat-ground); }
html[data-den-view="chat"] .chat-flow { background-color: transparent; }   /* the pane carries the ground, so the motif shows through */
html[data-den-view="chat"] .chat-pane::before {
  content: ""; position: absolute; inset: 0; z-index: -1; pointer-events: none;
  background: var(--motif-4); opacity: .7;
  -webkit-mask: url("img/wallpaper-tile.png") 0 0 / 96px 136px repeat;
  mask: url("img/wallpaper-tile.png") 0 0 / 96px 136px repeat;
  image-rendering: pixelated;
}

/* A day's label on that wallpaper: a soft pill (MEK's pick), the line's fill with the strong ink, so it stands off the
   pattern without a box's edge. Its round ends are a Deviation: the part's label is square. */
html[data-den-view="chat"] .chat-day { background-color: var(--line); color: var(--text-strong); border-radius: 99px; min-width: 14ch; padding-inline: var(--space-4); }   /* (one width for all, as the part's, so the stuck one covers the last) */
