/* Career Launcher UAE — the student portal's dark mode (owner, 30 Nov 2026: "in student portal below setting give a toggle of
   dark mode but default keep everything in day or light mode but people if they way can switch to dark more, ensure colors are
   all fine and alighned in dark mode"). Served on every page after portal.css (portal_page()), so the switch works at once.

   Light is everyone's default. Dark is <html data-theme="dark">, set by the server from this device's cookie (portal_look()) and by
   the switch (portal-test.js), never by the device's own setting. Only on a screen: paper always prints light.

   How it is built, so a new rule in portal.css stays right in both:
   1. The switch itself (both modes).
   2. portal.css's own colour names (--background, --card, --foreground ...) given dark values. Anything written with them is dark
      already. The CL orange text and lines are lifted (--primary) to read on the dark; where white words sit ON the orange, green
      or red, the brand's own deeper colour is kept (--cl-fill, --right-fill, --wrong-fill), so they read as in light.
   3. Where portal.css writes a colour outright (#fff, a tint, a border), its dark twin: the same selector inside
      :where([data-theme="dark"]), which adds nothing to its weight, so it wins only by coming later, never over a more particular
      rule (a done chapter's outline Start keeps its outline).
   4. Pictures and drawings stay as printed: a question's figure, a board's paper crop and the IGCSE graphs and diagrams sit on a
      light panel of their own, never inverted.
   A rule added to portal.css with a written colour needs its twin here; scripts/layout-check.sh opens every portal page dark too
   and fails on words that read worse than in light (low-contrast-dark). */

/* ── 1. The switch: in the account menu under Settings, and on Settings → General ─────────────────────────────────────────── */
.portal-logo--dark { display: none; }
.portal-brand .portal-logo--dark, .dg-cobrand .portal-logo--dark { display: none; }
.pt-theme { margin: 0; }
.portal-me-panel form.pt-theme { padding-top: 0; border-top: 0; }
.pt-theme-label { flex: 1 1 auto; min-width: 0; }
.pt-switch {
  position: relative; flex: none; width: 40px; height: 24px; border-radius: 999px; background: var(--switch-off, #8a8a80);
  transition: background-color 0.18s var(--ease);
}
.pt-switch::after {
  content: ''; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3); transition: transform 0.18s var(--ease);
}
[aria-checked="true"] > .pt-switch { background: var(--cl-fill, var(--primary)); }
[aria-checked="true"] > .pt-switch::after { transform: translateX(16px); }
.pt-theme--settings { max-width: 560px; margin: 32px 0 0; padding: 14px 20px 16px; border: 1px solid var(--border); border-radius: 16px; background: var(--background); }
.pt-theme--settings button {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 44px; padding: 0; border: 0; background: none; color: var(--foreground);
  font: inherit; font-size: 16px; font-weight: 700; text-align: left; cursor: pointer;
}
.pt-theme--settings button svg { flex: none; color: var(--muted-foreground); }
.pt-theme-hint { margin: 2px 0 0 30px; font-size: 14px; line-height: 1.5; color: var(--muted-foreground); }
@media (max-width: 479px) { .pt-theme--settings { padding: 12px 16px 14px; } .pt-theme-hint { margin-left: 0; } }
/* High contrast (Windows): the system's own colours, so the switch still shows on and off. */
@media (forced-colors: active) {
  .pt-switch { border: 1px solid CanvasText; background: Canvas; }
  .pt-switch::after { background: CanvasText; }
  [aria-checked="true"] > .pt-switch { background: Highlight; }
}

