/* ============================================================
   BASE — The Ai Toolz
   @font-face, modern CSS reset, global typography, utilities
   ============================================================ */

/* ── Self-hosted fonts ── */
@font-face {
  font-family: 'Inter Variable';
  src: url('../fonts/inter/InterVariable.woff2') format('woff2-variations');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'Inter Variable';
  src: url('../fonts/inter/InterVariable-Italic.woff2') format('woff2-variations');
  font-weight: 100 900;
  font-style: italic;
  font-display: swap;
}

@font-face {
  font-family: 'JetBrains Mono';
  src: url('../fonts/jetbrains-mono/JetBrainsMono[wght].woff2') format('woff2-variations');
  font-weight: 100 800;
  font-style: normal;
  font-display: swap;
}

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

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

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
}

body {
  font-family: var(--font-sans);
  font-size: var(--text-body);
  line-height: var(--line-height-body);
  color: var(--color-text);
  background-color: var(--color-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  font-feature-settings: 'cv01' 1, 'cv02' 1, 'cv05' 1, 'ss01' 1;
  overflow-x: hidden;
  min-height: 100dvh;
}

/* ── Typography base ── */
h1, h2, h3, h4, h5, h6 {
  font-weight: var(--font-weight-bold);
  line-height: var(--line-height-heading);
  letter-spacing: var(--letter-spacing-tight);
  color: var(--color-text);
  text-wrap: balance;
}

h1 { font-size: var(--text-h1); }
h2 { font-size: var(--text-h2); }
h3 { font-size: var(--text-h3); }
h4 { font-size: var(--text-h4); font-weight: var(--font-weight-semibold); }
h5 { font-size: var(--text-h5); font-weight: var(--font-weight-semibold); }
h6 {
  font-size: var(--text-h6);
  font-weight: var(--font-weight-semibold);
  letter-spacing: var(--letter-spacing-wider);
  text-transform: uppercase;
  color: var(--color-text-muted);
}

p {
  color: var(--color-text);
}

/* Prose styles for long-form text */
.prose { max-width: var(--max-prose-width); }
.prose p + p { margin-top: var(--space-4); }
.prose h2 { margin-top: var(--space-12); margin-bottom: var(--space-4); }
.prose h3 { margin-top: var(--space-8);  margin-bottom: var(--space-3); }
.prose h4 { margin-top: var(--space-6);  margin-bottom: var(--space-2); }
.prose ul, .prose ol { list-style: revert; padding-left: var(--space-6); }
.prose li + li { margin-top: var(--space-1); }
.prose a { text-decoration: underline; text-underline-offset: 3px; }

/* ── Links ── */
a {
  color: var(--color-primary);
  text-decoration: none;
  transition: color var(--trans-fast);
}

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

/* ── Focus rings ── */
:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
  border-radius: 2px;
}

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

/* ── Media ── */
img, video, svg, canvas {
  display: block;
}

img {
  max-width: 100%;
  height: auto;
}

svg {
  flex-shrink: 0;
}

/* ── Icon helper ── */
.icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  pointer-events: none;
}

/* ── Code & monospace ── */
code, kbd, samp, pre {
  font-family: var(--font-mono);
  font-size: 0.875em;
}

code {
  background: var(--color-surface-2);
  color: var(--color-text);
  padding: 0.1em 0.35em;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  white-space: nowrap;
}

pre {
  overflow-x: auto;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-card);
  padding: var(--space-4) var(--space-6);
  line-height: 1.6;
}

pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: var(--text-sm);
  white-space: pre;
}

/* ── Form reset ── */
button {
  font-family: inherit;
  cursor: pointer;
}

fieldset { border: none; }

legend {
  font-weight: var(--font-weight-semibold);
  margin-bottom: var(--space-2);
}

label {
  display: block;
  font-size: var(--text-sm);
  font-weight: var(--font-weight-medium);
  color: var(--color-text);
  cursor: pointer;
  line-height: 1.4;
}

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

/* ── Tables ── */
table { border-collapse: collapse; width: 100%; }

th {
  font-weight: var(--font-weight-semibold);
  text-align: left;
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  letter-spacing: var(--letter-spacing-wide);
  text-transform: uppercase;
}

td, th { padding: var(--space-3) var(--space-4); }

.table-striped tr:nth-child(even) td {
  background: var(--color-surface);
}

/* ── Divider ── */
hr {
  border: none;
  border-top: 1px solid var(--color-border);
  margin-block: var(--space-8);
}

/* ── Text selection ── */
::selection {
  background: rgba(79, 70, 229, 0.2);
  color: var(--color-text);
}

[data-theme="dark"] ::selection {
  background: rgba(129, 140, 248, 0.3);
}

/* ── Custom scrollbars ── */
::-webkit-scrollbar        { width: 6px; height: 6px; }
::-webkit-scrollbar-track  { background: transparent; }
::-webkit-scrollbar-thumb  {
  background: var(--color-border-strong);
  border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover { background: var(--color-text-muted); }

/* ── 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;
  }
}

/* ── Global utilities ── */
.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;
}

.not-sr-only {
  position: static;
  width: auto; height: auto;
  padding: 0; margin: 0;
  overflow: visible;
  clip: auto;
  white-space: normal;
}

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

.text-muted     { color: var(--color-text-muted); }
.text-sm        { font-size: var(--text-sm); }
.text-xs        { font-size: var(--text-xs); }
.text-lg        { font-size: var(--text-lg); }
.font-mono      { font-family: var(--font-mono); }
.font-semibold  { font-weight: var(--font-weight-semibold); }
.font-bold      { font-weight: var(--font-weight-bold); }
.text-center    { text-align: center; }
.text-balance   { text-wrap: balance; }

.d-flex         { display: flex; }
.flex-col       { flex-direction: column; }
.flex-wrap      { flex-wrap: wrap; }
.items-center   { align-items: center; }
.items-start    { align-items: flex-start; }
.justify-center { justify-content: center; }
.justify-between{ justify-content: space-between; }
.gap-1          { gap: var(--space-1); }
.gap-2          { gap: var(--space-2); }
.gap-3          { gap: var(--space-3); }
.gap-4          { gap: var(--space-4); }
.gap-6          { gap: var(--space-6); }
.flex-1         { flex: 1 1 0%; min-width: 0; }

.hidden         { display: none; }
[hidden]        { display: none !important; }
.invisible      { visibility: hidden; }

.mt-auto        { margin-top: auto; }
.ml-auto        { margin-left: auto; }
