/* ==========================================================================
   BASE.CSS — Reset, Typography, Foundational Styles
   ========================================================================== */

/* ── Modern CSS Reset ──────────────────────────────────────────────────── */

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

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

body {
  font-family: var(--font-sans);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  font-weight: 400;
  min-height: 100vh;
  overflow-x: hidden;
}

/* Remove default list styles */
ul,
ol {
  list-style: none;
}

/* Prevent images from overflowing */
img,
picture,
video,
canvas,
svg {
  display: block;
  max-width: 100%;
  height: auto;
}

/* Inherit fonts for form elements */
input,
button,
textarea,
select {
  font: inherit;
  color: inherit;
}

/* Remove default button styles */
button {
  cursor: pointer;
  border: none;
  background: none;
}

/* Remove textarea resize handle on non-tool pages */
textarea {
  resize: vertical;
}

/* Table reset */
table {
  border-collapse: collapse;
  border-spacing: 0;
}

/* Anchor reset */
a {
  text-decoration: none;
  color: inherit;
}

/* Strong and emphasis */
strong,
b {
  font-weight: 700;
}

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

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

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-sans);
  color: var(--text-primary);
  margin-bottom: var(--space-4);
}

h1 {
  font-size: var(--text-4xl);
  font-weight: 800;
  line-height: 1.2;
  letter-spacing: -0.025em;
}

h2 {
  font-size: var(--text-3xl);
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -0.02em;
}

h3 {
  font-size: var(--text-2xl);
  font-weight: 600;
  line-height: 1.3;
}

h4 {
  font-size: var(--text-xl);
  font-weight: 600;
  line-height: 1.3;
}

h5 {
  font-size: var(--text-lg);
  font-weight: 600;
  line-height: 1.4;
}

h6 {
  font-size: var(--text-base);
  font-weight: 600;
  line-height: 1.4;
}

p {
  margin-bottom: var(--space-4);
}

p:last-child {
  margin-bottom: 0;
}

/* ── Links ─────────────────────────────────────────────────────────────── */

a:not([class]) {
  color: var(--accent-blue);
  transition: color var(--transition-fast);
}

a:not([class]):hover {
  color: var(--accent-blue-dim);
}

a:not([class]):focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
  border-radius: 2px;
}

/* ── Code & Preformatted ───────────────────────────────────────────────── */

code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background-color: var(--bg-secondary);
  padding: 0.15em 0.4em;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
}

pre {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  background-color: var(--bg-secondary);
  padding: var(--space-4);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  overflow-x: auto;
  line-height: 1.7;
  tab-size: 2;
}

pre code {
  background: none;
  padding: 0;
  border: none;
  font-size: inherit;
}

/* ── Selection ─────────────────────────────────────────────────────────── */

::selection {
  background-color: var(--accent-blue);
  color: #ffffff;
}

::-moz-selection {
  background-color: var(--accent-blue);
  color: #ffffff;
}

/* ── Scrollbar Styling ─────────────────────────────────────────────────── */

/* Webkit (Chrome, Safari, Edge) */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
  background: var(--bg-tertiary);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-tertiary);
}

/* Firefox */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--bg-tertiary) var(--bg-primary);
}

/* ── Accessibility: Skip Link ──────────────────────────────────────────── */

.skip-to-content {
  position: absolute;
  top: -100%;
  left: var(--space-4);
  z-index: 10000;
  padding: var(--space-3) var(--space-6);
  background-color: var(--accent-blue);
  color: #ffffff;
  font-size: var(--text-sm);
  font-weight: 600;
  border-radius: 0 0 var(--radius-md) var(--radius-md);
  transition: top var(--transition-fast);
}

.skip-to-content:focus {
  top: 0;
  outline: 2px solid var(--accent-blue-dim);
  outline-offset: 2px;
}

/* ── Accessibility: Screen Reader Only ─────────────────────────────────── */

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

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

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

/* ── Container ─────────────────────────────────────────────────────────── */

.container {
  width: 100%;
  max-width: var(--container-max);
  margin-left: auto;
  margin-right: auto;
  padding-left: var(--container-padding);
  padding-right: var(--container-padding);
}

/* ── Utility: Monospace ────────────────────────────────────────────────── */

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

/* ── Focus Visible ─────────────────────────────────────────────────────── */

:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}

:focus:not(:focus-visible) {
  outline: none;
}