@media screen {
  /* ── 2. The dark palette ───────────────────────────────────────────────────────────────────────────────────────────────── */
  :root[data-theme="dark"] {
    color-scheme: dark;
    --background: #161814;
    --foreground: #ecebe4;
    --card: #1f221c;
    --muted: #2a2d26;
    --muted-foreground: #a9a99d;
    --primary: #ec7b52;          /* CL orange lifted for words, links and lines on the dark */
    --primary-hover: #f39a73;
    --cl-fill: #c7441c;          /* CL orange itself, under white words */
    --cl-fill-hover: #a93816;
    --orange-light: #3a251b;
    --border: #34372f;
    --border-strong: #4a4d44;
    --dark: #2c3027;             /* the olive panel, a step above the cards */
    --on-dark: #f9f8f4;
    --on-dark-muted: #c9c8bd;
    --peach: #eeb093;
    --right: #6cc08f;
    --right-fill: #2f7d4f;
    --right-light: #1b3325;
    --wrong: #f2877c;
    --wrong-fill: #b3261e;
    --wrong-light: #3d1f1c;
    --developing: #e3ac4a;
    --developing-light: #3a2e15;
    --shadow: 0 16px 32px -20px rgba(0, 0, 0, 0.75);
    --switch-off: #85877b;
    --tint-orange-border: #5a3626;
    --tint-red-border: #5e2d28;
    --tint-green-border: #2d5a3e;
  }

  /* The logo: ivory lettering on no background (cl-logo.png is drawn on white). */
  :where([data-theme="dark"]) .portal-brand .portal-logo, :where([data-theme="dark"]) .dg-cobrand .portal-logo { display: none; }
  :where([data-theme="dark"]) .portal-brand .portal-logo--dark, :where([data-theme="dark"]) .dg-cobrand .portal-logo--dark { display: block; }

  /* ── 3. Written colours, their dark twins ──────────────────────────────────────────────────────────────────────────────── */
  /* White words on the CL orange: the brand's own orange, as in light. */
  :where([data-theme="dark"]) .portal-button, :where([data-theme="dark"]) .pt-start { background: var(--cl-fill); }
  :where([data-theme="dark"]) .portal-button:hover, :where([data-theme="dark"]) .pt-start:hover { background: var(--cl-fill-hover); }
  :where([data-theme="dark"]) .pt-grade:hover .pt-go, :where([data-theme="dark"]) .pt-subject:hover .pt-go { border-color: var(--cl-fill); background: var(--cl-fill); }
  :where([data-theme="dark"]) label.pt-choice:has(input:checked) .pt-letter { border-color: var(--cl-fill); background: var(--cl-fill); }
  :where([data-theme="dark"]) .dg-tab[aria-selected="true"] { border-color: var(--cl-fill); background: var(--cl-fill); box-shadow: 0 8px 22px rgba(0, 0, 0, 0.4); }
  :where([data-theme="dark"]) .dg-btn--primary { border-color: var(--cl-fill); background: var(--cl-fill); }
  :where([data-theme="dark"]) .dg-btn--primary:hover { border-color: var(--cl-fill-hover); background: var(--cl-fill-hover); }
  /* The shop's first page and the locked tiles on sale (30 Nov 2026): a ticked subject's box and a tile's price on hover. */
  :where([data-theme="dark"]) .sp-opt input:checked ~ .sp-opt-tick { border-color: var(--cl-fill); background: var(--cl-fill); }
  :where([data-theme="dark"]) a.ig-subj.is-for-sale:hover .ig-subj-price { border-color: var(--cl-fill); background: var(--cl-fill); }
  :where([data-theme="dark"]) .portal-bell-count, :where([data-theme="dark"]) .pn-new, :where([data-theme="dark"]) .pc-today,
  :where([data-theme="dark"]) .ig-subj.is-on .ig-subj-icon, :where([data-theme="dark"]) .ig-theme-tag,
  :where([data-theme="dark"]) .ig-themes-list a[aria-current] .ig-themes-n { background: var(--cl-fill); }
  :where([data-theme="dark"]) .pie-send { background: var(--cl-fill); }
  :where([data-theme="dark"]) .pie-send:hover { background: var(--cl-fill-hover); }
  :where([data-theme="dark"]) .ig-pager-row .ig-pager-next { border-color: var(--cl-fill); background: var(--cl-fill); }
  :where([data-theme="dark"]) .ig-pager-row .ig-pager-next:hover { background: var(--cl-fill-hover); }
  :where([data-theme="dark"]) .pt-ext, :where([data-theme="dark"]) .pt-inlink { text-decoration-color: rgba(236, 123, 82, 0.45); }
  :where([data-theme="dark"]) .pt-bp-chips a { border-color: rgba(236, 123, 82, 0.35); }
  :where([data-theme="dark"]) .pt-bp-next .pt-btn { border-color: rgba(236, 123, 82, 0.4); }

  /* White words on green and red (an answer, a level, the palette, the question map, the clock running out). */
  :where([data-theme="dark"]) .pt-choice.is-answer .pt-letter { border-color: var(--right-fill); background: var(--right-fill); }
  :where([data-theme="dark"]) .pt-choice.is-chosen-wrong .pt-letter { border-color: var(--wrong-fill); background: var(--wrong-fill); }
  :where([data-theme="dark"]) .pt-why-tag { background: var(--right-fill); }
  :where([data-theme="dark"]) .pt-why-tag--you { background: #4a4d44; }
  :where([data-theme="dark"]) .pt-pal.is-answered { border-color: var(--right-fill); background: var(--right-fill); }
  :where([data-theme="dark"]) .pt-pal.is-answered.is-marked { border-color: var(--primary); background: var(--right-fill); }
  :where([data-theme="dark"]) .pt-key.is-answered { border-color: var(--right-fill); background: var(--right-fill); }
  :where([data-theme="dark"]) .pt-map-q.is-right { background: var(--right-fill); }
  :where([data-theme="dark"]) .pt-map-q.is-wrong { background: var(--wrong-fill); }
  :where([data-theme="dark"]) .pt-level.is-mastered { background: var(--right-fill); }
  :where([data-theme="dark"]) .ig-ex-answer > .ig-ex-label { background: var(--right-fill); }
  :where([data-theme="dark"]) .pt-clock.is-low { background: var(--wrong-fill); }

  /* Ink chips (a filter chosen, the topic's tab open, Jump to a theme): light on the dark, dark words. */
  :where([data-theme="dark"]) .pt-filter[aria-pressed="true"] { color: var(--background); }
  :where([data-theme="dark"]) .pt-filter[aria-pressed="true"] span { color: #4a4c44; }
  :where([data-theme="dark"]) .ig-tabs a[aria-current] { color: var(--background); }
  :where([data-theme="dark"]) .ig-tabs a[aria-current] span { background: rgba(0, 0, 0, 0.12); }
  :where([data-theme="dark"]) .ig-themes-btn { color: var(--background); }
  /* What next, at a topic's end on a phone: the olive panel. */
  :where([data-theme="dark"]) .ig-next { background: var(--dark); }

  /* Surfaces and tints written out in portal.css. */
  :where([data-theme="dark"]) .pt-ch:hover { background: #24271f; }
  :where([data-theme="dark"]) label.pt-choice:hover { background: var(--card); }
  :where([data-theme="dark"]) button.ig-choice:hover:not(:disabled) { background: var(--card); }
  :where([data-theme="dark"]) .pn-item.is-unread .pn-open { background: #2b221c; }
  :where([data-theme="dark"]) .hm-card.is-news { border-color: var(--tint-orange-border); background: #241c17; }
  :where([data-theme="dark"]) .hm-due a { border-color: var(--tint-orange-border); background: #241c17; }
  :where([data-theme="dark"]) .hm-due.is-late a { border-color: var(--tint-red-border); background: #261918; }
  :where([data-theme="dark"]) .hm-c-scroll { --hs-rail: rgba(236, 235, 228, 0.2); }
  :where([data-theme="dark"]) a.ig-subj.is-on { background: #2b201a; }
  :where([data-theme="dark"]) .pt-ch.ig-theme-ch { border-top-color: var(--tint-orange-border); }
  :where([data-theme="dark"]) .pt-ch.ig-theme-ch:hover { background: #452b1f; }
  :where([data-theme="dark"]) .ig-theme-ch .pt-ch-meta { color: #d2c3b8; }
  :where([data-theme="dark"]) .ig-theme-ch .pt-prof-bar { background: rgba(255, 255, 255, 0.12); }
  :where([data-theme="dark"]) .pt-score-parts .is-partly { color: var(--primary-hover); }
  :where([data-theme="dark"]) .pt-progress-bar--done span { background: var(--muted-foreground); }
  :where([data-theme="dark"]) .al-fsec.is-given { box-shadow: inset 4px 0 0 var(--muted-foreground); }
  :where([data-theme="dark"]) .portal-avatar { background: #42463b; }
  /* Schedule | Attendance: the one chosen is raised above its track, as in light. */
  :where([data-theme="dark"]) .pc-switch a[aria-current="page"] { background: #3a3e34; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.4); }
  :where([data-theme="dark"]) .dg-ai-name { color: var(--foreground); }
  :where([data-theme="dark"]) .pt-input { border-color: #75776c; }
  :where([data-theme="dark"]) .pt-input:hover, :where([data-theme="dark"]) .pt-input:focus { border-color: var(--foreground); }
  :where([data-theme="dark"]) .pt-field.has-error .pt-input { border-color: var(--wrong); }

  /* Tinted borders: the orange, red and green notes, tiles and cards. */
  :where([data-theme="dark"]) .pt-notice { border-color: var(--tint-orange-border); }
  :where([data-theme="dark"]) .pt-asg-tile.is-soon, :where([data-theme="dark"]) .pt-asg-banner, :where([data-theme="dark"]) .hm-card.is-due,
  :where([data-theme="dark"]) .rv-start { border-color: var(--tint-orange-border); }
  :where([data-theme="dark"]) .pt-alert--error, :where([data-theme="dark"]) .pt-asg-tile.is-late, :where([data-theme="dark"]) .hm-card.is-late { border-color: var(--tint-red-border); }
  :where([data-theme="dark"]) .pt-alert--ok, :where([data-theme="dark"]) .pt-asg-banner.is-done { border-color: var(--tint-green-border); }

  /* Dialogs (Hand in?, Before you start, Request a change, Save this course?) and what lies behind them. */
  :where([data-theme="dark"]) .pt-confirm { border: 1px solid var(--border); background: var(--card); color: var(--foreground); box-shadow: 0 24px 64px rgba(0, 0, 0, 0.6); }
  :where([data-theme="dark"]) .pt-confirm::backdrop { background: rgba(0, 0, 0, 0.6); }
  :where([data-theme="dark"]) .pn-dialog { box-shadow: 0 24px 48px -24px rgba(0, 0, 0, 0.8); }
  :where([data-theme="dark"]) .pn-dialog::backdrop { background: rgba(0, 0, 0, 0.5); }
  :where([data-theme="dark"]) .pt-palette.is-open { box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.6); }

  /* The olive panels on a dark page: the preview's strip stands apart from the header. */
  :where([data-theme="dark"]) .pt-preview { border-bottom: 1px solid #4a4f40; background: #353a2e; }

  /* The gate: the Library blurred behind its lock fades into the dark page; the veil is a dark card. */
  :where([data-theme="dark"]) .pt-gate-peek::after {
    background: linear-gradient(180deg, rgba(22, 24, 20, 0) 0%, rgba(22, 24, 20, 0.15) 40%, rgba(22, 24, 20, 0.9) 100%);
  }
  :where([data-theme="dark"]) .pt-gate-veil { background: rgba(31, 34, 28, 0.95); }
  :where([data-theme="dark"]) .pt-gate-veil-mark { background: #42463b; }
  :where([data-theme="dark"]) .pt-gate-tabs li.is-asked { background: #3a3e34; }

  /* Marks over time (Progress): the bands in dark tints, the line and dots in light ink, the tip inverted. */
  :where([data-theme="dark"]) .ac-band.is-mastered { background: #1e3527; }
  :where([data-theme="dark"]) .ac-band.is-proficient { background: #19291f; }
  :where([data-theme="dark"]) .ac-band.is-developing { background: #33291a; }
  :where([data-theme="dark"]) .ac-band.is-beginning { background: #38231b; }
  :where([data-theme="dark"]) .ac-band-word, :where([data-theme="dark"]) .ac-x-label, :where([data-theme="dark"]) .ac-y { color: var(--muted-foreground); }
  :where([data-theme="dark"]) .ac-line polyline { stroke: var(--foreground); }
  :where([data-theme="dark"]) .ac-dot { border-color: var(--card); background: var(--foreground); }
  :where([data-theme="dark"]) .ac-dot.is-mastered { background: #4fae78; }
  :where([data-theme="dark"]) .ac-dot.is-proficient { background: #8cc9a3; }
  :where([data-theme="dark"]) .ac-dot.is-developing { background: #e3ac4a; }
  :where([data-theme="dark"]) .ac-dot.is-beginning { background: var(--primary); }
  :where([data-theme="dark"]) .ac-dot.is-again { border-color: var(--foreground); background: var(--card); }
  :where([data-theme="dark"]) .ac-dot:focus-visible { outline-color: var(--primary); }
  :where([data-theme="dark"]) .ac-dot::after { background: #f9f8f4; color: #252721; }

  /* ── 4. Pictures and drawings as printed, on a light panel ─────────────────────────────────────────────────────────────── */
  /* A question's figure (drawn on white or on nothing). */
  :where([data-theme="dark"]) .pt-figure { padding: 8px; border-radius: 8px; background: #fff; }
  /* The IGCSE and A Level graphs, sketches, charts and diagrams (igcse-graphs.php): drawn in portal.css's light colours, on white. */
  :where([data-theme="dark"]) svg.ig-graph {
    --background: #f9f8f4; --foreground: #252721; --card: #fff; --muted: #efeee8; --muted-foreground: #66675f; --primary: #c7441c;
    --orange-light: #f4e6dd; --border: #e0e0d6; --border-strong: #cfcdc1; --dark: #282b24; --peach: #eeb093; --right: #2f7d4f; --wrong: #b3261e;
    border-radius: 8px; background: #fff;
  }
  /* A board's paper crop is a picture on white already, its corners rounded on white (.ig-photo img, portal.css): nothing to add. */
}
