/*
 * app.css - the shell and every shared component.
 *
 * Built only from the tokens in theme.css. Area-specific styles live in
 * css/<area>.css and load with their views; nothing here knows about a feature.
 *
 * Mobile-first: the base rules are the phone; @media (min-width: 900px) adds the
 * desktop pill navigation and wider pages.
 */

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  background: var(--background);
}

/* Telegram Desktop on Windows draws a real scrollbar; anything a pixel too wide
   would then scroll the whole app sideways and cut its left edge. */
html, body { overflow-x: clip; }

body {
  min-height: 100dvh;
  margin: 0;
  overscroll-behavior-y: none;
  -webkit-tap-highlight-color: transparent;
}

body.has-modal { overflow: hidden; }

img, svg, video { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }
h1, h2, h3, h4, p { margin: 0; }
hr.divider { height: 1px; margin: 0; border: 0; background: var(--border); }

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

.skip-link {
  position: fixed;
  top: var(--space-2);
  left: var(--space-2);
  z-index: 100;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  background: var(--primary);
  color: var(--primary-foreground);
  transform: translateY(-200%);
}

.skip-link:focus { transform: none; }

.icon { flex: none; }

/* ------------------------------------------------------------- utility --- */

.stack { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-3); }
.stack-lg { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-5); }
.cluster { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.spread { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.grow { flex: 1; min-width: 0; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.text-sm { font-size: var(--text-sm); }
.text-xs { font-size: var(--text-xs); }
.muted { color: var(--muted-foreground); }
.center { text-align: center; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-3); }
.grid-auto { display: grid; grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); gap: var(--space-3); }

/* ---------------------------------------------------------------- frame --- */

.app { min-height: 100dvh; }

.app-top {
  position: relative;
  z-index: 40;
  display: flex;
  justify-content: center;
  padding: calc(var(--safe-top) + var(--space-2)) var(--space-3) 0;
  pointer-events: none;
}

.appbar {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: var(--space-1);
  width: 100%;
  max-width: 46rem;
  min-height: 3.25rem;
  padding: var(--space-1) var(--space-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: color-mix(in oklch, var(--background) 78%, transparent);
  box-shadow: var(--shadow-md);
  -webkit-backdrop-filter: blur(20px) saturate(1.1);
  backdrop-filter: blur(20px) saturate(1.1);
  pointer-events: auto;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  flex: none;
  margin-right: 0;
  padding: var(--space-1);
  border-radius: var(--radius-pill);
  font-weight: 600;
  letter-spacing: -0.01em;
  text-decoration: none;
}

.brand-mark { display: grid; place-items: center; }
.mark { width: 1.75rem; height: 1.75rem; object-fit: contain; }
.bear { width: auto; height: 7.5rem; object-fit: contain; }
.scene { width: auto; object-fit: contain; }
.product-art { flex: none; object-fit: contain; }

.appbar-nav {
  display: none;
  min-width: 0;
}

.nav-item {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: var(--space-1);
  min-width: 0;
  min-height: 2.75rem;
  padding: var(--space-1);
  border-radius: var(--radius-md);
  color: var(--muted-foreground);
  font-size: var(--text-xs);
  font-weight: 500;
  text-decoration: none;
}

.nav-item:hover, .nav-item.is-active { background: var(--accent); color: var(--foreground); }
.nav-item > span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.appbar-end { display: flex; flex: none; align-items: center; gap: var(--space-1); }

.primary-menu-btn {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 2.75rem;
  margin-left: auto;
  padding: 0 var(--space-2);
  border: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--muted-foreground);
  font-size: var(--text-sm);
  font-weight: 500;
  cursor: pointer;
}

.primary-menu-btn:hover { background: var(--accent); color: var(--foreground); }
.menu-item.is-active { background: var(--accent); }

@media (max-width: 599px) {
  .appbar-end .coin-chip { display: none; }
}

.coin-chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  height: 2.25rem;
  padding: 0 var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--secondary);
  font-size: var(--text-sm);
  font-weight: 600;
  text-decoration: none;
  transition: background var(--duration-fast) var(--ease-out);
}

.coin-chip:hover { background: var(--accent); }

.coin-dot {
  position: absolute;
  top: -2px; right: -2px;
  width: 0.625rem; height: 0.625rem;
  border: 2px solid var(--background);
  border-radius: var(--radius-pill);
  background: var(--success);
  animation: pulse-dot 2s var(--ease-in-out) infinite;
}

