/* Design tokens + core components (.ibm-button, .ibm-chip, .ibm-panel,
   .ibm-tile, .ibm-progress). Must stay the first rule in this file. The
   older .ibm-btn / .ibm-card / .ibm-tag below are kept for the pages that
   already use them; new work uses the tokens.css components. */
@import url('/css/tokens.css');

/* =================================================================
   IB Math Revision — Shared design system.
   Import via: <link rel="stylesheet" href="/ibmath.css">
   Pages must remain single-file HTML for GitHub Pages — this stylesheet is
   deliberately narrow: variables + primitive components. Page-specific
   layouts continue to live inline in each page's <style> block.
   ================================================================= */
:root {
  /* Aliases of the shared brand tokens in /css/tokens.css (same values
     as before) — change colours there, not here. */
  --color-primary: var(--ibm-dark, #062559);
  --color-primary-hover: #041a40;
  --color-secondary: var(--ibm-primary, #0d3d8f);
  --color-accent: var(--ibm-accent, #5ec8ff);
  --color-accent-hover: var(--ibm-accent-hover, #3ab0f0);
  --color-bg: #f4f7fc;
  --color-surface: #ffffff;
  --color-surface-alt: #eef2f9;
  --color-text: #0f172a;
  --color-text-muted: #475569;
  --color-border: #cbd5e1;
  --color-border-soft: #d6dfec;
  --color-success: #10b981;
  --color-warning: #f59e0b;
  --color-danger: #ef4444;

  --font-sans: var(--ibm-font, 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif);
  --font-mono: ui-monospace, SFMono-Regular, Menlo, monospace;

  --text-h1: clamp(1.8rem, 4vw, 2.4rem);
  --text-h2: clamp(1.35rem, 3vw, 1.6rem);
  --text-h3: 1.15rem;
  --text-body: 1rem;
  --text-small: 0.88rem;
  --text-xs: 0.78rem;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-6: 24px;
  --space-8: 32px;
  --space-12: 48px;

  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-full: 9999px;

  --shadow-sm: 0 1px 3px rgba(6,37,89,0.06);
  --shadow-md: 0 4px 14px rgba(6,37,89,0.10);
  --shadow-hard: 4px 4px 0 0 var(--color-primary);

  --transition-fast: 120ms ease-out;
}

/* Base */
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; font-family: var(--font-sans); background: var(--color-bg); color: var(--color-text); line-height: 1.55; font-size: var(--text-body); -webkit-font-smoothing: antialiased; }
h1, h2, h3, h4, h5 { color: var(--color-primary); font-weight: 700; letter-spacing: -0.02em; margin-top: 0; }
h1 { font-size: var(--text-h1); }
h2 { font-size: var(--text-h2); }
h3 { font-size: var(--text-h3); }
a  { color: var(--color-secondary); }
a:hover { color: var(--color-primary); }

/* ================= Nav ================= */
.ibm-nav { background: var(--color-surface); border-bottom: 1px solid var(--color-border-soft); position: sticky; top: 0; z-index: 100; }
.ibm-nav__inner { max-width: 1180px; margin: 0 auto; padding: 14px 24px; display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; }
.ibm-nav__brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--color-primary); font-weight: 700; font-size: 1.05rem; }
.ibm-nav__brand img { height: 32px; width: 32px; }
.ibm-nav__link { color: var(--color-primary); text-decoration: none; font-size: var(--text-small); font-weight: 600; padding: 6px 10px; border-radius: var(--radius-sm); transition: background var(--transition-fast); }
.ibm-nav__link:hover, .ibm-nav__link.is-active { background: var(--color-surface-alt); }
.ibm-nav__spacer { flex: 1; }

/* .ibm-nav has no hamburger/collapse of its own (unlike nav.topnav above),
   so its 5-6 links just wrap onto their own flex line each at narrow
   widths -- 3-4 stacked rows before any page content, on every page that
   uses this nav (path-to-7.html, the preib-*.html pages, activities.html,
   predicted-papers.html, prior-knowledge.html). Keep it to one scrollable
   row instead, and size the links for a thumb while we're in here (they
   were ~34px tall with no min-height -- under the 44px guideline). */
@media (max-width: 640px) {
  .ibm-nav__inner { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .ibm-nav__inner::-webkit-scrollbar { display: none; }
  .ibm-nav__brand { flex-shrink: 0; }
  .ibm-nav__link { flex-shrink: 0; min-height: 44px; box-sizing: border-box; display: inline-flex; align-items: center; }
}

/* ================= Buttons ================= */
.ibm-btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: none; padding: 10px 18px; border-radius: var(--radius-md); font-weight: 700; font-size: var(--text-small); cursor: pointer; text-decoration: none; font-family: inherit; transition: background var(--transition-fast), transform var(--transition-fast); line-height: 1.2; }
.ibm-btn--primary  { background: var(--color-primary); color: #fff; }
.ibm-btn--primary:hover  { background: var(--color-primary-hover); }
.ibm-btn--secondary { background: transparent; color: var(--color-primary); border: 1px solid var(--color-primary); }
.ibm-btn--secondary:hover { background: var(--color-surface-alt); }
.ibm-btn--accent { background: var(--color-accent); color: var(--color-primary); }
.ibm-btn--accent:hover { background: var(--color-accent-hover); }
.ibm-btn--danger { background: transparent; color: var(--color-danger); border: 1px solid var(--color-danger); }
.ibm-btn--danger:hover { background: rgba(239,68,68,0.08); }
.ibm-btn--lg { padding: 14px 26px; font-size: 1rem; }
.ibm-btn--sm { padding: 6px 12px; font-size: var(--text-xs); }
.ibm-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none !important; }
.ibm-btn:active:not(:disabled) { transform: translateY(1px); }

/* ================= Cards ================= */
.ibm-card { background: var(--color-surface); border: 1px solid var(--color-border-soft); border-radius: var(--radius-lg); padding: var(--space-6); box-shadow: var(--shadow-sm); }
.ibm-card--flat { box-shadow: none; }
.ibm-card__title { color: var(--color-primary); font-size: 1.05rem; font-weight: 700; margin: 0 0 var(--space-2); }
.ibm-card__sub { color: var(--color-text-muted); font-size: var(--text-small); margin: 0 0 var(--space-4); }

/* ================= Tags / chips ================= */
.ibm-tag { display: inline-flex; align-items: center; padding: 3px 10px; border-radius: var(--radius-full); font-size: var(--text-xs); font-weight: 700; letter-spacing: 0.3px; }
.ibm-tag--brand   { background: var(--color-surface-alt); color: var(--color-primary); }
.ibm-tag--accent  { background: var(--color-accent); color: var(--color-primary); }
.ibm-tag--success { background: #dcfce7; color: #14532d; }
.ibm-tag--warn    { background: #fef3c7; color: #78350f; }
.ibm-tag--danger  { background: #fee2e2; color: #7f1d1d; }

/* ================= Forms ================= */
.ibm-input, .ibm-select, .ibm-textarea {
  width: 100%; padding: 10px 12px; background: var(--color-surface);
  border: 1px solid var(--color-border); border-radius: var(--radius-md);
  font-family: inherit; font-size: var(--text-body); color: var(--color-text);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.ibm-input:focus, .ibm-select:focus, .ibm-textarea:focus {
  outline: none; border-color: var(--color-secondary);
  box-shadow: 0 0 0 3px rgba(13,61,143,0.15);
}
.ibm-label { display: block; margin: var(--space-4) 0 6px; color: var(--color-primary); font-size: var(--text-xs); font-weight: 700; letter-spacing: 0.4px; text-transform: uppercase; }

/* ================= Status banners ================= */
.ibm-status { padding: 10px 14px; border-radius: var(--radius-md); margin-bottom: var(--space-4); font-size: var(--text-small); }
.ibm-status--ok    { background: #e8f5e9; color: #1b5e20; border: 1px solid var(--color-success); }
.ibm-status--warn  { background: #fff8e1; color: #5a3f0a; border: 1px solid var(--color-warning); }
.ibm-status--error { background: #fdecea; color: #7f1d1d; border: 1px solid var(--color-danger); }

/* ================= Utility ================= */
.ibm-container { max-width: 1180px; margin: 0 auto; padding: var(--space-6) var(--space-6); }
.ibm-hide { display: none !important; }
.ibm-muted { color: var(--color-text-muted); }
.ibm-mono  { font-family: var(--font-mono); }

/* ================= Print ================= */
@media print {
  .ibm-nav, .ibm-hide-print { display: none !important; }
  body { background: #fff; }
  .ibm-card { box-shadow: none; border-color: #d1d5db; page-break-inside: avoid; }
}

/* Nav topbar — shared logo + link constraints so pages that don't inline the topnav CSS still get proper sizing. */
nav.topnav { border-bottom: 1px solid #d6dfec; background: #fff; position: sticky; top: 0; z-index: 100; }
nav.topnav .inner { max-width: 1180px; margin: 0 auto; padding: 12px 20px; display: flex; align-items: center; gap: 10px; }
nav.topnav .brand { display:flex; align-items:center; gap:10px; font-weight: 700; color: #062559; text-decoration: none; font-size: 1.05rem; flex-shrink: 0; }
nav.topnav .nav-logo { height: 32px; width: 32px; object-fit: contain; }
nav.topnav .brand-txt { color: #062559; font-size: 1.05rem; font-weight: 700; }
nav.topnav .nav-links { display:flex; align-items:center; gap:2px; flex-wrap:wrap; flex:1; }
nav.topnav .nav-link { color: #062559; text-decoration:none; font-size:0.88rem; font-weight:600; padding:10px 12px; border-radius:5px; white-space:nowrap; min-height:40px; box-sizing:border-box; display:inline-flex; align-items:center; }
nav.topnav .nav-link:hover { background:#e6ecf7; }
nav.topnav .nav-hamburger { display:none; background:none; border:none; font-size:1.5rem; color:#062559; cursor:pointer; padding:4px 8px; }
@media (max-width: 900px) {
    nav.topnav .nav-hamburger { display: block; }
    nav.topnav .nav-links { display: none; flex-direction: column; align-items: stretch; width: 100%; padding-top: 8px; border-top: 1px solid #d6dfec; }
    nav.topnav .nav-links.open { display: flex; }
    nav.topnav .inner { flex-wrap: wrap; }
}

/* ---------------------------------------------------------------------------
   Math overflow safety — Feb 2026 UX audit fix.
   MathJax equations, and any element that renders LaTeX (question prompts,
   card prompts, working boxes), can produce content wider than a narrow
   phone screen (matrices, long fractions, integrals with wide integrands).
   Without an overflow strategy the equation blows the layout and forces
   the whole page to scroll horizontally. Local overflow-x:auto lets ONLY
   the equation scroll while the layout stays fluid.
   --------------------------------------------------------------------------- */
mjx-container,
mjx-container[jax="CHTML"][display="true"],
.MathJax,
.qbody,
.card-prompt,
.q-prompt {
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
}
mjx-container[display="true"] { display: block; }

/* -----------------------------------------------------------------------
 * Accessibility — WCAG 2.5.5 / Apple HIG minimum tap targets on mobile.
 * Applies at ≤ 480 px to button-like elements only. Inline body-text
 * links are intentionally left alone (a 44px min on every `<a>` inside
 * `<p>` would visibly break reading flow).
 * ----------------------------------------------------------------------- */
@media (max-width: 480px) {
  a.card, .btn, a.btn, button:not(.tap-tight):not(.ss-close):not(.nav-hamburger),
  input[type="submit"], input[type="button"] {
    min-height: 44px;
  }
  .btn, a.btn, button:not(.tap-tight):not(.ss-close):not(.nav-hamburger) {
    padding: 10px 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
}


/* --- Global accessibility: "Skip to main content" link -------------------
 * Every page has an <a class="skip-to-content" href="#main"> anchor for
 * keyboard users. Historically each page inlined its own CSS; this global
 * rule replaces those (and covers pages that forgot to inline it, so the
 * link no longer flashes on load in mobile Chrome).
 */
.skip-to-content {
  position: absolute;
  left: -9999px;
  top: auto;
  width: 1px;
  height: 1px;
  overflow: hidden;
  z-index: 99999;
}
.skip-to-content:focus {
  position: fixed;
  top: 8px;
  left: 8px;
  width: auto;
  height: auto;
  padding: 10px 16px;
  background: #062559;
  color: #fff;
  border-radius: 6px;
  font-weight: 700;
  text-decoration: none;
  box-shadow: 0 4px 12px rgba(6, 37, 89, 0.35);
}
