/* ==================================================
   Modern, Accessible, System-Aware Base Stylesheet
   ================================================== */

/* ---------- Reset ---------- */
*, *::before, *::after {
  box-sizing: border-box;
}

* {
  margin: 0;
}

html, body {
  height: 100%;
}

body {
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Design Tokens (Light Default) ---------- */
:root {
  /* Let browser know we support both */
  color-scheme: light dark;

  /* Colors */
  --color-bg: #f8fafc;
  --color-surface: #ffffff;
  --color-text: #0f172a;
  --color-text-muted: #64748b;
  --color-border: #e2e8f0;
  --color-primary: #3b82f6;
  --color-primary-hover: #2563eb;

  /* Semantic aliases (future-proofing) */
  --surface-1: var(--color-bg);
  --surface-2: var(--color-surface);
  --text-1: var(--color-text);
  --text-2: var(--color-text-muted);

  /* Fonts */
  --font-sans: system-ui, -apple-system, BlinkMacSystemFont,
               "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;

  /* Radius */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
}

/* ---------- Auto Dark Mode ---------- */
@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #0f172a;
    --color-surface: #020617;
    --color-text: #e5e7eb;
    --color-text-muted: #94a3b8;
    --color-border: #1e293b;
    --color-primary: #60a5fa;
    --color-primary-hover: #3b82f6;

    --shadow-sm: 0 1px 2px rgba(0,0,0,0.4);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.6);
  }
}

/* ---------- Optional Manual Overrides ---------- */
body.dark {
  --color-bg: #0f172a;
  --color-surface: #020617;
  --color-text: #e5e7eb;
  --color-text-muted: #94a3b8;
  --color-border: #1e293b;
  --color-primary: #60a5fa;
  --color-primary-hover: #3b82f6;
}

body.light {
  --color-bg: #f8fafc;
  --color-surface: #ffffff;
  --color-text: #0f172a;
  --color-text-muted: #64748b;
  --color-border: #e2e8f0;
  --color-primary: #3b82f6;
  --color-primary-hover: #2563eb;
}

/* ---------- Base Styles ---------- */
body {
  font-family: var(--font-sans);
  background-color: var(--color-bg);
  color: var(--color-text);

  /* Prevent content from touching edges */
  padding: 1.5rem;

  /* Smooth theme transitions */
  transition: background-color 0.2s ease, color 0.2s ease;
}

/* ---------- Accessibility ---------- */
:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ---------- Links ---------- */
a {
  color: var(--color-primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* ---------- Typography ---------- */
h1, h2, h3, h4, h5, h6 {
  line-height: 1.25;
  margin-bottom: 0.5em;
}

p {
  margin-bottom: 1em;
}

small {
  color: var(--color-text-muted);
}

.prose {
  max-width: 65ch;
}

code, pre {
  font-family: var(--font-mono);
  background: #f1f5f9;
  border-radius: var(--radius-sm);
}

@media (prefers-color-scheme: dark) {
  code, pre {
    background: #020617;
  }
}

code {
  padding: 0.2em 0.4em;
}

pre {
  padding: 1rem;
  overflow-x: auto;
}

/* ---------- Media Defaults ---------- */
img,
video {
  max-width: 100%;
  height: auto;
  display: block;
}

/* ---------- Layout ---------- */
.container {
  max-width: 1100px;
  margin: 0 auto;
}

.card {
  background: var(--color-surface);
  padding: 1.5rem;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  transition: background-color 0.2s ease;
}

/* Stack utility */
.stack > * + * {
  margin-top: var(--stack-space, 1rem);
}

/* ---------- Buttons ---------- */
button,
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font: inherit;
  padding: 0.6rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: var(--color-primary);
  color: #fff;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.05s ease;
}

button:hover,
.button:hover {
  background: var(--color-primary-hover);
}

button:active {
  transform: translateY(1px);
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Optional toggle button styling */
.dark-toggle {
  position: fixed;
  top: 1rem;
  right: 1rem;
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow-sm);
  padding: 0.5rem 0.75rem;
  border-radius: 999px;
}

/* ---------- Forms ---------- */
input,
textarea,
select {
  width: 100%;
  font: inherit;
  font-size: 16px; /* Prevent iOS zoom */
  padding: 0.6rem 0.7rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px rgba(59,130,246,0.25);
}

input:disabled,
textarea:disabled,
select:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

::placeholder {
  color: var(--color-text-muted);
}

/* ---------- Tables ---------- */
table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  padding: 0.75rem;
  border-bottom: 1px solid var(--color-border);
  text-align: left;
}

th {
  color: var(--color-text-muted);
  font-weight: 600;
}

/* ---------- Utilities ---------- */
.text-muted { color: var(--color-text-muted); }
.text-center { text-align: center; }
.hidden { display: none !important; }

/* ---------- Scroll ---------- */
html {
  scroll-behavior: smooth;
}
