/* OllyOlly shared components (docs/DESIGN.md). Needs tokens.css first.

   Every class starts with "ui-" so this file can load next to the older page styles (portal, games,
   chess) without changing anything until a screen opts in. Nothing here styles bare elements,
   except inside .ui-page (opt-in page base).

   Rules: cards never nest, tap targets are 44px+ (56px for little ones), focus is always visible,
   motion respects prefers-reduced-motion and <html data-motion="reduce">. */

/* ---------- page base (opt-in: <body class="ui-page">) ---------- */
.ui-page {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: var(--weight-body) var(--text-md) / var(--leading) var(--font-body);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  min-height: 100dvh;
}
/* [ios] iPhone and iPad: no rubber-band bounce showing a white page edge (Safari 16+; the page
   color is behind it anyway), text keeps its size when the phone turns sideways, and a quick
   double tap never zooms (touch-action on the page applies to everything inside it; pinch zoom
   and scrolling still work everywhere, and canvases keep touch-action: none). */
html:has(> body.ui-page) { background: var(--bg); overscroll-behavior: none; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
.ui-page { touch-action: manipulation; }
.ui-page *, .ui-page *::before, .ui-page *::after { box-sizing: border-box; }
.ui-page h1, .ui-page h2, .ui-page h3 { font-family: var(--font-display); line-height: var(--leading-tight); margin: 0; letter-spacing: -0.01em; }
.ui-page p { margin: 0; }
/* [a11y] :where() keeps this at one class, so .ui-btn (and any page class) sets a link's color: a link-button on amber was
   getting the page ink (light text on amber in the evening theme). */
.ui-page :where(a) { color: inherit; }
.ui-page img { max-width: 100%; }
.ui-page [hidden] { display: none !important; }
.ui-page :focus-visible,
:where(.ui-btn, .ui-iconbtn, .ui-tab, .ui-tile, .ui-row, .ui-chip, .ui-stepper button, .ui-input, .ui-appbar a, .ui-link):focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  box-shadow: 0 0 0 2px var(--focus-inner);
}

.ui-sr { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.ui-icon { display: inline-block; flex: none; vertical-align: middle; }
.ui-hand { font-family: var(--font-greeting); font-size: 1.5em; line-height: 1.1; }
.ui-muted { color: var(--ink-muted); }
.ui-stack { display: grid; gap: var(--space-3); }
.ui-cluster { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.ui-link { color: var(--accent-text); font-weight: var(--weight-strong); text-underline-offset: 3px; border-radius: 4px; }

/* ---------- buttons ---------- */
.ui-btn {
  --btn-bg: var(--surface-sunken);
  --btn-ink: var(--ink);
  --btn-line: transparent;
  position: relative;
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-height: var(--tap); padding: 10px 18px;
  border: 2px solid var(--btn-line); border-radius: var(--radius-md);
  background: var(--btn-bg); color: var(--btn-ink);
  font: var(--weight-strong) 16px/1.2 var(--font-body);
  text-decoration: none; cursor: pointer; user-select: none; -webkit-tap-highlight-color: transparent;
  transition: transform var(--dur-fast) var(--press-ease), filter var(--dur-fast), background-color var(--dur-fast), box-shadow var(--dur-fast);
}
.ui-btn:hover { filter: brightness(0.96); }
.ui-btn:active { transform: scale(var(--press-scale)); }
.ui-btn--primary { --btn-bg: var(--accent); --btn-ink: var(--accent-ink); box-shadow: var(--glow-accent); }
.ui-btn--primary:hover { filter: brightness(1.05); }
.ui-btn--secondary { --btn-bg: var(--surface); --btn-ink: var(--ink); --btn-line: var(--line-strong); }
.ui-btn--ghost { --btn-bg: transparent; --btn-ink: var(--ink); }
.ui-btn--ghost:hover { --btn-bg: var(--surface-sunken); filter: none; }
.ui-btn--danger { --btn-bg: transparent; --btn-ink: var(--danger-text); --btn-line: currentColor; }
.ui-btn--danger:hover { --btn-bg: var(--danger-soft); filter: none; }
.ui-btn--danger-solid { --btn-bg: var(--danger-strong, var(--danger)); --btn-ink: #FFFFFF; } /* [a11y] 4.5:1 */
.ui-btn--on-brand { --btn-bg: rgba(255, 255, 255, 0.12); --btn-ink: var(--on-brand); }
.ui-btn--sm { min-height: 44px; padding: 6px 12px; font-size: 14px; border-radius: 10px; } /* [a11y2] 44px like every tap target (was 36px) */
.ui-btn--lg { min-height: 56px; padding: 14px 22px; font-size: 18px; }
.ui-btn--block { display: flex; width: 100%; }
.ui-btn:disabled, .ui-btn[aria-disabled="true"] { opacity: 0.45; cursor: not-allowed; transform: none; filter: none; box-shadow: none; }
/* Loading: <button class="ui-btn" aria-busy="true"> keeps its size, hides the label, shows a spinner. */
.ui-btn[aria-busy="true"] { color: transparent; pointer-events: none; }
.ui-btn[aria-busy="true"] > * { visibility: hidden; }
.ui-btn[aria-busy="true"]::after {
  content: ""; position: absolute; inset: 0; margin: auto; width: 20px; height: 20px; border-radius: 50%;
  border: 3px solid var(--btn-ink); border-right-color: transparent; animation: ui-spin 0.8s linear infinite;
}
.ui-spinner { display: inline-block; width: 22px; height: 22px; border-radius: 50%; border: 3px solid currentColor; border-right-color: transparent; animation: ui-spin 0.8s linear infinite; }
@keyframes ui-spin { to { transform: rotate(360deg); } }

.ui-iconbtn {
  display: inline-grid; place-items: center; flex: none;
  width: var(--tap); height: var(--tap); padding: 0; border: 0; border-radius: var(--radius-md);
  background: transparent; color: inherit; cursor: pointer; text-decoration: none;
  transition: background-color var(--dur-fast), transform var(--dur-fast) var(--press-ease);
}
.ui-iconbtn:hover { background: color-mix(in srgb, currentColor 10%, transparent); }
.ui-iconbtn:active { transform: scale(var(--press-scale)); }
.ui-iconbtn:disabled { opacity: 0.4; cursor: not-allowed; }
.ui-iconbtn--filled { background: var(--surface-sunken); }

/* ---------- app bar: back, title, one help ---------- */
.ui-appbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: var(--space-2);
  min-height: calc(var(--appbar-h) + env(safe-area-inset-top, 0px));
  padding: env(safe-area-inset-top, 0px) max(var(--space-2), env(safe-area-inset-right, 0px)) 0 max(var(--space-2), env(safe-area-inset-left, 0px));
  background: color-mix(in srgb, var(--brand) 94%, transparent);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  color: var(--on-brand); overflow: hidden;
}
.ui-appbar > .ui-sky { position: absolute; inset: 0; z-index: -1; border-radius: 0; }
.ui-appbar-title {
  flex: 1; min-width: 0; margin: 0; padding-inline: var(--space-1);
  font: var(--weight-display) var(--text-lg) / 1.2 var(--font-display);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ui-appbar-actions { display: flex; align-items: center; gap: var(--space-1); }
/* [polish2] On a phone the title sits next to four buttons: a little smaller, and a long one ("Set up
   your family") wraps to a second line instead of being cut to "Set up your f...". */
@media (max-width: 480px) {
  .ui-appbar-title {
    font-size: var(--text-md); line-height: 1.15; white-space: normal; overflow-wrap: normal;
    display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2;
  }
}
.ui-appbar--light { background: var(--bg); color: var(--ink); border-bottom: 1px solid var(--line); }

/* ---------- bottom tab bar, side rail at 900px+ ---------- */
.ui-tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  min-height: var(--tabbar-h);
  padding: 4px max(4px, env(safe-area-inset-right, 0px)) env(safe-area-inset-bottom, 0px) max(4px, env(safe-area-inset-left, 0px));
  background: var(--surface); border-top: 1px solid var(--line); box-shadow: 0 -8px 24px -18px rgba(0, 0, 0, 0.35);
}
.ui-tab {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: var(--tap); padding: 6px 2px; border: 0; border-radius: var(--radius-md);
  background: transparent; color: var(--ink-muted); text-decoration: none; cursor: pointer;
  font: var(--weight-strong) 12px/1.1 var(--font-body);
  transition: color var(--dur-fast), transform var(--dur-fast) var(--press-ease);
}
.ui-tab .ui-icon { width: 26px; height: 26px; padding: 2px 12px; box-sizing: content-box; border-radius: var(--radius-full); transition: background-color var(--dur-med); }
.ui-tab:active { transform: scale(var(--press-scale)); }
.ui-tab[aria-current="page"], .ui-tab[aria-selected="true"] { color: var(--ink); }
.ui-tab[aria-current="page"] .ui-icon, .ui-tab[aria-selected="true"] .ui-icon { background: var(--accent-soft); color: var(--accent-text); }
.ui-tab .ui-badge { position: absolute; top: 2px; left: calc(50% + 8px); }
:where([data-skin="little"]) .ui-tab { font-size: 14px; }
:where([data-skin="little"]) .ui-tab .ui-icon { width: 30px; height: 30px; }
/* Leave room so content never hides under the bar. */
.ui-with-tabbar { padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + var(--space-4)); }
@media (min-width: 900px) {
  .ui-tabbar {
    top: 0; right: auto; width: var(--rail-w);
    grid-auto-flow: row; grid-auto-rows: max-content; align-content: start; gap: var(--space-2);
    padding: calc(var(--appbar-h) + var(--space-4)) var(--space-2) var(--space-4) max(var(--space-2), env(safe-area-inset-left, 0px));
    border-top: 0; border-right: 1px solid var(--line); box-shadow: none;
  }
  .ui-tab { padding-block: 8px; font-size: 13px; }
  .ui-with-tabbar { padding-bottom: var(--space-6); padding-left: var(--rail-w); }
}

/* ---------- main column ---------- */
.ui-main { max-width: var(--content-max); margin: 0 auto; padding: var(--space-4) var(--space-4) var(--space-7); display: grid; gap: var(--space-5); align-content: start; }
@media (max-width: 480px) { .ui-main { padding-inline: var(--space-3); gap: var(--space-4); } }

/* ---------- section header ---------- */
.ui-section-head { display: flex; align-items: baseline; gap: var(--space-3); margin: 0 0 var(--space-2); }
.ui-section-head > h2, .ui-section-title { flex: 1; min-width: 0; margin: 0; font: var(--weight-display) var(--text-lg) / 1.2 var(--font-display); }
.ui-section-head .ui-link, .ui-section-head .ui-btn { flex: none; }
.ui-eyebrow { font-size: var(--text-xs); font-weight: var(--weight-strong); letter-spacing: 0.06em; color: var(--ink-muted); }

/* ---------- card (never nested: an inner .ui-card renders flat) ---------- */
.ui-card {
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--radius-lg);
  padding: var(--space-4); display: grid; gap: var(--space-3); align-content: start;
  box-shadow: var(--shadow-2);
}
.ui-card .ui-card { border: 0; box-shadow: none; padding: 0; border-radius: 0; background: transparent; }
.ui-card--flush { padding: 0; overflow: hidden; }
.ui-card--brand { background: var(--brand); color: var(--on-brand); border-color: transparent; }
.ui-divider { height: 1px; background: var(--line); border: 0; margin: 0; }

