/* =========================================================================
   Reset, typography and small utilities
   ========================================================================= */

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

* { margin: 0; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
  tab-size: 4;
}

body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
}

img, svg, video, canvas { display: block; max-width: 100%; height: auto; }

input, button, textarea, select { font: inherit; color: inherit; }

button { background: none; border: 0; cursor: pointer; }

a { color: var(--text-brand); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }

ul, ol { padding: 0; list-style: none; }

h1, h2, h3, h4, h5, h6 {
  font-weight: var(--weight-bold);
  line-height: var(--leading-tight);
  letter-spacing: var(--tracking-tight);
  color: var(--text);
  text-wrap: balance;
}

h1 { font-size: var(--text-3xl); }
h2 { font-size: var(--text-2xl); }
h3 { font-size: var(--text-xl); }
h4 { font-size: var(--text-lg); }
h5, h6 { font-size: var(--text-md); }

p { text-wrap: pretty; }

hr { border: 0; border-top: 1px solid var(--border); margin: var(--space-6) 0; }

code, kbd, pre { font-family: var(--font-mono); font-size: 0.9em; }

::selection { background: var(--brand-200); color: var(--ink-900); }

/* Focus: always visible for keyboard users, never a stray ring on a mouse click. */
:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--brand-500);
  outline-offset: 2px;
  border-radius: var(--radius-xs);
}

/* Skip link - the first thing a keyboard or screen-reader user meets. */
.skip-link {
  position: absolute;
  left: var(--space-4);
  top: -100px;
  z-index: var(--z-toast);
  padding: var(--space-3) var(--space-5);
  background: var(--brand-600);
  color: #fff;
  border-radius: var(--radius-sm);
  font-weight: var(--weight-semibold);
  transition: top var(--duration-base) var(--ease-out);
}
.skip-link:focus { top: var(--space-4); text-decoration: none; }

/* ---- scrollbars --------------------------------------------------------- */
* { scrollbar-width: thin; scrollbar-color: var(--ink-300) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: var(--ink-300);
  border-radius: var(--radius-pill);
  border: 3px solid transparent;
  background-clip: content-box;
}
*::-webkit-scrollbar-thumb:hover { background: var(--ink-400); background-clip: content-box; }

/* =========================================================================
   Layout utilities
   ========================================================================= */

.container {
  width: 100%;
  max-width: var(--container);
  margin-inline: auto;
  padding-inline: var(--space-5);
}
.container-narrow { max-width: var(--container-narrow); }
.container-wide   { max-width: var(--container-wide); }

@media (min-width: 768px) {
  .container { padding-inline: var(--space-8); }
}

.stack > * + * { margin-top: var(--space-4); }
.stack-sm > * + * { margin-top: var(--space-2); }
.stack-lg > * + * { margin-top: var(--space-6); }
.stack-xl > * + * { margin-top: var(--space-10); }

.row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
}
.row-between { justify-content: space-between; }
.row-end { justify-content: flex-end; }
.row-center { justify-content: center; }
.row-top { align-items: flex-start; }
.row-nowrap { flex-wrap: nowrap; }
.row-tight { gap: var(--space-2); }

.grid { display: grid; gap: var(--space-5); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr)); }

.split { display: grid; gap: var(--space-6); }
@media (min-width: 900px) {
  .split { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .split-wide { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); }
  .split-narrow { grid-template-columns: minmax(0, 1fr) minmax(0, 1.6fr); }
}

.spacer { flex: 1 1 auto; }

/* ---- text --------------------------------------------------------------- */
.text-xs { font-size: var(--text-xs); }
.text-sm { font-size: var(--text-sm); }
.text-md { font-size: var(--text-md); }
.text-lg { font-size: var(--text-lg); }
.text-xl { font-size: var(--text-xl); }
.text-2xl { font-size: var(--text-2xl); }
.text-3xl { font-size: var(--text-3xl); }

