/* ==========================================================================
   Glint web — foundation: base, type, primitives, app shell, overlays.
   Cyanotype tokens only (public/css/tokens.css, GENERATED). No build step.
   Files: app.css (this), components.css, pages.css.
   ========================================================================== */

/* --- Base --------------------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  background: var(--bg-base);
  /* The navigate progress bar uses the brand color of the active theme. */
  --livewire-progress-bar-color: var(--brand-500);
  --sidebar-w: var(--layout-web-sidebar);
  --tabbar-h: 50px;
  --topbar-h: 44px;
  --page-max: 935px;
  --ring-close: #3DD68C;
  --ring-live: #FF4467;
  --ease-sheet: cubic-bezier(0.2, 0.9, 0.3, 1);
}

html:root { --livewire-progress-bar-color: var(--brand-500); }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg-base);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: var(--type-body-size);
  line-height: var(--type-body-line);
  font-weight: var(--type-body-weight);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

img, video, canvas, svg { display: block; max-width: 100%; }
img { border: 0; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
button:disabled { cursor: default; }
a { color: inherit; text-decoration: none; }
h1, h2, h3, h4, p, ul, ol, figure, blockquote, dl, dd { margin: 0; }
ul, ol { padding: 0; list-style: none; }
hr { border: 0; border-top: 1px solid var(--border-subtle); margin: 0; }
[hidden] { display: none !important; }
[x-cloak] { display: none !important; }
::selection { background: color-mix(in srgb, var(--brand-500) 35%, transparent); }

/* Visible focus for keyboard users only. */
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--brand-400); outline-offset: 2px; border-radius: 4px; }
input:focus-visible, textarea:focus-visible, select:focus-visible { outline: none; }

.skip-link {
  position: fixed; left: 12px; top: -60px; z-index: 1000;
  background: var(--brand-500); color: var(--on-brand);
  padding: 8px 14px; border-radius: var(--radius-control); font-weight: 600;
}
.skip-link:focus { top: 12px; }

