/*
 * Base layer: reset, ambient background, typography, layout shell (app bar, tab bar).
 * Mobile-first; 44×44px minimum touch targets; safe-area aware.
 */
*, *::before, *::after { box-sizing: border-box; }

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

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-sans);
  font-size: var(--text-body);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
}

/* Ambient gradients: fixed layer so scrolling never repaints them. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(circle at 10% 10%, var(--ambient-1), transparent 35%),
    radial-gradient(circle at 90% 80%, var(--ambient-2), transparent 35%);
}

/* Theme switch: animate colours briefly, only while switching. */
html.theme-switching body,
html.theme-switching body * {
  transition: background-color var(--dur-slow) var(--ease), border-color var(--dur-slow) var(--ease), color var(--dur-slow) var(--ease), fill var(--dur-slow) var(--ease) !important;
}

a { color: var(--color-primary-text); text-decoration: none; }
button { font: inherit; color: inherit; }
img, svg { display: block; }
.icon { flex: none; }

:focus-visible {
  outline: 3px solid var(--color-primary);
  outline-offset: 2px;
  border-radius: var(--radius-xs);
}
h1:focus, h2:focus, p:focus { outline: none; }

::selection { background: var(--color-primary-soft); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
}

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

/* ---------- typography ---------- */
.page__title {
  margin: 0;
  font-family: var(--font-display);
  font-size: var(--text-h1);
  font-weight: var(--weight-bold);
  line-height: 1.15;
  letter-spacing: var(--tracking-tight);
}
.page__sub { margin: var(--space-1) 0 0; color: var(--color-text-secondary); font-size: var(--text-body); }
.eyebrow {
  margin: 0 0 var(--space-1);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  color: var(--color-primary-text);
}
.section-title {
  margin: 0;
  font-size: var(--text-h3);
  font-weight: var(--weight-semibold);
  letter-spacing: -0.01em;
}
.muted { color: var(--color-text-secondary); }
.num, .tabular { font-variant-numeric: tabular-nums; }

/* ---------- layout ---------- */
.screen { max-width: var(--content-max); margin: 0 auto; min-height: 100vh; min-height: 100dvh; }
.screen--wide { max-width: var(--content-wide); }
.page {
  padding: var(--space-4) calc(var(--space-4) + var(--safe-right)) var(--space-8) calc(var(--space-4) + var(--safe-left));
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}
.screen.has-tabbar .page { padding-bottom: calc(var(--nav-h) + var(--space-9) + var(--safe-bottom)); }
.page-head { display: flex; flex-direction: column; }
.section { display: flex; flex-direction: column; gap: var(--space-3); }
.section__head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-3); }
.section__action {
  display: inline-flex; align-items: center; gap: 2px; min-height: 44px;
  font-size: var(--text-sm); font-weight: var(--weight-semibold); color: var(--color-primary-text);
}
.stack { display: flex; flex-direction: column; gap: var(--space-3); }
.cluster { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); }
.grid-auto { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: var(--space-3); }

/* ---------- app bar (glass) ---------- */
.appbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 60px;
  padding: calc(var(--space-2) + var(--safe-top)) calc(var(--space-4) + var(--safe-right)) var(--space-2) calc(var(--space-4) + var(--safe-left));
  background: var(--color-surface-glass);
  -webkit-backdrop-filter: var(--glass-filter);
  backdrop-filter: var(--glass-filter);
  border-bottom: 1px solid var(--color-border);
}
.appbar__brand { display: flex; align-items: center; gap: var(--space-2); min-width: 0; color: var(--color-text); }
.appbar__name { font-weight: var(--weight-bold); font-size: var(--text-body-lg); letter-spacing: -0.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appbar__title { flex: 1; min-width: 0; font-weight: var(--weight-semibold); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appbar__back {
  display: inline-flex; align-items: center; gap: var(--space-1);
  min-height: 44px; padding: 0 var(--space-3) 0 var(--space-2); margin-left: calc(-1 * var(--space-2));
  border-radius: var(--radius-pill); color: var(--color-text); font-weight: var(--weight-semibold);
  transition: background-color var(--dur-fast) var(--ease);
}
.appbar__back:hover { background: var(--color-surface-hover); }
.appbar__back:active { transform: scale(.97); }
.appbar__actions { margin-left: auto; display: flex; align-items: center; gap: var(--space-2); }
.appbar__lang { min-height: 44px; font-weight: var(--weight-semibold); color: var(--color-text); }

.brand-mark {
  flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: 10px;
  color: #fff;
  background: var(--gradient-brand);
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.30), inset 0 1px 0 rgba(255, 255, 255, 0.35);
}
.brand-mark--lg { width: 80px; height: 80px; border-radius: 26px; box-shadow: 0 16px 40px rgba(79, 70, 229, 0.32), inset 0 1px 0 rgba(255, 255, 255, 0.4); }

/* ---------- bottom tab bar (glass, floating) ---------- */
.tabbar {
  position: fixed;
  left: 50%;
  bottom: calc(var(--space-3) + var(--safe-bottom));
  transform: translateX(-50%);
  z-index: 12;
  width: calc(100% - 2 * var(--space-4));
  max-width: 520px;
  height: var(--nav-h);
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  align-items: center;
  padding: 0 var(--space-2);
  border-radius: var(--radius-lg);
  background: var(--color-surface-glass);
  -webkit-backdrop-filter: var(--glass-filter);
  backdrop-filter: var(--glass-filter);
  border: 1px solid var(--color-glass-border);
  box-shadow: var(--shadow-lg), var(--glass-highlight);
}
html[data-effects="reduced"] .tabbar { border-color: var(--color-border); }
.tabbar__item {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 52px; border-radius: var(--radius-md);
  color: var(--color-text-secondary);
  font-size: 11px; font-weight: var(--weight-semibold); letter-spacing: .01em;
  transition: color var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
.tabbar__item:active { transform: scale(.94); }
.tabbar__item.is-active { color: var(--color-primary-text); }
.tabbar__label { white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.tabbar__item--primary .tabbar__icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 52px; height: 52px; margin-top: -26px; border-radius: 18px;
  color: #fff;
  background: var(--gradient-primary);
  box-shadow: var(--shadow-primary), inset 0 1px 0 rgba(255, 255, 255, 0.3);
}
.tabbar__item--primary .tabbar__icon svg { margin-left: 3px; }
.tabbar__item--primary { color: var(--color-text); }

@media (min-width: 600px) {
  .page { padding: var(--space-6) var(--space-6) var(--space-9); gap: var(--space-6); }
}

/* ---------- route transition (navigation only, not re-renders) ---------- */
.route-enter .page, .route-enter .mcontent, .route-enter .mlogin { animation: route-in var(--dur-slow) var(--ease) both; }
@keyframes route-in { from { opacity: 0; transform: translateY(8px); } }

/* ---------- boot skeleton (static markup in index.html, replaced by the first render) ---------- */
.boot { max-width: var(--content-max); margin: 0 auto; padding: calc(var(--space-6) + var(--safe-top)) var(--space-4); display: flex; flex-direction: column; gap: var(--space-4); }
.boot__bar { height: 28px; width: 55%; border-radius: var(--radius-xs); }
.boot__card { height: 140px; border-radius: var(--radius-lg); }
.boot__card--sm { height: 84px; }
.boot__bar, .boot__card { background: linear-gradient(90deg, var(--color-surface-sunken) 0%, var(--color-surface-hover) 40%, var(--color-surface-sunken) 80%); background-size: 200% 100%; animation: shimmer 1.4s linear infinite; }
