/* =====================================================================
   themes/amber-crt.css — fun theme: early amber monochrome CRT.
   Activated by <html data-theme="amber-crt">. Load AFTER theme-base.css
   and the brand layer. Local CSS only: no fonts, images or URLs.

   Everything is sized in CHARACTER CELLS:
     1 cell wide  = 1ch                               (--cell-w)
     1 cell tall  = 1em × line-height                 (--cell-h)
   Every font size is the same (CRTs had one size), line-height is fixed,
   so every line of text is exactly one cell tall. Spacing is whole cells:
   horizontal in ch (--space-*), vertical in lines (--line-*).
   Frames use inset box-shadows instead of borders, so a 1px rule never
   pushes content off the grid.

   This is the one fun theme that also has component rules: a CRT can't
   show headings by size or status by colour, so it needs uppercase,
   reverse video and prefix glyphs. Every rule is scoped to
   :root[data-theme="amber-crt"] so it can never leak into other themes.
   ===================================================================== */

/* ---------- 1. Tokens (check-contrast.py reads this block) ----------- */
:root[data-theme="amber-crt"] {
  color-scheme: dark;

  /* Phosphor palette: one hue, several brightnesses */
  --color-bg:            #0d0800;  /* unlit tube                         */
  --color-surface:       #140c00;  /* cards: barely lit                  */
  --color-surface-2:     #1c1200;  /* table heads, inline code           */
  --color-tint:          #2a1b00;  /* default tags, highlights           */
  --color-border:        #7a5200;  /* frames (dim phosphor)              */
  --color-text:          #ffb000;  /* P3 amber phosphor                  */
  --color-text-muted:    #c48600;  /* dimmer amber, 5.9:1 on surface-2   */
  --color-accent:        #ffc233;  /* brighter amber: primary fill       */
  --color-accent-contrast: #0d0800;/* reverse video: tube colour on lit  */
  --color-accent-2:      #d99600;  /* secondary fill (dimmer)            */
  --color-accent-2-contrast: #0d0800;
  --color-link:          #ffcc4d;
  --color-link-hover:    #ffe3a3;
  --color-focus:         #ffe3a3;  /* brightest: focus = full intensity  */
  /* Status: still amber, so they also differ by glyph + weight + video:
       success  "[+]"  normal       warning "[!]" bold
       danger   "[X]"  bold, reverse-video label                       */
  --color-success:       #ffcc4d;
  --color-warning:       #ffb000;
  --color-danger:        #ff9d2e;  /* hotter, more orange amber          */
  --color-code-bg:       #080500;
  --color-code-fg:       #ffb000;  /* code is the same amber             */
  --brand-gradient:      linear-gradient(180deg, #1c1200 0%, #140c00 100%);
  --brand-gradient-fg:   #ffc233;
  --brand-accent2-deco:  #d99600;  /* holiday-research SVG strokes       */
  /* 13month category tags: four brightnesses, dark label */
  --cat-1: #ff9d2e;  --cat-2: #d99600;  --cat-3: #ffc233;  --cat-4: #ffd77a;
  --cat-fg: #0d0800;
  /* Reverse video (lit cell, dark glyph): headings, buttons, focus */
  --crt-reverse-fg:      #0d0800;
  --crt-reverse-bg:      #ffb000;

  /* --- Character-cell grid ------------------------------------------- */
  --crt-size:     1rem;                       /* the ONE type size         */
  --crt-leading:  1.5;                        /* line-height, unitless     */
  --cell-w:       1ch;                        /* one character wide        */
  --cell-h:       calc(1em * var(--crt-leading)); /* one line tall         */
  /* Content width in whole characters. 80 columns, 40 on narrow screens
     (see the @media block below). */
  --crt-cols:     80;
  --measure:      calc(var(--crt-cols) * var(--cell-w));   /* 80ch        */
  /* Fallback page width (no round()): never wider than the viewport.
     The @supports block below snaps it down to a whole number of ch. */
  --page-max:     min(var(--measure), 100%);
  --page-gutter:  var(--cell-w);

  /* Spacing: whole cells. Horizontal (inline) in ch …                     */
  --space-1: calc(1 * var(--cell-w));  --space-2: calc(1 * var(--cell-w));
  --space-3: calc(2 * var(--cell-w));  --space-4: calc(2 * var(--cell-w));
  --space-5: calc(3 * var(--cell-w));  --space-6: calc(4 * var(--cell-w));
  --space-7: calc(6 * var(--cell-w));  --space-8: calc(8 * var(--cell-w));
  /* … vertical (block) in lines. */
  --line-1: calc(1 * var(--cell-h));   --line-2: calc(2 * var(--cell-h));
  --line-3: calc(3 * var(--cell-h));   --line-4: calc(4 * var(--cell-h));

  /* Shape: a CRT has no rounded cells */
  --radius-sm: 0; --radius-md: 0; --radius-lg: 0; --radius-pill: 0;
  --shadow-sm: none;
  --shadow-md: none;
  --crt-frame: inset 0 0 0 1px var(--color-border);  /* border w/o layout */

  /* Type: monospace everything, one size, one leading */
  --font-body:    ui-monospace, "Cascadia Mono", "DejaVu Sans Mono", Menlo, Consolas, monospace;
  --font-display: var(--font-body);
  --font-mono:    var(--font-body);
  --text-xs: var(--crt-size);  --text-sm: var(--crt-size);  --text-md: var(--crt-size);
  --text-lg: var(--crt-size);  --text-xl: var(--crt-size);  --text-2xl: var(--crt-size);
  --text-3xl: var(--crt-size);
  --leading: var(--crt-leading);
  --leading-tight: var(--crt-leading);

  /* Effects (set an alpha to 0 to switch one off for a whole site) */
  --crt-glow: 0 0 .12em rgb(255 176 0 / .55), 0 0 .45em rgb(255 140 0 / .22);
  --crt-scanline-alpha: .14;
  --crt-vignette-alpha: .42;
}

/* 40-column mode on narrow screens (~640px and below). */
@media (max-width: 40em) {
  :root[data-theme="amber-crt"] { --crt-cols: 40; }
}
/* Snap the page width DOWN to a whole number of characters.
   round(down, A, 1ch) = the largest multiple of 1ch that is <= A. */
@supports (width: round(down, 100%, 1ch)) {
  :root[data-theme="amber-crt"] {
    --page-max: round(down, min(var(--measure), 100%), var(--cell-w));
  }
}

/* ---------- 2. Base elements on the grid ----------------------------- */
:root[data-theme="amber-crt"] body {
  font: var(--crt-size)/var(--crt-leading) var(--font-body);
  text-shadow: var(--crt-glow);
  overflow-wrap: anywhere;          /* pl/ru/pt… words wrap at any cell   */
  hyphens: auto;
  scrollbar-color: var(--color-border) var(--color-bg);
  caret-color: var(--color-text);
}
:root[data-theme="amber-crt"] * { font-size: inherit; line-height: inherit; }
:root[data-theme="amber-crt"] ::selection {
  background: var(--crt-reverse-bg); color: var(--crt-reverse-fg); text-shadow: none;
}

/* Page containers: snap to whole characters, centred. Point your site's
   own wrapper at the same tokens: max-width: var(--page-max). */
:root[data-theme="amber-crt"] main,
:root[data-theme="amber-crt"] .wrap {
  max-width: calc(var(--page-max) + 2 * var(--page-gutter));
  padding-inline: var(--page-gutter);
  margin-inline: auto;
}

/* Headings: same size as body. Shown by case, weight and reverse video.
   Each heading + its decoration is a whole number of lines. */
:root[data-theme="amber-crt"] :is(h1, h2, h3, h4) {
  font-weight: 700;
  text-transform: uppercase;
  margin: var(--line-1) 0 0;
  overflow-wrap: anywhere;
}
:root[data-theme="amber-crt"] h1 {                  /* reverse video bar */
  width: fit-content; max-width: 100%;
  padding-inline: var(--cell-w);
  background: var(--crt-reverse-bg); color: var(--crt-reverse-fg);
  text-shadow: none;
  box-shadow: 0 0 .6em rgb(255 176 0 / .35);
}
:root[data-theme="amber-crt"] h2::after {           /* ==== underline    */
  content: "================================================================================";
  content: "================================================================================" / "";
  display: block; height: var(--cell-h);
  overflow: hidden; white-space: nowrap; font-weight: 400;
  color: var(--color-text-muted);
}
:root[data-theme="amber-crt"] h3::before {          /* "> " prompt       */
  content: ">\00A0"; content: ">\00A0" / "";   /* U+00A0: keep ">" on the word */
  color: var(--color-text-muted);
}
:root[data-theme="amber-crt"] :is(p, ul, ol, table, pre, blockquote) {
  margin-block: 0 var(--line-1);
}
:root[data-theme="amber-crt"] p { max-width: var(--measure); }
:root[data-theme="amber-crt"] :is(ul, ol) { padding-inline-start: calc(3 * var(--cell-w)); }
:root[data-theme="amber-crt"] strong, :root[data-theme="amber-crt"] b { font-weight: 700; }

:root[data-theme="amber-crt"] a { text-underline-offset: .2em; }
:root[data-theme="amber-crt"] a:hover { text-decoration-thickness: 2px; }

/* Focus = reverse video + a full-intensity outline (both, for clarity) */
:root[data-theme="amber-crt"] :focus-visible {
  outline: 2px solid var(--color-focus);
  outline-offset: 2px;
}
:root[data-theme="amber-crt"] :is(a, .btn, button, summary):focus-visible {
  background: var(--color-focus); color: var(--crt-reverse-fg); text-shadow: none;
}

:root[data-theme="amber-crt"] :is(code, kbd, samp, pre) { font-size: 1em; }
:root[data-theme="amber-crt"] pre {
  padding: var(--line-1) var(--space-4);
  box-shadow: var(--crt-frame);
}
:root[data-theme="amber-crt"] :not(pre) > code { padding: 0; }
:root[data-theme="amber-crt"] kbd {
  padding-inline: var(--cell-w);
  background: var(--crt-reverse-bg); color: var(--crt-reverse-fg); text-shadow: none;
}

/* A rule is one full line with a 1px phosphor trace through the middle */
:root[data-theme="amber-crt"] hr {
  height: var(--cell-h); margin: 0 0 var(--line-1); border: 0;
  background: linear-gradient(var(--color-border), var(--color-border)) center / 100% 1px no-repeat;
}

/* Icons: currentColor (from the base) plus the same phosphor glow.
   One line tall, two cells wide. */
:root[data-theme="amber-crt"] svg.icon {
  width: calc(2 * var(--cell-w)); height: 1em; vertical-align: -.125em;
  filter: drop-shadow(0 0 .1em rgb(255 176 0 / .6));
}

/* ---------- 3. Components -------------------------------------------- */
:root[data-theme="amber-crt"] .card {
  border: 0;
  box-shadow: var(--crt-frame);
  padding: var(--line-1) var(--space-4);
}
:root[data-theme="amber-crt"] :is(.card, .alert) > :first-child { margin-top: 0; }
:root[data-theme="amber-crt"] :is(.card, .alert) > :last-child  { margin-bottom: 0; }

/* Buttons: one line tall, reverse video. Hover/active swap brightness. */
:root[data-theme="amber-crt"] .btn {
  border: 0;
  padding: 0 var(--cell-w);
  font-weight: 700;
  text-transform: uppercase;
  text-shadow: none;
  box-shadow: 0 0 .5em rgb(255 176 0 / .25);
}
:root[data-theme="amber-crt"] .btn:hover {
  filter: none;
  background: var(--color-link-hover); color: var(--crt-reverse-fg);
}
:root[data-theme="amber-crt"] .btn--secondary:hover { background: var(--color-accent); }
:root[data-theme="amber-crt"] .btn--ghost {     /* [ GHOST ] in brackets */
  background: transparent; color: var(--color-link);
  text-shadow: var(--crt-glow); box-shadow: none; padding: 0;
}
:root[data-theme="amber-crt"] .btn--ghost::before { content: "[ "; content: "[ " / ""; }
:root[data-theme="amber-crt"] .btn--ghost::after  { content: " ]"; content: " ]" / ""; }
:root[data-theme="amber-crt"] .btn--ghost:hover {
  background: var(--color-tint); color: var(--color-link-hover);
}

/* Tags: reverse video for categories, dim cell for the default */
:root[data-theme="amber-crt"] .tag {
  padding: 0 var(--cell-w);
  text-shadow: none;
}
:root[data-theme="amber-crt"] .tag:not([class*="tag--"]) {
  text-shadow: var(--crt-glow);
  box-shadow: var(--crt-frame);
}

/* Alerts: framed, plus a status glyph, because colour alone can't tell
   them apart on a monochrome tube. The glyphs are hidden from screen
   readers ("/ ''"), so keep the real meaning in the alert's text. */
:root[data-theme="amber-crt"] .alert {
  border: 0;
  padding: var(--line-1) var(--space-4);
  gap: var(--cell-w);
  box-shadow: inset 0 0 0 1px var(--alert-color, var(--color-border));
  color: var(--alert-color, var(--color-text));
}
:root[data-theme="amber-crt"] .alert::before {
  flex: none; white-space: pre;
}
:root[data-theme="amber-crt"] .alert--success::before { content: "[+]"; content: "[+]" / ""; }
:root[data-theme="amber-crt"] .alert--warning { font-weight: 700; }
:root[data-theme="amber-crt"] .alert--warning::before { content: "[!]"; content: "[!]" / ""; }
:root[data-theme="amber-crt"] .alert--danger  { font-weight: 700; }
:root[data-theme="amber-crt"] .alert--danger::before {
  content: "[X]"; content: "[X]" / "";
  background: var(--color-danger); color: var(--crt-reverse-fg); text-shadow: none;
}
/* Generic status text helpers (optional, for site CSS) */
:root[data-theme="amber-crt"] .is-success::before { content: "+ "; content: "+ " / ""; }
:root[data-theme="amber-crt"] .is-warning::before { content: "! "; content: "! " / ""; }
:root[data-theme="amber-crt"] .is-danger::before  { content: "X "; content: "X " / ""; }

/* Forms: one line tall, framed, no borders */
:root[data-theme="amber-crt"] :is(input, select, textarea) {
  border: 0;
  padding: 0 var(--cell-w);
  min-height: var(--cell-h);
  box-shadow: var(--crt-frame);
  text-shadow: var(--crt-glow);
}
:root[data-theme="amber-crt"] ::placeholder { color: var(--color-text-muted); opacity: 1; }

/* Tables: rules drawn as inset shadows so rows stay one line tall */
:root[data-theme="amber-crt"] :is(th, td) {
  border: 0;
  padding: 0 var(--cell-w);
  box-shadow: inset 0 -1px 0 var(--color-border);
}
:root[data-theme="amber-crt"] thead th { text-transform: uppercase; }

:root[data-theme="amber-crt"] .site-header {
  padding: var(--line-1) 0;
  box-shadow: inset 0 -1px 0 var(--color-border);
  text-shadow: var(--crt-glow);
}

/* Blinking block cursor: <span class="crt-cursor" aria-hidden="true"></span>
   Exactly one cell (U+2588 FULL BLOCK is 1ch wide in monospace fonts). */
:root[data-theme="amber-crt"] .crt-cursor::after {
  content: "\2588"; content: "\2588" / "";
  display: inline-block; width: var(--cell-w); overflow: hidden;
  vertical-align: top;
}

/* ---------- 4. Screen effects (CSS only, never block clicks) --------- */
/* Scanlines: 1px dark line every 3px, over everything. */
:root[data-theme="amber-crt"] body::before,
:root[data-theme="amber-crt"] body::after {
  content: ""; position: fixed; inset: 0;
  pointer-events: none; z-index: 2147483646;
}
:root[data-theme="amber-crt"] body::before {
  background: repeating-linear-gradient(to bottom,
      rgb(0 0 0 / var(--crt-scanline-alpha)) 0 1px, transparent 1px 3px);
}
/* Vignette: darker tube edges. */
:root[data-theme="amber-crt"] body::after {
  background: radial-gradient(ellipse at center,
      transparent 62%, rgb(0 0 0 / var(--crt-vignette-alpha)) 100%);
}
/* Opt-out per page: <html data-theme="amber-crt" data-crt="flat"> */
:root[data-theme="amber-crt"][data-crt="flat"] body::before,
:root[data-theme="amber-crt"][data-crt="flat"] body::after { display: none; }

/* All motion lives here. */
@media (prefers-reduced-motion: no-preference) {
  :root[data-theme="amber-crt"] .crt-cursor::after {
    animation: crt-blink 1.06s steps(1, end) infinite;
  }
  :root[data-theme="amber-crt"] body {
    animation: crt-warmup .6s ease-out 1;   /* tube warming up, once */
  }
}
@keyframes crt-blink   { 50% { opacity: 0; } }
@keyframes crt-warmup  { from { filter: brightness(.4) blur(.6px); } to { filter: none; } }

/* High contrast: no scanlines, no vignette, no glow. */
@media (prefers-contrast: more) {
  :root[data-theme="amber-crt"] body::before,
  :root[data-theme="amber-crt"] body::after { display: none; }
  :root[data-theme="amber-crt"] body,
  :root[data-theme="amber-crt"] body * { text-shadow: none; }
  :root[data-theme="amber-crt"] svg.icon { filter: none; }
}
@media (forced-colors: active) {
  :root[data-theme="amber-crt"] body::before,
  :root[data-theme="amber-crt"] body::after { display: none; }
}

/* 40-column mode: thinner frames' padding so 40 columns stay usable.
   (Kept last so it wins over the component rules above.) */
@media (max-width: 40em) {
  :root[data-theme="amber-crt"] :is(.card, .alert, pre) { padding-inline: var(--cell-w); }
}