.sr-only {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* --- Type ---------------------------------------------------------------- */

.t-display { font-family: var(--font-display); font-size: var(--type-display-size); line-height: var(--type-display-line); font-weight: 600; letter-spacing: var(--type-display-tracking); }
.t-title-lg { font-size: var(--type-title-lg-size); line-height: var(--type-title-lg-line); font-weight: 600; }
.t-title-md { font-size: var(--type-title-md-size); line-height: var(--type-title-md-line); font-weight: 600; }
.t-body { font-size: var(--type-body-size); line-height: var(--type-body-line); font-weight: 400; }
.t-strong { font-size: var(--type-body-strong-size); line-height: var(--type-body-strong-line); font-weight: 600; }
.t-meta { font-size: var(--type-meta-size); line-height: var(--type-meta-line); font-weight: 400; color: var(--text-secondary); }
.t-micro { font-size: var(--type-micro-size); line-height: var(--type-micro-line); font-weight: 500; }
.t-secondary { color: var(--text-secondary); }
.t-tertiary { color: var(--text-tertiary); }
.t-danger { color: var(--status-danger); }
.t-success { color: var(--status-success); }
.t-link { color: var(--brand-400); font-weight: 600; }
.t-link:hover { text-decoration: underline; }
.tnum, .count { font-feature-settings: "tnum"; font-variant-numeric: tabular-nums; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.center { text-align: center; }

/* Usernames: body.strong in text.primary, never colored, never underlined. */
.username { font-weight: 600; color: var(--text-primary); text-decoration: none !important; }
.username-row { display: inline-flex; align-items: center; gap: 4px; min-width: 0; max-width: 100%; }
.verified { color: var(--brand-500); flex: none; width: var(--verified-size); height: var(--verified-size); }

/* @mentions and #tags in brand.400 (MentionText). */
.mention, .hashtag { color: var(--brand-400); }
.mention:hover, .hashtag:hover { text-decoration: underline; }

/* --- Icons --------------------------------------------------------------- */

.icon { flex: none; }
.icon-duotone .duo { fill: var(--brand-500); opacity: 0.2; }

/* --- Buttons ------------------------------------------------------------- */

.btn {
  --btn-h: var(--button-height);
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: var(--btn-h); padding: 0 16px; border-radius: var(--radius-control);
  font-size: var(--type-body-strong-size); font-weight: 600; line-height: 1; white-space: nowrap;
  border: 1px solid transparent; transition: background-color 120ms, opacity 120ms;
  user-select: none; -webkit-user-select: none;
}
.btn .icon { width: 18px; height: 18px; }
.btn-primary { background: var(--brand-500); color: var(--on-brand); }
.btn-primary:hover { background: color-mix(in srgb, var(--brand-500) 88%, #000); }
.btn-secondary { background: var(--bg-raised); color: var(--text-primary); }
.btn-secondary:hover { background: color-mix(in srgb, var(--bg-raised) 85%, var(--text-primary)); }
.btn-ghost { background: transparent; color: var(--text-primary); }
.btn-ghost:hover { background: var(--bg-raised); }
.btn-danger { background: var(--status-danger); color: #fff; }
.btn-danger:hover { background: color-mix(in srgb, var(--status-danger) 88%, #000); }
.btn-link { background: none; border: 0; height: auto; padding: 0; color: var(--brand-400); }
.btn-link:hover { text-decoration: underline; }
.btn-block { width: 100%; }
.btn-lg { --btn-h: 44px; font-size: var(--type-body-size); }
.btn-sm { --btn-h: 28px; padding: 0 12px; font-size: var(--type-meta-size); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.45; pointer-events: none; }
.btn.is-busy { position: relative; color: transparent !important; pointer-events: none; }
.btn.is-busy::after {
  content: ""; position: absolute; width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid currentColor; border-color: var(--on-brand) var(--on-brand) transparent transparent;
  animation: spin 700ms linear infinite;
}
.btn-secondary.is-busy::after, .btn-ghost.is-busy::after { border-color: var(--text-primary) var(--text-primary) transparent transparent; }

.icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px; margin: -8px;
  border-radius: 50%; color: var(--text-primary); position: relative; flex: none;
}
.icon-btn .icon { width: var(--icon-nav); height: var(--icon-nav); }
.icon-btn:hover { color: var(--text-secondary); }
.icon-btn.sm { width: 32px; height: 32px; margin: -4px; }
.icon-btn.sm .icon { width: 20px; height: 20px; }

.link-btn { color: var(--brand-400); font-weight: 600; }
.link-btn:hover { color: var(--text-primary); }
.text-btn { font-weight: 600; color: var(--text-primary); }
.text-btn:hover { color: var(--text-secondary); }

/* --- Inputs -------------------------------------------------------------- */

.input, .textarea, .select {
  width: 100%; min-height: 40px; padding: 10px 12px;
  background: var(--bg-raised); border: 1px solid var(--border-subtle); border-radius: var(--radius-control);
  color: var(--text-primary); font-size: var(--type-body-size); line-height: 1.35;
  transition: border-color 120ms;
}
.input::placeholder, .textarea::placeholder { color: var(--text-secondary); }
.input:focus, .textarea:focus, .select:focus { border-color: var(--text-secondary); }
.input.is-invalid, .textarea.is-invalid { border-color: var(--status-danger); }
.textarea { resize: vertical; min-height: 88px; }
.select { appearance: none; -webkit-appearance: none; padding-right: 36px; background-image: linear-gradient(45deg, transparent 50%, var(--text-secondary) 50%), linear-gradient(135deg, var(--text-secondary) 50%, transparent 50%); background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; }
.field { display: grid; gap: 6px; }
.field-label { font-size: var(--type-meta-size); font-weight: 600; color: var(--text-primary); }
.field-hint { font-size: var(--type-meta-size); color: var(--text-secondary); }
.field-error { font-size: var(--type-meta-size); color: var(--status-danger); }
.field-counter { font-size: var(--type-meta-size); color: var(--text-tertiary); text-align: right; }

/* Floating label (auth screens). */
.float { position: relative; display: block; }
.float .input { height: 48px; padding: 20px 12px 6px; }
.float .input.has-trailing { padding-right: 76px; }
.float label {
  position: absolute; left: 13px; top: 50%; transform: translateY(-50%);
  color: var(--text-secondary); font-size: var(--type-body-size); pointer-events: none;
  transition: transform 150ms var(--ease-sheet), font-size 150ms, top 150ms;
}
.float .input:focus + label, .float .input:not(:placeholder-shown) + label { top: 13px; transform: translateY(-50%); font-size: 11px; }
.float .trailing { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); display: flex; align-items: center; gap: 6px; }
.float .trailing .t-link { font-size: var(--type-meta-size); padding: 6px; }
.float .state-icon { width: 22px; height: 22px; }
.float .state-icon.ok { color: var(--status-success); }
.float .state-icon.bad { color: var(--status-danger); }

/* Toggle switch. */
.switch { position: relative; display: inline-block; width: 44px; height: 26px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--bg-raised); border: 1px solid var(--border-subtle); transition: background-color 150ms, border-color 150ms; }
.switch span::after { content: ""; position: absolute; left: 3px; top: 50%; width: 20px; height: 20px; margin-top: -10px; border-radius: 50%; background: #fff; transition: transform 150ms var(--ease-sheet); }
.switch input:checked + span { background: var(--brand-500); border-color: var(--brand-500); }
.switch input:checked + span::after { transform: translateX(17px); }
.switch input:focus-visible + span { outline: 2px solid var(--brand-400); outline-offset: 2px; }

/* Radio / checkbox rows. */
.check { appearance: none; -webkit-appearance: none; width: 22px; height: 22px; margin: 0; flex: none; border: 1.5px solid var(--text-tertiary); border-radius: 50%; display: grid; place-items: center; cursor: pointer; }
.check[type="checkbox"] { border-radius: 6px; }
.check:checked { border-color: var(--brand-500); background: var(--brand-500); }
.check:checked::after { content: ""; width: 10px; height: 6px; border: 2px solid var(--on-brand); border-top: 0; border-right: 0; transform: translateY(-1px) rotate(-45deg); }
.check[type="radio"]:checked::after { width: 8px; height: 8px; border: 0; border-radius: 50%; background: var(--on-brand); transform: none; }
.check:focus-visible { outline: 2px solid var(--brand-400); outline-offset: 2px; }

/* Range slider (editor, settings). */
.range { -webkit-appearance: none; appearance: none; width: 100%; height: 24px; background: transparent; cursor: pointer; }
.range::-webkit-slider-runnable-track { height: 2px; background: linear-gradient(var(--text-primary), var(--text-primary)) 0 / var(--fill, 50%) 100% no-repeat, var(--border-subtle); border-radius: 2px; }
.range::-moz-range-track { height: 2px; background: var(--border-subtle); border-radius: 2px; }
.range::-moz-range-progress { height: 2px; background: var(--text-primary); }
.range::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; margin-top: -8px; border-radius: 50%; background: var(--text-primary); border: 0; }
.range::-moz-range-thumb { width: 18px; height: 18px; border-radius: 50%; background: var(--text-primary); border: 0; }

/* --- Avatar + story ring -------------------------------------------------- */
/* Size is the photo; the ring (stroke + 2px gap) is drawn outside it, so a ring
   never shifts layout. The gap is transparent (masked), whatever sits behind. */

.avatar {
  --size: 44px;
  --ring-stroke: 0px;
  --ring-inset: 4.5px;
  position: relative; display: inline-block; flex: none;
  width: var(--size); height: var(--size); border-radius: 50%;
  vertical-align: middle;
}
.avatar img, .avatar .avatar-fallback {
  width: 100%; height: 100%; border-radius: 50%; object-fit: cover;
  background: var(--bg-raised);
}
.avatar .avatar-fallback { display: grid; place-items: center; color: var(--text-tertiary); }
.avatar .avatar-fallback .icon { width: 62%; height: 62%; }
/* Hairline so avatars never melt into the background. */
.avatar::after { content: ""; position: absolute; inset: 0; border-radius: 50%; box-shadow: inset 0 0 0 0.5px color-mix(in srgb, var(--text-primary) 12%, transparent); pointer-events: none; }
.avatar[data-ring]:not([data-ring="none"])::before {
  content: ""; position: absolute; inset: calc(-1 * var(--ring-inset)); border-radius: 50%;
  padding: var(--ring-stroke); background: var(--ring-bg);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor; mask: linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0);
  pointer-events: none;
}
.avatar[data-ring="unseen"] { --ring-stroke: 2.5px; --ring-bg: conic-gradient(from 200deg, var(--ring-from), var(--ring-to), var(--ring-from)); }
.avatar[data-ring="close"] { --ring-stroke: 2.5px; --ring-bg: var(--ring-close); }
.avatar[data-ring="live"] { --ring-stroke: 2.5px; --ring-bg: var(--ring-live); }
.avatar[data-ring="seen"] { --ring-stroke: 1px; --ring-bg: var(--border-subtle); }
/* The ring's only ambient animation: one conic rotation while stories load. */
.avatar.is-loading[data-ring]::before { animation: ring-load var(--motion-ring) 1; }
@keyframes ring-load { to { transform: rotate(360deg); } }
.avatar .live-pill {
  position: absolute; left: 50%; bottom: calc(-1 * var(--ring-inset) - 6px); transform: translateX(-50%);
  background: var(--ring-live); color: var(--on-flash); border: 2px solid var(--bg-base);
  font-size: 9px; font-weight: 700; letter-spacing: 0.04em; line-height: 1; padding: 2px 5px; border-radius: 4px;
}
.avatar-24 { --size: 24px; --ring-inset: 3.5px; }
.avatar-32 { --size: 32px; --ring-inset: 4px; }
.avatar-44 { --size: 44px; }
.avatar-56 { --size: 56px; }
.avatar-64 { --size: 64px; }
.avatar-86 { --size: 86px; --ring-inset: 5px; }
.avatar-150 { --size: 150px; --ring-inset: 6px; }
.avatar-24[data-ring="unseen"], .avatar-24[data-ring="close"] { --ring-stroke: 1.5px; }
.avatar-150[data-ring="unseen"], .avatar-150[data-ring="close"] { --ring-stroke: 3px; }
.avatar-group { position: relative; display: inline-block; flex: none; }
.avatar-group .avatar + .avatar { position: absolute; right: -2px; bottom: -2px; box-shadow: 0 0 0 2px var(--bg-base); border-radius: 50%; }

/* --- Badges -------------------------------------------------------------- */

.badge {
  display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 999px; background: var(--accent-flash); color: var(--on-flash);
  font-size: var(--type-micro-size); font-weight: 600; line-height: 1; font-feature-settings: "tnum";
}
.badge-brand { background: var(--brand-500); color: var(--on-brand); }
.badge-new { background: var(--accent-selenium); color: var(--bg-base); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent-flash); flex: none; }
.dot-brand { background: var(--brand-500); }
.pill { display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 8px; border-radius: 999px; font-size: var(--type-micro-size); font-weight: 600; background: var(--bg-raised); color: var(--text-secondary); }

/* --- Wordmark ------------------------------------------------------------ */
/* Live text: Unbounded 600, -0.02em, "ı" + a solid selenium tittle. */

.wordmark {
  display: inline-flex; align-items: baseline; font-family: var(--font-display); font-weight: 600;
  letter-spacing: -0.02em; line-height: 1; color: var(--text-primary); font-size: 26px; white-space: nowrap;
}
.wordmark .wm-i { position: relative; display: inline-block; }
.wordmark .wm-dot {
  position: absolute; left: 50%; top: -0.035em; width: 0.235em; height: 0.235em; margin-left: -0.1175em;
  border-radius: 50%; background: var(--accent-selenium);
}
.wordmark img { height: 1em; width: auto; }

/* --- App shell ------------------------------------------------------------ */

.shell { min-height: 100vh; min-height: 100dvh; }
.main { min-height: 100vh; min-height: 100dvh; margin-left: var(--sidebar-w); display: flex; flex-direction: column; }
.main > .page { flex: 1; }

.sidebar {
  position: fixed; inset: 0 auto 0 0; z-index: 40; width: var(--sidebar-w);
  display: flex; flex-direction: column; padding: 8px 12px 20px;
  background: var(--bg-base); border-right: 1px solid var(--border-subtle);
}
.sidebar-brand { display: flex; align-items: center; height: 92px; padding: 25px 12px 16px; flex: none; }
.sidebar-brand .wordmark { font-size: 26px; }
.sidebar-brand .brand-mark { display: none; width: 28px; height: 28px; border-radius: 8px; }
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-item {
  position: relative; display: flex; align-items: center; gap: 16px; width: 100%;
  height: 48px; padding: 12px; border-radius: var(--radius-control);
  color: var(--text-primary); font-size: var(--type-body-size); text-align: left;
  transition: background-color 120ms;
}
.nav-item:hover { background: var(--bg-raised); }
.nav-item:hover .nav-icon { transform: scale(1.05); }
.nav-icon { position: relative; display: grid; place-items: center; width: 24px; height: 24px; flex: none; transition: transform 120ms; }
.nav-icon .icon { width: 24px; height: 24px; }
.nav-icon .on { display: none; }
.nav-item[data-current] .nav-icon .on, .nav-item.is-active .nav-icon .on { display: block; }
.nav-item[data-current] .nav-icon .off, .nav-item.is-active .nav-icon .off { display: none; }
.nav-item[data-current] .nav-label, .nav-item.is-active .nav-label { font-weight: 600; }
.nav-item .avatar { --size: 24px; }
.nav-item[data-current] .avatar::after, .nav-item.is-active .avatar::after { box-shadow: 0 0 0 1.5px var(--text-primary); inset: -2px; }
.nav-badge { position: absolute; top: -7px; left: 13px; }
.nav-dot { position: absolute; top: -1px; right: -1px; box-shadow: 0 0 0 2px var(--bg-base); }
.nav-label { white-space: nowrap; overflow: hidden; }
.nav-bottom { display: flex; flex-direction: column; gap: 2px; position: relative; }

/* Icon-only sidebar: 768–1023, and whenever a slide-over panel is open. */
.sidebar.is-collapsed, .shell-panel-open .sidebar { width: var(--layout-web-sidebar-icons); padding-inline: 12px; }
.sidebar.is-collapsed .nav-label, .shell-panel-open .sidebar .nav-label { display: none; }
.sidebar.is-collapsed .wordmark, .shell-panel-open .sidebar .wordmark { display: none; }
.sidebar.is-collapsed .brand-mark, .shell-panel-open .sidebar .brand-mark { display: block; }
.sidebar.is-collapsed .sidebar-brand, .shell-panel-open .sidebar .sidebar-brand { padding-inline: 10px; }
.shell-panel-open .sidebar { border-right-color: transparent; }

/* Menus (More, post ⋯ on desktop). Emulsion, radius 10; light mode gets the one shadow. */
.menu {
  min-width: 240px; padding: 8px; border-radius: 16px;
  background: var(--bg-surface); border: 1px solid var(--border-subtle); box-shadow: var(--shadow-sheet);
}
.menu-item {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 44px; padding: 10px 12px;
  border-radius: var(--radius-control); color: var(--text-primary); text-align: left; font-size: var(--type-body-size);
}
.menu-item:hover, .menu-item:focus-visible { background: var(--bg-raised); outline: none; }
.menu-item .icon { width: 20px; height: 20px; }
.menu-item.danger { color: var(--status-danger); }
.menu-sep { height: 1px; background: var(--border-subtle); margin: 6px -8px; }
.menu-head { display: flex; align-items: center; gap: 10px; padding: 8px 12px 4px; color: var(--text-secondary); font-size: var(--type-meta-size); }
.more-menu { position: absolute; left: 0; bottom: 56px; width: 266px; z-index: 60; }

/* Theme picker (More → Switch appearance). */
.theme-picker { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; padding: 4px; }
.theme-option { display: grid; justify-items: center; gap: 6px; padding: 10px 6px; border-radius: var(--radius-control); border: 1px solid var(--border-subtle); font-size: var(--type-meta-size); color: var(--text-secondary); }
.theme-option .icon { width: 22px; height: 22px; color: var(--text-primary); }
.theme-option[aria-checked="true"] { border-color: var(--brand-500); color: var(--text-primary); background: var(--brand-100); }

/* Slide-over panel (Search, Notifications): 400px, from the collapsed sidebar. */
.panel {
  position: fixed; top: 0; bottom: 0; left: var(--layout-web-sidebar-icons); z-index: 35;
  width: var(--layout-web-slide-over); display: flex; flex-direction: column;
  background: var(--bg-base); border-right: 1px solid var(--border-subtle);
  border-radius: 0 var(--radius-sheet) var(--radius-sheet) 0; box-shadow: var(--shadow-sheet);
  transform: translateX(calc(-100% - var(--layout-web-sidebar-icons) - 16px)); visibility: hidden;
  transition: transform var(--motion-sheet), visibility 0s linear 280ms;
}
.panel.is-open { transform: none; visibility: visible; transition: transform var(--motion-sheet), visibility 0s; }
.panel-head { padding: 24px 24px 12px; }
.panel-title { font-size: 24px; font-weight: 600; line-height: 1.2; margin-bottom: 24px; }
.panel-body { flex: 1; overflow-y: auto; overscroll-behavior: contain; }
/* As a full page (/notifications, /search) the body grows with the document, which scrolls; a non-scrolling
   overflow box with overscroll containment would otherwise swallow the mouse wheel over the list. */
.panel-inner.is-page .panel-body { overflow: visible; overscroll-behavior: auto; }
.panel-scrim { position: fixed; inset: 0; z-index: 30; }

/* Mobile bars (<768). */
.topbar {
  position: sticky; top: 0; z-index: 30; height: var(--topbar-h); display: none; align-items: center; gap: 12px;
  padding: 0 16px; background: var(--bg-base); border-bottom: 1px solid var(--border-subtle);
}
.topbar-title { flex: 1; min-width: 0; font-size: var(--type-title-md-size); font-weight: 600; text-align: center; }
.topbar-title.left { text-align: left; }
.topbar .wordmark { font-size: 24px; }
.topbar-actions { display: flex; align-items: center; gap: 20px; margin-left: auto; }
.topbar .icon-btn .nav-dot { top: 6px; right: 6px; }
.topbar .spacer { width: 24px; flex: none; }

/* Bottom tabs: a frosted surface the content scrolls under (solid where backdrop-filter is missing),
   hairline top border, softer inactive icons, fill + a brand dot when active, a brand Create key. */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; display: none;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  background: var(--bg-surface); border-top: 1px solid var(--border-subtle);
}
@supports ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .tabbar {
    background: color-mix(in srgb, var(--bg-surface) 82%, transparent);
    -webkit-backdrop-filter: blur(20px) saturate(160%); backdrop-filter: blur(20px) saturate(160%);
  }
}
@media (min-resolution: 2dppx) { .tabbar { border-top-width: 0.5px; } }
.tabbar ul { display: grid; grid-template-columns: repeat(5, 1fr); height: var(--tabbar-h); }
.tab {
  position: relative; display: grid; place-items: center; height: 100%; color: var(--text-secondary);
  -webkit-tap-highlight-color: transparent; transition: transform 100ms ease-out;
}
.tab:active { transform: scale(0.92); }
.tab[data-current] { color: var(--text-primary); }
.tab .icon { width: var(--icon-nav); height: var(--icon-nav); }
.tab .on { display: none; }
.tab[data-current] .on { display: block; }
.tab[data-current] .off { display: none; }
.tab > .icon, .tab > .avatar, .tab > .create-key { margin-top: -6px; }
.tab[data-current]::after {
  content: ''; position: absolute; left: 50%; bottom: 5px; width: 4px; height: 4px; margin-left: -2px;
  border-radius: 50%; background: var(--brand-500);
}
.tab .avatar { --size: 26px; }
.tab[data-current] .avatar::after { box-shadow: 0 0 0 1.5px var(--text-primary); inset: -2px; }
.tab-create[data-current]::after { display: none; }
.tab-create .create-key {
  display: grid; place-items: center; width: 40px; height: 30px; border-radius: 10px;
  background: var(--brand-500); color: var(--on-brand);
}
.tab-create .create-key .icon { width: 18px; height: 18px; }
@media (prefers-reduced-motion: reduce) { .tab, .tab:active { transform: none; transition: none; } }