@keyframes pulse-dot {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in oklch, var(--success) 50%, transparent); }
  50% { box-shadow: 0 0 0 5px color-mix(in oklch, var(--success) 0%, transparent); }
}

.bell-btn {
  position: relative;
  display: grid;
  place-items: center;
  width: 2.25rem; height: 2.25rem;
  padding: 0;
  border: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--muted-foreground);
  cursor: pointer;
  transition: background var(--duration-fast) var(--ease-out), color var(--duration-fast) var(--ease-out);
}

.bell-btn:hover, .bell-btn.has-unread { color: var(--foreground); }
.bell-btn:hover { background: var(--accent); }

.bell-badge {
  position: absolute;
  top: -0.125rem; right: -0.25rem;
  min-width: 1.125rem; height: 1.125rem;
  padding: 0 0.25rem;
  border: 2px solid var(--background);
  border-radius: var(--radius-pill);
  background: var(--foreground);
  color: var(--background);
  font-size: 0.5625rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 0.875rem;
  text-align: center;
}

.account-btn {
  display: grid;
  place-items: center;
  width: 2.75rem; height: 2.75rem;
  padding: 0;
  border: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  cursor: pointer;
}

.app-main {
  display: block;
  padding: var(--space-5) 0 calc(var(--safe-bottom) + var(--space-5));
  outline: none;
}

.app:not(.has-frame) .app-main { padding: 0; }

.page {
  display: grid;
  /* Grid children default to min-width: auto, which lets one long word or a
     wide table push the whole page sideways. */
  grid-template-columns: minmax(0, 1fr);
  gap: 1.25rem;
  width: 100%;
  min-width: 0;
  max-width: 46rem;
  margin: 0 auto;
  padding: var(--space-1) var(--space-4) var(--space-5);
  animation: page-in var(--duration-base) var(--ease-out);
}

.page-wide { max-width: 72rem; }
.page > *, .section, .t-card, .modal-head-text { min-width: 0; }
.page { padding-inline: max(var(--space-4), env(safe-area-inset-left, 0px)) max(var(--space-4), env(safe-area-inset-right, 0px)); }

@keyframes page-in { from { opacity: 0; transform: translateY(4px); } }

/* Bottom tab bar: the phone's primary navigation. */
.app-bottom {
  display: none;
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 40;
}

.tabbar {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  padding: var(--space-1) var(--space-2) calc(var(--safe-bottom) + var(--space-1));
  border-top: 1px solid var(--border);
  background: color-mix(in oklch, var(--background) 86%, transparent);
  -webkit-backdrop-filter: blur(20px) saturate(1.1);
  backdrop-filter: blur(20px) saturate(1.1);
}

.tabbar-item {
  display: grid;
  justify-items: center;
  gap: 0.125rem;
  min-height: 3.25rem;
  padding: var(--space-2) 0 var(--space-1);
  border-radius: var(--radius-md);
  color: var(--muted-foreground);
  font-size: 0.6875rem;
  font-weight: 500;
  text-decoration: none;
  transition: color var(--duration-fast) var(--ease-out);
}

.tabbar-item.is-active { color: var(--foreground); }
.tabbar-item:active { background: var(--accent); }

@media (min-width: 900px) {
  .appbar {
    flex-wrap: nowrap;
    width: auto;
    max-width: none;
    height: 2.875rem;
    min-height: 2.875rem;
    gap: var(--space-1);
    padding: 0 var(--space-2) 0 var(--space-3);
    border-radius: var(--radius-pill);
  }

  .brand { margin-right: var(--space-2); padding-right: var(--space-3); border-right: 1px solid var(--border); border-radius: 0; }

  .appbar-nav { display: flex; flex-basis: auto; order: 0; align-items: center; gap: 0.125rem; padding-top: 0; border-top: 0; }
  .primary-menu-btn { display: none; }

  .nav-item {
    display: inline-flex;
    flex-direction: row;
    align-items: center;
    gap: var(--space-2);
    height: 2.125rem;
    min-height: 2.125rem;
    padding: 0 var(--space-3);
    border-radius: var(--radius-pill);
    color: var(--muted-foreground);
    font-size: var(--text-sm);
    font-weight: 500;
    text-decoration: none;
    transition: background var(--duration-fast) var(--ease-out), color var(--duration-fast) var(--ease-out);
  }

  .nav-item:hover { color: var(--foreground); }
  .nav-item.is-active { background: var(--accent); color: var(--foreground); }

  .appbar-end { margin-left: var(--space-2); padding-left: var(--space-3); border-left: 1px solid var(--border); }

  .app-bottom { display: none; }

  .app-main { padding: var(--space-5) 0 var(--space-7); }

  .page { padding: var(--space-3) var(--space-5) var(--space-7); gap: var(--space-5); }
}

