/* base.css: the owner's look, ready to drop in (App Playbook kit/look-and-checks).
   Rules it carries, with the owner's words and dates, are in the comments. Rename the --accent colours for the app;
   keep the structure. Class names are generic: .dialog-wrap/.dialog/.dlg-x, .sheet, .toast, .btn, .tabs, .menu-pop,
   .card, .row, .av, .seg (the Light/Dark/Larger control). */

/* ---- Colour tokens. Light on :root; dark twice (device setting unless the person chose Light, and an explicit
   choice of Dark): "Dark mode: each colour token redefined under prefers-color-scheme guarded by
   :not([data-theme="light"]), plus an explicit data-theme="dark"" (KAS, Oct 2026). Body text on --bg and --surface is
   at least 4.5:1 in both; render-audit.js measures it. */
:root {
  --bg: #f7f6f3; --surface: #ffffff; --surface-2: #efede8; --fg: #1d1c1a; --muted: #66625a;
  --line: #e0ddd5; --accent: #1f5fbf; --accent-fg: #ffffff; --accent-soft: #e4edfa;
  --bar: #1f5fbf; --bar-fg: #ffffff;
  --ok: #26683f; --warn: #8f5400; --danger: #9a2a2a;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.06);
  --scrim: rgba(10,12,14,.5);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141413; --surface: #1e1d1b; --surface-2: #292825; --fg: #ecebe7; --muted: #a6a29a;
    --line: #353330; --accent: #7fb0f5; --accent-fg: #0a1526; --accent-soft: #1b2a40;
    --bar: #16294a; --bar-fg: #f0f4fb;
    --ok: #7cc39a; --warn: #e3b060; --danger: #e89090; --shadow: none; --scrim: rgba(0,0,0,.62);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #141413; --surface: #1e1d1b; --surface-2: #292825; --fg: #ecebe7; --muted: #a6a29a;
  --line: #353330; --accent: #7fb0f5; --accent-fg: #0a1526; --accent-soft: #1b2a40;
  --bar: #16294a; --bar-fg: #f0f4fb;
  --ok: #7cc39a; --warn: #e3b060; --danger: #e89090; --shadow: none; --scrim: rgba(0,0,0,.62);
  color-scheme: dark;
}

/* ---- Type scale and spacing. Use these, not loose pixel values: "Aligned, measured spacing" (Playbook 4.8). */
:root {
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --fs-xs: 12px; --fs-sm: 13px; --fs-md: 15px; --fs-lg: 17px; --fs-xl: 21px; --fs-xxl: 28px;
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 24px; --sp-6: 32px;
  --gutter: 16px;                 /* phone side gutter: nothing sits closer to the edge than this */
  --radius: 10px; --radius-lg: 18px;
  --tap: 44px;                    /* the smallest finger target */
  --z-bar: 40; --z-fab: 60; --z-menu: 62; --z-dialog: 64; --z-toast: 70;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font: var(--fs-md)/1.55 var(--font); }
a { color: var(--accent); text-decoration: none; }              /* no underlined chrome links (owner, 17-18 Oct 2026: "look pretty old school") */
p a, .prose a { text-decoration: underline; text-decoration-color: color-mix(in srgb, currentColor 40%, transparent); text-underline-offset: 3px; }
a:hover { text-decoration-color: currentColor; }
h1, h2, h3 { font-weight: 700; letter-spacing: -.01em; line-height: 1.2; }
h1 { font-size: var(--fs-xxl); margin: var(--sp-1) 0 var(--sp-2); }
h2 { font-size: var(--fs-xl); margin: var(--sp-5) 0 var(--sp-3); }
h3 { font-size: var(--fs-lg); margin: var(--sp-4) 0 var(--sp-2); }
.muted { color: var(--muted); } .small { font-size: var(--fs-sm); }
/* No ALL-CAPS: "looks like you are shouting at someone" (owner, 18 Oct 2026). Nothing here sets text-transform;
   render-audit.js flags any that does. */
th, label, summary, button { text-transform: none; }
:root { accent-color: var(--accent); }
img { max-width: 100%; }

/* ---- Safe areas: every fixed bottom element adds the inset (Playbook 4.7 #72). */
.safe-bottom { padding-bottom: calc(var(--sp-3) + env(safe-area-inset-bottom)); }
.safe-top { padding-top: env(safe-area-inset-top); }
.bar-top { position: sticky; top: 0; z-index: var(--z-bar); background: var(--bar); color: var(--bar-fg);
  padding: calc(var(--sp-2) + env(safe-area-inset-top)) max(var(--gutter), env(safe-area-inset-right)) var(--sp-2) max(var(--gutter), env(safe-area-inset-left)); }