/* Page header used by inner pages on mobile (back · title · action). */
.page-header { display: none; }

/* --- Breakpoints (spec §4) -------------------------------------------------- */

@media (min-width: 1024px) and (max-width: 1263px) { .rail { display: none !important; } }

@media (min-width: 768px) and (max-width: 1023px) {
  html { --sidebar-w: var(--layout-web-sidebar-icons); }
  .sidebar { width: var(--layout-web-sidebar-icons); padding-inline: 12px; }
  .sidebar .nav-label, .sidebar .wordmark { display: none; }
  .sidebar .brand-mark { display: block; }
  .sidebar .sidebar-brand { padding-inline: 10px; }
  .rail { display: none !important; }
}

@media (max-width: 767px) {
  html { --sidebar-w: 0px; }
  .sidebar, .panel, .rail, .desktop-only { display: none !important; }
  .main { margin-left: 0; padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); }
  .tabbar { display: block; }
  .topbar { display: flex; }
  .page-header {
    position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 12px; height: var(--topbar-h);
    padding: 0 16px; background: var(--bg-base); border-bottom: 1px solid var(--border-subtle);
  }
  .page-header h1 { flex: 1; min-width: 0; text-align: center; font-size: var(--type-title-md-size); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .page-header .spacer { width: 24px; flex: none; }
}
@media (min-width: 768px) { .mobile-only { display: none !important; } }

