*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body { margin: 0; background: var(--bg); color: var(--text); font: 400 var(--fs-md)/1.6 var(--font-body); -webkit-font-smoothing: antialiased; }
h1, h2, h3 { font-family: var(--font-display); font-weight: 400; letter-spacing: 0.01em; line-height: 1.1; margin: 0 0 var(--s-3); text-wrap: balance; }
h1 { font-size: var(--fs-3xl); } h2 { font-size: var(--fs-2xl); } h3 { font-size: var(--fs-xl); }
p { margin: 0 0 var(--s-4); text-wrap: pretty; }
a { color: var(--brand); text-underline-offset: 3px; }
img, svg { max-width: 100%; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.ico { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2); min-height: 44px; padding: 0 var(--s-5); border: 1px solid transparent; border-radius: var(--r-pill); font: 600 var(--fs-sm)/1 var(--font-body); cursor: pointer; text-decoration: none; background: var(--brand); color: var(--on-brand); transition: transform var(--t-fast) var(--ease), background var(--t-fast), box-shadow var(--t-med) var(--ease); -webkit-tap-highlight-color: transparent; }
.btn:hover { background: var(--brand-hover); }
.btn:active, .pressable:active { transform: scale(0.97); }
.btn-cta { background: var(--cta); color: var(--on-cta); box-shadow: var(--shadow-1); } .btn-cta:hover { background: var(--cta-hover); box-shadow: var(--shadow-2); }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--line); } .btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: var(--red-600); color: #fff; } .btn-danger:hover { background: var(--red-600); filter: brightness(0.92); }
.btn-sm { min-height: 36px; padding: 0 var(--s-4); } .btn-block { width: 100%; }
.btn[disabled] { opacity: 0.5; pointer-events: none; }
.btn.busy { pointer-events: none; opacity: 0.75; } .btn.busy::after { content: ""; width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin 700ms linear infinite; }

/* Fields */
.field { display: grid; gap: 6px; margin-bottom: var(--s-4); }
.field label { font: 600 var(--fs-sm)/1.2 var(--font-body); }
.field .hint { color: var(--text-2); font-size: var(--fs-xs); }
.field .err { color: var(--red-600); font-size: var(--fs-xs); min-height: 0; }
input, textarea, select { width: 100%; min-height: 44px; padding: 10px 14px; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface); color: var(--text); font: inherit; transition: border-color var(--t-fast), box-shadow var(--t-fast); }
textarea { min-height: 120px; resize: vertical; line-height: 1.5; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 25%, transparent); }
input[aria-invalid="true"] { border-color: var(--red-600); }

