/* Base styles - resets, typography, and base elements */

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

* {
  margin: 0;
}

html,
body {
  height: 100%;
}

body {
  line-height: var(--line-height-normal);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

img,
picture,
video,
canvas,
svg {
  display: block;
  max-width: 100%;
}

input,
button,
textarea,
select {
  font: inherit;
}

p,
h1,
h2,
h3,
h4,
h5,
h6 {
  overflow-wrap: break-word;
}

#root {
  overflow-wrap: break-word;
}

/* Typography */
body {
  font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, "Roboto", "Helvetica Neue", Arial, sans-serif;
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-normal);
  color: var(--app-text);
  background: var(--app-bg);
}

h1,
h2,
h3,
h4,
h5,
h6 {
  font-weight: var(--font-weight-semibold);
  line-height: var(--line-height-tight);
  color: var(--app-text);
  margin-bottom: var(--space-3);
}

h1 {
  font-size: var(--font-size-3xl);
  font-weight: var(--font-weight-bold);
}

h2 {
  font-size: var(--font-size-2xl);
  font-weight: var(--font-weight-bold);
}

h3 {
  font-size: var(--font-size-xl);
}

h4 {
  font-size: var(--font-size-lg);
}

h5 {
  font-size: var(--font-size-md);
}

h6 {
  font-size: var(--font-size-sm);
}

p {
  margin-bottom: var(--space-4);
  line-height: var(--line-height-normal);
  color: var(--app-text);
}

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

/* Links */
a {
  color: var(--app-link);
  text-decoration: none;
  transition: color var(--transition-fast);
}

a:hover {
  color: var(--accent);
  text-decoration: underline;
}

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

/* Lists */
ul,
ol {
  list-style: none;
  margin: 0;
  padding: 0;
}

/* Text elements */
strong,
b {
  font-weight: var(--font-weight-semibold);
  color: var(--app-text);
}

em,
i {
  font-style: italic;
}

small {
  font-size: var(--font-size-sm);
  color: var(--app-hint);
}

mark {
  background: var(--warning-bg);
  color: var(--warning-text);
  padding: var(--space-1);
  border-radius: var(--radius-sm);
}

code {
  font-family: "SF Mono", Monaco, "Cascadia Code", "Roboto Mono", Consolas, "Courier New", monospace;
  font-size: 0.875em;
  background: var(--surface-2);
  color: var(--app-text);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
  border: 1px solid var(--surface-3);
}

pre {
  font-family: "SF Mono", Monaco, "Cascadia Code", "Roboto Mono", Consolas, "Courier New", monospace;
  background: var(--surface-2);
  color: var(--app-text);
  padding: var(--space-4);
  border-radius: var(--radius-md);
  border: 1px solid var(--surface-3);
  overflow-x: auto;
  line-height: var(--line-height-relaxed);
}

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

/* Blockquote */
blockquote {
  margin: var(--space-4) 0;
  padding: var(--space-3) var(--space-4);
  border-left: 4px solid var(--accent);
  background: var(--surface-1);
  color: var(--app-hint);
  border-radius: var(--radius-md);
}

blockquote p {
  margin-bottom: 0;
  font-style: italic;
}

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

/* Horizontal rule */
hr {
  border: none;
  height: 1px;
  background: var(--surface-3);
  margin: var(--space-6) 0;
}

/* Tables */
table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: var(--space-4);
}

th,
td {
  padding: var(--space-3);
  text-align: left;
  border-bottom: 1px solid var(--surface-3);
}

th {
  font-weight: var(--font-weight-semibold);
  color: var(--app-text);
  background: var(--surface-1);
}

td {
  color: var(--app-text);
}

/* Headings with meta */
.heading-with-meta {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}

.heading-with-meta h1,
.heading-with-meta h2,
.heading-with-meta h3,
.heading-with-meta h4,
.heading-with-meta h5,
.heading-with-meta h6 {
  margin-bottom: 0;
}