/* --- Overlays: modal, sheet, dialog, toast -------------------------------- */

.scrim {
  position: fixed; inset: 0; z-index: 90; background: var(--overlay-scrim);
  animation: fade-in var(--motion-sheet) both;
}
.overlay { position: fixed; inset: 0; z-index: 91; display: grid; place-items: center; padding: 24px; pointer-events: none; }
.overlay > * { pointer-events: auto; }
.overlay-close { position: fixed; top: 12px; right: 16px; z-index: 92; color: #fff; }
.overlay-close .icon { width: 28px; height: 28px; }

.dialog {
  width: min(400px, 100%); max-height: calc(100dvh - 48px); overflow: hidden; display: flex; flex-direction: column;
  background: var(--bg-surface); border-radius: var(--radius-sheet); box-shadow: var(--shadow-sheet);
  animation: dialog-in var(--motion-sheet) both;
}
.dialog-wide { width: min(560px, 100%); }
.dialog-head { position: relative; display: flex; align-items: center; justify-content: center; min-height: 48px; padding: 0 48px; border-bottom: 1px solid var(--border-subtle); flex: none; }
.dialog-head h2 { font-size: var(--type-title-md-size); font-weight: 600; text-align: center; }
.dialog-head .icon-btn { position: absolute; top: 50%; transform: translateY(-50%); margin: 0; }
.dialog-head .icon-btn.start { left: 8px; }
.dialog-head .icon-btn.end { right: 8px; }
.dialog-head .head-action { position: absolute; right: 16px; top: 50%; transform: translateY(-50%); }
.dialog-body { overflow-y: auto; overscroll-behavior: contain; flex: 1; }
.dialog-pad { padding: 24px; }
.dialog-message { padding: 32px 24px 20px; text-align: center; display: grid; gap: 8px; }
.dialog-message h2 { font-size: var(--type-title-md-size); font-weight: 600; }
.dialog-message p { color: var(--text-secondary); font-size: var(--type-body-size); }
.dialog-actions { display: grid; border-top: 1px solid var(--border-subtle); }
.dialog-actions > button, .dialog-actions > a {
  min-height: 48px; padding: 4px 16px; display: grid; place-items: center; font-size: var(--type-body-size);
  border-top: 1px solid var(--border-subtle); color: var(--text-primary); width: 100%;
}
.dialog-actions > :first-child { border-top: 0; }
.dialog-actions > .strong { font-weight: 600; }
.dialog-actions > .danger { color: var(--status-danger); font-weight: 600; }
.dialog-actions > .brand { color: var(--brand-400); font-weight: 600; }
.dialog-actions > :hover { background: var(--bg-raised); }

/* Bottom sheet (mobile menus, share, comments). Sheets: 20px top corners, 280ms. */
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 91; max-height: 92dvh; display: flex; flex-direction: column;
  background: var(--bg-surface); border-radius: var(--radius-sheet) var(--radius-sheet) 0 0; box-shadow: var(--shadow-sheet);
  padding-bottom: env(safe-area-inset-bottom); animation: sheet-in var(--motion-sheet) both;
  overflow: hidden; /* clip row hover/press backgrounds to the rounded corners */
}
.sheet-handle { width: 36px; height: 4px; border-radius: 999px; background: var(--border-subtle); margin: 8px auto 4px; flex: none; }
.sheet .menu-item { min-height: 52px; padding: 12px 20px; border-radius: 0; }
@media (min-width: 768px) {
  /* On desktop, action sheets render as centered dialogs. */
  .sheet.sheet-dialog { left: 50%; right: auto; bottom: auto; top: 50%; width: 400px; transform: translate(-50%, -50%); border-radius: var(--radius-sheet); animation: dialog-in-centered var(--motion-sheet) both; padding-bottom: 0; }
  .sheet.sheet-dialog .sheet-handle { display: none; }
}
.action-list { display: grid; min-height: 0; overflow-y: auto; }
/* Style only real rows: Alpine's <template x-for> is also a child, and giving it display:grid made it a blank row. */
.action-list > :is(button, a) { min-height: 48px; padding: 12px 16px; display: grid; place-items: center; text-align: center; font-size: var(--type-body-size); width: 100%; }
.action-list > :is(button, a) ~ :is(button, a) { border-top: 1px solid var(--border-subtle); }
.action-list > .danger { color: var(--status-danger); font-weight: 600; }
.action-list > .strong { font-weight: 600; }
.action-list > :hover { background: var(--bg-raised); }

