/* ============================================================================
   gc-tokens.css — Gcourses shared design-system foundation
   ----------------------------------------------------------------------------
   Additive & low-risk by design:
     1. Adds NEW system tokens (spacing / radius / shadow / type / motion / z)
        under the --gc-* namespace — no collision with existing page tokens.
     2. Adds DARK-MODE overrides for the color vocabulary every page already
        uses (--purple, --blush, --white, --text, ...). These use higher-
        specificity selectors (:root[data-theme="dark"]) so they win over each
        page's inline :root{} without touching any component CSS.
     3. Adds accessibility primitives: visible :focus-visible ring, .sr-only,
        and prefers-reduced-motion damping.

   Theme resolution (see gc-theme.js):
     • <html data-theme="dark">  → forced dark
     • <html data-theme="light"> → forced light (wins over OS dark)
     • no attribute             → follows the OS via prefers-color-scheme
   Load this BEFORE each page's own <style>/<link>. Keep first-paint flicker
   away with the inline snippet in gc-theme.js's header comment.
   ========================================================================== */

/* ---- 1. New system tokens (namespaced, purely additive) ------------------ */
:root{
  /* spacing scale (4px base) */
  --gc-space-1:.25rem; --gc-space-2:.5rem;  --gc-space-3:.75rem; --gc-space-4:1rem;
  --gc-space-5:1.5rem; --gc-space-6:2rem;   --gc-space-8:3rem;   --gc-space-10:4rem;
  /* radii */
  --gc-radius-sm:8px; --gc-radius-md:12px; --gc-radius-lg:18px; --gc-radius-xl:24px; --gc-radius-pill:100px;
  /* elevation (tuned to the brand purple shadow) */
  --gc-shadow-1:0 2px 10px rgba(160,80,159,.08);
  --gc-shadow-2:0 8px 28px rgba(160,80,159,.14);
  --gc-shadow-3:0 18px 54px rgba(160,80,159,.20);
  /* type scale */
  --gc-fs-xs:.72rem; --gc-fs-sm:.82rem; --gc-fs-md:.95rem; --gc-fs-lg:1.15rem;
  --gc-fs-xl:1.5rem; --gc-fs-2xl:2rem;  --gc-lh-tight:1.25; --gc-lh-base:1.6;
  /* motion */
  --gc-ease:cubic-bezier(.4,0,.2,1); --gc-dur-fast:.14s; --gc-dur-base:.24s; --gc-dur-slow:.4s;
  /* z-index scale */
  --gc-z-nav:200; --gc-z-overlay:400; --gc-z-modal:500; --gc-z-toast:600; --gc-z-boot:700;
  /* focus ring */
  --gc-focus:var(--purple,#a0509f);
  color-scheme:light;
}

/* ---- 2a. Dark palette — explicit toggle ---------------------------------- */
:root[data-theme="dark"]{
  color-scheme:dark;
  /* surfaces */
  --blush:#1a121d;            /* page background            */
  --white:#251a29;            /* card / raised surface      */
  --cream:#2c2030;            /* alternate surface          */
  /* text */
  --text:#ece3ee;            /* body                       */
  --deep:#f6eef7;            /* headings                   */
  --muted:#b79cb6;           /* secondary text             */
  /* lines / accents */
  --line:rgba(218,181,213,.16);
  --lavender:#3a2a3c;         /* subtle borders / fills     */
  /* brand */
  --purple:#c884c4;          /* links / accents on dark    */
  --mid:#dcaad8;             /* hover / brighter accent    */
  /* status */
  --ok:#5fbf8c; --good:#5fbf8c;
  --err:#e2809a; --bad:#e2809a; --warn:#e0b25f;
  /* gc-experience.css namespace mirror */
  --gc-purple:#c884c4; --gc-mid:#dcaad8; --gc-lavender:#3a2a3c;
  --gc-blush:#1a121d;  --gc-white:#251a29; --gc-deep:#f6eef7;
  --gc-focus:#c884c4;
}

/* ---- 2b. Dark palette — OS preference when no explicit choice ------------ */
@media (prefers-color-scheme:dark){
  :root:not([data-theme="light"]){
    color-scheme:dark;
    --blush:#1a121d; --white:#251a29; --cream:#2c2030;
    --text:#ece3ee; --deep:#f6eef7; --muted:#b79cb6;
    --line:rgba(218,181,213,.16); --lavender:#3a2a3c;
    --purple:#c884c4; --mid:#dcaad8;
    --ok:#5fbf8c; --good:#5fbf8c; --err:#e2809a; --bad:#e2809a; --warn:#e0b25f;
    --gc-purple:#c884c4; --gc-mid:#dcaad8; --gc-lavender:#3a2a3c;
    --gc-blush:#1a121d; --gc-white:#251a29; --gc-deep:#f6eef7; --gc-focus:#c884c4;
  }
}

/* ---- 2c. Contrast fixes for known white-on-purple components -------------
   In dark mode the brand purple is lightened for legibility as text/links,
   so filled purple surfaces need dark labels to stay AA. Targeted + safe:
   these selectors out-specify the components' inline color:#fff. ---------- */
:root[data-theme="dark"] .btn:not(.ghost):not(.danger),
:root[data-theme="dark"] .auth-btn,
:root[data-theme="dark"] .rail .ritem.on{ color:#241127; }
@media (prefers-color-scheme:dark){
  :root:not([data-theme="light"]) .btn:not(.ghost):not(.danger),
  :root:not([data-theme="light"]) .auth-btn,
  :root:not([data-theme="light"]) .rail .ritem.on{ color:#241127; }
}

/* ---- 3. Accessibility primitives (additive, global) ---------------------- */
/* Keyboard focus ring — only shows for keyboard users, never on mouse click. */
:where(a,button,input,select,textarea,[tabindex]):focus-visible{
  outline:2px solid var(--gc-focus);
  outline-offset:2px;
  border-radius:4px;
}
/* Screen-reader-only helper */
.sr-only{
  position:absolute!important;width:1px;height:1px;padding:0;margin:-1px;
  overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0;
}
/* Respect users who ask for less motion */
@media (prefers-reduced-motion:reduce){
  *,*::before,*::after{
    animation-duration:.001ms!important;animation-iteration-count:1!important;
    transition-duration:.001ms!important;scroll-behavior:auto!important;
  }
}

/* ---- 3b. Learning-journey state chip (reusable component) -----------------
   One vocabulary for chapter/module progress, shared by the course sidebar
   and the dashboard: Locked · Available · In progress · Completed · Needs review.
   Uses color-mix so a single rule themes correctly in light and dark. -------*/
.gc-state{
  display:inline-flex; align-items:center; gap:.35rem; white-space:nowrap; line-height:1;
  font-size:.64rem; font-weight:700; letter-spacing:.02em;
  padding:.22rem .5rem .22rem .42rem; border-radius:100px; border:1px solid transparent;
}
.gc-state .gc-dot{ width:7px; height:7px; border-radius:50%; flex:none; }
.gc-state.s-locked   { background:color-mix(in srgb,var(--muted) 14%,transparent); color:var(--muted); border-color:var(--line); }
.gc-state.s-available{ background:color-mix(in srgb,var(--purple) 10%,transparent); color:var(--purple); border-color:color-mix(in srgb,var(--purple) 28%,transparent); }
.gc-state.s-progress { background:color-mix(in srgb,var(--purple) 16%,transparent); color:var(--purple); border-color:color-mix(in srgb,var(--purple) 44%,transparent); }
.gc-state.s-completed{ background:color-mix(in srgb,var(--ok) 15%,transparent);    color:var(--ok);     border-color:color-mix(in srgb,var(--ok) 38%,transparent); }
.gc-state.s-review   { background:color-mix(in srgb,var(--err) 14%,transparent);   color:var(--err);    border-color:color-mix(in srgb,var(--err) 38%,transparent); }
.gc-state.s-locked   .gc-dot{ background:var(--muted); }
.gc-state.s-available .gc-dot{ background:var(--purple); box-shadow:0 0 0 3px color-mix(in srgb,var(--purple) 20%,transparent); }
.gc-state.s-progress .gc-dot{ background:var(--purple); }
.gc-state.s-completed .gc-dot{ background:var(--ok); }
.gc-state.s-review   .gc-dot{ background:var(--err); }

/* ---- 4. Floating theme toggle (auto-injected by gc-theme.js) ------------- */
.gc-theme-toggle{
  position:fixed;top:14px;right:14px;z-index:var(--gc-z-toast);
  width:40px;height:40px;display:inline-flex;align-items:center;justify-content:center;
  border:1px solid var(--line,rgba(218,181,213,.4));border-radius:var(--gc-radius-pill);
  background:var(--white,#fff);color:var(--purple,#a0509f);cursor:pointer;
  box-shadow:var(--gc-shadow-1);transition:background var(--gc-dur-fast) var(--gc-ease),
    color var(--gc-dur-fast) var(--gc-ease),transform var(--gc-dur-fast) var(--gc-ease);
}
.gc-theme-toggle:hover{transform:translateY(-1px);box-shadow:var(--gc-shadow-2)}
.gc-theme-toggle svg{width:20px;height:20px;fill:none;stroke:currentColor;
  stroke-width:1.9;stroke-linecap:round;stroke-linejoin:round}
.gc-theme-toggle .gc-sun{display:none}
:root[data-theme="dark"] .gc-theme-toggle .gc-sun{display:block}
:root[data-theme="dark"] .gc-theme-toggle .gc-moon{display:none}
@media (prefers-color-scheme:dark){
  :root:not([data-theme="light"]) .gc-theme-toggle .gc-sun{display:block}
  :root:not([data-theme="light"]) .gc-theme-toggle .gc-moon{display:none}
}
/* On the portal, sit clear of the top bar tools on small screens */
@media (max-width:640px){ .gc-theme-toggle{top:10px;right:10px;width:36px;height:36px} }