/* --------------------------------------------------------------- gates --- */

.gate {
  display: grid;
  place-items: center;
  min-height: 100dvh;
  padding: var(--space-5);
}

.gate-card {
  display: grid;
  justify-items: center;
  gap: var(--space-4);
  width: min(100%, 22rem);
  text-align: center;
}

.gate-mark { display: grid; place-items: center; }
.gate-title { font-size: var(--text-xl); font-weight: 600; letter-spacing: -0.02em; line-height: 1.2; }
.gate-text { color: var(--muted-foreground); font-size: var(--text-sm); }
.gate-actions { display: grid; gap: var(--space-2); width: 100%; margin-top: var(--space-2); }

.noscript { padding: var(--space-5); text-align: center; }

/* ----------------------------------------------------------- page head --- */

.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-3);
}

.page-head-text { display: grid; gap: var(--space-1); min-width: 0; }

.page-eyebrow {
  color: var(--muted-foreground);
  font-size: var(--text-xs);
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.page-title {
  font-size: 1.4375rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.15;
}

.page-subtitle { color: var(--muted-foreground); font-size: var(--text-sm); }
.page-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); }

@media (min-width: 900px) {
  .page-title { font-size: 1.75rem; }
}

.section { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0.625rem; }

.section-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-3);
}

.section-title { font-size: var(--text-md); font-weight: 600; letter-spacing: -0.01em; }
.section-subtitle { margin-top: 0.125rem; color: var(--muted-foreground); font-size: var(--text-sm); }
.section-actions { display: flex; gap: var(--space-2); }

/* ---------------------------------------------------------- cards/rows --- */

.card-interactive { transition: background var(--duration-fast) var(--ease-out), border-color var(--duration-fast) var(--ease-out); }
.card-interactive:hover { border-color: color-mix(in oklch, var(--foreground) 16%, transparent); }

.list { overflow: hidden; }

.row-button {
  width: 100%;
  border-top: 0; border-left: 0; border-right: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.row-button[disabled] { opacity: 0.55; cursor: not-allowed; }

.row-leading {
  display: grid;
  place-items: center;
  flex: none;
  width: 2.25rem; height: 2.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--secondary);
  color: var(--muted-foreground);
}

.row-leading:has(.avatar) { width: auto; height: auto; border: 0; background: none; }

.row-main { display: grid; flex: 1; gap: 0.125rem; min-width: 0; }
.row-title { overflow: hidden; font-weight: 500; text-overflow: ellipsis; white-space: nowrap; }
.row-subtitle { overflow: hidden; color: var(--muted-foreground); font-size: var(--text-sm); text-overflow: ellipsis; white-space: nowrap; }
.row-trailing { display: flex; flex: none; align-items: center; gap: var(--space-2); color: var(--muted-foreground); font-size: var(--text-xs); }

.stat {
  display: grid;
  gap: var(--space-1);
  padding: 0.75rem 0.875rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--card);
}