@keyframes fade-in { from { opacity: 0; } }
@keyframes sheet-in { from { transform: translateY(100%); } }
@keyframes dialog-in { from { opacity: 0; transform: scale(1.04); } }
@keyframes dialog-in-centered { from { opacity: 0; transform: translate(-50%, -50%) scale(1.04); } }
@keyframes spin { to { transform: rotate(360deg); } }

/* Toast: bottom, above the tab bar on mobile, 3s. */
.toasts { position: fixed; left: 50%; bottom: 24px; z-index: 120; transform: translateX(-50%); display: grid; gap: 8px; width: min(420px, calc(100vw - 24px)); pointer-events: none; }
.toast {
  display: flex; align-items: center; gap: 12px; min-height: 48px; padding: 12px 16px; pointer-events: auto;
  background: var(--bg-raised); color: var(--text-primary); border-radius: var(--radius-control); box-shadow: var(--shadow-sheet);
  font-size: var(--type-body-size); animation: toast-in 200ms var(--ease-sheet) both;
}
.toast .icon { width: 20px; height: 20px; }
.toast-msg { flex: 1; min-width: 0; }
.toast-action { color: var(--brand-400); font-weight: 600; flex: none; }
.toast.is-danger .icon { color: var(--status-danger); }
.toast.is-success .icon { color: var(--status-success); }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px); } }
@media (max-width: 767px) { .toasts { bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 12px); } }

