/* Night Gallery screens. Tokens: tokens.css. Reference: docs/design/prototype-night-gallery.html. */

*, *::before, *::after { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { background: var(--bg); color: var(--ink); font: var(--body); -webkit-text-size-adjust: 100%; overflow-x: hidden; }
body { margin: 0; min-height: 100vh; min-height: 100dvh; overflow-x: hidden; }
html.is-locked, html.is-locked body { overflow: hidden; }
img { -webkit-user-drag: none; user-select: none; }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--tint); outline-offset: 2px; }
:lang(ar), [dir="rtl"] { font-family: var(--font-arabic); }

/* pressed state on pointer-DOWN (class added in JS) and :active as a fallback */
.press { transition: transform var(--press-dur) ease-out; }
.press:active, .press.is-down { transform: scale(var(--press-scale)); }

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

/* ---------- Top bar: appears when the large title scrolls away (scroll-edge fade, no hard divider) ---------- */
.topbar { position: fixed; inset: 0 0 auto 0; height: calc(64px + env(safe-area-inset-top)); z-index: 4; pointer-events: none;
  background: linear-gradient(rgba(0,0,0,.9), rgba(0,0,0,.75) 60%, rgba(0,0,0,0));
  -webkit-backdrop-filter: blur(18px) saturate(160%); backdrop-filter: blur(18px) saturate(160%);
  -webkit-mask: linear-gradient(#000 70%, transparent); mask: linear-gradient(#000 70%, transparent);
  opacity: 0; } /* opacity follows the scroll position (app.mjs followScroll) */
.topbar b { position: absolute; left: 0; right: 0; bottom: 22px; text-align: center; font: 600 17px/1 var(--font-ui); letter-spacing: -0.01em; }

/* ---------- Page ---------- */
.shell { max-width: 1200px; margin: 0 auto; padding: calc(44px + env(safe-area-inset-top)) 0 calc(130px + env(safe-area-inset-bottom)); }
.head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 var(--gutter) 10px; }
.head > div:first-child { min-width: 0; } /* shrink to fit "Stacky" + mascot at 360px instead of pushing the seg control out */
.large-title { font: var(--large-title); letter-spacing: var(--tracking-large); margin: 0; }
.count { font: var(--caption); color: var(--ink-2); margin: 4px 0 0; }
.demo-tag { display: inline-block; margin-left: 8px; padding: 2px 7px; border-radius: 6px; background: var(--cell-2); color: var(--ink-2); font: 600 11px/1.4 var(--font-ui); letter-spacing: .04em; text-transform: uppercase; vertical-align: 2px; }

/* segmented control (Gallery / List) */
.seg { position: relative; display: flex; flex: none; background: var(--fill); border-radius: 9px; padding: 2px; margin-bottom: 4px; }
.seg__thumb { position: absolute; top: 2px; left: 2px; width: 40px; height: 30px; border-radius: 7px; background: #636366; box-shadow: 0 2px 6px rgba(0,0,0,.4);
  transition: transform var(--spring-dur, 450ms) var(--spring-ease, cubic-bezier(.2,.8,.2,1)); }
