/*-----------------------------------------------
  THEME VARIABLES & TRANSITIONS
-----------------------------------------------*/
:root {
  color-scheme: light;
  --bg-color: #f4f6f8;
  --surface-1: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #edf2f7;
  --text-color: #172b42;
  --text-secondary: #536479;
  --border-color: #d8e0e9;
  --border-rgb: 216, 224, 233;
  --accent-color: #1559b7;
  --accent-hover: #104b9c;
  --accent-active: #0c3e83;
  --accent-rgb: 21, 89, 183;
  /* Button fills remain deep blue in both themes; link colors can be lighter. */
  --action-bg: #1559b7;
  --action-hover: #104b9c;
  --action-ink: #ffffff;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 3px rgba(23, 43, 66, 0.05);
  --shadow-md: 0 8px 24px rgba(23, 43, 66, 0.09);
  --control-height: 42px;
  --transition-duration: 0.18s;
  --shadow-color: rgba(23, 43, 66, 0.07);
}

.dark {
  color-scheme: dark;
  --bg-color: #101923;
  --surface-1: #182432;
  --surface-2: #202e3f;
  --surface-3: #29394c;
  --text-color: #edf2f7;
  --text-secondary: #b5c2d2;
  --border-color: #35465c;
  --border-rgb: 53, 70, 92;
  --accent-color: #86b8ff;
  --accent-hover: #b0d0ff;
  --accent-active: #c9dfff;
  --accent-rgb: 134, 184, 255;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.16);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.22);
  --shadow-color: rgba(0, 0, 0, 0.18);
}

/* Resolve aliases on the themed element, including a dark body. */
:root, .dark {
  /* Compatibility aliases for existing course components. */
  --primary-color: var(--text-color);
  --secondary-color: var(--text-secondary);
  --color-dark: var(--text-color);
  --card-bg: var(--surface-1);
  --info-bg: var(--surface-1);
  --hover-bg: var(--surface-3);
  --header-text: var(--text-color);
  --footer-bg: var(--surface-1);
  --card-icon-color: var(--accent-color);
}

/*-----------------------------------------------
  GLOBAL RESET & BASE STYLES
-----------------------------------------------*/
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Inter', 'SF Pro Text', 'SF Pro Icons', 'Helvetica Neue', Helvetica, Arial, sans-serif;
  background: var(--bg-color);
  color: var(--text-color);
  line-height: 1.6;
  transition: background var(--transition-duration),
    color var(--transition-duration);
  padding: 0;
  margin: 0;
  min-height: 100vh;
  font-feature-settings: 'kern' 1, 'liga' 1, 'calt' 1;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  padding-top: 50px; /* Account for fixed header */
}

#page-content {
  flex: 1;
}

/*-----------------------------------------------
  TITLES (Page & Section)
-----------------------------------------------*/
.page-title,
.section-title {
  text-align: center;
  margin: 1.5rem 0 1rem;
  font-size: clamp(1.75rem, 1.25rem + 1.5vw, 2.5rem);
  line-height: 1.2;
  text-wrap: balance;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--primary-color);
  transition: color var(--transition-duration);
}

body.dark .page-title,
body.dark .section-title {
  color: var(--header-text);
}

.section-header {
  text-align: center;
  font-size: 1.5rem;
  margin: 1.5rem 0 1rem;
  padding-bottom: 0.25rem;
  border-bottom: 2px solid var(--accent-color);
  transition: color var(--transition-duration);
  font-weight: 600;
  letter-spacing: -0.01em;
}

/*-----------------------------------------------
  INFO-BOX
-----------------------------------------------*/
.info-box {
  background: var(--info-bg);
  padding: 1.2em;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  margin-bottom: 1.5em;
  transition: background var(--transition-duration);
}

/*-----------------------------------------------
  RESPONSIVE IMAGES AND IMAGE CONTAINERS
-----------------------------------------------*/
.responsive-image {
  max-width: 100%;
  height: auto;
  margin: 1rem auto;
  border-radius: 6px;
  box-shadow: 0 1px 4px var(--shadow-color);
  display: block;
}

.image-container {
  margin-bottom: 2rem;
  text-align: center;
}

.image-container h3 {
  margin-top: 1.5rem;
  margin-bottom: 0.5rem;
  color: var(--primary-color);
}

.image-container p {
  margin: 0.5rem auto 1rem;
  max-width: 90%;
  color: var(--text-secondary);
}

body.dark .image-container h3 {
  color: var(--text-color);
}

.reference {
  margin-top: 2rem;
  font-size: 0.9rem;
  border-top: 1px solid var(--border-color);
  padding-top: 1rem;
  color: var(--text-secondary);
}

.reference a {
  color: var(--accent-color);
  text-decoration: none;
}

.reference a:hover {
  text-decoration: underline;
}

/*-----------------------------------------------
  CONTAINER
-----------------------------------------------*/
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem 2rem;
}

@media (max-width: 600px) {
  .container {
    padding: 1rem;
  }
}

