/* =============================================================================
   base.css — Design tokens, CSS reset, and typographic foundation
   Johnson English Language Laboratory
   =============================================================================
   Loading order: base.css → layout.css → mobile.css
   This file defines the visual language of the system.
   ============================================================================= */

/* -----------------------------------------------------------------------------
   1. DESIGN TOKENS
   All visual values are derived from these custom properties.
   Changing a token propagates automatically throughout the interface.
   ----------------------------------------------------------------------------- */
:root {
  /* -- Colour palette -------------------------------------------------------- */
  /* Academic warm neutrals — evokes printed textbooks, not digital games */
  --color-bg:           #faf8f4;     /* off-white parchment */
  --color-bg-alt:       #f2efe8;     /* slightly darker parchment */
  --color-surface:      #ffffff;
  --color-surface-alt:  #f7f5f0;
  --color-border:       #d9d4c7;
  --color-border-light: #ebe7de;

  /* Text */
  --color-text-primary:   #1a1714;   /* near-black, warm */
  --color-text-secondary: #5a5550;   /* mid-grey warm */
  --color-text-muted:     #8a837a;   /* light grey warm */
  --color-text-inverse:   #faf8f4;

  /* Accent: classic ink blue — scholarly, not flashy */
  --color-accent:       #1e3a5f;
  --color-accent-light: #2e5a8f;
  --color-accent-bg:    #e8eef5;

  /* Semantic */
  --color-success:      #2d6a4f;
  --color-success-bg:   #d8f3dc;
  --color-warning:      #7d5a00;
  --color-warning-bg:   #fef3cd;
  --color-error:        #9b1d1d;
  --color-error-bg:     #fde8e8;

  /* Trivium stage colours — subtle, academic */
  --color-grammar:      #1e3a5f;   /* Grammar = deep blue (absorption) */
  --color-logic:        #3d4f1e;   /* Logic   = deep green (structure)  */
  --color-rhetoric:     #5f2a1e;   /* Rhetoric= deep burgundy (production) */
  --color-pronunciation: #5b21b6;  /* Pronunciation = deep violet */

  /* Backgrounds de etapa */
  --color-grammar-bg:    #eff6ff;
  --color-grammar-border:#93c5fd;
  --color-logic-bg:      #ecfdf5;
  --color-logic-border:  #6ee7b7;
  --color-pronunciation-bg: #f5f3ff;

  /* -- Typography ------------------------------------------------------------ */
  --font-serif:   'Georgia', 'Times New Roman', 'DejaVu Serif', serif;
  --font-sans:    system-ui, -apple-system, 'Segoe UI', Helvetica, Arial, sans-serif;
  --font-mono:    'Courier New', Courier, monospace;

  /* Scale — modular, 1.25 ratio */
  --text-xs:   0.75rem;    /* 12px */
  --text-sm:   0.875rem;   /* 14px */
  --text-base: 1rem;       /* 16px */
  --text-md:   1.125rem;   /* 18px */
  --text-lg:   1.25rem;    /* 20px */
  --text-xl:   1.5rem;     /* 24px */
  --text-2xl:  1.875rem;   /* 30px */
  --text-3xl:  2.25rem;    /* 36px */

  --line-height-tight:  1.25;
  --line-height-normal: 1.6;
  --line-height-loose:  1.9;

  /* -- Spacing --------------------------------------------------------------- */
  /* 4px base unit */
  --space-1:  0.25rem;
  --space-2:  0.5rem;
  --space-3:  0.75rem;
  --space-4:  1rem;
  --space-5:  1.25rem;
  --space-6:  1.5rem;
  --space-8:  2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;
  --space-16: 4rem;
  --space-20: 5rem;

  /* -- Borders and Radius ---------------------------------------------------- */
  --radius-sm: 2px;
  --radius:    4px;
  --radius-md: 6px;
  --radius-lg: 10px;

  --border-width: 1px;

  /* -- Shadows --------------------------------------------------------------- */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow:    0 2px 6px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.10), 0 2px 4px rgba(0, 0, 0, 0.06);

  /* -- Transitions ----------------------------------------------------------- */
  --transition-fast:   0.15s ease;
  --transition-normal: 0.25s ease;

  /* -- Layout ---------------------------------------------------------------- */
  --content-max-width: 860px;
  --sidebar-width:     260px;
  --header-height:     60px;
}

