/* ==========================================================================
   GAINZ — Base Styles
   Reset, dark background, base typography, app shell layout, safe-area insets.
   Imports tokens.css first; all values use custom properties only.
   ========================================================================== */

/* ---------- Box-sizing reset ---------- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* ---------- Root / HTML ---------- */
html {
  /* Prevent font size inflation on mobile Safari */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  /* Force dark color-scheme so browser chrome (scrollbars, inputs) matches */
  color-scheme: dark;
  height: 100%;
}

body {
  height: 100%;
  background-color: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  font-weight: var(--weight-normal);
  /* Prevent horizontal overflow on mobile */
  overflow-x: hidden;
  /* Smooth scroll for in-page anchors */
  scroll-behavior: smooth;
  /* Anti-aliasing */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ---------- App root element ---------- */
#root {
  height: 100%;
  display: flex;
  flex-direction: column;
  /* Stretch to fill device viewport including safe areas */
  min-height: 100dvh;
  min-height: -webkit-fill-available;
}

/* ---------- App shell layout ---------- */
.app-shell {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 100dvh;
  position: relative;
}

/* Screen content area — scrolls independently, above the nav */
.screen-content {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  /* Push content above the fixed bottom nav */
  padding-bottom: calc(var(--nav-height) + var(--safe-bottom) + var(--space-4));
  /* Top safe area for notched devices */
  padding-top: var(--safe-top);
  /* Momentum scrolling on iOS */
  -webkit-overflow-scrolling: touch;
}

/* ---------- Base typography ---------- */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-body);
  font-weight: var(--weight-bold);
  line-height: var(--leading-tight);
  color: var(--color-text);
}

h1 { font-size: var(--text-xl); }
h2 { font-size: var(--text-lg); }
h3 { font-size: var(--text-md); }

p {
  line-height: var(--leading-normal);
  color: var(--color-text);
}

small {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

/* ---------- Links ---------- */
a {
  color: var(--color-accent);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}
a:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* ---------- Focus visible (keyboard navigation) ---------- */
:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}
:focus:not(:focus-visible) {
  outline: none;
}

/* ---------- Interactive element reset ---------- */
button {
  cursor: pointer;
  border: none;
  background: none;
  font: inherit;
  color: inherit;
  padding: 0;
  /* Ensure tap targets are reachable */
  min-height: var(--tap-min);
  /* No tap highlight on mobile */
  -webkit-tap-highlight-color: transparent;
}
button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

/* ---------- Form elements ---------- */
input, select, textarea {
  font: inherit;
  color: var(--color-text);
  background: var(--color-surface);
  border: 1.5px solid var(--color-rack);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  min-height: var(--tap-min);
  width: 100%;
  -webkit-tap-highlight-color: transparent;
  color-scheme: dark;
}
input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 0;
  border-color: var(--color-accent);
}
input::placeholder, textarea::placeholder {
  color: var(--color-text-muted);
}

/* ---------- Lists ---------- */
ul, ol {
  list-style: none;
}

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

/* ---------- Horizontal rule ---------- */
hr {
  border: none;
  border-top: 1px solid var(--color-rack);
  margin: var(--space-4) 0;
}

/* ---------- Selection ---------- */
::selection {
  background: var(--color-belt);
  color: var(--color-iron);
}

/* ---------- Scrollbar (Webkit) — keep dark ---------- */
::-webkit-scrollbar {
  width: 4px;
  height: 4px;
}
::-webkit-scrollbar-track {
  background: var(--color-iron);
}
::-webkit-scrollbar-thumb {
  background: var(--color-rack);
  border-radius: var(--radius-full);
}

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

/* ---------- Screen reader only 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-width: 0;
}
