/* ═══════════════════════════════════════════════════════════
   TRISTAN Control Center v3 — Base CSS
   Reset, typography, animation tokens, keyframes, utilities
   ═══════════════════════════════════════════════════════════ */

/* ── Reset ─────────────────────────────────────────────── */

*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

body {
  min-height: 100dvh;
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--bg-base);
  font-family: var(--font-body);
  overflow-x: hidden;
  transition: background-color 0.25s ease, color 0.25s ease;
}

img, svg {
  display: block;
  max-width: 100%;
}

button, input, textarea, select {
  font: inherit;
  color: inherit;
  border: none;
  background: none;
  outline: none;
}

button {
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
}

a {
  color: inherit;
  text-decoration: none;
}

ul, ol {
  list-style: none;
}

/* ── Typography Scale ──────────────────────────────────── */

:root {
  /* Display — hero numbers and titles */
  --text-display-xl: 48px;
  --text-display-lg: 36px;
  --text-display: 32px;

  /* Headings */
  --text-h1: 28px;
  --text-h2: 22px;
  --text-h3: 18px;

  /* Body — optimized for mobile readability */
  --text-body-lg: 17px;
  --text-body: 15px;
  --text-body-sm: 14px;

  /* Caption */
  --text-caption: 13px;
  --text-caption-sm: 11px;

  /* Line heights */
  --lh-tight: 1.2;
  --lh-normal: 1.5;
  --lh-relaxed: 1.65;

  /* Font weights */
  --fw-regular: 400;
  --fw-medium: 500;
  --fw-semibold: 600;
  --fw-bold: 700;

  /* Letter spacing */
  --ls-tight: -0.02em;
  --ls-normal: 0;
  --ls-wide: 0.04em;
  --ls-caps: 0.08em;
}

/* ── Spacing Scale ─────────────────────────────────────── */

:root {
  --sp-2: 2px;
  --sp-4: 4px;
  --sp-6: 6px;
  --sp-8: 8px;
  --sp-10: 10px;
  --sp-12: 12px;
  --sp-16: 16px;
  --sp-20: 20px;
  --sp-24: 24px;
  --sp-32: 32px;
  --sp-40: 40px;
  --sp-48: 48px;
  --sp-64: 64px;

  /* Safe area (iPhone notch / home indicator) */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

/* ── Animation Tokens ──────────────────────────────────── */

:root {
  /* Easing curves */
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-bounce: cubic-bezier(0.68, -0.55, 0.265, 1.55);
  --ease-smooth: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-sharp: cubic-bezier(0.4, 0, 0.2, 1);

  /* Durations */
  --dur-instant: 0.1s;
  --dur-fast: 0.2s;
  --dur-normal: 0.3s;
  --dur-slow: 0.5s;
  --dur-slower: 0.8s;
}

/* ── Keyframes ─────────────────────────────────────────── */

/* Card reveal on page load */
@keyframes cardReveal {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Modal / bottom sheet slide up */
@keyframes modalSlideUp {
  from {
    opacity: 0;
    transform: translateY(100%);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Toast slide down from top */
@keyframes toastIn {
  from {
    opacity: 0;
    transform: translate(-50%, -80px);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

/* Toast exit */
@keyframes toastOut {
  from {
    opacity: 1;
    transform: translate(-50%, 0);
  }
  to {
    opacity: 0;
    transform: translate(-50%, -80px);
  }
}

/* AI Spotlight pull-down */
@keyframes aiReveal {
  from {
    opacity: 0;
    transform: translateY(-100%);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Loading shimmer */
@keyframes shimmer {
  0% { background-position: -200% center; }
  100% { background-position: 200% center; }
}

/* Fade in generic */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Scale pop — for chips, badges appearing */
@keyframes scalePop {
  from {
    opacity: 0;
    transform: scale(0.8);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* ── Component Base Classes ────────────────────────────── */

/* Tap feedback — use on all interactive elements */
.tappable {
  transition: transform var(--dur-fast) var(--ease-spring);
  will-change: transform;
}

.tappable:active {
  transform: scale(0.96);
}

/* Card reveal with stagger */
.card {
  animation: cardReveal var(--dur-slow) var(--ease-spring) backwards;
}

.card:nth-child(1) { animation-delay: 0.05s; }
.card:nth-child(2) { animation-delay: 0.10s; }
.card:nth-child(3) { animation-delay: 0.15s; }
.card:nth-child(4) { animation-delay: 0.20s; }
.card:nth-child(5) { animation-delay: 0.25s; }
.card:nth-child(6) { animation-delay: 0.30s; }

/* Skeleton loader */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--glass-bg) 25%,
    var(--glass-bg-strong) 50%,
    var(--glass-bg) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--r-small, 10px);
}

/* ── Reduced Motion ────────────────────────────────────── */

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

/* ── Utility ───────────────────────────────────────────── */

.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;
}

/* Safe area padding for fixed bottom elements */
.safe-bottom {
  padding-bottom: calc(var(--sp-16) + var(--safe-bottom));
}

/* ── View Transitions (style/theme switching) ──────────── */

::view-transition-old(root),
::view-transition-new(root) {
  animation-duration: 0.25s;
  animation-timing-function: ease;
}

/* Crossfade: old fades out, new fades in simultaneously */
::view-transition-old(root) {
  animation-name: fadeOut;
}

::view-transition-new(root) {
  animation-name: fadeIn;
}

@keyframes fadeOut {
  from { opacity: 1; }
  to { opacity: 0; }
}