/* -----------------------------------------------------------------------------
   2. RESET
   Opinionated reset. Avoids browser inconsistencies without over-normalising.
   ----------------------------------------------------------------------------- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;             /* baseline; rem units derive from this */
  scroll-behavior: smooth;
  text-size-adjust: 100%;
  -webkit-text-size-adjust: 100%; /* Safari/Chrome — ignorado pelo Firefox */
}

body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--line-height-normal);
  color: var(--color-text-primary);
  background-color: var(--color-bg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  /* -moz-osx-font-smoothing removido — propriedade não padronizada, Firefox gera warning */
}

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

a {
  color: var(--color-accent);
  text-decoration: underline;
  text-underline-offset: 2px;
  transition: color var(--transition-fast);
}

a:hover, a:focus-visible {
  color: var(--color-accent-light);
}

button {
  cursor: pointer;
  font-family: inherit;
  font-size: inherit;
  border: none;
  background: none;
}

input, textarea, select {
  font-family: inherit;
  font-size: inherit;
}

ul, ol {
  list-style: none;
}

/* Accessible focus ring — visible only on keyboard navigation */
:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 3px;
}

/* Remove focus ring on mouse click */
:focus:not(:focus-visible) {
  outline: none;
}

/* -----------------------------------------------------------------------------
   3. TYPOGRAPHY ELEMENTS
   Semantic heading hierarchy. Headings use serif for academic feel.
   ----------------------------------------------------------------------------- */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-serif);
  font-weight: normal;
  line-height: var(--line-height-tight);
  color: var(--color-text-primary);
}

h1 { font-size: var(--text-3xl); letter-spacing: -0.01em; }
h2 { font-size: var(--text-2xl); }
h3 { font-size: var(--text-xl); }
h4 { font-size: var(--text-lg); }
h5 { font-size: var(--text-md); font-family: var(--font-sans); font-weight: 600; }
h6 { font-size: var(--text-base); font-family: var(--font-sans); font-weight: 600; }

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

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

strong { font-weight: 600; }
em     { font-style: italic; }

small {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
}

code, pre {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  background-color: var(--color-surface-alt);
  border: var(--border-width) solid var(--color-border-light);
  border-radius: var(--radius-sm);
}

code {
  padding: 0.1em 0.35em;
}

pre {
  padding: var(--space-4);
  overflow-x: auto;
  border-radius: var(--radius-md);
}

blockquote {
  border-left: 3px solid var(--color-accent);
  padding-left: var(--space-4);
  color: var(--color-text-secondary);
  font-style: italic;
  margin: var(--space-4) 0;
}

hr {
  border: none;
  border-top: var(--border-width) solid var(--color-border);
  margin: var(--space-8) 0;
}

/* -----------------------------------------------------------------------------
   4. UTILITY CLASSES
   Single-purpose, composable helpers. Keep minimal — avoid utility bloat.
   ----------------------------------------------------------------------------- */

/* Accessibility: screen-reader only text */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* Text helpers */
.text-muted    { color: var(--color-text-muted); }
.text-small    { font-size: var(--text-sm); }
.text-serif    { font-family: var(--font-serif); }
.text-center   { text-align: center; }

/* Display helpers */
.hidden        { display: none !important; }
.visually-hidden { visibility: hidden; }

/* Spacing helpers */
.mt-auto       { margin-top: auto; }
.mb-0          { margin-bottom: 0; }

/* -----------------------------------------------------------------------------
   5. LOADING STATE
   Shown while the application bootstraps and loads JSON data.
   ----------------------------------------------------------------------------- */
.loading-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 40vh;
  color: var(--color-text-muted);
  font-size: var(--text-lg);
}

/* Trivium stage badge colours */
.stage-badge {
  display: inline-block;
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.stage-badge--grammar  { background: var(--color-accent-bg); color: var(--color-grammar); }
.stage-badge--logic    { background: #eaf2ea; color: var(--color-logic); }
.stage-badge--rhetoric { background: #f5eae8; color: var(--color-rhetoric); }