/* ---------- tiles (3 sizes) ---------- */
.ui-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(var(--tile-min), 100%), 1fr)); gap: var(--space-3); }
.ui-tiles--sm { grid-template-columns: repeat(auto-fill, minmax(min(calc(var(--tile-min) * 0.7), 100%), 1fr)); }
.ui-tile {
  --tile-hue: var(--hue-0);
  position: relative;
  display: grid; align-content: space-between; justify-items: start; gap: var(--space-2);
  min-height: var(--tile-h); padding: var(--space-3) var(--space-3) var(--space-3) var(--space-4);
  border: 0; border-radius: var(--tile-radius);
  background: color-mix(in oklab, var(--tile-hue) calc(var(--tile-tint) * var(--tile-tint-scale, 1)), var(--surface));
  color: var(--ink); text-align: left; text-decoration: none; cursor: pointer;
  font: var(--weight-display) var(--tile-label) / 1.15 var(--font-body);
  transition: transform var(--dur-fast) var(--press-ease), box-shadow var(--dur-med);
}
.ui-tile:hover { box-shadow: var(--shadow-2); }
.ui-tile:active { transform: scale(var(--press-scale)); }
.ui-tile > .ui-tile-art, .ui-tile > .ui-icon { width: var(--tile-icon); height: var(--tile-icon); }
.ui-tile > .ui-icon { color: color-mix(in srgb, var(--tile-hue) 70%, var(--ink)); }
.ui-tile-art { display: block; border-radius: calc(var(--tile-radius) * 0.7); }
.ui-tile small, .ui-tile-sub { display: block; font-weight: var(--weight-body); font-size: var(--text-xs); color: var(--ink-muted); }
.ui-tile[aria-disabled="true"] { opacity: 0.55; cursor: default; transform: none; }
.ui-tile .ui-badge { position: absolute; top: var(--space-2); right: var(--space-2); }
.ui-tile--sm { min-height: calc(var(--tile-h) * 0.66); --tile-icon: 32px; grid-template-columns: auto minmax(0, 1fr); align-items: center; align-content: center; font-size: var(--text-sm); }
.ui-tile--sm > :not(svg) { min-width: 0; overflow-wrap: anywhere; }
.ui-tile--lg { min-height: calc(var(--tile-h) * 1.5); grid-column: span 2; --tile-icon: calc(var(--tile-h) * 0.6); font-size: var(--text-lg); }
@media (max-width: 360px) { .ui-tile--lg { grid-column: auto; } }
.ui-hue-0 { --tile-hue: var(--hue-0); } .ui-hue-1 { --tile-hue: var(--hue-1); } .ui-hue-2 { --tile-hue: var(--hue-2); }
.ui-hue-3 { --tile-hue: var(--hue-3); } .ui-hue-4 { --tile-hue: var(--hue-4); } .ui-hue-5 { --tile-hue: var(--hue-5); }

