/* Handled · the shell: the top bar, the bottom tab bar (phones), the left rail and two panes (1024 px and up), the
   main column, the listening panel. Story Becomes' buyer-account chrome (account.css .ac-top, .ac-tabbar, .ac-nav) in
   Handled's tokens, mobile first: base styles for a 360-390 px phone, then min-width layers at 640 and 1024. Every
   colour, radius and shadow is a brand.css token (tools/test/layout.test.mjs fails on a raw hex here). Owner: ui-core. */

.app { min-height: 100dvh; }
.col { min-width: 0; }

/* ---- the mark: ink tab, paper letter, in either theme */
.brand-mark, .rail-mark { display: inline-flex; flex: none; width: 26px; height: 26px; }
.brand-mark svg, .rail-mark svg { width: 100%; height: 100%; }
.mk-t { fill: var(--sb-ink); }
.mk-g { fill: var(--sb-paper); }

/* ---- the top bar: sticky, glass over the scroll, a search button on every screen */
.top { position: sticky; top: 0; z-index: 60; height: calc(var(--sb-top) + env(safe-area-inset-top)); padding-top: env(safe-area-inset-top);
  background: var(--sb-glass); -webkit-backdrop-filter: saturate(1.4) blur(10px); backdrop-filter: saturate(1.4) blur(10px); border-bottom: 1px solid var(--sb-chrome-line); }