.seg[data-view="list"] .seg__thumb { transform: translateX(40px); }
.seg__btn { all: unset; position: relative; cursor: pointer; width: 40px; height: 30px; display: grid; place-items: center; border-radius: 7px; color: var(--ink-2); transition: color .15s; }
.seg__btn::after { content: ""; position: absolute; inset: -7px -2px; } /* 44px touch target */
.seg__btn[aria-pressed="true"] { color: #fff; }
.seg__btn svg { width: 17px; height: 17px; }

/* Settings button: round glass, same as the sheet's close button; sits left of the segmented control */
.settings-open { all: unset; cursor: pointer; position: relative; flex: none; margin: 0 0 5px auto; width: 32px; height: 32px; border-radius: 50%; background: rgba(44,44,46,.8); -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); display: grid; place-items: center; color: #fff; }
.settings-open::after { content: ""; position: absolute; inset: -6px; }
.settings-open svg { width: 17px; height: 17px; }

/* category chips */
.chips { display: flex; gap: 8px; padding: 2px var(--gutter) 14px; overflow-x: auto; scrollbar-width: none; overscroll-behavior-x: contain; }
.chips::-webkit-scrollbar { display: none; }
.chip { all: unset; flex: none; cursor: pointer; position: relative; font: 600 13px/1 var(--font-ui); padding: 10px 13px; border-radius: 999px; background: var(--cell); color: var(--ink-2); display: flex; gap: 6px; align-items: center; white-space: nowrap; }
.chip::after { content: ""; position: absolute; inset: -4px 0; }
.chip__dot { width: 7px; height: 7px; border-radius: 50%; background: var(--c); }
.chip__n { font-weight: 500; opacity: .75; font-variant-numeric: tabular-nums; }
.chip[aria-pressed="true"] { background: #fff; color: #000; }

/* install hint: a small glass card under the chips */
.hint { display: flex; align-items: center; gap: 10px; margin: 0 var(--gutter) 14px; padding: 10px 10px 10px 12px; border-radius: 16px;
  background: var(--glass); -webkit-backdrop-filter: blur(22px) saturate(170%); backdrop-filter: blur(22px) saturate(170%); border-top: 1px solid var(--glass-edge); box-shadow: 0 8px 24px rgba(0,0,0,.4); }
.hint__ic { flex: none; width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; background: var(--tint-soft); color: var(--tint); }
.hint__ic svg { width: 18px; height: 18px; }
.hint__text { flex: 1; min-width: 0; margin: 0; font: 600 13.5px/1.3 var(--font-ui); letter-spacing: -0.005em; }
.hint__acts { flex: none; display: flex; gap: 6px; }
.hint__btn { all: unset; cursor: pointer; position: relative; height: 32px; padding: 0 12px; border-radius: 999px; background: var(--cell-2); color: var(--ink); font: 600 13px/32px var(--font-ui); white-space: nowrap; }
.hint__btn::after { content: ""; position: absolute; inset: -6px -3px; }
.hint__btn--how { background: var(--tint); color: #fff; }

/* batch progress ("Sorting 3 of 20", brief AC3) */
.progress { margin: 0 var(--gutter) 12px; padding: 10px 14px; border-radius: var(--r-row); background: var(--cell); font: var(--caption); color: var(--ink-2); display: flex; align-items: center; gap: 10px; }
.progress__bar { flex: 1; height: 4px; border-radius: 2px; background: var(--cell-3); overflow: hidden; }
.progress__bar i { display: block; height: 100%; width: 0; background: var(--tint); border-radius: 2px; transition: width .3s ease; }
.progress b { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }

.view { animation: view-in var(--fade-dur) ease; }
@keyframes view-in { from { opacity: 0; } to { opacity: 1; } }

/* ---------- Gallery: masonry of the pictures ---------- */
.masonry { display: flex; gap: var(--gap); padding: 0 10px; align-items: flex-start; }
.masonry__col { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; gap: var(--gap); }
@media (min-width: 768px) { .masonry { padding: 0 var(--gutter); } }

.tile { all: unset; display: block; cursor: pointer; position: relative; border-radius: var(--r-tile); overflow: hidden; background: #111; width: 100%; box-sizing: border-box; }
.tile__img { width: 100%; display: block; min-height: 90px; max-height: 340px; object-fit: cover; object-position: top; background: #151517; }
.tile__cap { position: absolute; left: 0; right: 0; bottom: 0; padding: 26px 10px 9px; background: linear-gradient(rgba(0,0,0,0), rgba(0,0,0,.85)); font: 600 12.5px/1.25 var(--font-ui); letter-spacing: -0.005em; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.tile__dot { position: absolute; top: 9px; left: 9px; width: 8px; height: 8px; border-radius: 50%; background: var(--c); box-shadow: 0 0 0 2px rgba(0,0,0,.5); }
.tile__badge { position: absolute; top: 8px; right: 8px; font: 700 10px/1 var(--font-ui); letter-spacing: .02em; padding: 4px 6px; border-radius: 6px; background: var(--new); color: #fff; }
.tile__badge--done { background: rgba(44,44,46,.85); color: var(--ink-2); }
.tile.is-done .tile__img { opacity: .55; }

/* pending / failed pictures (brief AC2, AC10) */
.tile--pending { cursor: default; }
.tile--pending .tile__img { opacity: .45; filter: saturate(.6); }
.tile__status { position: absolute; left: 0; right: 0; bottom: 0; padding: 30px 10px 10px; background: linear-gradient(rgba(0,0,0,0), rgba(0,0,0,.9)); }
.tile__status b { display: block; font: 600 12.5px/1.25 var(--font-ui); }
.tile__status small { display: block; margin-top: 3px; font: var(--footnote); color: var(--ink-2); }
.tile__actions { display: flex; gap: 6px; margin-top: 8px; }
.mini-btn { all: unset; cursor: pointer; position: relative; font: 600 12px/1 var(--font-ui); padding: 8px 11px; border-radius: 999px; background: var(--cell-2); color: var(--ink); }
.mini-btn::after { content: ""; position: absolute; inset: -6px -2px; }
.mini-btn--primary { background: var(--tint); }
.shimmer { position: absolute; inset: 0; background: linear-gradient(100deg, transparent 30%, rgba(255,255,255,.09) 50%, transparent 70%); background-size: 250% 100%; animation: shimmer 1.4s linear infinite; }
@keyframes shimmer { from { background-position: 120% 0; } to { background-position: -120% 0; } }
.spinner { display: inline-block; width: 12px; height: 12px; border-radius: 50%; border: 2px solid rgba(255,255,255,.25); border-top-color: #fff; animation: spin .8s linear infinite; vertical-align: -2px; margin-right: 6px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- List: inset grouped rows (dark System Shelf) ---------- */
.listwrap { padding: 0 var(--gutter); max-width: 760px; }
.sorter { display: flex; justify-content: space-between; align-items: center; margin: 2px 4px 8px; font: var(--caption); color: var(--ink-2); }
.sorter__btn { all: unset; cursor: pointer; color: var(--tint); font: 500 13px/1 var(--font-ui); padding: 14px 0 14px 12px; margin: -14px 0; }
.sec { font: 600 13px/1 var(--font-ui); color: var(--ink-2); text-transform: uppercase; letter-spacing: .03em; margin: 18px 4px 7px; }
.group { background: var(--cell); border-radius: var(--r-row); overflow: hidden; }
.row { all: unset; cursor: pointer; display: flex; gap: 12px; align-items: center; padding: 9px 12px; position: relative; width: 100%; box-sizing: border-box; min-height: 68px; }
.row + .row::before { content: ""; position: absolute; top: 0; left: 74px; right: 0; border-top: .5px solid var(--sep); }
.row__thumb { width: 50px; height: 50px; object-fit: cover; object-position: top; border-radius: var(--r-thumb); flex: none; background: #151517; }
.row__text { flex: 1; min-width: 0; }
.row__title { display: block; font: 600 15.5px/1.25 var(--font-ui); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row__meta { display: block; font: var(--footnote); color: var(--ink-2); margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row__cat { font-weight: 600; color: var(--c); }
.row__new { color: var(--tint); font-weight: 600; }
.row__chev { color: var(--ink-3); font-size: 20px; line-height: 1; flex: none; }
.row.is-done .row__thumb, .row.is-done .row__title { opacity: .55; }
.row--pending { cursor: default; }

/* footer: habit check (brief AC8) */
.foot { text-align: center; font: var(--footnote); color: var(--ink-3); margin: 28px var(--gutter) 0; }

/* ---------- Empty / no results ---------- */
.empty { display: grid; justify-items: center; text-align: center; padding: 56px 32px 24px; }
.empty__art { width: 132px; height: 112px; margin-bottom: 22px; }
.empty__title { font: 700 22px/1.2 var(--font-ui); letter-spacing: -0.015em; margin: 0 0 8px; }
.empty__line { font: var(--body); color: var(--ink-2); margin: 0 0 22px; max-width: 30ch; }
.pill-btn { all: unset; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: var(--tap); padding: 0 22px; border-radius: 999px; background: #fff; color: #000; font: 600 15px/1 var(--font-ui); }
.pill-btn--quiet { background: var(--cell-2); color: var(--ink); }

/* ---------- Floating glass dock ---------- */
.dock { position: fixed; left: 50%; bottom: calc(22px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 5; display: flex; gap: 6px; align-items: center; padding: 6px; border-radius: 999px; max-width: calc(100vw - 24px);
  background: var(--glass); -webkit-backdrop-filter: blur(22px) saturate(170%); backdrop-filter: blur(22px) saturate(170%);
  border-top: 1px solid var(--glass-edge); box-shadow: 0 10px 30px rgba(0,0,0,.55); }
.dock__btn { all: unset; cursor: pointer; height: var(--tap); padding: 0 16px; border-radius: 999px; font: 600 13px/44px var(--font-ui); color: #fff; letter-spacing: .01em; display: inline-flex; align-items: center; gap: 7px; }
.dock__btn svg { width: 16px; height: 16px; }
.dock__add { width: var(--tap); padding: 0; justify-content: center; background: #fff; color: #000; }
.dock__add svg { width: 20px; height: 20px; }
.dock__field { display: none; align-items: center; gap: 8px; height: var(--tap); padding: 0 14px; border-radius: 999px; background: rgba(118,118,128,.24); width: min(300px, calc(100vw - 130px)); }
.dock__field svg { width: 16px; height: 16px; color: var(--ink-2); flex: none; }
.dock__input { all: unset; flex: 1; min-width: 0; font: 400 16px/1 var(--font-ui); color: #fff; }
.dock__input::placeholder { color: var(--ink-2); }
.dock.is-searching .dock__field { display: flex; }
.dock.is-searching .dock__btn:not(.dock__cancel) { display: none; }
.dock__cancel { display: none; }
.dock.is-searching .dock__cancel { display: inline-flex; color: var(--tint); }

/* ---------- Detail sheet: grows from the tapped picture ---------- */
.scrim { position: fixed; inset: 0; background: var(--scrim); opacity: 0; z-index: 8; pointer-events: none; }
.scrim.is-on { pointer-events: auto; }
.sheet { position: fixed; inset: 0; z-index: 9; background: var(--sheet-bg); border-radius: var(--r-sheet) var(--r-sheet) 0 0; overflow: hidden; will-change: transform, clip-path; transform-origin: 0 0; --b: 1; }
@media (min-width: 760px) {
  .sheet { inset: 24px auto 24px 50%; width: min(640px, calc(100vw - 48px)); margin-left: calc(min(640px, calc(100vw - 48px)) / -2); border-radius: var(--r-sheet); box-shadow: 0 30px 80px rgba(0,0,0,.6); }
}
.sheet__in { position: absolute; inset: 0; overflow-y: auto; overflow-x: hidden; padding-bottom: calc(40px + env(safe-area-inset-bottom)); scrollbar-width: none; overscroll-behavior: contain; touch-action: pan-y; }
.sheet__in::-webkit-scrollbar { display: none; }
.sheet__doc { will-change: transform; }
/* the tapped tile's dot, badge and caption ride along on the picture and fade by 1/3 of the open */
.sheet__ghost { position: absolute; top: 0; left: 0; z-index: 2; transform-origin: 0 0; pointer-events: none; overflow: hidden; }
.sheet__grab, .sheet__close { opacity: var(--b); }
.sheet__grab { position: absolute; top: 0; left: 50%; transform: translateX(-50%); width: 120px; height: 24px; z-index: 3; touch-action: none; cursor: grab; }
.sheet__grab::before { content: ""; position: absolute; top: 8px; left: 41px; width: 38px; height: 5px; border-radius: 3px; background: rgba(255,255,255,.35); }
.sheet__close { all: unset; cursor: pointer; position: absolute; top: 14px; right: 14px; z-index: 3; width: 32px; height: 32px; border-radius: 50%; background: rgba(44,44,46,.8); -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); display: grid; place-items: center; color: #fff; }
.sheet__close::after { content: ""; position: absolute; inset: -6px; }
.sheet__close svg { width: 13px; height: 13px; }

/* the hero's height is set once per open (the picture's crop); the picture inside is its full height
   and clip-path shows the tile's crop at first, then the hero's */
.hero { position: relative; background: #111; touch-action: none; cursor: zoom-in; user-select: none; min-height: 120px; }
.hero:focus-visible { outline-offset: -3px; } /* the sheet clips anything outside it */
.hero__img { position: absolute; top: 0; left: 0; width: 100%; height: auto; display: block; will-change: clip-path; }
.hero::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 90px; background: linear-gradient(rgba(11,11,12,0), var(--sheet-bg)); pointer-events: none; opacity: var(--b); }
/* tap the picture to see all of it: the badge sits above the page's overlap (.detail's -34px) */
.hero__expand { position: absolute; right: 12px; bottom: 46px; z-index: 2; width: 32px; height: 32px; border-radius: 50%; background: rgba(0,0,0,.6); -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); display: grid; place-items: center; color: #fff; pointer-events: none; opacity: var(--b); }
.hero__expand svg { width: 15px; height: 15px; }

/* ---------- Full-picture viewer: the sheet's picture grows to the whole screen on black ---------- */
.viewer { position: fixed; inset: 0; z-index: 11; touch-action: none; overflow: hidden; cursor: zoom-out; }
.viewer__bg { position: absolute; inset: 0; background: #000; opacity: 0; }
.viewer__img { position: absolute; left: 0; top: 0; max-width: none; transform-origin: 0 0; will-change: transform, clip-path; }
.viewer__close { all: unset; cursor: pointer; position: absolute; top: calc(14px + env(safe-area-inset-top)); right: 14px; z-index: 2; width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; color: #fff; opacity: 0; }
.viewer__close::before { content: ""; position: absolute; inset: 6px; border-radius: 50%; background: rgba(44,44,46,.8); -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); z-index: -1; }
.viewer__close svg { width: 13px; height: 13px; }

.detail { padding: 0 20px; margin-top: -34px; position: relative; opacity: var(--b); transform: translateY(calc((1 - var(--b)) * 24px)); }
.cat-pill { all: unset; cursor: pointer; position: relative; display: inline-flex; gap: 6px; align-items: center; font: 700 11.5px/1 var(--font-ui); letter-spacing: .04em; text-transform: uppercase; padding: 7px 10px; border-radius: 7px; background: rgba(255,255,255,.08); color: var(--c); }
.cat-pill::after { content: ""; position: absolute; inset: -8px -4px; }
.cat-pill__dot { width: 7px; height: 7px; border-radius: 50%; background: var(--c); }
.cat-pill__edit { color: var(--ink-3); font-weight: 600; letter-spacing: 0; text-transform: none; }
.cat-pick { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.cat-pick .chip { padding: 9px 11px; font-size: 12.5px; }
.detail__title { font: var(--title-2); letter-spacing: var(--tracking-title); margin: 12px 0 4px; overflow-wrap: anywhere; }
.detail__meta { font: var(--caption); font-weight: 400; color: var(--ink-2); }
.detail__summary { font: var(--body); color: var(--ink-body); margin: 14px 0 0; overflow-wrap: anywhere; }

.list-empty { margin: 28px 4px; text-align: center; font: var(--caption); color: var(--ink-2); }
.card { position: relative; background: var(--cell); border-radius: var(--r-card); margin-top: 16px; overflow: hidden; }
/* copy button in a card's heading row (Explained, Text in the picture) - 44px target, small glyph */
.card__copy { all: unset; cursor: pointer; position: absolute; top: 0; inset-inline-end: 0; width: 44px; height: 40px; display: grid; place-items: center; color: var(--ink-2); }
.card__copy svg { width: 16px; height: 16px; }
.card__copy:focus-visible { outline: 2px solid var(--tint, #0a84ff); outline-offset: -4px; border-radius: 10px; }
.card__copy + .xp-text, .card__copy + .ocr { margin-top: 0; }
.card__h { margin: 0; padding: 12px 14px 6px; font: var(--section); letter-spacing: .06em; text-transform: uppercase; color: var(--ink-2); }
.fact { display: flex; justify-content: space-between; gap: 12px; padding: 10px 14px; border-top: .5px solid var(--sep); font: 400 14.5px/1.35 var(--font-ui); }
.card__h + .fact { border-top: 0; }
.fact__k { color: var(--ink-2); flex: none; max-width: 45%; }
.fact__v { font-weight: 600; text-align: end; min-width: 0; overflow-wrap: anywhere; }
.fact--solo .fact__v { text-align: start; font-weight: 500; }
.link { all: unset; cursor: pointer; display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-top: .5px solid var(--sep); width: 100%; box-sizing: border-box; min-height: 56px; }
.card__h + .link { border-top: 0; }
.link__ic { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; background: var(--tint-soft); color: var(--tint); flex: none; }
.link__ic svg { width: 14px; height: 14px; }
.link__text { min-width: 0; }
.link__label { display: block; font: 600 14.5px/1.2 var(--font-ui); color: var(--tint); overflow-wrap: anywhere; }
.link__sub { font: 400 12px/1.3 var(--font-ui); color: var(--ink-2); }
.creator-note { padding: 2px 14px 12px; font: 400 12px/1.4 var(--font-ui); color: var(--ink-2); margin: 0; overflow-wrap: anywhere; }
.ocr { padding: 4px 14px 14px; font: 400 13.5px/1.55 var(--font-ui); color: var(--ink-ocr); white-space: pre-line; overflow-wrap: anywhere; margin: 0; }

/* ---------- Explained / Where it's from / Go further / More like this (docs/design/detail-explain-spec.md):
   the same cards and headings as Pulled out; port of the prototype's xp-* rules ---------- */
.ocr.xp-clamp { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 6; overflow: hidden; padding-bottom: 0; margin-bottom: 14px; }
.xp-more { all: unset; cursor: pointer; display: block; min-height: var(--tap); padding: 0 14px; margin-top: -8px; font: 600 13.5px/44px var(--font-ui); color: var(--tint); }
.xp-text { padding: 4px 14px 6px; }
.xp-text p { margin: 0 0 10px; max-width: 62ch; font: 400 15px/1.55 var(--font-ui); color: var(--ink-body); overflow-wrap: anywhere; }
.xp-src { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; padding: 6px 14px 13px; font: 400 14.5px/1.35 var(--font-ui); overflow-wrap: anywhere; }
.xp-src i { font-style: italic; }
.xp-conf { flex: none; font: 600 12px/1 var(--font-ui); padding: 6px 9px; border-radius: 999px; white-space: nowrap; }
.xp-conf--recognised { background: rgba(255,255,255,.08); color: var(--ink); }
.xp-conf--best_guess { box-shadow: inset 0 0 0 1px var(--ink-3); color: var(--ink-2); }
.xp-conf--unknown { color: var(--ink-3); }
.xp-ref { all: unset; cursor: pointer; display: flex; align-items: center; gap: 10px; min-height: var(--tap); padding: 10px 14px; border-top: .5px solid var(--sep); width: 100%; box-sizing: border-box; }
.card__h + .xp-ref, .card__h + .xp-skrow { border-top: 0; }
.xp-main { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.xp-main b { font: 600 14.5px/1.3 var(--font-ui); color: var(--tint); }
.xp-kind { display: inline-block; vertical-align: 1px; margin-inline-start: 6px; font: 600 10.5px/1 var(--font-ui); letter-spacing: .03em; padding: 3px 6px; border-radius: 5px; background: rgba(255,255,255,.08); color: var(--ink-2); }
.xp-why { display: block; margin-top: 3px; font: 400 13px/1.4 var(--font-ui); color: var(--ink-2); }
.xp-via { flex: none; display: flex; align-items: center; gap: 6px; text-align: end; font: 400 11px/1.3 var(--font-ui); color: var(--ink-3); white-space: nowrap; }
.xp-via span { color: var(--tint); font-size: 14px; line-height: 1; }
.xp-via i { font-style: normal; }
.xp-foot { margin: 12px 4px 0; font: 400 12px/1.4 var(--font-ui); color: var(--ink-3); }
.xp-redo { all: unset; cursor: pointer; position: relative; color: var(--tint); font-weight: 600; white-space: nowrap; }
.xp-redo::after { content: ""; position: absolute; inset: -14px -8px; } /* 44 px tap target around the small inline word */
.xp-redo-wait { color: var(--ink-2); white-space: nowrap; }
.xp-skel { padding: 6px 14px 14px; }
.xp-bar { position: relative; overflow: hidden; height: 12px; border-radius: 6px; background: var(--cell-2); margin-top: 10px; }
.xp-bar:first-child { margin-top: 4px; }
.xp-bar--thin { height: 10px; }
.xp-bar::after { content: ""; position: absolute; inset: 0; transform: translateX(-100%); background: linear-gradient(90deg, rgba(255,255,255,0), rgba(255,255,255,.08), rgba(255,255,255,0)); animation: xp-shine 1.1s ease-in-out infinite; }
.xp-skrow { padding: 10px 14px; border-top: .5px solid var(--sep); }
@keyframes xp-shine { to { transform: translateX(100%); } }

.actions { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; margin-top: 18px; }
.action { all: unset; cursor: pointer; text-align: center; min-height: var(--tap); padding: 0 6px; border-radius: 12px; background: var(--cell); font: 600 14px/44px var(--font-ui); box-sizing: border-box; }
.action--primary { background: var(--tint); }
.action--danger { color: var(--danger); }
.action--danger[aria-pressed="true"] { background: var(--danger); color: #fff; }

/* ---------- Toast (Undo) ---------- */
.toast { position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translate(-50%, 16px) scale(.94); opacity: 0; z-index: 12; max-width: calc(100vw - 32px);
  padding: 0 8px 0 16px; min-height: 44px; border-radius: 999px; background: var(--glass); -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px); border-top: 1px solid var(--glass-edge);
  font: 600 13px/1.3 var(--font-ui); display: flex; gap: 6px; align-items: center; transition: opacity .18s, transform var(--spring-dur, 450ms) var(--spring-ease, cubic-bezier(.2,.8,.2,1)); pointer-events: none; box-shadow: 0 10px 30px rgba(0,0,0,.5); }
.toast.is-on { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.toast__msg { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding-right: 8px; }
.toast__undo { all: unset; cursor: pointer; color: var(--tint); padding: 0 10px; min-height: 44px; display: flex; align-items: center; }

/* ---------- Passcode panel ---------- */
.panel { position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 14; width: min(360px, calc(100vw - 32px)); padding: 22px 20px 18px; border-radius: 20px; background: var(--cell); box-shadow: 0 30px 80px rgba(0,0,0,.7); }
.panel__title { font: 700 19px/1.25 var(--font-ui); letter-spacing: -0.01em; margin: 0 0 6px; }
.panel__line { font: var(--caption); font-weight: 400; color: var(--ink-2); margin: 0 0 16px; }
.panel__input { all: unset; display: block; width: 100%; box-sizing: border-box; height: var(--tap); padding: 0 14px; border-radius: 12px; background: var(--cell-2); font: 400 16px/1 var(--font-ui); color: #fff; }
.panel__err { font: var(--footnote); color: var(--danger); min-height: 18px; margin: 8px 0 4px; }
.panel__row { display: flex; gap: 10px; justify-content: flex-end; }
.panel-scrim { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 13; }

/* ---------- Settings: a dark full-height panel that slides up (spring in app.mjs) ---------- */
.settings-scrim { position: fixed; inset: 0; z-index: 10; background: var(--scrim); opacity: 0; }
.settings { position: fixed; z-index: 10; left: 0; right: 0; top: calc(10px + env(safe-area-inset-top)); bottom: 0; display: flex; flex-direction: column;
  background: var(--sheet-bg); border-radius: var(--r-sheet) var(--r-sheet) 0 0; box-shadow: 0 -10px 40px rgba(0,0,0,.5); overflow: hidden; will-change: transform; }
@media (min-width: 760px) {
  .settings { top: 24px; bottom: 24px; left: 50%; right: auto; width: min(560px, calc(100vw - 48px)); margin-left: calc(min(560px, calc(100vw - 48px)) / -2); border-radius: var(--r-sheet); box-shadow: 0 30px 80px rgba(0,0,0,.6); }
}
.settings__bar { flex: none; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 20px 16px 6px 20px; }
.settings__title { font: var(--title-2); letter-spacing: var(--tracking-title); margin: 0; }
.settings__close { all: unset; cursor: pointer; position: relative; flex: none; width: 32px; height: 32px; border-radius: 50%; background: rgba(44,44,46,.8); -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); display: grid; place-items: center; color: #fff; }
.settings__close::after { content: ""; position: absolute; inset: -6px; }
.settings__close svg { width: 13px; height: 13px; }
.settings__body { position: relative; flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; padding: 0 16px calc(40px + env(safe-area-inset-bottom)); scrollbar-width: none; }
.settings__body::-webkit-scrollbar { display: none; }

.settings__sec { font: 600 13px/1 var(--font-ui); color: var(--ink-2); text-transform: uppercase; letter-spacing: .03em; margin: 26px 16px 8px; }
.settings__sec:first-child { margin-top: 16px; }
.settings__group { background: var(--cell); border-radius: var(--r-row); overflow: hidden; }
.settings__group > * { position: relative; }
.settings__group > * + *::before { content: ""; position: absolute; top: 0; left: 16px; right: 0; border-top: .5px solid var(--sep); }
.settings__row { all: unset; box-sizing: border-box; position: relative; cursor: pointer; display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; min-height: var(--tap); padding: 11px 16px;
  font: 400 16px/1.3 var(--font-ui); color: var(--ink); transition: background-color .2s; }
.settings__row.is-down { background: var(--cell-2); transition: none; }
.settings__row--action { color: var(--tint); }
.settings__row--danger { color: var(--danger); }
.settings__row:disabled { cursor: default; color: var(--ink); }
.settings__row:focus-visible { outline-offset: -3px; border-radius: var(--r-row); }
.settings__value { flex: none; color: var(--ink-2); }
.settings__chev { flex: none; width: 8px; height: 14px; color: var(--ink-3); }
.settings__how { margin: 0; padding: 11px 16px 13px; font: 400 14.5px/1.4 var(--font-ui); color: var(--ink-body); }
.settings__confirm { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 12px; padding: 10px 12px 10px 16px; }
.settings__ask { font: 500 15px/1.3 var(--font-ui); }
.settings__pair { display: flex; gap: 8px; margin-inline-start: auto; }
.settings__btn { all: unset; cursor: pointer; position: relative; height: 34px; padding: 0 16px; border-radius: 999px; background: var(--cell-2); color: var(--ink); font: 600 14px/34px var(--font-ui); }
.settings__btn::after { content: ""; position: absolute; inset: -5px -2px; }
.settings__btn--danger { background: var(--danger); color: #fff; }
.settings__note { font: var(--footnote); color: var(--ink-2); margin: 8px 16px 0; }

/* ---------- Shelfy's first-open guide (app/ui/guide.mjs; spec docs/design/shelfy-mascot-spec-v2.md, first-open
   guide): a translucent bottom sheet, materialising with blur + scale + translate
   together (apple-design: never a plain fade on arrival), over a dimming scrim. ---------- */
.guide-scrim { position: fixed; inset: 0; z-index: 15; background: var(--scrim); opacity: 0; pointer-events: none; transition: opacity .35s; }
.guide-scrim.is-on { opacity: .55; pointer-events: auto; }
.guide { position: fixed; left: 0; right: 0; bottom: 0; z-index: 16; padding: 0 16px calc(28px + env(safe-area-inset-bottom)); pointer-events: none;
  opacity: 0; filter: blur(8px); transform: translateY(40px) scale(.98);
  transition: transform .5s var(--spring-ease, cubic-bezier(.2,.8,.2,1)), opacity .35s, filter .45s; }
.guide.is-on { opacity: 1; filter: none; transform: none; pointer-events: auto; }
.guide__sheet { max-width: 480px; margin: 0 auto; padding: 18px 18px 16px; border-radius: var(--r-sheet);
  background: var(--glass); -webkit-backdrop-filter: blur(24px) saturate(170%); backdrop-filter: blur(24px) saturate(170%);
  border: 1px solid var(--glass-edge); box-shadow: 0 -10px 40px rgba(0,0,0,.5); }
.guide__mascot { height: 130px; display: flex; align-items: center; justify-content: center; }
.guide__h { font: var(--title-2); letter-spacing: var(--tracking-title); margin: 6px 0 4px; }
.guide__p { margin: 0; font: var(--body); color: var(--ink-body); }
.guide__row { display: flex; align-items: center; gap: 10px; margin-top: 16px; }
.guide__dots { flex: 1; display: flex; gap: 5px; }
.guide__dots i { display: block; width: 6px; height: 6px; border-radius: 50%; background: var(--ink-3); transition: width .4s var(--spring-ease, cubic-bezier(.2,.8,.2,1)), background-color .2s; }
.guide__dots i.is-on { width: 18px; border-radius: 3px; background: #fff; }
.guide__skip { all: unset; cursor: pointer; position: relative; font: 600 14px/1 var(--font-ui); padding: 11px 8px; color: var(--ink-2); }
.guide__skip::after { content: ""; position: absolute; inset: -6px; }
.guide__next { all: unset; cursor: pointer; position: relative; font: 600 14px/1 var(--font-ui); padding: 11px 18px; border-radius: 999px; background: #fff; color: #000; transition: transform var(--press-dur) ease-out; }
.guide__next:active { transform: scale(var(--press-scale)); }

/* ---------- Accessibility preferences ---------- */
@media (prefers-reduced-transparency: reduce) {
  .dock, .topbar, .toast, .sheet__close, .hero__expand, .viewer__close::before, .settings-open, .settings__close, .hint, .guide__sheet { background: var(--glass-solid); -webkit-backdrop-filter: none; backdrop-filter: none; }
}
@media (prefers-reduced-motion: reduce) {
  .view, .shimmer, .spinner { animation: none; }
  .xp-bar::after { animation: none; display: none; }
  .toast { transition: opacity .2s; transform: translate(-50%, 0); }
  .seg__thumb { transition: none; }
  .detail { transform: none; }
}
/* the app sets html.is-reduced from matchMedia at startup (app/ui/app.mjs) - the guide's own switch:
   still appears/disappears (never a blank state), but a plain fast cross-fade, no slide/blur/scale */
.is-reduced .guide, .is-reduced .guide-scrim { transition: opacity .2s; }
.is-reduced .guide { filter: none; transform: none; }
@media (prefers-contrast: more) {
  .dock, .toast { border: 1px solid #fff; }
  .row__meta, .count, .detail__meta { color: #fff; }
}

/* ---------- Shelfy, the mascot (app/ui/mascot.mjs; spec docs/design/shelfy-mascot-spec-v2.md) ----------
   Sal's final cubes, CSS copied as-is from docs/design/shelfy-cubes-final.html (class names and
   keyframes prefixed shelfy-). He sits inside the large title right after the word (left of it in
   RTL), centred on it; the title row grows to his height so he never covers the count below.
   SIZE: one line - --shelfy-size. 64px matches Sal's chosen prototype (10 Oct 2026: 66px there), 54px on narrow phones. */
:root { --shelfy-size: 64px; }
@media (max-width: 374px) { :root { --shelfy-size: 54px; } }
.large-title.has-shelfy { display: flex; align-items: center; }
.shelfy { flex: none; display: inline-block; width: var(--shelfy-size); height: var(--shelfy-size); margin-inline-start: 10px;
  cursor: pointer; -webkit-tap-highlight-color: transparent; touch-action: manipulation; -webkit-user-select: none; user-select: none; }
.shelfy-svg { display: block; width: 100%; height: 100%; overflow: visible; }
.shelfy-face { transition: opacity .24s ease; }
.shelfy-z { font-weight: 800; fill: var(--zc, #fff); opacity: 0; }
.shelfy-sleeping .shelfy-z { animation: shelfy-zz 2.6s ease-out infinite; }
.shelfy-sleeping .shelfy-z2 { animation-delay: .9s; }
.shelfy-sleeping .shelfy-z3 { animation-delay: 1.8s; }
@keyframes shelfy-zz { 0% { opacity: 0; transform: translate(0,0) scale(.6); } 20% { opacity: .9; } 100% { opacity: 0; transform: translate(10px,-26px) scale(1.1); } }
.shelfy-breathe { animation: shelfy-br 3.6s ease-in-out infinite; transform-box: fill-box; transform-origin: 50% 100%; }
@keyframes shelfy-br { 50% { transform: scale(1.012,.985); } }
.shelfy-tile { transition: opacity .5s ease, transform .5s ease; transform-box: fill-box; transform-origin: 50% 50%; }
@media (prefers-reduced-motion: reduce) { .shelfy-breathe, .shelfy-sleeping .shelfy-z { animation: none; } }
/* the guide's mount: the same character, bigger, centred in the sheet */
.guide__mascot .shelfy { --shelfy-size: 120px; margin: 0; }