/* ---------- list rows ---------- */
.ui-list { list-style: none; margin: 0; padding: 0; display: grid; }
.ui-list > li + li, .ui-list > .ui-row + .ui-row { border-top: 1px solid var(--line); }
.ui-list > .ui-row, .ui-list > li > .ui-row { border-radius: 0; } /* straight dividers between rows */
.ui-row {
  display: flex; align-items: center; gap: var(--space-3);
  min-height: var(--tap); padding: var(--row-pad) var(--space-1);
  color: inherit; text-decoration: none; background: transparent; border: 0; width: 100%; text-align: left; font: inherit;
}
a.ui-row, button.ui-row, .ui-row--link { cursor: pointer; border-radius: var(--radius-md); transition: background-color var(--dur-fast); }
a.ui-row:hover, button.ui-row:hover, .ui-row--link:hover { background: color-mix(in srgb, var(--ink) 5%, transparent); }
.ui-row-main { flex: 1; min-width: 0; display: grid; gap: 2px; }
.ui-row-title { font-weight: var(--weight-strong); overflow-wrap: anywhere; }
.ui-row-sub { font-size: var(--text-sm); color: var(--ink-muted); }
.ui-row-end { flex: none; display: flex; align-items: center; gap: var(--space-2); color: var(--ink-muted); }
.ui-row > .ui-icon:first-child { color: var(--ink-muted); }

/* ---------- inputs ---------- */
.ui-field { display: grid; gap: 6px; }
.ui-label { font-weight: var(--weight-strong); font-size: var(--text-sm); }
.ui-hint { font-size: var(--text-xs); color: var(--ink-muted); }
.ui-field-error { font-size: var(--text-sm); color: var(--danger-text); font-weight: var(--weight-strong); }
.ui-input {
  width: 100%; min-height: var(--tap); padding: 10px 12px;
  font: var(--weight-body) var(--text-md) / 1.3 var(--font-body); color: var(--ink);
  background: var(--surface); border: 2px solid var(--line-strong); border-radius: var(--radius-sm);
  transition: border-color var(--dur-fast);
}
.ui-input::placeholder { color: var(--ink-faint); }
.ui-input:hover { border-color: var(--ink-faint); }
.ui-input:focus { border-color: var(--focus); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 30%, transparent); }
.ui-input[aria-invalid="true"] { border-color: var(--danger); }
.ui-input:disabled { opacity: 0.55; }
textarea.ui-input { min-height: 96px; resize: vertical; }
select.ui-input { appearance: none; padding-right: 40px; background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%); background-position: calc(100% - 20px) 50%, calc(100% - 14px) 50%; background-size: 6px 6px; background-repeat: no-repeat; }
.ui-input--code { font-family: var(--font-mono); font-size: 24px; letter-spacing: 0.12em; text-transform: uppercase; text-align: center; }

/* ---------- segmented control (radio semantics) ----------
   <div class="ui-seg" role="radiogroup" aria-label="How hard?">
     <label><input type="radio" name="lvl" value="easy" checked><span>Easy</span></label> ... </div> */
.ui-seg { display: inline-flex; flex-wrap: wrap; gap: 2px; padding: 3px; border-radius: calc(var(--radius-md) - 2px); background: var(--surface-sunken); }
.ui-seg--block { display: flex; }
.ui-seg--block > label { flex: 1; }
.ui-seg > label { position: relative; display: grid; cursor: pointer; }
.ui-seg input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.ui-seg span {
  display: grid; place-items: center; min-height: calc(var(--tap) - 6px); padding: 6px 14px; border-radius: calc(var(--radius-md) - 5px);
  font: var(--weight-strong) var(--text-sm) / 1.2 var(--font-body); color: var(--ink-muted); text-align: center;
  transition: background-color var(--dur-fast), color var(--dur-fast);
}
.ui-seg input:checked + span { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-1); }
.ui-seg input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 1px; }
.ui-seg input:disabled + span { opacity: 0.45; }

/* ---------- switch ----------
   <label class="ui-switch"><span>Chat</span><input type="checkbox" role="switch"><span class="ui-switch-track" aria-hidden="true"></span></label> */
.ui-switch { position: relative; display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); min-height: var(--tap); cursor: pointer; font-weight: 600; }
.ui-switch > input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.ui-switch-track { position: relative; flex: none; width: 50px; height: 30px; border-radius: var(--radius-full); background: var(--line-strong); transition: background-color var(--dur-med); }
.ui-switch-track::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%;
  background: #FFFFFF; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3); transition: transform var(--dur-med) var(--press-ease);
}
.ui-switch > input:checked + .ui-switch-track { background: var(--success); }
.ui-switch > input:checked + .ui-switch-track::after { transform: translateX(20px); }
.ui-switch > input:focus-visible + .ui-switch-track { outline: 3px solid var(--focus); outline-offset: 2px; box-shadow: 0 0 0 2px var(--focus-inner); }
.ui-switch > input:disabled + .ui-switch-track { opacity: 0.45; }

/* ---------- stepper ----------
   <div class="ui-stepper"><button aria-label="Less">-</button><output>30</output><button aria-label="More">+</button></div> */
.ui-stepper { display: inline-flex; align-items: center; border-radius: var(--radius-md); background: var(--surface-sunken); padding: 2px; }
.ui-stepper button { display: grid; place-items: center; width: var(--tap); height: var(--tap); border: 0; border-radius: calc(var(--radius-md) - 2px); background: transparent; color: var(--ink); cursor: pointer; }
.ui-stepper button:hover { background: var(--surface); }
.ui-stepper button:disabled { opacity: 0.35; cursor: not-allowed; }
.ui-stepper output { min-width: 4.5ch; text-align: center; font: var(--weight-display) var(--text-lg) / 1 var(--font-display); font-variant-numeric: tabular-nums; }

/* ---------- chip picker ----------
   <div class="ui-chips" role="group"><label class="ui-chip"><input type="checkbox"><span>Mornings</span></label></div> */
.ui-chips { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.ui-chip { position: relative; display: inline-grid; cursor: pointer; }
.ui-chip > input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.ui-chip > span {
  display: inline-flex; align-items: center; gap: 6px; min-height: var(--tap); padding: 6px 14px;
  border: 2px solid var(--line-strong); border-radius: var(--radius-full); background: var(--surface);
  font: var(--weight-strong) var(--text-sm) / 1.2 var(--font-body); color: var(--ink);
  transition: background-color var(--dur-fast), border-color var(--dur-fast);
}
.ui-chip > input:checked + span { background: var(--accent-soft); border-color: var(--accent); color: var(--ink); }
.ui-chip > input:checked + span::before { content: ""; width: 10px; height: 6px; border: solid currentColor; border-width: 0 0 2.5px 2.5px; transform: translateY(-2px) rotate(-45deg); }
.ui-chip > input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }
.ui-chip > input:disabled + span { opacity: 0.45; }
button.ui-chip { min-height: var(--tap); padding: 6px 14px; border: 2px solid var(--line-strong); border-radius: var(--radius-full); background: var(--surface); color: var(--ink); font: var(--weight-strong) var(--text-sm) / 1.2 var(--font-body); }
button.ui-chip[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); }