.stat-label { display: inline-flex; align-items: center; gap: var(--space-1); color: var(--muted-foreground); font-size: var(--text-xs); font-weight: 500; }
.stat-value { font-size: var(--text-lg); font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.stat-hint { color: var(--muted-foreground); font-size: var(--text-xs); }

.kv { display: grid; margin: 0; }
.kv-row { display: flex; justify-content: space-between; gap: var(--space-3); padding: var(--space-2) 0; border-bottom: 1px solid var(--border); font-size: var(--text-sm); }
.kv-row:last-child { border-bottom: 0; }
.kv dt { color: var(--muted-foreground); }
.kv dd { margin: 0; font-weight: 500; text-align: right; }

/* ---------------------------------------------------------- badges ---- */

.badge-success { border-color: color-mix(in oklch, var(--success) 35%, transparent); background: color-mix(in oklch, var(--success) 14%, transparent); color: var(--success); }
.badge-warning { border-color: color-mix(in oklch, var(--warning) 35%, transparent); background: color-mix(in oklch, var(--warning) 14%, transparent); color: var(--warning); }
.badge-danger { border-color: color-mix(in oklch, var(--destructive) 35%, transparent); background: color-mix(in oklch, var(--destructive) 14%, transparent); color: var(--destructive); }
.badge-info { color: var(--foreground); }
.badge-premium { border-color: color-mix(in oklch, var(--rarity-legendary) 35%, transparent); color: var(--rarity-legendary); }

/* -------------------------------------------------------------- avatar --- */

.avatar {
  position: relative;
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 2.25rem; height: 2.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--accent);
  color: var(--muted-foreground);
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.avatar img { position: absolute; inset: 0; width: 100%; height: 100%; border-radius: inherit; object-fit: cover; }
.avatar-sm { width: 2rem; height: 2rem; font-size: 0.625rem; }
.avatar-lg { width: 3rem; height: 3rem; font-size: var(--text-sm); }
.avatar-xl { width: 4rem; height: 4rem; font-size: var(--text-md); }

.avatar-dot {
  position: absolute;
  right: -1px; bottom: -1px;
  width: 0.625rem; height: 0.625rem;
  border: 2px solid var(--card);
  border-radius: var(--radius-pill);
  background: var(--success);
}

/* ------------------------------------------------------------- buttons --- */

.btn-block { width: 100%; }
/* A link styled as a button (linkButton, a.t-btn) must not keep the link underline. */
a.t-btn { text-decoration: none; }
.btn-label { overflow: hidden; text-overflow: ellipsis; }

.t-btn:hover:not([disabled]) { opacity: 0.92; }
.t-btn-secondary:hover:not([disabled]), .t-btn-ghost:hover:not([disabled]) { opacity: 1; }
.t-btn.is-busy { cursor: progress; }

.btn-spinner {
  width: 0.9rem; height: 0.9rem;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: var(--radius-pill);
  animation: spin 0.7s linear infinite;
}

/* Square: the width follows the button height in theme.css. */
.icon-btn { position: relative; width: 2.5rem; padding: 0; }
.icon-btn.t-btn-sm { width: 2.125rem; }

@media (pointer: fine) {
  .icon-btn { width: 2.25rem; }
  .icon-btn.t-btn-sm { width: 1.875rem; }
  .t-input { min-height: 2.25rem; }
}

.icon-btn-badge {
  position: absolute;
  top: 0.25rem; right: 0.25rem;
  min-width: 1rem; height: 1rem;
  padding: 0 0.25rem;
  border-radius: var(--radius-pill);
  background: var(--destructive);
  color: oklch(100% 0 0);
  font-size: 0.625rem;
  line-height: 1rem;
}

.spinner {
  display: inline-block;
  width: 1.25rem; height: 1.25rem;
  border: 2px solid var(--border);
  border-top-color: var(--foreground);
  border-radius: var(--radius-pill);
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------------------------------------------------------- tabs --- */

.tab-badge {
  display: inline-grid;
  place-items: center;
  min-width: 1.125rem; height: 1.125rem;
  margin-left: var(--space-1);
  padding: 0 0.3rem;
  border-radius: var(--radius-pill);
  background: var(--accent);
  color: var(--foreground);
  font-size: 0.625rem;
  font-weight: 600;
}

.t-tab { display: inline-flex; align-items: center; gap: var(--space-2); }

.segmented {
  display: flex;
  gap: var(--space-1);
  padding: var(--space-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--muted);
}

.segmented-option { flex: 1; cursor: pointer; }

.segmented-option > span {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 2.25rem;
  padding: 0 var(--space-3);
  border-radius: var(--radius-md);
  color: var(--muted-foreground);
  font-size: var(--text-sm);
  font-weight: 500;
  transition: background var(--duration-fast) var(--ease-out);
}

.segmented-option input:checked + span { background: var(--card); color: var(--foreground); box-shadow: var(--shadow-sm); }
.segmented-option input:focus-visible + span { outline: 2px solid var(--ring); outline-offset: 2px; }

/* --------------------------------------------------------------- forms --- */

.field { display: grid; gap: var(--space-1); }
.field-label { font-size: var(--text-sm); font-weight: 500; }
.field-required { color: var(--destructive); }
.field-hint { color: var(--muted-foreground); font-size: var(--text-xs); }
.field-error { color: var(--destructive); font-size: var(--text-xs); }
.t-input[aria-invalid="true"] { border-color: var(--destructive); }
.t-input:focus { border-color: var(--ring); outline: none; }

.t-select {
  appearance: none;
  padding-right: var(--space-6);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-position: right var(--space-3) center;
  background-repeat: no-repeat;
}

.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.toggle-text { display: grid; gap: 0.125rem; }
.toggle-label { font-size: var(--text-sm); font-weight: 500; }
.toggle-hint { color: var(--muted-foreground); font-size: var(--text-xs); }

.switch {
  position: relative;
  flex: none;
  width: 2.75rem; height: 1.625rem;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--muted);
  cursor: pointer;
  transition: background var(--duration-fast) var(--ease-out);
}

.switch-thumb {
  position: absolute;
  top: 2px; left: 2px;
  width: 1.25rem; height: 1.25rem;
  border-radius: var(--radius-pill);
  background: var(--muted-foreground);
  transition: transform var(--duration-base) var(--ease-out), background var(--duration-fast) var(--ease-out);
}

.switch[aria-checked="true"] { background: var(--primary); }
.switch[aria-checked="true"] .switch-thumb { background: var(--primary-foreground); transform: translateX(1.125rem); }
.switch[disabled] { opacity: 0.5; cursor: not-allowed; }

.checkbox { display: flex; align-items: flex-start; gap: var(--space-2); cursor: pointer; font-size: var(--text-sm); }
.checkbox-input { width: 1.125rem; height: 1.125rem; margin: 0.125rem 0 0; accent-color: var(--primary); }
.checkbox-text { display: grid; gap: 0.125rem; }
.checkbox-hint { color: var(--muted-foreground); font-size: var(--text-xs); }

/* -------------------------------------------------------------- states --- */

.state {
  display: grid;
  justify-items: center;
  gap: var(--space-2);
  padding: var(--space-5) var(--space-4);
  text-align: center;
}

.state-icon {
  display: grid;
  place-items: center;
  width: 3rem; height: 3rem;
  margin-bottom: var(--space-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--secondary);
  color: var(--muted-foreground);
}

.state-art { display: grid; place-items: center; margin-bottom: var(--space-1); }
.state-art .scene { height: 4.75rem; }
.state-icon-danger { color: var(--destructive); }
.state-icon-success { color: var(--success); }
.state-title { font-size: var(--text-md); font-weight: 600; }
.state-text { max-width: 28rem; color: var(--muted-foreground); font-size: var(--text-sm); }
.state .t-btn { margin-top: var(--space-2); }

/* Members-only wall (forum, roulette, workshop without an active subscription). */
.sub-gate {
  display: grid;
  justify-items: center;
  gap: var(--space-2);
  padding: var(--space-5) var(--space-4);
  text-align: center;
}

.sub-gate-art { display: grid; place-items: center; }
.sub-gate-art .bear { height: 5.5rem; }
.sub-gate-title { font-size: var(--text-md); font-weight: 600; }
.sub-gate-text { max-width: 24rem; color: var(--muted-foreground); font-size: var(--text-sm); }

.sub-gate-actions {
  display: grid;
  /* Two buttons side by side only when both labels fit; stacked otherwise. */
  grid-template-columns: repeat(auto-fit, minmax(11.5rem, 1fr));
  gap: var(--space-2);
  width: min(100%, 22rem);
  margin-top: var(--space-2);
}

.state-inline {
  grid-template-columns: auto minmax(0, 1fr);
  justify-items: start;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-4);
  text-align: left;
}