.bar-bottom { position: fixed; left: 0; right: 0; bottom: 0; z-index: var(--z-bar); background: var(--surface); border-top: 1px solid var(--line);
  padding: var(--sp-2) var(--gutter) calc(var(--sp-2) + env(safe-area-inset-bottom)); }
html.kb-open .bar-bottom.hide-on-kb, html.kb-open .fab { display: none !important; }   /* out of the way while typing (S7) */
.fab { position: fixed; right: 18px; bottom: calc(18px + env(safe-area-inset-bottom)); z-index: var(--z-fab); }
.fab[hidden] { display: none !important; }

/* ---- Larger text (owner, 18 Oct 2026: "for members who find the site small to read"): the whole page a step
   larger by zoom so every proportion holds. Anything sized from the window (vh/dvh) is divided back so it can't
   overshoot the screen; anything placed from measured pixels divides by pageZoom() (look.js). */
html[data-text="large"] body { zoom: 1.15; }
html[data-text="large"] .dialog { max-height: calc((100vh - 32px) / 1.15); max-height: calc((100dvh - 32px) / 1.15); }
@media (max-width: 640px) { html[data-text="large"] .dialog { max-height: calc(88vh / 1.15); max-height: calc(88dvh / 1.15); } }
html[data-text="large"] .sheet { max-height: calc(88vh / 1.15); max-height: calc(88dvh / 1.15); }
/* Photo screens keep their usual size at Larger ("the photo is the point, and they zoom themselves", 19-20 Oct
   2026): 1/1.15 cancels the page zoom. Put .keep-size on any viewer, zoomable picture or drawing canvas. */
html[data-text="large"] .keep-size, html[data-text="large"] .viewer { zoom: 0.869565; }
/* A phone's packed top bar already has big tap targets: it keeps its size too. */
@media (max-width: 760px) { html[data-text="large"] .bar-top { zoom: 0.869565; } }

/* ---- Text fields at least 16px on touch screens, and never block zoom (owner's global rule, 18 Oct 2026, after a
   comment box zoomed an iPhone). Never fix it with maximum-scale=1 or user-scalable=no. */
@media (pointer: coarse) {
  input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="button"]):not([type="submit"]):not([type="file"]),
  textarea, select, [contenteditable="true"] { font-size: max(16px, 1em) !important; }
}
input:not([type="checkbox"]):not([type="radio"]):not([type="range"]), textarea, select {
  font: inherit; color: var(--fg); background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  padding: 10px 12px; min-height: var(--tap); max-width: 100%; }
textarea { min-height: 96px; resize: vertical; }
::placeholder { color: var(--muted); opacity: 1; }

/* ---- Focus rings: visible for keyboard users, quiet for a mouse. */
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
:focus:not(:focus-visible) { outline: none; }

/* ---- Buttons: finger-size on phones (44px), compact with a mouse (Playbook 4.7 #81). */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 36px; padding: 6px 14px;
  font: inherit; font-weight: 600; line-height: 1.2; color: var(--fg); background: var(--surface); border: 1px solid var(--line);
  border-radius: 8px; cursor: pointer; white-space: nowrap; max-width: 100%; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.08); background: var(--accent); }
.btn.danger { color: var(--danger); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .5; cursor: default; }
.btn.icon, .icon-btn { width: 36px; padding: 0; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; height: 36px; border: 0; border-radius: 50%;
  background: transparent; color: inherit; cursor: pointer; }
.icon-btn:hover { background: var(--surface-2); }
@media (pointer: coarse), (max-width: 640px) {
  .btn, .icon-btn, .tabs > a, .tabs > button, .menu-pop a, .menu-pop button { min-height: var(--tap); }
  .btn { min-width: var(--tap); }            /* a one-word or icon button is still a finger-size target (the audit found 40px-wide ones) */
  .btn.icon, .icon-btn { width: var(--tap); }
}
.icon { width: 1.15em; height: 1.15em; flex: none; vertical-align: -.2em; }

/* ---- Tabs: the selected one is shown three ways, so colour is never the only signal (owner, 17 Oct 2026: "not very
   clear with which tab is currently selected"): bold, a thick underline bar, and a filled background. */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.tabs > a, .tabs > button { display: inline-flex; align-items: center; padding: 10px 14px; font: inherit; color: var(--muted);
  background: transparent; border: 0; border-bottom: 3px solid transparent; border-radius: 8px 8px 0 0; white-space: nowrap; cursor: pointer; }