/* Font sizing */
body.large-font { 
  font-size: 130% !important; 
}

/* Use a stable size: nested lists and table cells must not compound em scaling. */
body.large-font p,
body.large-font li,
body.large-font td,
body.large-font th,
body.large-font input,
body.large-font label,
body.large-font button,
body.large-font .card p,
body.large-font .footer-copy,
body.large-font .footer-btns button {
  font-size: 1.25rem !important;
}

body.large-font h1 { font-size: 2.6rem !important; }
body.large-font h2 { font-size: 2.2rem !important; }
body.large-font h3 { font-size: 1.8rem !important; }
body.large-font h4 { font-size: 1.5rem !important; }
body.large-font h5 { font-size: 1.3rem !important; }
body.large-font h6 { font-size: 1.1rem !important; }

body.large-font .page-title,
body.large-font .section-title {
  font-size: 2.8rem !important;
}

body.large-font .section-header {
  font-size: 1.8rem !important;
}

/* Ensure tables are readable with large font */
body.large-font .custom-table {
  line-height: 1.6 !important;
}

h1, h2, h3, h4, h5, h6 {
  color: var(--primary-color);
  transition: color var(--transition-duration);
}

body.dark h1,
body.dark h2,
body.dark h3,
body.dark h4,
body.dark h5,
body.dark h6 {
  color: var(--text-color);
}

/* Avoid a theme flash before saved appearance settings have loaded. */
body:not(.transitions-enabled),
body:not(.transitions-enabled) * {
  transition: none !important;
}

/* Hover/theme transitions only. Opacity and transform here made every
   enter animation (and the 0.5s home card fade) double-play as a blink. */
body.transitions-enabled * {
  transition-property: background-color, color, border-color, box-shadow;
  transition-duration: var(--transition-duration);
  transition-timing-function: ease;
}

/*-----------------------------------------------
  ACCESSIBILITY & PRINT STYLES
-----------------------------------------------*/
@media print {
  header, footer, .no-print {
    display: none !important;
  }
  
  body {
    background: white !important;
    color: black !important;
  }
  
  .container, .cards-container, .info-box {
    margin: 0 !important;
    padding: 0 !important;
    box-shadow: none !important;
  }
  
  a {
    text-decoration: underline;
    color: #0066cc !important;
  }
  
  .page-title, .section-title {
    margin: 20px 0 !important;
  }
}

/* Media queries for responsive images */
@media (max-width: 768px) {
  .image-container {
    margin-bottom: 1.5rem;
  }
  
  .image-container h3 {
    margin-top: 1rem;
    font-size: 1.2rem;
  }
  
  .image-container p {
    font-size: 0.9rem;
  }
}

/* Enhanced scroll behavior */
html {
  scroll-behavior: smooth;
  scroll-padding-top: 80px; /* Account for fixed header */
}

/* Custom scrollbar */
::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-color);
}

::-webkit-scrollbar-thumb {
  background: linear-gradient(135deg, var(--accent-color), var(--primary-color));
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(135deg, var(--accent-hover), var(--primary-hover));
}

/* Dark mode scrollbar */
body.dark ::-webkit-scrollbar-track {
  background: var(--bg-color);
}

body.dark ::-webkit-scrollbar-thumb {
  background: linear-gradient(135deg, var(--accent-color), var(--primary-color));
}
/* Keyboard-accessible bypass link shared by every page. */
.skip-link {
  position: fixed;
  top: 0.75rem;
  left: 0.75rem;
  z-index: 100000;
  padding: 0.7rem 1rem;
  border-radius: 0.55rem;
  background: #102a43;
  color: #fff;
  font-weight: 700;
  text-decoration: none;
  transform: translateY(-160%);
  transition: transform 0.16s ease;
}

.skip-link:focus {
  transform: translateY(0);
}

/* Shared reading and keyboard support. Keep intrinsic figure dimensions intact. */
main, #page-content { min-width: 0; }
button, input, select, textarea { font: inherit; }
:where(p, li, dd, td, th) { overflow-wrap: break-word; }
:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: 3px solid var(--accent-color, #0066cc) !important;
  outline-offset: 3px;
}
.card:focus-within { outline: 3px solid var(--accent-color); outline-offset: 3px; }
.card-link:focus-visible { outline-offset: -4px; }
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}
@media (prefers-reduced-motion: reduce) {
  html, html body, html body *, html body *::before, html body *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    transition-delay: 0ms !important;
  }
}

/* Native controls and keyboard focus share the page theme. */
button, input, select, textarea { font-family: inherit; }
:where(button, input, select, textarea) { accent-color: var(--action-bg); }
:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: 3px solid var(--accent-color);
  outline-offset: 3px;
}
:where(input, textarea)::placeholder { color: var(--text-secondary); opacity: 1; }

/* Unstyled and visited text links remain readable in either theme. */
:where(a, a:visited) { color: var(--accent-color); text-underline-offset: .18em; }
