/**
 * Base Styles
 * Typography, body defaults, links, and basic element styles
 * Uses design tokens from tokens.css
 * 
 * CSS Layers: base layer for foundational styles
 */

@layer base {
  /* Root */
  :root {
    font-size: 100%; /* Respect user font-size preferences */
    scroll-behavior: smooth;
    /* No grey flash on tap: every control shows its own press (inherited, so once here, audit P-7) */
    -webkit-tap-highlight-color: transparent;
    /* Keep the type size when a phone turns to landscape (audit P-7) */
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
  }


/* Body */
body {
  font-family: var(--font-sans);
  font-size: var(--text-default-size);
  font-weight: var(--text-default-weight);
  line-height: var(--text-default-leading);
  letter-spacing: var(--text-default-tracking);
  color: var(--color-text-strong);
  background-color: var(--color-bg);
  min-height: 100vh;
  /* Installed (standalone) on a phone with a notch or home indicator, viewport-fit=cover lets the
     page reach the screen edges; these insets keep content clear of them. 0 everywhere else. */
  padding:
    env(safe-area-inset-top) env(safe-area-inset-right)
    env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* Form elements - ensure Inter font */
button, input, select, textarea {
  font-family: var(--font-sans);
}

/* Icons: <svg class="icon"><use href="#ph-…"/></svg>, drawn from the inline sprite at the top
   of each page. The duotone back layer is part of each symbol (opacity 0.2). */
.icon-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.icon {
  width: var(--text-base-size);
  height: var(--text-base-size);
  flex-shrink: 0;
  fill: currentColor;
  vertical-align: middle;
}

/* Text fields never below 16 px: iOS Safari zooms into smaller ones on focus.
   Component rules that set a size keep the same floor with max(1rem, ...). */
input, select, textarea {
  font-size: max(1rem, 1em);
}

/* Headings */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-sans);
  font-weight: var(--font-semibold);
  text-wrap: balance;
  color: var(--color-text-strong);
}

h1 {
  font-size: var(--text-xl-size);
  font-weight: var(--font-bold);
  line-height: var(--text-xl-leading);
  letter-spacing: var(--text-xl-tracking);
}

h2 {
  font-size: var(--text-lg-size);
  line-height: var(--text-lg-leading);
  letter-spacing: var(--text-lg-tracking);
}

/* A scale that steps down: h3 was as large as h1 (audit UI-13) */
h3 {
  font-size: var(--text-md-size);
  line-height: var(--text-lg-leading);
  letter-spacing: var(--text-lg-tracking);
}

h4 {
  font-size: var(--text-default-size);
  line-height: var(--text-default-leading);
  letter-spacing: var(--text-default-tracking);
}

h5, h6 {
  font-size: var(--text-default-size);
  line-height: var(--text-default-leading);
  letter-spacing: var(--text-default-tracking);
}

/* Paragraphs */
p {
  font-size: var(--text-default-size);
  line-height: var(--text-default-leading);
  letter-spacing: var(--text-default-tracking);
  color: var(--color-text-strong);
  max-width: var(--max-width-prose);
  text-wrap: pretty;
}

/* Links */
a {
  color: var(--color-text-strong);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
  transition: var(--transition-colors);
}

/* Hover only where a pointer can hover, so a tap never leaves it on (audit P-4) */
@media (hover: hover) and (pointer: fine) {
  a:hover {
    color: var(--color-accent-hover);
  }
}

/* Strong / Bold */
strong, b {
  font-weight: var(--font-semibold);
}

/* Emphasis */
em, i {
  font-style: italic;
}

/* Small */
small {
  font-size: var(--text-xs-size);
  font-weight: var(--text-xs-weight);
  line-height: var(--text-xs-leading);
  letter-spacing: var(--text-xs-tracking);
  color: var(--color-text-secondary);
}

/* Code */
code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  padding: 0.125em 0.375em;
  background-color: var(--color-surface-raised);
  border-radius: var(--radius-sm);
}

pre {
  font-family: var(--font-mono);
  font-size: var(--text-sm-size);
  padding: var(--space-4);
  background-color: var(--color-surface-raised);
  border-radius: var(--radius-md);
  overflow-x: auto;
}

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

/* Blockquote */
blockquote {
  padding-inline-start: var(--space-4);
  border-inline-start: 3px solid var(--color-text-strong);
  font-style: italic;
  color: var(--color-text-secondary);
}

/* Horizontal rule */
hr {
  border: none;
  border-top: 1px solid var(--color-border-strong);
  margin: var(--space-6) 0;
}

/* Lists */
ul, ol {
  padding-inline-start: var(--space-6);
}

li {
  font-size: var(--text-default-size);
  line-height: var(--text-default-leading);
  color: var(--color-text-strong);
  margin-block-end: var(--space-1);
}

li::marker {
  color: var(--color-text-secondary);
}

/* Definition lists */
dt {
  font-weight: var(--font-medium);
}

dd {
  margin-inline-start: 0;
  color: var(--color-text-secondary);
}

/* Tables */
table {
  width: 100%;
  text-align: left;
}

th {
  font-weight: var(--font-medium);
  padding: var(--space-2) var(--space-3);
  color: var(--color-text-strong);
  border-bottom: 1px solid var(--color-border-strong);
}

td {
  padding: var(--space-2) var(--space-3);
  color: var(--color-text-strong);
  border-bottom: 1px solid var(--color-border-strong);
}

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

/* Placeholder */
::placeholder {
  color: var(--color-text-secondary);
  opacity: 1;
}

/* Mark / Highlight */
mark {
  background-color: var(--color-warning-soft);
  padding: 0.125em 0.25em;
  border-radius: var(--radius-sm);
}

/* Abbreviations */
abbr[title] {
  text-decoration: underline dotted;
  cursor: help;
}

/* Keyboard input */
kbd {
  font-family: var(--font-mono);
  font-size: 0.85em;
  padding: 0.125em 0.375em;
  background-color: var(--color-surface-raised);
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border-strong);
  box-shadow: 0 1px 0 var(--color-border-strong);
  color: var(--color-text-strong);
}

/* Details / Summary */
details {
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  background-color: var(--color-surface);
}

summary {
  font-weight: var(--font-medium);
  color: var(--color-text-strong);
  cursor: pointer;
  user-select: none;
}

@media (hover: hover) and (pointer: fine) {
  summary:hover {
    color: var(--color-text-strong);
  }
}

details[open] summary {
  margin-block-end: var(--space-3);
}
}