.tabs > .on, .tabs > [aria-selected="true"], .tabs > [aria-current="page"] { color: var(--fg); font-weight: 700;
  border-bottom-color: var(--accent); background: var(--accent-soft); }

/* ---- Segmented control for 2-3 choices (Light/Dark/Device, Normal/Larger); selected looks clearly different. */
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--surface); }
.seg button { font: inherit; padding: 6px 14px; min-height: 36px; border: 0; background: transparent; color: var(--fg); cursor: pointer; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-fg); font-weight: 700; }
@media (pointer: coarse), (max-width: 640px) { .seg button { min-height: var(--tap); } }   /* after the base rule above, or it loses (the audit found 36px ones) */
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); flex-wrap: wrap; padding: var(--sp-2) 0; }

/* ---- Menus: a popover on a computer, a bottom sheet on a phone; tapping outside only closes it (look.js, S3). */
details.menu { position: relative; display: inline-block; }
details.menu > summary { list-style: none; cursor: pointer; display: inline-flex; align-items: center; min-height: 36px; }
details.menu > summary::-webkit-details-marker { display: none; }
.menu-pop { position: absolute; right: 0; top: calc(100% + 6px); z-index: var(--z-menu); min-width: 200px; max-width: calc(100vw - 2 * var(--gutter));
  display: flex; flex-direction: column; padding: 6px; background: var(--surface); color: var(--fg); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: var(--shadow), 0 8px 28px rgba(0,0,0,.18); overscroll-behavior: contain; }
.menu-pop a, .menu-pop button { display: flex; align-items: center; gap: 10px; padding: 9px 12px; font: inherit; text-align: left;
  color: var(--fg); background: transparent; border: 0; border-radius: 8px; cursor: pointer; }
.menu-pop a:hover, .menu-pop button:hover { background: var(--surface-2); }   /* a hover shade, not an underline */
@media (max-width: 640px) {
  details.menu[open]::before { content: ""; position: fixed; inset: 0; z-index: calc(var(--z-menu) - 1); background: var(--scrim); touch-action: none; }
  details.menu[open] > .menu-pop { position: fixed; left: 0; right: 0; bottom: 0; top: auto; max-width: none; max-height: 80dvh; overflow-y: auto;
    border-radius: 20px 20px 0 0; padding: 10px 10px calc(14px + env(safe-area-inset-bottom)); animation: sheetUp .22s ease-out; }
}

/* ---- Cards, and rows that stay level however long a caption is (owner, 17 Oct 2026: "the entire row should still
   be..."): fixed-height cells, truncate, no wrapping that makes one card taller than its neighbour. */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: var(--sp-4); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: var(--sp-3); }
.grid > .card { min-width: 0; }
.row { display: flex; align-items: center; gap: var(--sp-3); min-height: 56px; padding: var(--sp-2) 0; border-bottom: 1px solid var(--line); }
.row > .grow { flex: 1; min-width: 0; }                       /* min-width:0 is what lets a long name truncate */
.row .name, .truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.clamp-2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; min-height: 2lh; }
.row > .btn, .row > .icon-btn { flex: none; }
/* Avatars: initials as the placeholder, same size whether or not the picture has arrived (no layout change). */
.av { flex: none; width: 40px; height: 40px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  overflow: hidden; background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: var(--fs-sm); line-height: 1; user-select: none; }
.av img { width: 100%; height: 100%; object-fit: cover; display: block; }
.av-stack { display: inline-flex; } .av-stack > .av { box-shadow: 0 0 0 2px var(--surface); } .av-stack > .av + .av { margin-left: -10px; }
.empty { padding: var(--sp-6) var(--sp-4); text-align: center; color: var(--muted); }
.tag { display: inline-flex; align-items: center; padding: 1px 8px; border-radius: 999px; font-size: var(--fs-xs); background: var(--surface-2); color: var(--fg); }

/* ---- The page stays still behind anything laid over it (owner, 20 Oct 2026: "the page behind the menu scrolls if you
   swipe on the menu itself. Check that everywhere"). */