/* ---------- badge ---------- */
.ui-badge {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  min-width: 20px; height: 20px; padding: 0 7px; border-radius: var(--radius-full);
  background: var(--surface-sunken); color: var(--ink-muted);
  font: 800 12px/1 var(--font-body); white-space: nowrap; font-variant-numeric: tabular-nums;
}
.ui-badge--count { background: var(--danger-strong, var(--danger)); color: #FFFFFF; } /* [a11y] 4.5:1 */
.ui-badge--accent { background: var(--accent); color: var(--accent-ink); }
.ui-badge--success { background: var(--success-soft); color: var(--success-text, var(--success)); }
.ui-badge--info { background: var(--info-soft); color: var(--info-text, var(--info)); }
.ui-badge--dot { min-width: 10px; width: 10px; height: 10px; padding: 0; background: var(--danger); box-shadow: 0 0 0 2px var(--surface); }
.ui-badge--new { background: var(--accent-soft); color: var(--accent-text); }

/* ---------- safety level pill ---------- */
.ui-level { display: inline-flex; align-items: center; gap: 6px; font-size: var(--text-xs); font-weight: var(--weight-strong); white-space: nowrap; color: var(--lvl, var(--lvl-off)); }
.ui-level::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: currentColor; }
.ui-level--off { --lvl: var(--lvl-off); } .ui-level--log { --lvl: var(--lvl-log); } .ui-level--nudge { --lvl: var(--lvl-nudge); }
.ui-level--notify { --lvl: var(--lvl-notify); } .ui-level--block { --lvl: var(--lvl-block); } .ui-level--urgent { --lvl: var(--lvl-urgent); }

/* ---------- banner (offline, time left, info) ---------- */
.ui-banner {
  display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md); background: var(--info-soft); color: var(--ink);
  font-weight: 600; font-size: var(--text-sm);
}
.ui-banner > .ui-icon { color: var(--info-text, var(--info)); }
.ui-banner-text { flex: 1; min-width: 0; }
.ui-banner--warning { background: var(--warning-soft); } .ui-banner--warning > .ui-icon { color: var(--warning-text, var(--warning)); }
.ui-banner--danger { background: var(--danger-soft); } .ui-banner--danger > .ui-icon { color: var(--danger-text); }
.ui-banner--success { background: var(--success-soft); } .ui-banner--success > .ui-icon { color: var(--success-text, var(--success)); }
.ui-banner--offline { background: var(--brand); color: var(--on-brand); } .ui-banner--offline > .ui-icon { color: var(--accent); }
.ui-banner--bar { border-radius: 0; justify-content: center; padding-block: 6px; }

/* ---------- avatar ---------- */
.ui-avatar {
  --av: 44px;
  position: relative; display: inline-grid; place-items: center; flex: none; overflow: hidden;
  width: var(--av); height: var(--av); border-radius: calc(var(--av) * 0.34);
  background: var(--av-bg, var(--accent-soft));
}
.ui-avatar > svg { width: 100%; height: 100%; display: block; }
.ui-avatar--xs { --av: 24px; } .ui-avatar--sm { --av: 32px; } .ui-avatar--lg { --av: 64px; } .ui-avatar--xl { --av: 96px; }
.ui-avatar--round { border-radius: 50%; }
.ui-avatar-stack { display: flex; }
.ui-avatar-stack > .ui-avatar { box-shadow: 0 0 0 2px var(--surface); }
.ui-avatar-stack > .ui-avatar + .ui-avatar { margin-left: calc(var(--av) * -0.25); }
.ui-avatar-pick { display: grid; grid-template-columns: repeat(auto-fill, minmax(56px, 1fr)); gap: var(--space-2); }
.ui-avatar-pick button { padding: 3px; border: 3px solid transparent; border-radius: 18px; background: none; cursor: pointer; }
.ui-avatar-pick button[aria-pressed="true"] { border-color: var(--accent); }

/* ---------- empty state ---------- */
.ui-empty { display: grid; justify-items: center; gap: var(--space-3); padding: var(--space-6) var(--space-4); text-align: center; }
.ui-empty-art { position: relative; display: grid; place-items: center; width: 120px; height: 104px; color: var(--ink-faint); }
.ui-empty-art > svg { width: 88px; height: 88px; }
.ui-empty-text { max-width: 36ch; color: var(--ink-muted); font-size: var(--text-md); }

/* ---------- skeleton loader ---------- */
.ui-skel {
  display: block; border-radius: var(--radius-sm); min-height: 14px;
  background: linear-gradient(90deg, var(--surface-sunken) 25%, color-mix(in srgb, var(--surface-sunken) 50%, var(--surface)) 50%, var(--surface-sunken) 75%);
  background-size: 300% 100%; animation: ui-shimmer 1.4s ease-in-out infinite;
}
.ui-skel--text { height: 14px; width: 70%; }
.ui-skel--title { height: 22px; width: 45%; }
.ui-skel--tile { height: var(--tile-h); border-radius: var(--tile-radius); }
.ui-skel--row { height: 56px; border-radius: var(--radius-md); }
.ui-skel--circle { width: 44px; height: 44px; border-radius: 50%; }
@keyframes ui-shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }

/* ---------- toast (ui.js toast() puts them in a polite live region) ---------- */
.ui-toasts {
  position: fixed; left: 0; right: 0; z-index: 90; pointer-events: none;
  bottom: calc(var(--space-4) + env(safe-area-inset-bottom, 0px));
  display: grid; justify-items: center; gap: var(--space-2); padding-inline: var(--space-4);
}
.ui-with-tabbar ~ .ui-toasts, .ui-toasts--above-tabbar { bottom: calc(var(--tabbar-h) + var(--space-3) + env(safe-area-inset-bottom, 0px)); }
.ui-toast {
  pointer-events: auto; display: inline-flex; align-items: center; gap: var(--space-2);
  max-width: min(520px, 100%); padding: 12px 18px; border-radius: var(--radius-full);
  background: var(--brand); color: var(--on-brand); box-shadow: var(--shadow-3);
  font-weight: 600; animation: ui-rise var(--dur-slow) var(--ease-out);
}
.ui-toast--success > .ui-icon { color: #8FD6A8; }
.ui-toast--danger { background: var(--danger); color: #FFFFFF; }
.ui-toast.is-leaving { opacity: 0; transform: translateY(8px); transition: opacity var(--dur-med), transform var(--dur-med); }
/* [steady1] Toasts sit on top of each other in one spot (a new one covers the last, which fades), so a
   toast never pushes another one up or down. */
.ui-toast { grid-area: 1 / 1; align-self: end; }
@keyframes ui-rise { from { opacity: 0; transform: translateY(12px); } }

/* ---------- sheet / modal (native <dialog>: focus trap and Escape; ui.js openSheet returns focus) ---------- */
dialog.ui-sheet {
  width: min(560px, 100% - 24px); max-height: min(88vh, 100% - 24px); margin: auto auto 12px; padding: 0;
  border: 0; border-radius: var(--radius-lg); background: var(--surface-raised); color: var(--ink);
  box-shadow: var(--shadow-3); overflow: hidden;
}
dialog.ui-sheet[open] { display: flex; flex-direction: column; animation: ui-sheet-in var(--dur-slow) var(--ease-out); }
dialog.ui-sheet::backdrop { background: var(--scrim); }
@media (min-width: 640px) { dialog.ui-sheet { margin: auto; } }
.ui-sheet-head { display: flex; align-items: center; gap: var(--space-2); padding: var(--space-3) var(--space-2) 0 var(--space-5); }
.ui-sheet-title { flex: 1; margin: 0; font: var(--weight-display) var(--text-xl) / 1.15 var(--font-display); }
.ui-sheet-body { padding: var(--space-3) var(--space-5); overflow-y: auto; display: grid; gap: var(--space-3); }
.ui-sheet-actions { display: grid; gap: var(--space-2); padding: var(--space-3) var(--space-5) var(--space-5); }
@media (min-width: 640px) { .ui-sheet-actions { grid-auto-flow: column; justify-content: end; } }
@keyframes ui-sheet-in { from { opacity: 0; transform: translateY(24px); } }

/* ---------- safety dialog (nudge / held / crisis): same words in portal, games and chess ---------- */
.ui-safety .ui-sheet-body { justify-items: center; text-align: center; padding-top: var(--space-5); }
.ui-safety-art { display: grid; place-items: center; width: 72px; height: 72px; border-radius: 50%; background: var(--accent-soft); color: var(--accent-text); }
.ui-safety-art > .ui-icon { width: 36px; height: 36px; }
.ui-safety--held .ui-safety-art { background: var(--info-soft); color: var(--info-text, var(--info)); }
.ui-safety--crisis .ui-safety-art { background: var(--danger-soft); color: var(--danger-text); }
.ui-safety-text { font-size: var(--text-md); max-width: 38ch; }
.ui-safety .ui-sheet-actions { grid-auto-flow: row; justify-content: stretch; }
.ui-safety-crisis-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-2); }

/* ---------- time-of-day sky (sky.js) ----------
   Layers are placed separately (percent positions), so the sky works at any shape: a tall card,
   a wide banner or the thin app bar (.ui-sky--compact). */
