/* 1. Design Tokens (The API) */
:root {
  color-scheme: light dark;

  /* Colors - Using modern light-dark() function */
  --color-primary: #2563eb;
  --color-primary-hover: #1d4ed8;

  --color-success: light-dark(#059669, #10b981);
  --color-success-bg: light-dark(#d1fae5, #064e3b);
  --color-success-border: light-dark(#6ee7b7, #065f46);

  --color-warning: light-dark(#f59e0b, #fbbf24);
  --color-warning-bg: light-dark(#fef3c7, #78350f);
  --color-warning-border: light-dark(#fbbf24, #92400e);

  --color-error: light-dark(#dc2626, #ef4444);
  --color-error-bg: light-dark(#fee2e2, #7f1d1d);
  --color-error-border: light-dark(#fca5a5, #991b1b);

  --color-bg-base: light-dark(#f8fafc, #0f172a);
  --color-bg-surface: light-dark(#ffffff, #1e293b);
  --color-text-main: light-dark(#0f172a, #f8fafc);
  --color-text-muted: light-dark(#64748b, #94a3b8);
  --color-border: light-dark(#e2e8f0, #334155);

  /* Spacing Scale - Fluid spacing */
  --space-xs: clamp(0.375rem, 0.75vw, 0.5rem);
  --space-sm: clamp(0.5rem, 1vw, 0.75rem);
  --space-md: clamp(0.75rem, 1.5vw, 1rem);
  --space-lg: clamp(1rem, 2vw, 1.5rem);
  --space-xl: clamp(1.5rem, 2.5vw, 2rem);
  --space-2xl: clamp(2rem, 4vw, 3rem);

  /* Borders */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;

  /* Shadows - Using light-dark() */
  --shadow-sm: light-dark(
    0 1px 2px 0 rgba(0, 0, 0, 0.05),
    0 1px 2px 0 rgba(0, 0, 0, 0.3)
  );
  --shadow-md: light-dark(
    0 4px 6px -1px rgba(0, 0, 0, 0.1) 0 2px 4px -1px rgba(0, 0, 0, 0.06),
    0 4px 6px -1px rgba(0, 0, 0, 0.4) 0 2px 4px -1px rgba(0, 0, 0, 0.3)
  );
  --shadow-lg: light-dark(
    0 10px 15px -3px rgba(0, 0, 0, 0.1) 0 4px 6px -2px rgba(0, 0, 0, 0.05),
    0 10px 15px -3px rgba(0, 0, 0, 0.5) 0 4px 6px -2px rgba(0, 0, 0, 0.3)
  );
  --shadow-xl: light-dark(
    0 20px 25px -5px rgba(0, 0, 0, 0.1) 0 10px 10px -5px rgba(0, 0, 0, 0.04),
    0 20px 25px -5px rgba(0, 0, 0, 0.5) 0 10px 10px -5px rgba(0, 0, 0, 0.4)
  );

  /* Typography - Fluid sizing with clamp() */
  --font-size-xs: clamp(0.7rem, 0.9vw, 0.75rem);
  --font-size-sm: clamp(0.8rem, 1vw, 0.875rem);
  --font-size-base: clamp(0.9rem, 1.2vw, 1rem);
  --font-size-lg: clamp(1rem, 1.3vw, 1.125rem);
  --font-size-xl: clamp(1.1rem, 1.5vw, 1.25rem);
  --font-size-2xl: clamp(1.25rem, 2vw, 1.5rem);
  --font-size-3xl: clamp(1.5rem, 2.5vw, 1.875rem);
  --font-size-4xl: clamp(1.75rem, 3vw, 2.25rem);

  /* Transitions */
  --transition-fast: 150ms ease-in-out;
  --transition-base: 200ms ease-in-out;
  --transition-slow: 300ms ease-in-out;
}

/* 2. Base Reset */
* {
  box-sizing: border-box;
}

body {
  background-color: var(--color-bg-base);
  color: var(--color-text-main);
  font-family: system-ui, -apple-system, sans-serif;
  margin: 0;
  line-height: 1.5;
  font-size: var(--font-size-base);
}

/* 3. Typography */
h1, h2, h3, h4, h5, h6 {
  margin: 0 0 var(--space-md) 0;
  font-weight: 600;
  line-height: 1.2;
  color: var(--color-text-main);
}

h1 { font-size: var(--font-size-4xl); }
h2 { font-size: var(--font-size-3xl); }
h3 { font-size: var(--font-size-2xl); }
h4 { font-size: var(--font-size-xl); }
h5 { font-size: var(--font-size-lg); }
h6 { font-size: var(--font-size-base); }

p {
  margin: 0 0 var(--space-md) 0;
}

a {
  color: var(--color-primary);
  text-decoration: none;
  transition: color var(--transition-fast);
}

a:hover {
  color: var(--color-primary-hover);
}

/* 4. Form Elements */
label {
  display: block;
  font-size: var(--font-size-sm);
  font-weight: 500;
  margin-bottom: var(--space-xs);
  color: var(--color-text-main);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="search"],
input[type="url"],
input[type="tel"],
input[type="number"],
input[type="date"],
input[type="time"],
input[type="datetime-local"],
textarea,
select {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: var(--font-size-base);
  font-family: inherit;
  background: var(--color-bg-surface);
  color: var(--color-text-main);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  line-height: 1.5;
}

input[type="text"]:focus,
input[type="email"]:focus,
input[type="password"]:focus,
input[type="search"]:focus,
input[type="url"]:focus,
input[type="tel"]:focus,
input[type="number"]:focus,
input[type="date"]:focus,
input[type="time"]:focus,
input[type="datetime-local"]:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

input::placeholder,
textarea::placeholder {
  color: var(--color-text-muted);
}

input:disabled,
textarea:disabled,
select:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  background: var(--color-bg-base);
}

textarea {
  resize: vertical;
  min-height: 80px;
}

select {
  cursor: pointer;
}

/* Checkbox and Radio */
input[type="checkbox"],
input[type="radio"] {
  width: auto;
  margin-right: var(--space-xs);
  cursor: pointer;
}

/* Range Slider */
input[type="range"] {
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: var(--color-border);
  outline: none;
  cursor: pointer;
}

/* Button Base Styles */
button {
  font-family: inherit;
  font-size: var(--font-size-base);
  font-weight: 500;
  padding: 8px 16px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
  border: 1px solid transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--color-primary);
  color: white;
}

button:hover:not(:disabled) {
  background: var(--color-primary-hover);
}

button:active:not(:disabled) {
  transform: translateY(1px);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* 5. Tables */
table {
  width: 100%;
  border-collapse: collapse;
  border-spacing: 0;
  margin: var(--space-md) 0;
  background: var(--color-bg-surface);
  border-radius: var(--radius-md);
  overflow: hidden;
}

thead {
  background: var(--color-bg-base);
}

th {
  text-align: left;
  padding: 12px 16px;
  font-weight: 600;
  font-size: var(--font-size-sm);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
  border-bottom: 1px solid var(--color-border);
}

td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--color-border);
}

tbody tr:last-child td {
  border-bottom: none;
}

tbody tr:hover {
  background: var(--color-bg-base);
}

/* 6. Lists */
ul, ol {
  margin: 0 0 var(--space-md) 0;
  padding-left: var(--space-lg);
}

ul ul, ol ol, ul ol, ol ul {
  margin-bottom: 0;
}

li {
  margin-bottom: var(--space-xs);
}

/* 7. Code */
code {
  font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
  font-size: 0.9em;
  background: var(--color-bg-base);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  color: var(--color-text-main);
}

pre {
  background: var(--color-bg-base);
  padding: var(--space-md);
  border-radius: var(--radius-md);
  overflow-x: auto;
  margin: var(--space-md) 0;
  border: 1px solid var(--color-border);
}

pre code {
  background: none;
  padding: 0;
}

/* 8. Blockquote */
blockquote {
  margin: var(--space-md) 0;
  padding-left: var(--space-lg);
  border-left: 4px solid var(--color-primary);
  color: var(--color-text-muted);
  font-style: italic;
}

/* 9. Horizontal Rule */
hr {
  border: none;
  border-top: 1px solid var(--color-border);
  margin: var(--space-lg) 0;
}

/* 10. Images */
img {
  max-width: 100%;
  height: auto;
  display: block;
}

/* 11. Details/Summary */
details {
  background: var(--color-bg-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  margin: var(--space-md) 0;
}

summary {
  cursor: pointer;
  font-weight: 600;
  user-select: none;
  list-style: none;
}

summary::-webkit-details-marker {
  display: none;
}

summary::before {
  content: '▶';
  display: inline-block;
  margin-right: var(--space-xs);
  transition: transform var(--transition-fast);
}

details[open] summary::before {
  transform: rotate(90deg);
}

details[open] {
  padding-bottom: var(--space-md);
}

/* 12. Dialog */
dialog {
  border: none;
  border-radius: var(--radius-lg);
  padding: 0;
  box-shadow: var(--shadow-xl);
  background: var(--color-bg-surface);
  color: var(--color-text-main);
  max-width: 90vw;
  max-height: 90vh;
}

dialog::backdrop {
  background-color: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(2px);
}