.top-in { height: var(--sb-top); max-width: 760px; margin: 0 auto; padding: 0 calc(var(--sb-gutter) - 10px) 0 var(--sb-gutter); display: flex; align-items: center; gap: 4px; }
.top-brand { flex: 1; display: inline-flex; align-items: center; gap: 8px; min-height: 44px; font-weight: 800; font-size: 19px; letter-spacing: -0.05em; color: var(--sb-ink); text-decoration: none; }
.top-title { flex: 1; min-width: 0; font-size: 17px; font-weight: 750; letter-spacing: -0.04em; text-transform: lowercase; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-back { margin-left: -12px; color: var(--sb-ink); }
.top-actions { display: inline-flex; align-items: center; gap: 2px; }
.top-actions .icon-btn, .top-search { color: var(--sb-ink); }

/* ---- the main column */
.main { max-width: 760px; margin: 0 auto; padding: 24px var(--sb-gutter) calc(var(--sb-tabbar) + env(safe-area-inset-bottom) + 48px); outline: none; }
.pane { min-width: 0; }
/* A screen rises in (Story Becomes' ac-rise); a redraw after an action does not. backwards, not both: a finished
   entrance leaves no transform behind (a transformed ancestor would trap every fixed child: sheets, the tip). */
.view { animation: hd-rise 0.34s var(--sb-ease-snap) backwards; }
.view.is-redraw, .pane--list.view { animation: none; }
@keyframes hd-rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
/* the shell focuses each new screen's h1 (tabindex -1) for screen readers; no ring for that */
[tabindex="-1"]:focus { outline: none; }

/* ---- the bottom tab bar: five tabs, Ask in the centre as a raised 3D key (hold it to talk) */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 60; height: calc(var(--sb-tabbar) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: var(--sb-paper); border-top: 1px solid var(--sb-chrome-line); display: grid; grid-template-columns: repeat(5, 1fr); align-items: stretch; }
.tab { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; min-height: 44px;
  color: var(--sb-ink-2); text-decoration: none; font-size: 11.5px; font-weight: 700; letter-spacing: -0.02em; text-transform: lowercase;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.tab .ic { width: 23px; height: 23px; }
.tab-ic { position: relative; display: inline-flex; }
.tab[aria-current="page"] { color: var(--sb-ink); }
.tab[aria-current="page"] .tab-label { position: relative; }
.tab[aria-current="page"] .tab-label::before { content: ""; position: absolute; left: 50%; top: -6px; width: 4px; height: 4px; margin-left: -2px; border-radius: 50%; background: var(--sb-ink); }
.tab--center { gap: 3px; }
.tab--center .tab-ic { align-items: center; justify-content: center; width: 54px; height: 40px; margin-top: -16px; margin-left: 4px;
  background: var(--sb-ink); color: var(--sb-paper); border-radius: var(--sb-r);
  box-shadow: -1px 1px 0 var(--sb-extrude), -2px 2px 0 var(--sb-extrude), -3px 3px 0 var(--sb-extrude), -4px 4px 0 var(--sb-extrude);
  transition: transform 0.25s var(--sb-ease-snap), box-shadow 0.25s var(--sb-ease-snap); }
.tab--center:active .tab-ic { transform: translate(-4px, 4px); box-shadow: none; }
.tab--center[aria-current="page"] .tab-label::before { display: none; }
.tab--center .ic { width: 22px; height: 22px; }
.tab-dot { position: absolute; top: 5px; left: calc(50% + 7px); min-width: 17px; height: 17px; padding: 0 4px; border-radius: 9px; border: 2px solid var(--sb-paper); box-sizing: content-box;
  background: var(--sb-ribbon); color: var(--sb-on-ribbon); font-size: 10.5px; font-weight: 800; line-height: 17px; text-align: center; }
.tab-dot--quiet { background: var(--sb-ink); color: var(--sb-paper); }

/* ---- the listening panel (hold to talk): an ink folder tab above the tab bar */
.listen { position: fixed; z-index: 950; left: 12px; right: 12px; bottom: calc(var(--sb-tabbar) + env(safe-area-inset-bottom) + 14px); display: flex; align-items: center; gap: 14px;
  padding: 16px 18px; background: var(--sb-ink); color: var(--sb-paper); border-radius: var(--sb-r-lg); box-shadow: -6px 6px 0 var(--sb-ribbon); animation: sb-sheet-up 0.3s var(--sb-ease-snap) backwards; }
.listen.is-cancel { box-shadow: -6px 6px 0 var(--sb-paper-2); }
.listen-text { flex: 1; display: grid; gap: 2px; font-size: 13.5px; color: var(--sb-paper-2); }
.listen-text b { color: var(--sb-paper); font-size: 17px; letter-spacing: -0.03em; text-transform: lowercase; }
.listen-time { font-variant-numeric: tabular-nums; font-weight: 800; font-size: 17px; }
.listen-bars { display: inline-flex; align-items: center; gap: 3px; height: 30px; }
.listen-bars i { width: 3px; height: 30%; border-radius: 2px; background: var(--sb-ribbon); animation: hd-bar 0.9s ease-in-out infinite; }
.listen-bars i:nth-child(2n) { animation-delay: -0.3s; }
.listen-bars i:nth-child(3n) { animation-delay: -0.55s; }
.listen-bars i:nth-child(5n) { animation-delay: -0.15s; }
@keyframes hd-bar { 50% { height: 100%; } }
@media (min-width: 1024px) { .listen { left: auto; right: 24px; bottom: 24px; width: 380px; } }

/* ---- the rail: hidden on phones */
.rail { display: none; }

/* ---- flows (pairing, first run): no bars */
.is-flow .tabbar, .is-flow .rail, .is-flow .top-search { display: none; }
.is-flow .main { max-width: 640px; padding-bottom: 64px; }

/* ---- the boot skeleton (index.html draws it before any script) */
.skel-title { display: block; width: 40%; height: 26px; }
.skel { display: grid; gap: 16px; }
.skel-h1 { height: 46px; width: 62%; }
.skel-pills { height: 72px; width: 100%; }
.skel-card { height: 92px; }
.skel-card--open { height: 290px; }
.skel-strip { height: 132px; }

@media (min-width: 640px) {
  .main { padding-top: 36px; }
}

/* ---- 1024 px and up: the left rail with the same entries, two panes for a list and its detail */
@media (min-width: 1024px) {
  .app { display: grid; grid-template-columns: 248px minmax(0, 1fr); }
  .tabbar { display: none; }
  .rail { display: flex; flex-direction: column; gap: 2px; position: sticky; top: 0; height: 100dvh; overflow-y: auto; padding: 18px 14px 18px; border-right: 1px solid var(--sb-chrome-line); background: var(--sb-paper); }
  .rail-brand { display: flex; align-items: center; gap: 10px; padding: 6px 10px 16px; font-weight: 800; font-size: 20px; letter-spacing: -0.05em; text-decoration: none; color: var(--sb-ink); }
  .rail-search { display: flex; align-items: center; gap: 10px; min-height: 42px; margin: 0 0 12px; padding: 0 10px 0 12px; border: var(--sb-bw) solid var(--sb-line); border-radius: var(--sb-r); color: var(--sb-ink-2); text-decoration: none; font-weight: 600; }
  .rail-search span { flex: 1; }
  .rail-item { position: relative; display: flex; align-items: center; gap: 12px; min-height: 42px; padding: 0 12px; border: var(--sb-bw) solid transparent; border-radius: var(--sb-r);
    color: var(--sb-ink-2); text-decoration: none; font-weight: 650; font-size: 16px; letter-spacing: -0.03em; text-transform: lowercase; }
  .rail-item .ic { width: 20px; height: 20px; }
  .rail-item[aria-current="page"] { background: var(--sb-ink); color: var(--sb-paper); border-color: var(--sb-ink); }
  .rail-item--sub { min-height: 38px; font-size: 15px; }
  .rail-item .tab-dot { position: static; margin-left: auto; border: 0; }
  .rail-sep { margin: 14px 12px 6px; padding-top: 12px; border-top: 1px solid var(--sb-line-soft); color: var(--sb-ink-2); font-size: 12.5px; font-weight: 700; text-transform: lowercase; }
  .rail-keys { margin-top: auto; align-self: flex-start; border: 0; background: none; color: var(--sb-ink-2); font: inherit; font-size: 13px; cursor: pointer; padding: 8px 10px; }
  .top-in, .main { max-width: 1180px; }
  .top-brand { display: none; }
  .top-in { padding-left: 40px; }
  .main { padding: 36px 40px 80px; }
  .is-split .main { display: grid; grid-template-columns: minmax(320px, 420px) minmax(0, 1fr); gap: 40px; align-items: start; }
  .is-split .pane--list { position: sticky; top: calc(var(--sb-top) + 20px); max-height: calc(100dvh - var(--sb-top) - 40px); overflow-y: auto; padding: 4px 8px 24px 6px; }
  .is-split .pane--list .h1 { font-size: 2.3rem; }
  .is-split .pane--detail { min-width: 0; }
  .pane--list [aria-current="true"] { background: var(--sb-grey); box-shadow: inset 3px 0 0 var(--sb-ink); }
  .is-flow .app { grid-template-columns: minmax(0, 1fr); }
  .keyrow { display: flex; align-items: center; gap: 14px; min-height: 40px; border-bottom: 1px solid var(--sb-line-soft); }
  .keyrow kbd { min-width: 64px; }
}

@media (hover: hover) {
  .rail-item:hover:not([aria-current="page"]), .rail-search:hover { background: var(--sb-grey); color: var(--sb-ink); }
  .tab:hover { color: var(--sb-ink); }
}
@media (prefers-reduced-motion: reduce) {
  .view, .listen { animation: none; }
  .listen-bars i { animation: none; height: 60%; }
  .tab--center .tab-ic { transition: none; }
}

/* ---- two panes: the card whose detail is open is marked by its extrusion turning red, not by a highlighted link */
@media (min-width: 1024px) {
  .pane--list .card-link[aria-current="true"] { background: none; box-shadow: none; }
  .pane--list .card:has(.card-link[aria-current="true"]) { box-shadow: -6px 6px 0 var(--sb-ribbon); }
}

/* ---- screens with a fixed composer (Ask, Week's add bar): toasts sit above it, and the screen does not rise in
   (a transformed pane would carry the fixed composer with it for the length of the entrance) */
.has-composer .toasts { bottom: calc(var(--sb-tabbar) + env(safe-area-inset-bottom) + 104px); }
.view[data-view="ask"], .view[data-view="week"] { animation: none; }
@media (min-width: 1024px) { .has-composer .toasts { bottom: 104px; } }
/* one pane on a wide screen keeps a reading measure; two panes use the width */
@media (min-width: 1024px) { .main > .pane:only-child { max-width: 860px; } }