html:has(#dialog:not([hidden])), html:has(.sheet) { overflow: hidden; }
@media (max-width: 640px) { html:has(details.menu[open]) { overflow: hidden; } }

/* ---- Dialog: every window has a way out at its top, a sticky X (owner, 18 Oct 2026: "There needs to be a way to
   close this box as well other than going all the way down to done"). The X is a 44px target drawing a 34px
   circle and stays in view while the window scrolls. */
.dialog-wrap { position: fixed; inset: 0; z-index: var(--z-dialog); display: flex; align-items: center; justify-content: center;
  padding: 16px; background: var(--scrim); top: var(--vv-top, 0px); bottom: auto; height: var(--vv-h, 100%); }
.dialog-wrap[hidden] { display: none; }
.dialog { position: relative; display: flex; flex-direction: column; width: min(520px, 100%); max-height: min(88dvh, calc(var(--vv-h, 100dvh) - 24px));
  overflow-y: auto; overscroll-behavior: contain; padding: 22px 22px calc(22px + env(safe-area-inset-bottom)); background: var(--surface);
  color: var(--fg); border-radius: var(--radius-lg); box-shadow: 0 18px 50px rgba(0,0,0,.35); }
.dialog.wide { width: min(860px, 100%); }
.dialog > .dlg-x, .sheet > .dlg-x { position: sticky; top: 0; z-index: 4; display: flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; margin: -6px -5px -38px auto; align-self: flex-end; flex: none; border: 0; border-radius: 50%; color: var(--fg);
  background: radial-gradient(circle, var(--surface-2) 16.5px, transparent 17px); cursor: pointer; }
.dialog > h2:first-of-type { margin-top: 0; padding-right: 44px; }
/* The action row is held at the foot while the body scrolls (owner, 18 Oct 2026: two sheets differed and one lost its
   handle); when the keyboard is up and focus is outside it, it drops back to its place so it can't cover the field. */
.dialog .actions, .sheet .actions { position: sticky; bottom: calc(-22px - env(safe-area-inset-bottom)); display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--sp-2);
  margin: var(--sp-4) -22px calc(-22px - env(safe-area-inset-bottom)); padding: var(--sp-3) 22px calc(var(--sp-3) + env(safe-area-inset-bottom)); background: var(--surface); border-top: 1px solid var(--line); }
html.kb-open .dialog .actions:not(:focus-within), html.kb-open .sheet .actions:not(:focus-within) { position: static; }

/* ---- Phone: dialogs become bottom sheets with a handle, a sticky title and the action row at the foot
   (owner, 18 Oct 2026; swipe down closes one, look.js). */
@keyframes sheetUp { from { transform: translateY(100%); } to { transform: none; } }
@media (max-width: 640px) {
  .dialog-wrap { align-items: flex-end; padding: 0; }
  .dialog { width: 100%; max-height: min(88dvh, calc(var(--vv-h, 100dvh) - 12px)); border-radius: 20px 20px 0 0; animation: sheetUp .22s ease-out; padding-top: 26px; }
  .dialog::before { content: ""; position: absolute; top: 8px; left: 50%; width: 40px; height: 5px; margin-left: -20px; border-radius: 3px; background: var(--line); }
}
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: var(--z-dialog); max-height: 88dvh; overflow-y: auto; overscroll-behavior: contain;
  background: var(--surface); color: var(--fg); border-radius: 20px 20px 0 0; padding: 22px 18px calc(22px + env(safe-area-inset-bottom)); animation: sheetUp .22s ease-out; box-shadow: 0 -8px 30px rgba(0,0,0,.25); }
.sheet::before { content: ""; position: absolute; top: 8px; left: 50%; width: 40px; height: 5px; margin-left: -20px; border-radius: 3px; background: var(--line); }
.sheet > .sheet-title { position: sticky; top: -22px; z-index: 3; margin: -8px -18px 8px; padding: 14px 62px 10px 18px; background: var(--surface); font-weight: 700; font-size: var(--fs-lg); }
/* Keyboard up: the room to scroll a low field above it. */
html.kb-open main, html.kb-open #app { padding-bottom: calc(72px + var(--kb-h, 0px)); }

/* ---- Toast: role=status, clears the bottom bar and the home-bar area. */
.toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: var(--z-toast);
  width: max-content; max-width: calc(100vw - 2 * var(--gutter)); padding: 10px 16px; border-radius: 8px; font-size: var(--fs-md);
  background: var(--fg); color: var(--bg); box-shadow: var(--shadow); }
.toast a { margin-left: 6px; color: inherit; font-weight: 700; text-decoration: underline; text-underline-offset: 3px; white-space: nowrap; }
@media (max-width: 640px) { .toast { bottom: calc(84px + env(safe-area-inset-bottom)); } }   /* clears a bottom bar */

/* ---- Reduced motion: no slides or fades for people who ask the device for none. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; scroll-behavior: auto !important; }
}
