/* Global Styles - Astro Haze Theme */
@import './tokens.css';
@import './glass.css';

/* Reset and base styles */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scrollbar-gutter: stable;
}

body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.6;
  color: var(--color-text);
  background-color: var(--color-bg);
  min-height: 100vh; /* fallback */
  min-height: 100dvh;
  overflow-x: hidden;
  overflow-wrap: break-word;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Typography */
h1,
h2,
h3,
h4,
h5,
h6 {
  font-weight: 700;
  line-height: 1.2;
  margin-top: 0;
  margin-bottom: var(--space-md);
  color: var(--color-text);
}

h1 {
  font-size: var(--text-5xl);
}
h2 {
  font-size: var(--text-4xl);
}
h3 {
  font-size: var(--text-3xl);
}
h4 {
  font-size: var(--text-2xl);
}
h5 {
  font-size: var(--text-xl);
}
h6 {
  font-size: var(--text-lg);
}

p {
  margin-bottom: var(--space-md);
}

a {
  color: var(--color-accent-text);
  text-decoration: none;
  transition: color var(--transition-fast);
}

a:hover {
  color: var(--color-accent);
  text-decoration: underline;
}

/* Lists */
ul,
ol {
  margin-bottom: var(--space-md);
  padding-left: var(--space-xl);
}

li {
  margin-bottom: var(--space-xs);
}

/* Code */
code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  background: rgba(0, 0, 0, 0.05);
  padding: 0.125em 0.25em;
  border-radius: var(--radius-sm);
}

pre {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  background: var(--glass-bg-solid);
  -webkit-backdrop-filter: blur(var(--glass-blur-sm));
  backdrop-filter: blur(var(--glass-blur-sm));
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  overflow-x: auto;
  margin-bottom: var(--space-md);
}

pre code {
  background: none;
  padding: 0;
}

/* Images */
img,
picture,
video,
canvas,
svg {
  display: block;
  max-width: 100%;
  height: auto;
}

/* Forms */
input,
button,
textarea,
select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  background: none;
  border: none;
  padding: 0;
}

/* Utility classes */
.container {
  width: 100%;
  max-width: var(--container-max);
  margin: 0 auto;
  padding: 0 var(--space-lg);
}

.section {
  padding: var(--space-3xl) 0;
}

.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;
}

/* Focus visible */
:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

/* Selection */
::selection {
  background-color: var(--color-accent);
  color: var(--color-text-inverse);
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 12px;
  height: 12px;
}

::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.05);
}

::-webkit-scrollbar-thumb {
  background: var(--glass-bg-solid);
  border-radius: var(--radius-full);
  border: 2px solid transparent;
  background-clip: content-box;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--color-accent);
  background-clip: content-box;
}

/* Print styles */
@media print {
  body {
    background: white;
    color: black;
  }

  .glass,
  .glass-panel,
  .glass-card {
    background: white !important;
    border: 1px solid black !important;
    box-shadow: none !important;
  }
}

/* Skip link */
.skip-link {
  position: absolute;
  top: -100px;
  left: 0;
  background: var(--color-accent-dark);
  color: white;
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-md);
  text-decoration: none;
  z-index: var(--z-toast);
}

.skip-link:focus {
  top: var(--space-sm);
}

/* Skip-link target. tabindex="-1" makes <main> focusable so focus actually
   moves there; the outline is suppressed (the visible scroll is feedback
   enough) and scroll-margin keeps it clear of the sticky header. */
#main {
  scroll-margin-top: calc(var(--header-height) + var(--space-lg));
}

#main:focus {
  outline: none;
}

/* Prose styling for content */
.prose {
  max-width: 65ch;
  color: var(--color-text);
}

.prose > * {
  margin-bottom: var(--space-md);
}

.prose h2 {
  margin-top: var(--space-2xl);
  margin-bottom: var(--space-lg);
}

.prose h3 {
  margin-top: var(--space-xl);
  margin-bottom: var(--space-md);
}

.prose a {
  color: var(--color-accent-text);
  text-decoration: underline;
}

.prose a:hover {
  color: var(--color-accent);
}

.prose blockquote {
  border-left: 4px solid var(--color-accent);
  padding-left: var(--space-lg);
  font-style: italic;
  color: var(--color-text-muted);
  margin: var(--space-lg) 0;
}

.prose hr {
  border: none;
  height: 1px;
  background: var(--glass-border);
  margin: var(--space-2xl) 0;
}

/* Table styles */
.prose table {
  display: block;
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-collapse: collapse;
  margin: var(--space-lg) 0;
}

.prose th,
.prose td {
  padding: var(--space-sm);
  text-align: left;
  border-bottom: 1px solid var(--glass-border);
}

.prose th {
  font-weight: 600;
  background: var(--glass-bg);
}

/* Mobile menu toggle */
.menu-toggle {
  display: none;
  flex-direction: column;
  gap: 4px;
  width: 44px;
  height: 44px;
  align-items: center;
  justify-content: center;
}

.menu-toggle span {
  width: 24px;
  height: 2px;
  background: currentColor;
  transition:
    transform var(--transition-fast),
    opacity var(--transition-fast);
}

.menu-toggle.active span:nth-child(1) {
  transform: rotate(45deg) translate(5px, 5px);
}

.menu-toggle.active span:nth-child(2) {
  opacity: 0;
}

.menu-toggle.active span:nth-child(3) {
  transform: rotate(-45deg) translate(5px, -5px);
}

@media (max-width: 768px) {
  .menu-toggle {
    display: flex;
  }
}

/* Scroll-driven entrance
 *
 * `.reveal` fades and lifts an element as it scrolls into view. The whole thing
 * — animation, keyframes, the opacity: 0 start — lives inside the @supports
 * block, so a browser without view() timelines never applies a starting state
 * it has no way to animate away from: the content is simply there, at full
 * opacity, from the first paint. That's the failure mode to design for; a
 * JS-free reveal that hides content on unsupported browsers is worse than no
 * reveal at all.
 *
 * Only opacity and transform animate, so nothing here can shift layout.
 */
@media (prefers-reduced-motion: no-preference) {
  @supports (animation-timeline: view()) {
    .reveal {
      animation-name: reveal-in;
      /* Required, and not the default: a progress-based timeline needs
         `auto` to map the range onto the animation. Left unset it resolves to
         a 0% duration, the animation never becomes active, and the element
         just sits at its base style. */
      animation-duration: auto;
      animation-timing-function: linear;
      animation-fill-mode: both;
      animation-timeline: view();
      /* Finish well before the element reaches the middle of the screen —
         a reveal still running when you're reading it is a distraction. */
      animation-range: entry 0% entry 40%;
    }

    @keyframes reveal-in {
      from {
        opacity: 0;
        transform: translateY(1.5rem);
      }
    }
  }
}