.ui-sky {
  --sky-top: #7EC3F0; --sky-bottom: #CFE9F7; --hill: #7FBF8E; --hill-2: #5FA874;
  position: relative; overflow: hidden; isolation: isolate; border-radius: var(--radius-lg);
  min-height: 140px; color: #1C2233;
  background: linear-gradient(180deg, var(--sky-top), var(--sky-bottom));
}
.ui-sky[data-phase="dawn"]   { --sky-top: #F6B99A; --sky-bottom: #FDE7C4; --hill: #8EB88E; --hill-2: #6E9E78; }
.ui-sky[data-phase="day"]    { --sky-top: #6FB8EC; --sky-bottom: #CDEAF8; --hill: #7FBF8E; --hill-2: #5FA874; }
.ui-sky[data-phase="golden"] { --sky-top: #F2A65A; --sky-bottom: #FCD9A0; --hill: #7C9E6A; --hill-2: #5C8455; }
.ui-sky[data-phase="dusk"]   { --sky-top: #2C3A66; --sky-bottom: #C9728A; --hill: #2E3F5C; --hill-2: #223050; color: #F3F1EA; }
.ui-sky[data-phase="night"]  { --sky-top: #0A0F1F; --sky-bottom: #243152; --hill: #18223C; --hill-2: #111A30; color: #F3F1EA; }
.ui-sky--subtle { filter: saturate(0.75); }
.ui-sky--subtle[data-phase="day"] { --sky-top: #9CCBEB; --sky-bottom: #DDEFF8; }
.ui-sky--compact { min-height: 0; border-radius: 0; }
.ui-sky-content { position: relative; z-index: 2; padding: var(--space-4); }
.ui-sky .sky-layer { position: absolute; pointer-events: none; z-index: 0; }
.ui-sky .sky-layer svg, .ui-sky svg.sky-layer { display: block; overflow: visible; }
/* sun and moon */
.ui-sky .sky-body { height: clamp(26px, 34%, 76px); aspect-ratio: 1; transform: translate(-50%, -50%); transition: left var(--dur-slow), top var(--dur-slow); }
.ui-sky .sky-body > svg { width: 100%; height: 100%; }
.ui-sky--playful .sky-body { height: clamp(30px, 42%, 92px); }
.ui-sky--compact .sky-body { height: 62%; }
.ui-sky .sky-sun { fill: #FFD35C; }
.ui-sky .sky-sun-glow { fill: #FFE9A8; opacity: 0.45; }
.ui-sky .sky-rays { stroke: #FFC23D; stroke-width: 3.2; stroke-linecap: round; }
.ui-sky[data-phase="golden"] .sky-sun, .ui-sky[data-phase="dawn"] .sky-sun { fill: #FFB547; }
.ui-sky .sky-moon { fill: #F6F0DC; }
.ui-sky .sky-moon-glow { fill: #FFF6D8; opacity: 0.16; }
.ui-sky .sky-face { fill: none; stroke: #5A3A12; stroke-width: 2.4; stroke-linecap: round; }
.ui-sky .sky-moon-face .sky-face { stroke: #4A4F66; }
.ui-sky .sky-cheek { fill: #F28B6B; opacity: 0.45; }
/* stars */
.ui-sky .sky-stars { inset: 0; }
.ui-sky .sky-star { position: absolute; width: 2px; height: 2px; border-radius: 50%; background: #FFF6D8; animation: ui-twinkle 4s ease-in-out infinite; }
.ui-sky .sky-star.is-big { width: 3px; height: 3px; }
.ui-sky .sky-star:nth-child(3n) { animation-delay: -1.3s; }
.ui-sky .sky-star:nth-child(3n + 1) { animation-delay: -2.6s; }
/* clouds */
.ui-sky .sky-clouds { inset: 0; animation: ui-cloud-drift 60s linear infinite alternate; }
.ui-sky .sky-cloud-g { position: absolute; width: clamp(40px, 14%, 90px); }
.ui-sky .sky-cloud-g.is-big { width: clamp(48px, 18%, 116px); }
.ui-sky--compact .sky-cloud-g { width: 44px; }
.ui-sky .sky-cloud { fill: #FFFFFF; opacity: 0.85; }
.ui-sky[data-phase="golden"] .sky-cloud, .ui-sky[data-phase="dawn"] .sky-cloud { fill: #FFF3E0; }
.ui-sky[data-phase="dusk"] .sky-cloud { fill: #8E7FA6; opacity: 0.45; }
/* hills and the streetlight */
.ui-sky .sky-hills { left: 0; bottom: 0; width: 100%; height: clamp(22px, 28%, 60px); }
.ui-sky--compact .sky-hills { height: 32%; }
.ui-sky .sky-hill { fill: var(--hill); }
.ui-sky .sky-hill-2 { fill: var(--hill-2); }
.ui-sky .sky-streetlight { right: 5%; bottom: 0; height: clamp(56px, 86%, 150px); aspect-ratio: 60 / 110; }
.ui-sky--compact .sky-streetlight { height: 96%; right: 72px; }
.ui-sky .sky-post { fill: #2A3350; }
.ui-sky[data-phase="dusk"] .sky-post, .ui-sky[data-phase="night"] .sky-post { fill: #0B1020; }
.ui-sky .sky-lamp { fill: #C9CFDD; transition: fill var(--dur-slow); }
.ui-sky .sky-lamp-glow { fill: #FFD98A; opacity: 0; filter: blur(5px); transition: opacity 1.2s; }
.ui-sky[data-lamp="on"] .sky-lamp { fill: #FFE29A; }
.ui-sky[data-lamp="on"] .sky-lamp-glow { opacity: 0.4; }
/* what shows when */
.ui-sky .sky-stars, .ui-sky .sky-moon-g { opacity: 0; transition: opacity 1.5s; }
.ui-sky[data-phase="night"] .sky-stars, .ui-sky[data-phase="night"] .sky-moon-g { opacity: 1; }
.ui-sky[data-phase="dusk"] .sky-stars { opacity: 0.45; }
.ui-sky[data-phase="dusk"] .sky-moon-g { opacity: 0.8; }
.ui-sky--subtle[data-phase="night"] .sky-stars { opacity: 0.6; }
.ui-sky--playful .sky-body > svg { animation: ui-bob 6s ease-in-out infinite; }
@keyframes ui-cloud-drift { to { transform: translateX(24px); } }
@keyframes ui-twinkle { 50% { opacity: 0.35; } }
@keyframes ui-bob { 50% { transform: translateY(-4px) rotate(-3deg); } }

/* fireflies (sky at night, loading and empty states, and fun.js bursts) */
.ui-fireflies { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.ui-firefly {
  position: absolute; width: 6px; height: 6px; border-radius: 50%;
  background: var(--firefly, #FFE29A); box-shadow: 0 0 10px 3px var(--firefly-glow, rgba(255, 214, 110, 0.6));
  animation: ui-drift 7s ease-in-out infinite;
}
.ui-sky .ui-firefly, .ui-card--brand .ui-firefly, .ui-appbar .ui-firefly { --firefly: #FFE29A; --firefly-glow: rgba(255, 214, 110, 0.6); }
@keyframes ui-drift {
  0%, 100% { transform: translate(0, 0); opacity: 0.3; }
  50% { transform: translate(14px, -18px); opacity: 1; }
}
.ui-burst { position: fixed; inset: 0; pointer-events: none; z-index: 95; }
.ui-burst .ui-firefly { animation: ui-burst var(--burst-dur, 1.8s) var(--ease-out) forwards; animation-delay: var(--delay, 0s); opacity: 0; }
@keyframes ui-burst {
  0% { transform: translate(0, 0) scale(0.6); opacity: 0; }
  12% { opacity: 1; }
  70% { opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) scale(1); opacity: 0; }
}

/* streetlights progress row (fun.js streetlights) */
.ui-streetlights { display: inline-flex; flex-wrap: wrap; max-width: 100%; align-items: flex-end; gap: 6px; color: var(--ink-faint); } /* [a11y2] wraps at 200% zoom instead of pushing the page wider */
.ui-streetlight { width: 18px; height: 34px; flex: none; }
.ui-streetlight .sl-post { fill: currentColor; }
.ui-streetlight .sl-lamp { fill: var(--surface-sunken); stroke: currentColor; stroke-width: 1.5; transition: fill var(--dur-slow); }
.ui-streetlight .sl-glow { fill: #FFD98A; opacity: 0; transition: opacity var(--dur-slow); }
.ui-streetlight.is-lit .sl-lamp { fill: #FFD35C; stroke: #E8A93A; }
.ui-streetlight.is-lit .sl-glow { opacity: 0.55; }
.ui-streetlight.is-new .sl-glow { animation: ui-glow-in 900ms var(--ease-out); }
@keyframes ui-glow-in { 0% { opacity: 0; } 50% { opacity: 0.9; } 100% { opacity: 0.55; } }
.ui-streetlights--lg .ui-streetlight { width: 26px; height: 48px; }

/* "come on out" peek: an avatar rises from behind a tile's top edge (fun.js peek). The clip box sits
   just above the tile, so the part of the avatar still "behind" the tile stays hidden. */
.ui-peek {
  position: absolute; bottom: 100%; right: 14px; z-index: 1; pointer-events: none;
  height: calc(var(--av, 44px) * 0.62); overflow: hidden;
}
.ui-peek--left { right: auto; left: 14px; }
.ui-peek > .ui-avatar { box-shadow: 0 0 0 3px var(--surface); transform: translateY(100%); animation: ui-peek 900ms var(--ease-play) 150ms forwards; }
@keyframes ui-peek { to { transform: translateY(6%); } }

/* boot counter (fun.js bootCounter) */
.ui-boot-text { font: var(--weight-display) var(--text-xl) / 1.2 var(--font-display); min-height: 1.3em; }
.ui-boot-text.is-final { font-family: var(--font-greeting); font-size: var(--text-2xl); color: var(--accent); }

/* ---------- [color-picker] any color (color-picker.js): the rainbow square, the darker strip, basics, recent ---------- */
dialog.ui-cp-sheet .ui-sheet-body { padding-inline: var(--space-4); }
.ui-cp { display: grid; gap: var(--space-3); }
.ui-cp-field { position: relative; width: 100%; aspect-ratio: 3 / 2; border-radius: var(--radius-md); box-shadow: inset 0 0 0 1px var(--line), var(--shadow-1); touch-action: none; user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent; cursor: crosshair; }
.ui-cp--little .ui-cp-field { aspect-ratio: 5 / 4; border-radius: var(--radius-lg); }
.ui-cp-canvas { display: block; width: 100%; height: 100%; border-radius: inherit; }
.ui-cp-loupe {
  position: absolute; width: 34px; height: 34px; margin: -17px 0 0 -17px; border-radius: 50%; background: var(--c, #fff);
  box-shadow: 0 0 0 3px #FFFFFF, 0 0 0 5px #1C2233, 0 3px 10px rgba(0, 0, 0, 0.35); pointer-events: none;
  transition: transform var(--dur-fast, 120ms) var(--ease-out, ease);
}
.ui-cp--little .ui-cp-loupe { width: 44px; height: 44px; margin: -22px 0 0 -22px; }
/* while a finger drags, the loupe grows and lifts above the fingertip so the color shows */
.ui-cp-field.is-dragging .ui-cp-loupe { transform: scale(1.5); }
.ui-cp-field.is-dragging.is-touch .ui-cp-loupe { transform: translateY(-44px) scale(1.7); }
.ui-cp-field:focus-visible, .ui-cp-strip:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
.ui-cp-strip { position: relative; height: 36px; margin-inline: 18px; border-radius: var(--radius-full); background: linear-gradient(to right, var(--base, #f00), #000); box-shadow: inset 0 0 0 1px var(--line); touch-action: none; cursor: pointer; }
.ui-cp-strip::before { content: ""; position: absolute; inset: 0 -18px; } /* a wider place to grab */
.ui-cp-knob { position: absolute; top: 50%; width: 30px; height: 30px; margin: -15px 0 0 -15px; border-radius: 50%; background: var(--c, #000); box-shadow: 0 0 0 3px #FFFFFF, 0 0 0 5px #1C2233; pointer-events: none; }
.ui-cp-show { display: flex; align-items: center; gap: var(--space-3); min-width: 0; }
.ui-cp-preview { flex: none; width: 56px; height: 56px; border-radius: var(--radius-md); background: var(--c, #fff); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--ink) 25%, transparent), var(--shadow-1); }
.ui-cp--little .ui-cp-preview { width: 72px; height: 72px; border-radius: 50%; }
.ui-cp-says { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-3); min-width: 0; flex: 1; }
.ui-cp-name { font: var(--weight-display) var(--text-lg) / 1.2 var(--font-display); }
.ui-cp--little .ui-cp-name { font-size: var(--text-xl); }
.ui-cp-hex { width: 7.5em; min-height: 40px; font-family: ui-monospace, "Cascadia Mono", Menlo, monospace; text-transform: uppercase; }
.ui-cp-row { display: flex; gap: 8px; padding: 6px; margin: -6px; overflow-x: auto; overscroll-behavior-x: contain; scrollbar-width: thin; }
.ui-cp-recent { display: grid; gap: var(--space-1, 4px); }
.ui-cp-label { font-size: var(--text-sm); color: var(--ink-muted); font-weight: 700; }
.ui-cp-swatch {
  flex: none; width: 44px; height: 44px; min-width: 0; padding: 0; border-radius: 50%; background: var(--c); cursor: pointer;
  border: 2px solid color-mix(in srgb, var(--ink) 20%, transparent); -webkit-tap-highlight-color: transparent;
}
.ui-cp-swatch--white { border-color: var(--line-strong); }
.ui-cp-swatch[aria-pressed="true"] { box-shadow: 0 0 0 3px var(--surface-raised), 0 0 0 5px var(--ink); }
.ui-cp-swatch:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
.ui-cp--little .ui-cp-swatch { width: 52px; height: 52px; }

/* ---------- little-one extras: picture-first tiles bounce a bit when pressed ---------- */
:where([data-skin="little"]) .ui-tile:active { transform: scale(var(--press-scale)) rotate(-1deg); }

/* ---------- reduced motion ---------- */
/* [a11y] A safety net for every page and game: with the phone's "reduce motion" (or Settings > Less
   movement, <html data-motion="reduce">) nothing bounces, spins, falls or flies. Animations end at
   once on their last frame (so "animationend" still fires and nothing is left half-way). The named
   rules below keep the few gentle ones (spinners slow down instead of stopping). */
@media (prefers-reduced-motion: reduce) {
  .ui-page *, .ui-page *::before, .ui-page *::after { animation-duration: 1ms !important; animation-delay: 0s !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; transition-delay: 0s !important; scroll-behavior: auto !important; }
}
:where(:root[data-motion="reduce"]) .ui-page *, :where(:root[data-motion="reduce"]) .ui-page *::before, :where(:root[data-motion="reduce"]) .ui-page *::after { animation-duration: 1ms !important; animation-delay: 0s !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; transition-delay: 0s !important; scroll-behavior: auto !important; }
@media (prefers-reduced-motion: reduce) {
  .ui-sky *, .ui-firefly, .ui-skel, .ui-toast, dialog.ui-sheet[open], .ui-peek > .ui-avatar, .ui-streetlight.is-new .sl-glow, .ui-btn, .ui-tile, .ui-tab, .ui-iconbtn, .ui-cp-loupe { animation: none !important; transition: none !important; }
  .ui-peek > .ui-avatar { transform: translateY(6%); }
  .ui-burst .ui-firefly { opacity: 0.8; transform: translate(calc(var(--dx) * 0.3), calc(var(--dy) * 0.3)); }
  .ui-btn[aria-busy="true"]::after, .ui-spinner { animation-duration: 2.4s !important; animation-iteration-count: infinite !important; }
}
:where(:root[data-motion="reduce"]) :is(.ui-btn[aria-busy="true"]::after, .ui-spinner) { animation-duration: 2.4s !important; animation-iteration-count: infinite !important; }
:where([data-motion="reduce"]) :is(.ui-sky *, .ui-firefly, .ui-skel, .ui-toast, dialog.ui-sheet[open], .ui-peek > .ui-avatar, .ui-streetlight.is-new .sl-glow, .ui-btn, .ui-tile, .ui-tab, .ui-iconbtn) { animation: none !important; transition: none !important; }
:where([data-motion="reduce"]) .ui-peek > .ui-avatar { transform: translateY(6%); }
:where([data-motion="reduce"]) .ui-burst .ui-firefly { opacity: 0.8; transform: translate(calc(var(--dx) * 0.3), calc(var(--dy) * 0.3)); }

/* ---------- [landscape] a phone on its side (wide and short) ----------
   The height is precious there (about 360 to 430px): the tab bar becomes a slim rail on the left (like
   the side rail at 900px+), the app bar is slimmer (tokens.css), sheets use the whole height and scroll
   inside, and notches on the side are respected (safe-area-inset-left and right). */
@media (orientation: landscape) and (max-height: 500px) {
  .ui-tabbar {
    top: 0; right: auto; width: calc(var(--rail-w) + env(safe-area-inset-left, 0px));
    grid-auto-flow: row; grid-auto-rows: max-content; align-content: center; gap: 2px; overflow-y: auto;
    padding: calc(var(--appbar-h) + env(safe-area-inset-top, 0px)) 4px max(4px, env(safe-area-inset-bottom, 0px)) calc(4px + env(safe-area-inset-left, 0px));
    border-top: 0; border-right: 1px solid var(--line); box-shadow: none;
  }
  .ui-tab { min-height: var(--tap); padding-block: 3px; font-size: 11px; }
  .ui-tab .ui-icon { width: 22px; height: 22px; padding: 3px 12px; }
  :where([data-skin="little"]) .ui-tab { font-size: 12px; }
  :where([data-skin="little"]) .ui-tab .ui-icon { width: 26px; height: 26px; }
  .ui-tab .ui-badge { left: calc(50% + 6px); }
  .ui-with-tabbar { padding-bottom: var(--space-4); padding-left: calc(var(--rail-w) + env(safe-area-inset-left, 0px)); }
  .ui-main { padding-top: var(--space-3); gap: var(--space-4); }
  .ui-appbar { --tap: 44px; } /* the little ones' bigger buttons too: 44px is still a full tap target */
  .ui-appbar-title { font-size: var(--text-md); }
  dialog.ui-sheet { margin: auto; max-height: calc(100vh - 16px); max-height: calc(100dvh - 16px); width: min(640px, 100% - 24px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px)); }
  .ui-sheet-head { padding-top: var(--space-2); }
  .ui-sheet-body { min-height: 0; padding-block: var(--space-2); }
  .ui-sheet-actions { grid-auto-flow: column; justify-content: end; padding-block: var(--space-2) var(--space-3); }
}

/* ---------- [a11y] Help me see colors ----------
   Game pieces told apart only by color carry a small shape (apps/games/public/cues.js): hidden until
   Settings > "Help me see colors" puts data-see="shapes" on <html>. Red triangle, blue circle, green
   square, yellow star, purple diamond, orange cross. */
.ui-cue { display: none; }
:root[data-see="shapes"] .ui-cue { display: inline; }
:root[data-see="shapes"] span.ui-cue {
  position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none;
  font: 900 calc(var(--cue-size, 1em)) / 1 var(--font-body); color: #FFFFFF; text-shadow: 0 0 2px rgba(0, 0, 0, 0.55);
}
:root[data-see="shapes"] span.ui-cue:is(.ui-cue--yellow, .ui-cue--orange) { color: #1C2233; text-shadow: 0 0 2px rgba(255, 255, 255, 0.7); }
:root[data-see="shapes"] text.ui-cue { fill: #FFFFFF; stroke: rgba(0, 0, 0, 0.45); stroke-width: 0.6px; paint-order: stroke; font-weight: 900; text-anchor: middle; dominant-baseline: central; pointer-events: none; }
:root[data-see="shapes"] text.ui-cue:is(.ui-cue--yellow, .ui-cue--orange) { fill: #1C2233; stroke: rgba(255, 255, 255, 0.6); }

/* ---------- [a11y] big text and zoom ----------
   With the phone's text made bigger or the page zoomed to 200% (a 375px phone then lays out at about
   188px), nothing may be cut off or pushed off the side (tools/a11y.mjs --zoom=2 checks it). One-column
   grids shrink to the screen instead of growing to their widest word, long words wrap, section heads
   and rows let their buttons drop to a new line, and a very narrow tab bar keeps its icons (the words
   stay for screen readers). */
.ui-page { overflow-wrap: anywhere; }
.ui-main, .ui-stack, .ui-list, .ui-sheet-body, .ui-sheet-actions { grid-template-columns: minmax(0, 1fr); } /* [storeready] sheets too: at 200% a long button's text grew past its border */
.ui-card, .ui-field, .ui-row-main, .ui-banner-text { min-width: 0; }
.ui-section-head { flex-wrap: wrap; }
/* [fixes-b] A real minimum width for the title, so a long muted note beside it wraps under it (the title used to break one letter per line). */
.ui-section-head > h2, .ui-section-head > .ui-section-title { min-width: min(100%, 9em); }
@media (max-width: 340px) {
  .ui-row { flex-wrap: wrap; }
  .ui-row-end { margin-left: auto; }
  .ui-appbar { gap: var(--space-1); }
  .ui-appbar-title { min-width: 0; font-size: var(--text-md); order: 5; flex-basis: 100%; white-space: normal; padding-bottom: var(--space-2); } /* the whole name on its own line below the buttons */
  .ui-tab > span:not(.ui-badge) { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
  .ui-tab .ui-icon { padding-inline: 4px; }
  .ui-tabbar { grid-auto-columns: minmax(0, 1fr); padding-inline: 2px; }
  .ui-tab { padding-inline: 0; }
  .ui-appbar { flex-wrap: wrap; row-gap: 0; }
  .ui-appbar-actions { margin-left: auto; }
  .ui-page input[type="range"] { min-width: 0; width: 100%; }
  .ui-seg { flex-wrap: wrap; }
  .ui-seg > label { flex: 1 1 auto; }
  .ui-btn { white-space: normal; max-width: 100%; }
  .ui-sheet-title { font-size: var(--text-md); hyphens: auto; } /* [storeready] a sheet's title breaks with a hyphen, not anywhere, at 200% */
  dialog.ui-sheet[open] { display: block; overflow-y: auto; } /* [storeready] the whole sheet scrolls (the buttons too), not a tiny window of it */
  .ui-sheet-body { overflow: visible; }
  .ui-appbar-actions { flex-wrap: wrap; justify-content: flex-end; max-width: 100%; } /* [storeready] a chat's four buttons fit */
  .ui-sheet-head { padding-left: var(--space-4); }
  .ui-sheet-body, .ui-sheet-actions { padding-left: var(--space-4); padding-right: var(--space-4); }
}

/* ---------- [ux] search and filters (public/ui/search.js) ---------- */
.ui-fd { display: grid; gap: var(--space-2); margin: 0 0 var(--space-4); min-width: 0; }
.ui-fd-search { position: relative; display: flex; align-items: center; min-width: 0; }
.ui-fd-search > .ui-icon { position: absolute; left: 14px; color: var(--ink-muted); pointer-events: none; }
.ui-fd-input { padding-left: 46px; padding-right: 48px; border-radius: var(--radius-full); }
.ui-fd-input::-webkit-search-cancel-button { display: none; }
.ui-fd-clear { position: absolute; right: 2px; }
.ui-fd-clear[hidden] { display: none; }
.ui-fd-rows { display: grid; gap: var(--space-2); min-width: 0; }
.ui-fd-row { display: flex; gap: var(--space-2); overflow-x: auto; padding: 2px 2px 4px; scrollbar-width: none; min-width: 0; }
.ui-fd-row::-webkit-scrollbar { display: none; }
.ui-fd-chip { flex: none; display: inline-flex; align-items: center; white-space: nowrap; cursor: pointer; }
.ui-fd-chip[aria-pressed="true"]::before { content: ""; display: inline-block; width: 10px; height: 6px; margin-right: 6px; border: solid currentColor; border-width: 0 0 2.5px 2.5px; transform: translateY(-2px) rotate(-45deg); }
.ui-fd-count { margin: 0; font-size: var(--text-sm); }
.ui-fd-count[hidden] { display: none; }
/* [games-browse] one "Filters" button that folds the chips away; a small count of what is chosen */
.ui-fd-toggle { justify-self: start; }
.ui-fd-toggle-n { display: inline-grid; place-items: center; min-width: 20px; height: 20px; margin-left: 6px; padding: 0 5px; border-radius: var(--radius-full); background: var(--accent); color: var(--accent-text, #fff); font-size: var(--text-xs); }
.ui-fd-toggle-n[hidden] { display: none; }
.ui-fd-rows[hidden] { display: none; }
.ui-fd-empty { padding-block: var(--space-6); }
.ui-fd-little { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: var(--space-3); margin: 0 0 var(--space-4); }
.ui-fd-big { display: grid; justify-items: center; align-content: center; gap: 6px; min-height: 112px; padding: var(--space-3) var(--space-2); border: 3px solid var(--line); border-radius: var(--radius-lg); background: var(--surface); color: var(--ink); font: var(--weight-strong) var(--text-md) / 1.15 var(--font-body); cursor: pointer; text-align: center; }
.ui-fd-big[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); }
.ui-fd-big:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.ui-fd-big-art { display: grid; place-items: center; width: 56px; height: 56px; }
.ui-fd-big-all { border-radius: 16px; background: var(--brand); color: #fff; }
@media (max-width: 340px) { .ui-fd-little { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
/* [ux] the search sheet from the app bar (public/screens/search.js) */
.ui-gs-results { display: grid; gap: var(--space-4); margin-top: var(--space-3); }
.ui-gs-results h3 { margin: 0 0 var(--space-1); font: var(--weight-strong) var(--text-sm) / 1.2 var(--font-body); color: var(--ink-muted); }
.ui-gs-hint { margin: var(--space-2) 0 0; }