.heading-with-meta .meta {
  font-size: var(--font-size-sm);
  color: var(--app-hint);
  font-weight: var(--font-weight-normal);
}

/* Text utilities */
.text-body {
  font-size: var(--font-size-base);
  line-height: var(--line-height-normal);
  color: var(--app-text);
}

.text-caption {
  font-size: var(--font-size-sm);
  line-height: var(--line-height-normal);
  color: var(--app-hint);
}

.text-label {
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  color: var(--app-text);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.text-meta {
  font-size: var(--font-size-xs);
  color: var(--app-hint);
  font-weight: var(--font-weight-normal);
}

.text-muted {
  color: var(--app-hint);
}

.text-uppercase {
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.text-lowercase {
  text-transform: lowercase;
}

.text-capitalize {
  text-transform: capitalize;
}

.text-nowrap {
  white-space: nowrap;
}

.text-break {
  word-wrap: break-word;
  word-break: break-word;
}

.text-ellipsis {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Selection */
::selection {
  background: var(--accent);
  color: var(--accent-text);
}

::-moz-selection {
  background: var(--accent);
  color: var(--accent-text);
}

/* Focus styles */
:focus-visible {
  outline: var(--focus-ring);
  outline-offset: var(--focus-ring-offset);
}

/* Touch interaction improvements */
* {
  -webkit-tap-highlight-color: var(--tap-highlight-color);
  touch-action: manipulation;
}

/* Scrollbar styles */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: var(--surface-2);
}

::-webkit-scrollbar-thumb {
  background: var(--surface-3);
  border-radius: var(--radius-full);
  border: 1px solid var(--surface-2);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--surface-4);
}

/* Firefox scrollbar */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--surface-3) var(--surface-2);
}

/* Form base styles */
label {
  display: block;
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  color: var(--app-text);
  margin-bottom: var(--space-2);
}

fieldset {
  border: 1px solid var(--surface-3);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  margin-bottom: var(--space-4);
}

legend {
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-semibold);
  color: var(--app-text);
  padding: 0 var(--space-2);
}

/* Button reset */
button {
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  font: inherit;
  color: inherit;
  cursor: pointer;
}

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

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

/* Input reset */
input,
textarea,
select {
  background: transparent;
  border: none;
  padding: 0;
  margin: 0;
  font: inherit;
  color: inherit;
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
}

/* Remove default styles */
[hidden] {
  display: none !important;
}

[disabled] {
  cursor: not-allowed;
  opacity: 0.6;
}

/* Print styles */
@media print {
  *,
  *::before,
  *::after {
    background: transparent !important;
    color: black !important;
    box-shadow: none !important;
    text-shadow: none !important;
  }

  a,
  a:visited {
    text-decoration: underline;
  }

  a[href]:after {
    content: " (" attr(href) ")";
  }

  abbr[title]:after {
    content: " (" attr(title) ")";
  }

  pre,
  blockquote {
    border: 1px solid #999;
    page-break-inside: avoid;
  }

  thead {
    display: table-header-group;
  }

  tr,
  img {
    page-break-inside: avoid;
  }

  img {
    max-width: 100% !important;
  }

  p,
  h2,
  h3 {
    orphans: 3;
    widows: 3;
  }

  h2,
  h3 {
    page-break-after: avoid;
  }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  :root {
    --surface-1: #000000;
    --surface-2: #1a1a1a;
    --surface-3: #333333;
    --surface-4: #4d4d4d;
    --app-text: #ffffff;
    --app-hint: #cccccc;
    --accent: #0066cc;
  }
}

/* Reduced motion support */
@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;
  }
}

/* Dark mode support for browsers that don't support prefers-color-scheme */
@media screen and (prefers-color-scheme: dark) {
  :root {
    /* Already handled in tokens.css */
  }
}

/* Light mode support */
@media screen and (prefers-color-scheme: light) {
  :root {
    /* Already handled in tokens.css */
  }
}