/* Offline notice. */
.offline {
  position: fixed; top: 0; left: 50%; z-index: 110; transform: translateX(-50%); margin-top: 12px;
  display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-radius: 999px;
  background: var(--bg-raised); border: 1px solid var(--border-subtle); box-shadow: var(--shadow-sheet);
  font-size: var(--type-meta-size); color: var(--text-primary); max-width: calc(100vw - 24px);
}
.offline .icon { width: 20px; height: 20px; }

/* --- Empty and error states: duotone 64px icon + one line of direction ---- */

.empty { display: grid; justify-items: center; gap: 12px; padding: 48px 24px; text-align: center; }
.empty .icon { width: var(--icon-empty); height: var(--icon-empty); color: var(--text-primary); }
.empty h2 { font-size: var(--type-title-md-size); font-weight: 600; }
.empty p { color: var(--text-secondary); max-width: 340px; font-size: var(--type-body-size); }
.empty .btn { margin-top: 8px; }
.empty-ring { width: 88px; height: 88px; border-radius: 50%; border: 2px solid var(--text-primary); display: grid; place-items: center; }
.empty-ring .icon { width: 44px; height: 44px; }

/* --- Skeleton: Plate → Emulsion shimmer, 1.4s -------------------------------- */

.sk {
  display: block; background: linear-gradient(90deg, var(--bg-surface) 0%, var(--bg-raised) 50%, var(--bg-surface) 100%);
  background-size: 200% 100%; animation: shimmer var(--motion-skeleton) linear infinite; border-radius: 6px;
}
.sk-circle { border-radius: 50%; }
.sk-line { height: 12px; border-radius: 6px; }
.sk-media { border-radius: var(--radius-photo-feed); width: 100%; }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }

/* --- Utility layout ------------------------------------------------------ */

.row { display: flex; align-items: center; gap: 12px; min-width: 0; }
.stack { display: grid; gap: 12px; }
.grow { flex: 1; min-width: 0; }
.divider { height: 1px; background: var(--border-subtle); }
.spinner { width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--border-subtle); border-top-color: var(--text-secondary); animation: spin 700ms linear infinite; margin: 24px auto; }
.spinner.sm { width: 18px; height: 18px; margin: 0; }
.load-sentinel { height: 1px; }

/* --- Reduced motion: everything settles instantly; sheets fade. ------------ */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; scroll-behavior: auto !important; }
  .sheet { animation: fade-in 200ms both !important; }
  .dialog, .sheet.sheet-dialog { animation: fade-in 200ms both !important; }
  .panel, .panel.is-open { transition: opacity 200ms !important; transform: none; opacity: 0; }
  .panel.is-open { opacity: 1; }
  .avatar.is-loading[data-ring]::before { animation: none !important; }
  .sk { animation: none !important; background: var(--bg-surface); }
  .spinner { animation-duration: 700ms !important; animation-iteration-count: infinite !important; }
}

/* Center transient UI over the content column, not the sidebar. */
@media (min-width: 768px) {
  .is-signed-in .toasts, .is-signed-in .offline { left: calc(50% + var(--sidebar-w) / 2); }
}
