/* ============================================================================
   Base , reset, typography, global rules
   ============================================================================ */

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

html { scroll-behavior: smooth; }

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

body {
  margin: 0;
  font-family: var(--font-body);
  font-size: var(--fs-body);
  line-height: 1.6;
  color: var(--text-body);
  background: var(--surface-page);
  -webkit-font-smoothing: antialiased;
  transition: background-color var(--transition-fast), color var(--transition-fast);
  /* Prevents iOS Safari auto-zoom-on-focus jank + gives predictable
     scrollbar gutter so layout doesn't shift between pages (mobile polish). */
  -webkit-text-size-adjust: 100%;
}

h1, h2, h3, h4 {
  font-family: var(--font-heading);
  color: var(--text-heading);
  font-weight: 700;
  margin: 0 0 var(--sp-2);
  line-height: 1.2;
}

h1 { font-size: var(--fs-h1); line-height: 1.15; }
h2 { font-size: var(--fs-h2); }
h3 { font-size: var(--fs-h3); line-height: 1.3; }
h4 { font-size: var(--fs-h4); line-height: 1.4; }

p { margin: 0 0 var(--sp-2); }

a { color: var(--color-primary-crimson); text-decoration: none; }
a:hover { color: var(--color-primary-crimson-dark); text-decoration: underline; }
html[data-theme="dark"] a { color: var(--color-primary-crimson-light); }
html[data-theme="dark"] a:hover { color: var(--color-gold-light); }

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

.cjk { font-family: var(--font-cjk); }

.container {
  max-width: var(--container-max);
  margin: 0 auto;
  padding: 0 20px;
}

@media (min-width: 600px) {
  .container { padding: 0 24px; }
}

.section {
  padding: var(--sp-8) 0;
}

@media (max-width: 599px) {
  .section { padding: var(--sp-6) 0; }
}

.section--alt { background: var(--surface-alt); }
.section--navy { background: var(--color-navy); color: var(--color-white); }
.section--navy h1, .section--navy h2, .section--navy h3 { color: var(--color-white); }

.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
}

:focus-visible {
  outline: 3px solid var(--color-info);
  outline-offset: 2px;
}

.skeleton {
  background: linear-gradient(90deg, var(--skeleton-a) 25%, var(--skeleton-b) 50%, var(--skeleton-a) 75%);
  background-size: 200% 100%;
  animation: skeleton-loading 1.4s ease infinite;
  border-radius: var(--radius-sm);
}

@keyframes skeleton-loading {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ---- Mobile-first touch & readability polish (ask #1) ---- */

/* Every tappable control keeps a real 44x44px hit target on touch
   devices, per UI/UX §5.1, even for icon-only buttons added post-spec
   (theme toggle, bell icon, etc). */
@media (hover: none) and (pointer: coarse) {
  .btn, button, a.badge, .nav-toggle, .theme-toggle, .bell-wrap {
    min-height: 44px;
  }
}

/* Tables (admin panel, quiz review) never overflow the viewport on
   phones , wrap in .table-responsive rather than letting the page
   itself scroll horizontally. */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.table-responsive table { min-width: 480px; }

/* Prevents any single wide/unbreakable element (long email, long code
   block, etc.) from forcing horizontal scroll on small screens. */
@media (max-width: 599px) {
  body { overflow-x: hidden; }
  h1 { word-break: break-word; }
}

/* ---- Responsive grid safety net ----
   A large share of page layouts here use an inline `display:grid;
   grid-template-columns:...` for their desktop column ratio. Rather than
   hand-writing a breakpoint for each one, any inline grid degrades to a
   single column below phone width automatically (ask #1) , smaller
   screens get one exception (a 4-up "how it works" grid) that steps down
   to 2-up first via .grid-4-responsive before collapsing further. */
@media (max-width: 900px) {
  .grid-4-responsive { grid-template-columns: repeat(2, 1fr) !important; }
  .grid-collapse-md { grid-template-columns: 1fr !important; }
}
@media (max-width: 599px) {
  .grid-4-responsive { grid-template-columns: 1fr !important; }
  [style*="grid-template-columns"] {
    grid-template-columns: 1fr !important;
  }
}