/* Switch: the knob stretches while pressed */
.switch { position: relative; width: 52px; height: 32px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; z-index: 1; }
.switch .track { position: absolute; inset: 0; border-radius: var(--r-pill); background: var(--n-300); transition: background var(--t-med) var(--ease); }
.switch .knob { position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: var(--r-pill); background: #fff; box-shadow: var(--shadow-1); transition: transform var(--t-med) var(--ease-spring), width var(--t-fast) var(--ease), scale var(--t-fast) var(--ease); }
.switch input:checked ~ .track { background: var(--brand); }
.switch input:checked ~ .knob { transform: translateX(20px); }
.switch input:active ~ .knob { width: 32px; } .switch input:checked:active ~ .knob { transform: translateX(14px); }
.switch input:focus-visible ~ .track { outline: 3px solid var(--focus); outline-offset: 2px; }

/* Surfaces */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: var(--s-5); box-shadow: var(--shadow-1); }
.card.hoverable { transition: transform var(--t-med) var(--ease), box-shadow var(--t-med) var(--ease); } .card.hoverable:hover { transform: translateY(-2px); box-shadow: var(--shadow-2); }
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border-radius: var(--r-pill); font: 600 var(--fs-xs)/1.6 var(--font-body); background: var(--surface-2); color: var(--text-2); }
.badge.ok { background: var(--green-50); color: var(--green-600); } .badge.warn { background: var(--amber-50); color: var(--amber-600); } .badge.bad { background: var(--red-50); color: var(--red-600); } .badge.brand { background: var(--brand-soft); color: var(--brand); }
.muted { color: var(--text-2); } .row { display: flex; align-items: center; gap: var(--s-3); } .between { justify-content: space-between; } .wrap { flex-wrap: wrap; } .grow { flex: 1; min-width: 0; }
.stack { display: grid; gap: var(--s-3); } .grid-2 { display: grid; gap: var(--s-4); grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.stat { font: 400 2rem/1 var(--font-display); } .stat-label { color: var(--text-2); font-size: var(--fs-xs); }
.chips { display: flex; gap: var(--s-2); overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; } .chip { padding: 6px 14px; border-radius: var(--r-pill); border: 1px solid var(--line); background: var(--surface); font: 600 var(--fs-sm)/1.2 var(--font-body); cursor: pointer; white-space: nowrap; color: var(--text); } .chip[aria-pressed="true"] { background: var(--brand); color: var(--on-brand); border-color: var(--brand); }

/* Skeleton */
.skel { border-radius: var(--r-md); background: linear-gradient(100deg, var(--surface-2) 30%, var(--line) 50%, var(--surface-2) 70%); background-size: 200% 100%; animation: shimmer 1.3s linear infinite; min-height: 18px; }

/* Toasts */
.toasts { position: fixed; left: 0; right: 0; bottom: calc(88px + env(safe-area-inset-bottom)); display: grid; gap: var(--s-2); justify-items: center; pointer-events: none; z-index: 60; padding: 0 var(--s-4); }
.toast { background: var(--ink); color: #fff; padding: 12px 18px; border-radius: var(--r-pill); font: 500 var(--fs-sm)/1.3 var(--font-body); box-shadow: var(--shadow-3); display: flex; gap: var(--s-2); align-items: center; animation: toast-in var(--t-med) var(--ease-spring) both; max-width: 100%; }
.toast.ok .ico { animation: pulse 600ms var(--ease) both; color: var(--yellow-400); } .toast.out { animation: toast-out var(--t-fast) var(--ease) both; }

/* Sheet */
.scrim { position: fixed; inset: 0; background: rgb(10 11 16 / 0.5); opacity: 0; transition: opacity var(--t-med) var(--ease); z-index: 40; } .scrim.on { opacity: 1; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; max-height: 90dvh; overflow: auto; background: var(--surface); border-radius: var(--r-lg) var(--r-lg) 0 0; padding: var(--s-3) var(--s-5) calc(var(--s-5) + env(safe-area-inset-bottom)); box-shadow: var(--shadow-3); transform: translateY(100%); transition: transform var(--t-med) var(--ease); z-index: 50; touch-action: pan-y; overscroll-behavior: contain; }
.sheet.on { transform: none; } .sheet.drag { transition: none; }
.grab { width: 40px; height: 5px; border-radius: 3px; background: var(--n-300); margin: 0 auto var(--s-4); }
@media (min-width: 720px) { .sheet { left: 50%; right: auto; width: 520px; bottom: 50%; border-radius: var(--r-lg); transform: translate(-50%, 60%); opacity: 0; transition: transform var(--t-med) var(--ease), opacity var(--t-med); } .sheet.on { transform: translate(-50%, 50%); opacity: 1; } .grab { display: none; } }

/* Reveal */
.reveal { opacity: 0; transform: translateY(14px); transition: opacity var(--t-slow) var(--ease), transform var(--t-slow) var(--ease); transition-delay: calc(var(--i, 0) * 30ms); }
.reveal.in { opacity: 1; transform: none; }
.fade-in { animation: fade var(--t-med) var(--ease) both; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shimmer { to { background-position: -200% 0; } }
@keyframes fade { from { opacity: 0; } }
@keyframes pulse { 0% { transform: scale(0.4); } 60% { transform: scale(1.25); } 100% { transform: scale(1); } }
@keyframes toast-in { from { opacity: 0; transform: translateY(16px) scale(0.96); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(8px); } }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }
.shake { animation: shake 360ms var(--ease); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; scroll-behavior: auto !important; }
  .reveal { transform: none; } .btn:active, .pressable:active, .card.hoverable:hover { transform: none; } .sheet, .toast { transform: none; }
  .fade-in, .reveal { transition: opacity 200ms linear; }
}
::view-transition-old(root), ::view-transition-new(root) { animation-duration: 180ms; }