.state-inline .state-art { margin: 0; }
.state-inline .state-art .scene { height: 4rem; }
.state-inline .state-body { display: grid; justify-items: start; gap: 0.125rem; min-width: 0; }
.state-inline .state-title { font-size: var(--text-sm); }
.state-inline .state-text { font-size: var(--text-xs); }

.skeleton-block { display: grid; gap: var(--space-2); }
.skeleton-line { display: block; height: 0.875rem; }
.skeleton-short { width: 60%; }
.skeleton-title { width: 40%; height: 2rem; }
.skeleton-avatar { flex: none; width: 2.25rem; height: 2.25rem; border-radius: var(--radius-pill); }
.page-skeleton { display: grid; gap: var(--space-3); }

/* ------------------------------------------------------------- overlay --- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-3) var(--space-3) max(var(--space-3), var(--safe-bottom));
  background: oklch(0% 0 0 / 0.5);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  animation: t-fade var(--duration-base) var(--ease-out);
}

.overlay.is-leaving { animation: fade-out 160ms var(--ease-out) forwards; }
@keyframes fade-out { to { opacity: 0; } }

.modal {
  display: flex;
  flex-direction: column;
  width: min(100%, 28rem);
  min-width: 0;
  max-height: calc(100dvh - var(--space-6));
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  background: var(--popover);
  color: var(--popover-foreground);
  box-shadow: var(--shadow-lg);
  outline: none;
  animation: t-rise var(--duration-base) var(--ease-out);
}

@keyframes sheet-up { from { transform: translateY(24px); opacity: 0; } }

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-4) 0;
  flex-shrink: 0;
}

.modal-head-text { display: grid; gap: var(--space-1); padding-top: var(--space-1); }

.modal { position: relative; }
.modal-close-float { position: absolute; top: var(--space-2); right: var(--space-2); z-index: 2; }
/* The account menu head shares the top row with the floating X. */
.account-menu .account-head { padding-right: 2.5rem; }
.modal-title { font-size: var(--text-lg); font-weight: 600; letter-spacing: -0.01em; }
.modal-subtitle { color: var(--muted-foreground); font-size: var(--text-sm); }

