/* =========================================================================
   mon-cms pixel theme — shared design tokens
   -------------------------------------------------------------------------
   Served from cms/server/static so both ContestWebServer and AdminWebServer
   load the same file:  static_url("static", "pixel", "pixel-tokens.css").
   The ranking server keeps its own copy under cmsranking/static/pixel/.

   This file defines ONLY tokens, fonts and a handful of primitives that every
   surface shares. Per-application overrides live in
     contest/static/cws_pixel.css   (contestant site, on top of Bootstrap 2)
     admin/static/aws_pixel.css     (organiser site, on top of aws_style.css)
     cmsranking/static/Ranking.css   (scoreboard; has its own copy of this file)

   Reference look: warm off-white paper with a faint dotted grid, chunky
   pixel display type in near-black, a dark-green block cursor, monospace
   body text, square 1px-bordered controls with a hard offset shadow.
   ========================================================================= */

/* ---- Fonts (self-hosted, OFL; see ../fonts/LICENSE.txt) ---------------- */
@font-face {
  font-family: "Silkscreen";
  font-style: normal; font-weight: 400; font-display: swap;
  src: url("../fonts/silkscreen-400-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Silkscreen";
  font-style: normal; font-weight: 400; font-display: swap;
  src: url("../fonts/silkscreen-400-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Silkscreen";
  font-style: normal; font-weight: 700; font-display: swap;
  src: url("../fonts/silkscreen-700-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Silkscreen";
  font-style: normal; font-weight: 700; font-display: swap;
  src: url("../fonts/silkscreen-700-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "JetBrains Mono";
  font-style: normal; font-weight: 400; font-display: swap;
  src: url("../fonts/jetbrains-mono-400-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "JetBrains Mono";
  font-style: normal; font-weight: 400; font-display: swap;
  src: url("../fonts/jetbrains-mono-400-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "JetBrains Mono";
  font-style: normal; font-weight: 500; font-display: swap;
  src: url("../fonts/jetbrains-mono-500-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "JetBrains Mono";
  font-style: normal; font-weight: 500; font-display: swap;
  src: url("../fonts/jetbrains-mono-500-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "JetBrains Mono";
  font-style: normal; font-weight: 700; font-display: swap;
  src: url("../fonts/jetbrains-mono-700-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "JetBrains Mono";
  font-style: normal; font-weight: 700; font-display: swap;
  src: url("../fonts/jetbrains-mono-700-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

/* ---- Tokens ------------------------------------------------------------ */
/* Two palettes live here, and only here. `:root` is the light one; the dark
   one is installed by the two blocks further down (an explicit
   `data-theme="dark"`, and `prefers-color-scheme: dark` when the reader has
   not explicitly asked for light). Every skin must reach a colour through a
   token: a literal in cws_pixel.css / aws_pixel.css / Ranking.css cannot
   follow the swap, and the swap is the whole mechanism.

   Contrast for BOTH palettes is measured by tools/check_contrast.py, which
   reads this file, resolves the pairs the skins actually paint, and exits 1
   under 4.5:1 for body text or 3:1 for large text and UI edges. Change a
   value here and run it. */
:root {
  color-scheme: light;

  /* ground */
  --px-paper:       #f4f3ee;   /* page background, warm off-white */
  --px-paper-2:     #ebe9e2;   /* alternate rows, wells, code blocks */
  --px-paper-3:     #e1dfd6;   /* pressed / selected */
  --px-grid:        #d6d4cb;   /* dots of the background grid */

  /* ink */
  --px-ink:         #141414;   /* text, borders, shadows */
  --px-ink-2:       #46463f;   /* secondary text */
  --px-ink-3:       #5c5c54;   /* meta, placeholders, disabled — 6.1:1 on paper (#77776f was 4.06:1, under the 4.5:1 floor) */

  /* accent — the green block cursor */
  --px-green:       #1f5e3a;
  --px-green-2:     #236b41;   /* hover / active — 5.81:1 on paper, 5.32:1 on
                                  paper-2, 5.23:1 on green-soft. #2b7a4b was
                                  4.33:1 / 4.26:1, under the 4.5:1 floor. */
  --px-green-soft:  #dcebe0;   /* tinted background */

  /* semantic (flat, no gradients) */
  --px-red:         #a8321f;   --px-red-soft:   #f3ddd8;
  --px-amber:       #7a5400;   --px-amber-soft: #f3e9c9;   /* amber text on amber-soft: 5.6:1 (#8f6300 was 4.38:1) */
  --px-blue:        #234a7a;   --px-blue-soft:  #dbe5f1;

  /* score ramp: 0 → red, partial → amber, full → green */
  --px-score-0:     var(--px-red);
  --px-score-0-bg:  var(--px-red-soft);
  --px-score-p:     var(--px-amber);
  --px-score-p-bg:  var(--px-amber-soft);
  --px-score-100:   var(--px-green);
  --px-score-100-bg:var(--px-green-soft);

  /* type */
  --px-font-display: "Silkscreen", "Courier New", monospace;
  --px-font-mono:    "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --px-text:         14px;
  --px-text-sm:      12px;
  --px-leading:      1.55;

  /* shape */
  --px-radius:      0px;       /* everything is square */
  --px-border:      1px solid var(--px-ink);
  --px-shadow:      3px 3px 0 var(--px-ink);
  --px-shadow-sm:   2px 2px 0 var(--px-ink);
  --px-grid-size:   24px;
  --px-gap:         16px;
  --px-focus:       0 0 0 2px var(--px-paper), 0 0 0 4px var(--px-green);

  /* ---- Promoted out of the skins ---------------------------------------
     Each of these was a literal in cws_pixel.css, aws_pixel.css or
     Ranking.css. A literal cannot follow the dark swap, so it became a
     token; the skins now alias these. */
  --px-field-bg:    #ffffff;   /* text inputs, textareas, the code editor */
  --px-paper-hi:    #fbfaf7;   /* a surface one step brighter than paper */
  --px-on-accent:   #ffffff;   /* text ON a saturated fill (green/red/…) */
  --px-scrim:       rgba(20, 20, 20, 0.62);   /* modal backdrops */

  /* Text-safe variants of two tokens that miss 4.5:1 as words but stay in
     use for borders and rules, where the ratio does not apply. */
  --px-meta:        #63635b;   /* was --cws-meta / --aws-ink-meta */
  --px-amber-text:  #7a5400;   /* was --cws-amber-text */

  /* Hover steps for the semantic fills (were literals in both skins). */
  --px-red-2:       #bf3a24;   /* 5.46:1 under --px-on-accent */
  --px-amber-2:     #976a00;   /* #a37200 was 4.23:1 under white — the fifth
                                  token to fail the measurement, and the first
                                  found by checking a *hover* state */
  --px-blue-2:      #2c5b95;   /* 6.75:1 under --px-on-accent */

  /* ---- Editor syntax ---------------------------------------------------
     web_editor/src/editor.js paints CodeMirror through these, so one bundle
     serves both palettes: the theme extension names the variable, this file
     decides the colour. They are aliases on purpose — syntax colour is the
     accent palette, not a second palette to keep in step. Measured against
     --px-field-bg, which is what the editor sits on. */
  --px-syn-comment: var(--px-meta);
  --px-syn-keyword: var(--px-red);
  --px-syn-string:  var(--px-green);
  --px-syn-number:  var(--px-amber-text);
  --px-syn-type:    var(--px-blue);
  --px-syn-punct:   var(--px-ink-2);

  /* ---- The dark palette, defined once ----------------------------------
     These are values, not the active palette: the two blocks below install
     them. Keeping the numbers in one place is what stops the "explicit
     dark" and "system dark" paths from drifting apart, and
     tools/check_contrast.py asserts that both installers cover every
     --px-d-* defined here. */
  --px-d-paper:       #15150f;
  --px-d-paper-2:     #1f1f18;
  --px-d-paper-3:     #2b2b22;
  --px-d-paper-hi:    #1a1a13;
  --px-d-grid:        #3b3a30;
  --px-d-field-bg:    #0e0e0a;

  --px-d-ink:         #f2efe3;
  --px-d-ink-2:       #cfcbbc;
  --px-d-ink-3:       #a9a595;
  --px-d-meta:        #b2ae9e;

  --px-d-green:       #6fd49a;
  --px-d-green-2:     #8fe4b4;
  --px-d-green-soft:  #17311f;

  --px-d-red:         #ff9078;
  --px-d-red-2:       #ffae9b;
  --px-d-red-soft:    #3b1c15;

  --px-d-amber:       #e3b155;
  --px-d-amber-2:     #f0c576;
  --px-d-amber-text:  #e3b155;
  --px-d-amber-soft:  #382a10;

  --px-d-blue:        #9cc0f2;
  --px-d-blue-2:      #b8d3f8;
  --px-d-blue-soft:   #16233b;

  --px-d-on-accent:   #10160f;   /* the fills are light now, so this is ink */
  --px-d-scrim:       rgba(0, 0, 0, 0.72);
}

/* ---- Dark palette ------------------------------------------------------
   Two installers, one value list. The media block is the "system" setting:
   it must not fire when the reader has explicitly chosen light, hence the
   :not(). The attribute block is the explicit choice and wins in both
   directions because it is not behind a media query.

   Note what is NOT redefined: --px-shadow and --px-border are
   `… var(--px-ink)`, so the hard offset shadow and the 1px edge become a
   light ink by themselves, and the dotted grid keeps its character because
   --px-grid moves with the paper. That is the point of the token layer. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --px-paper:       var(--px-d-paper);
    --px-paper-2:     var(--px-d-paper-2);
    --px-paper-3:     var(--px-d-paper-3);
    --px-paper-hi:    var(--px-d-paper-hi);
    --px-grid:        var(--px-d-grid);
    --px-field-bg:    var(--px-d-field-bg);
    --px-ink:         var(--px-d-ink);
    --px-ink-2:       var(--px-d-ink-2);
    --px-ink-3:       var(--px-d-ink-3);
    --px-meta:        var(--px-d-meta);
    --px-green:       var(--px-d-green);
    --px-green-2:     var(--px-d-green-2);
    --px-green-soft:  var(--px-d-green-soft);
    --px-red:         var(--px-d-red);
    --px-red-2:       var(--px-d-red-2);
    --px-red-soft:    var(--px-d-red-soft);
    --px-amber:       var(--px-d-amber);
    --px-amber-2:     var(--px-d-amber-2);
    --px-amber-text:  var(--px-d-amber-text);
    --px-amber-soft:  var(--px-d-amber-soft);
    --px-blue:        var(--px-d-blue);
    --px-blue-2:      var(--px-d-blue-2);
    --px-blue-soft:   var(--px-d-blue-soft);
    --px-on-accent:   var(--px-d-on-accent);
    --px-scrim:       var(--px-d-scrim);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --px-paper:       var(--px-d-paper);
  --px-paper-2:     var(--px-d-paper-2);
  --px-paper-3:     var(--px-d-paper-3);
  --px-paper-hi:    var(--px-d-paper-hi);
  --px-grid:        var(--px-d-grid);
  --px-field-bg:    var(--px-d-field-bg);
  --px-ink:         var(--px-d-ink);
  --px-ink-2:       var(--px-d-ink-2);
  --px-ink-3:       var(--px-d-ink-3);
  --px-meta:        var(--px-d-meta);
  --px-green:       var(--px-d-green);
  --px-green-2:     var(--px-d-green-2);
  --px-green-soft:  var(--px-d-green-soft);
  --px-red:         var(--px-d-red);
  --px-red-2:       var(--px-d-red-2);
  --px-red-soft:    var(--px-d-red-soft);
  --px-amber:       var(--px-d-amber);
  --px-amber-2:     var(--px-d-amber-2);
  --px-amber-text:  var(--px-d-amber-text);
  --px-amber-soft:  var(--px-d-amber-soft);
  --px-blue:        var(--px-d-blue);
  --px-blue-2:      var(--px-d-blue-2);
  --px-blue-soft:   var(--px-d-blue-soft);
  --px-on-accent:   var(--px-d-on-accent);
  --px-scrim:       var(--px-d-scrim);
}

/* ---- Primitives -------------------------------------------------------- */

/* The dotted paper. Apply to <body> (or the page wrapper). */
.px-paper {
  background-color: var(--px-paper);
  background-image: radial-gradient(var(--px-grid) 1px, transparent 1.4px);
  background-size: var(--px-grid-size) var(--px-grid-size);
  background-position: 12px 12px;
  color: var(--px-ink);
}

/* Display type: pixel font, for headings and the brand only. Silkscreen is
   illegible below ~18px — use .px-label for small text instead. */
.px-display {
  font-family: var(--px-font-display);
  font-weight: 700;
  letter-spacing: 0.01em;
  line-height: 1.05;
  color: var(--px-ink);
  text-transform: none;
  -webkit-font-smoothing: none;         /* keep the pixels crisp */
  text-rendering: optimizeSpeed;
}

/* The green block cursor that follows a heading ("Something big is coming_") */
.px-cursor::after {
  content: "";
  display: inline-block;
  width: 0.55em;
  height: 0.16em;
  margin-left: 0.12em;
  background: var(--px-green);
  vertical-align: baseline;
  animation: px-blink 1.2s steps(2, start) infinite;
}
@keyframes px-blink { to { visibility: hidden; } }
@media (prefers-reduced-motion: reduce) {
  .px-cursor::after { animation: none; }
}

/* Small monospace meta label: "soelinhtet.com", "stealth mode · 2026" */
.px-label {
  font-family: var(--px-font-mono);
  font-size: var(--px-text-sm);
  font-weight: 400;
  letter-spacing: 0.02em;
  color: var(--px-ink-3);
}

/* Boxed button with the hard offset shadow. Add .px-btn-primary for green. */
.px-btn {
  display: inline-block;
  font-family: var(--px-font-mono);
  font-size: var(--px-text);
  font-weight: 500;
  line-height: 1.2;
  padding: 9px 14px;
  color: var(--px-ink);
  background: var(--px-paper);
  border: var(--px-border);
  border-radius: var(--px-radius);
  box-shadow: var(--px-shadow);
  text-decoration: none;
  text-shadow: none;
  cursor: pointer;
  transition: transform 60ms steps(2), box-shadow 60ms steps(2);
}
.px-btn:hover, .px-btn:focus-visible {
  color: var(--px-ink);
  background: var(--px-paper-2);
  text-decoration: none;
  transform: translate(1px, 1px);
  box-shadow: var(--px-shadow-sm);
}
.px-btn:active {
  transform: translate(3px, 3px);
  box-shadow: 0 0 0 var(--px-ink);
}
.px-btn:focus-visible { outline: none; box-shadow: var(--px-shadow-sm), var(--px-focus); }
.px-btn-primary { background: var(--px-green); color: var(--px-on-accent); border-color: var(--px-ink); }
.px-btn-primary:hover, .px-btn-primary:focus-visible { background: var(--px-green-2); color: var(--px-on-accent); }
.px-btn-danger { background: var(--px-red); color: var(--px-on-accent); }
.px-btn[disabled], .px-btn.disabled {
  color: var(--px-ink-3); background: var(--px-paper-2);
  box-shadow: none; transform: none; cursor: not-allowed;
}

/* Bordered panel / card. */
.px-panel {
  background: var(--px-paper);
  border: var(--px-border);
  border-radius: var(--px-radius);
  box-shadow: var(--px-shadow);
  padding: var(--px-gap);
}
.px-panel-flat { box-shadow: none; }

/* Inputs. */
.px-input {
  font-family: var(--px-font-mono);
  font-size: var(--px-text);
  color: var(--px-ink);
  background: var(--px-field-bg);
  border: var(--px-border);
  border-radius: var(--px-radius);
  box-shadow: none;
  padding: 8px 10px;
}
.px-input:focus { outline: none; box-shadow: var(--px-focus); border-color: var(--px-ink); }
.px-input::placeholder { color: var(--px-ink-3); }

/* Pixel divider: a dotted rule in the grid colour. */
.px-rule { border: 0; border-top: 2px dotted var(--px-grid); margin: var(--px-gap) 0; }

/* Keycap / tag. */
.px-tag {
  display: inline-block;
  font-family: var(--px-font-mono);
  font-size: var(--px-text-sm);
  padding: 1px 6px;
  border: var(--px-border);
  background: var(--px-paper-2);
  color: var(--px-ink);
}

/* ---- Theme toggle ------------------------------------------------------
   Three states, not two: "system" is the default and must stay reachable,
   because a reader who has set their OS to dark and then pressed the button
   twice should be able to get back to following it. One <button> per state
   inside a labelled group, so a screen reader announces the choice; the
   pressed one is marked with aria-pressed and painted as the accent.
   The markup is emitted by the page (contest/admin base.html) and driven by
   the inline <head> script plus cws_utils.js / aws_utils.js. */
.px-theme {
  display: inline-flex;
  align-items: stretch;
  border: var(--px-border);
  background: var(--px-paper);
  box-shadow: var(--px-shadow-sm);
  line-height: 1;
}
.px-theme > button {
  font-family: var(--px-font-mono);
  font-size: var(--px-text-sm);
  line-height: 1;
  margin: 0;
  padding: 5px 8px;
  border: 0;
  border-left: 1px solid var(--px-grid);
  border-radius: 0;
  background: transparent;
  color: var(--px-ink-2);
  cursor: pointer;
}
.px-theme > button:first-child { border-left: 0; }
.px-theme > button:hover { background: var(--px-paper-2); color: var(--px-ink); }
.px-theme > button[aria-pressed="true"] {
  background: var(--px-green-soft);
  color: var(--px-ink);
  font-weight: 700;
}
.px-theme > button:focus-visible { outline: none; box-shadow: var(--px-focus); position: relative; }

/* Any theme-driven colour change must not animate for a reader who asked for
   less motion; the pixel look has no crossfade anyway, so this only has to
   stop the button transitions above. */
@media (prefers-reduced-motion: reduce) {
  .px-btn, .px-theme > button { transition: none; }
}

/* ---- Forced colours (Windows High Contrast) ---------------------------- */
/* Every focus affordance above is `outline: none` plus a box-shadow ring, and
   box-shadows are not painted in forced-colors mode — the ring would simply
   vanish. Restore a real outline, which the OS palette does paint. */
@media (forced-colors: active) {
  .px-btn:focus-visible,
  .px-input:focus,
  .px-input:focus-visible,
  a:focus-visible,
  button:focus-visible,
  input:focus-visible,
  select:focus-visible,
  textarea:focus-visible,
  [tabindex]:focus-visible {
    outline: 2px solid Highlight;
    outline-offset: 2px;
  }
  .px-cursor::after { forced-color-adjust: none; }
  /* The OS palette replaces both palettes here, so "which theme is selected"
     survives only if it is drawn with something forced-colors still paints. */
  .px-theme > button[aria-pressed="true"] {
    outline: 2px solid Highlight;
    outline-offset: -2px;
  }
}