.muted   { color: var(--text-muted); }
.subtle  { color: var(--text-subtle); }
.brand   { color: var(--text-brand); }
.success { color: var(--success-600); }
.warning { color: var(--warning-600); }
.danger  { color: var(--danger-600); }

.medium   { font-weight: var(--weight-medium); }
.semibold { font-weight: var(--weight-semibold); }
.bold     { font-weight: var(--weight-bold); }
.black    { font-weight: var(--weight-black); }

.uppercase { text-transform: uppercase; letter-spacing: var(--tracking-wide); }
.mono { font-family: var(--font-mono); font-variant-ligatures: none; }
.tabular { font-variant-numeric: tabular-nums; }
.center { text-align: center; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.lead {
  font-size: var(--text-lg);
  line-height: var(--leading-loose);
  color: var(--text-muted);
}

.gradient-text {
  background: var(--gradient-brand);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

/* ---- spacing helpers ---------------------------------------------------- */
.mt-0 { margin-top: 0; }
.mt-2 { margin-top: var(--space-2); }
.mt-3 { margin-top: var(--space-3); }
.mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }
.mt-8 { margin-top: var(--space-8); }
.mt-10 { margin-top: var(--space-10); }
.mb-0 { margin-bottom: 0; }
.mb-2 { margin-bottom: var(--space-2); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-6 { margin-bottom: var(--space-6); }
.mb-8 { margin-bottom: var(--space-8); }

/* ---- accessibility ------------------------------------------------------ */
.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

[hidden] { display: none !important; }

/* =========================================================================
   Motion
   Every animation below is opt-in via a class, and every one of them is
   switched off entirely when the visitor has asked for reduced motion.
   ========================================================================= */

@keyframes fade-up {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: none; }
}
@keyframes fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes scale-in {
  from { opacity: 0; transform: scale(0.96); }
  to   { opacity: 1; transform: none; }
}
@keyframes slide-in-right {
  from { transform: translateX(100%); }
  to   { transform: none; }
}
@keyframes shimmer {
  from { background-position: -200% 0; }
  to   { background-position: 200% 0; }
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse-soft {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.55; }
}
@keyframes float {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-8px); }
}

.animate-up   { animation: fade-up var(--duration-slow) var(--ease-out) both; }
.animate-in   { animation: fade-in var(--duration-base) var(--ease-out) both; }
.animate-pop  { animation: scale-in var(--duration-base) var(--ease-spring) both; }
.animate-float { animation: float 6s var(--ease-in-out) infinite; }

/* Stagger: children enter in sequence rather than all at once. */
.stagger > * { animation: fade-up var(--duration-slow) var(--ease-out) both; }
.stagger > *:nth-child(1) { animation-delay: 40ms; }
.stagger > *:nth-child(2) { animation-delay: 90ms; }
.stagger > *:nth-child(3) { animation-delay: 140ms; }
.stagger > *:nth-child(4) { animation-delay: 190ms; }
.stagger > *:nth-child(5) { animation-delay: 240ms; }
.stagger > *:nth-child(6) { animation-delay: 290ms; }
.stagger > *:nth-child(7) { animation-delay: 340ms; }
.stagger > *:nth-child(8) { animation-delay: 390ms; }

/* Revealed by IntersectionObserver in app.js. Without JS the element is
   simply visible from the start - the content never depends on the script. */
.reveal { opacity: 0; transform: translateY(18px); }
.reveal.is-visible {
  opacity: 1;
  transform: none;
  transition: opacity var(--duration-slower) var(--ease-out),
              transform var(--duration-slower) var(--ease-out);
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .reveal { opacity: 1; transform: none; }
}

/* =========================================================================
   Print
   ========================================================================= */
@media print {
  body { background: #fff; color: #000; }
  .no-print, .app-header, .app-sidebar, .app-footer, .toast-stack, .drawer { display: none !important; }
  .app-main { padding: 0 !important; }
  a[href]::after { content: " (" attr(href) ")"; font-size: 0.8em; color: #555; }
  .card, .panel { box-shadow: none !important; border: 1px solid #ddd !important; }
}