.modal-body {
  display: grid;
  gap: var(--space-4);
  min-height: 0;
  min-width: 0;
  grid-template-columns: minmax(0, 1fr);
  padding: var(--space-4);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.modal-text { color: var(--muted-foreground); font-size: var(--text-sm); line-height: 1.6; }

.modal-footer {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4) calc(var(--safe-bottom) + var(--space-4));
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.modal-footer > .t-btn { flex: 1 1 8rem; }

@media (min-width: 640px) {
  .overlay { align-items: center; padding: var(--space-5); }
  .modal { width: min(100%, 28rem); max-height: calc(100dvh - 4rem); border-bottom: 1px solid var(--border); border-radius: var(--radius-xl); animation: t-rise var(--duration-base) var(--ease-out); }
  .modal-sm { width: min(100%, 24rem); }
  .modal-lg { width: min(100%, 44rem); }
  .modal-footer { padding-bottom: var(--space-4); justify-content: flex-end; }
  .modal-footer > .t-btn { flex: 0 1 auto; }
}

/* Centred on every screen size: short announcements, not forms. */
.overlay-center { align-items: center; padding: var(--space-4); }

.overlay-center > .modal {
  border-bottom: 1px solid var(--border);
  border-radius: var(--radius-xl);
  animation: t-rise var(--duration-base) var(--ease-out);
}

.overlay-center .modal-footer { padding-bottom: var(--space-3); }

.modal-lightbox .modal-body { padding: var(--space-2); }
.lightbox-image { width: 100%; max-height: 78dvh; border-radius: var(--radius-md); object-fit: contain; }

/* account menu */
.account-head { display: flex; align-items: center; gap: var(--space-3); }
.account-head-text { display: grid; flex: 1; gap: 0.125rem; min-width: 0; }
.account-name { overflow: hidden; font-size: var(--text-md); text-overflow: ellipsis; white-space: nowrap; }
.account-roles { color: var(--muted-foreground); font-size: var(--text-xs); }
.uid-chip { cursor: pointer; }

.menu-group { overflow: hidden; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--card); }

.menu-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  min-height: 3rem;
  padding: 0 var(--space-4);
  border: 0;
  border-bottom: 1px solid var(--border);
  background: transparent;
  font-size: var(--text-sm);
  font-weight: 500;
  text-align: left;
  cursor: pointer;
}

.menu-item:last-child { border-bottom: 0; }
.menu-item:hover { background: var(--accent); }
.menu-item > .icon:first-child { color: var(--muted-foreground); }
.menu-item-label { flex: 1; }
.menu-item-label { min-width: 0; overflow-wrap: anywhere; }
.menu-meta, .menu-chevron { flex-shrink: 0; }
.menu-meta { color: var(--muted-foreground); font-size: var(--text-xs); }
.menu-chevron { color: var(--muted-foreground); }

/* -------------------------------------------------------------- toasts --- */

.toast-root {
  position: fixed;
  top: calc(var(--safe-top) + 4.5rem);
  left: 50%;
  z-index: 80;
  display: grid;
  gap: var(--space-2);
  width: min(calc(100% - 2rem), 26rem);
  transform: translateX(-50%);
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--popover);
  box-shadow: var(--shadow-lg);
  font-size: var(--text-sm);
  animation: t-rise var(--duration-base) var(--ease-out);
}

.toast.is-leaving { animation: fade-out 200ms var(--ease-out) forwards; }
.toast-success .icon { color: var(--success); }
.toast-error .icon { color: var(--destructive); }
.toast-warning .icon { color: var(--warning); }

/* ---------------------------------------------------------------- pager --- */

.pager { display: flex; align-items: center; justify-content: center; gap: var(--space-3); }
.pager-current { color: var(--muted-foreground); font-size: var(--text-sm); }

/* --------------------------------------------------------------- files --- */

.file-picker { display: grid; gap: var(--space-2); justify-items: start; }
.file-trigger { cursor: pointer; }
.file-list { display: grid; gap: var(--space-2); width: 100%; }

.file-chip {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--secondary);
}

.file-thumb { flex: none; width: 2.5rem; height: 2.5rem; border-radius: var(--radius-sm); object-fit: cover; }
.file-thumb-icon { display: grid; place-items: center; background: var(--accent); color: var(--muted-foreground); }
.file-meta { display: grid; flex: 1; min-width: 0; text-align: left; }
.file-name { overflow: hidden; font-size: var(--text-sm); font-weight: 500; text-overflow: ellipsis; white-space: nowrap; }
.file-size { color: var(--muted-foreground); font-size: var(--text-xs); }

.attachments { display: grid; grid-template-columns: repeat(auto-fill, minmax(7.5rem, 1fr)); gap: var(--space-2); }

.attachment {
  position: relative;
  overflow: hidden;
  min-height: 5.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--secondary);
}

.attachment-image { padding: 0; cursor: zoom-in; }
.attachment-image img { width: 100%; height: 100%; aspect-ratio: 4 / 3; object-fit: cover; }
.attachment-video { grid-column: 1 / -1; }
.attachment-video video { width: 100%; max-height: 22rem; background: oklch(0% 0 0); }
.attachment-file { display: flex; align-items: center; gap: var(--space-2); grid-column: span 2; padding: var(--space-3); cursor: pointer; text-align: left; }
.attachment-skeleton { position: absolute; inset: 0; border-radius: 0; }

/* -------------------------------------------------------------- markup --- */

.md { display: grid; gap: var(--space-3); overflow-wrap: anywhere; line-height: 1.65; }
.md-link { color: var(--foreground); text-decoration: underline; text-decoration-color: var(--muted-foreground); text-underline-offset: 3px; }
.md-code { padding: 0.1em 0.35em; border-radius: var(--radius-sm); background: var(--muted); font-family: var(--font-mono); font-size: 0.9em; }
.md-pre { overflow-x: auto; margin: 0; padding: var(--space-3); border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--muted); font-family: var(--font-mono); font-size: var(--text-sm); line-height: 1.55; }
.md-quote { margin: 0; padding: var(--space-1) var(--space-3); border-left: 2px solid var(--border); color: var(--muted-foreground); }

/* ------------------------------------------------------------- payment --- */

.payment-status { display: flex; align-items: center; gap: var(--space-3); color: var(--muted-foreground); font-size: var(--text-sm); }
.result-hero { display: grid; justify-items: center; gap: var(--space-2); text-align: center; }
.result-title { font-size: var(--text-xl); font-weight: 600; letter-spacing: -0.02em; }
.result-key { display: grid; gap: var(--space-2); }

.result-key-value {
  display: block;
  padding: var(--space-3);
  border: 1px dashed var(--border);
  border-radius: var(--radius-md);
  background: var(--muted);
  font-size: var(--text-md);
  text-align: center;
  word-break: break-all;
}

.countdown { font-variant-numeric: tabular-nums; }

@media (prefers-reduced-motion: reduce) {
  :root:not([data-motion="full"]) :is(.page, .modal, .toast, .overlay, .coin-dot) { animation: none; }
}

:root[data-motion="reduced"] :is(.page, .modal, .toast, .overlay, .coin-dot) { animation: none; }
