/* ---------- Start Thai theme ----------------------------------------------
   One palette for the whole site, loaded by every page before its own
   stylesheet. The reference is a Thai temple interior seen in daylight:
   mulberry-paper walls, black lacquer, gold leaf, and a jade green for
   anything that is neither.

   Shapes are square. The corners are kept at 2px only so that borders meet
   cleanly.

   Thai stacks vowels and tone marks above and below the line, so every rule
   that sets a line-height here leaves room for both; 1.1 is as tight as Thai
   text may be set before the marks start to collide.                        */

:root {
  /* The ground is temple stone rather than writing paper: a pale celadon with
     a green cast, which is what keeps this from reading as the same site as
     its Mandarin sibling in another accent. */
  --paper: #eef0e8;
  --paper-2: #f8f9f3;
  --paper-3: #dbe0d2;

  /* หมึก — ink with bronze in it, not soot */
  --ink: #16211c;
  --ink-2: #3c4a42;
  --ink-3: #74837a;

  /* บานเย็น — the magenta of Thai silk and of a tuk-tuk at dusk. The loudest
     thing on the site, so it marks and never fills. */
  --silk: #be1559;
  --silk-d: #9c0f49;
  --silk-l: #fbd9e7;

  /* เขียวหยก — the teal of benjarong and temple glass */
  --jade: #0e8585;
  --jade-l: #cfe9e7;

  /* ทอง — gold leaf. On a mural it is the line everything is drawn against,
     so here it rules, marks and traces rather than fills. */
  --gold: #d4a017;
  --gold-l: #f7e9c0;

  /* คราม — indigo, the ground a mural is painted on */
  --indigo: #2f4fa0;

  --line: rgba(22, 33, 28, 0.16);
  --line-soft: rgba(22, 33, 28, 0.08);
  --line-strong: rgba(22, 33, 28, 0.34);

  --radius: 2px;

  /* ลายประจำยาม — the diamond-and-flower lattice that runs across a temple
     wall. Faint enough to be a surface rather than a pattern you read, which
     is the only way a repeat this regular stays bearable behind text. */
  --kranok-band: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 72 18' fill='none' stroke='%23d4a017' stroke-width='1.3' stroke-linecap='round'%3E%3Cpath d='M0 9h22'/%3E%3Cpath d='M50 9h22'/%3E%3Cpath d='M36 3c3 3.5 7 5.3 14 6-7 .7-11 2.5-14 6-3-3.5-7-5.3-14-6 7-.7 11-2.5 14-6z'/%3E%3Cpath d='M22 9c-2.4 0-3.6-1.6-2.8-3 .6-1 2.2-1 2.8.4'/%3E%3Cpath d='M50 9c2.4 0 3.6 1.6 2.8 3-.6 1-2.2 1-2.8-.4'/%3E%3C/svg%3E");
  --kranok-mark: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 72 18' fill='none' stroke='%23d4a017' stroke-width='1.3' stroke-linecap='round'%3E%3Cpath d='M36 3c3 3.5 7 5.3 14 6-7 .7-11 2.5-14 6-3-3.5-7-5.3-14-6 7-.7 11-2.5 14-6z'/%3E%3Cpath d='M22 9h-8'/%3E%3Cpath d='M50 9h8'/%3E%3C/svg%3E");
  --lattice: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='44' height='44' viewBox='0 0 44 44'%3E%3Cg fill='none' stroke='%2316211c' stroke-opacity='.11' stroke-width='1'%3E%3Cpath d='M22 3 41 22 22 41 3 22Z'/%3E%3Cpath d='M22 13 31 22 22 31 13 22Z'/%3E%3Cpath d='M0 0 3 3M44 0 41 3M0 44 3 41M44 44 41 41'/%3E%3Cpath d='M22 3 22 13M41 22 31 22M22 41 22 31M3 22 13 22'/%3E%3C/g%3E%3Ccircle cx='22' cy='22' r='1.8' fill='%2316211c' fill-opacity='.12'/%3E%3C/svg%3E");
  --lattice-firm: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='44' height='44' viewBox='0 0 44 44'%3E%3Cg fill='none' stroke='%2316211c' stroke-opacity='.16' stroke-width='1'%3E%3Cpath d='M22 3 41 22 22 41 3 22Z'/%3E%3Cpath d='M22 13 31 22 22 31 13 22Z'/%3E%3Cpath d='M0 0 3 3M44 0 41 3M0 44 3 41M44 44 41 41'/%3E%3Cpath d='M22 3 22 13M41 22 31 22M22 41 22 31M3 22 13 22'/%3E%3C/g%3E%3Ccircle cx='22' cy='22' r='1.8' fill='%2316211c' fill-opacity='.18'/%3E%3C/svg%3E");

  /* Trirong is a Thai serif with the looped terminals the script is written
     with; it carries Latin too, so headings do not change voice between the
     two. Body text stays in Noto Serif Thai, which is quieter at small sizes. */
  --display: "Trirong", "Noto Serif Thai", Georgia, serif;
  --serif: "Noto Serif Thai", "Sarabun", "Thonburi", "Noto Serif", Georgia,
    "Times New Roman", serif;
  --sans: "Noto Sans Thai", "Sarabun", "Thonburi", "Helvetica Neue", Arial,
    sans-serif;

  /* kept so older rules that still reference them land somewhere sensible */
  --bg: var(--paper);
  --text: var(--ink);
  --muted: var(--ink-3);
  --accent: var(--jade-l);
}

/* The paper itself: a flat wash with two faint diagonals across it, so that
   large empty areas read as a sheet rather than as a blank screen. */
.paper-ground {
  background-color: var(--paper);
  background-image: var(--lattice);
}

/* The seal: a lacquer square with the letter cut out of it, used for the
   wordmark and for anything that needs to look stamped on. */
.seal {
  display: inline-grid;
  place-items: center;
  width: 2.1em;
  height: 2.1em;
  background: var(--silk);
  color: var(--paper-2);
  font-family: var(--display);
  font-weight: 600;
  line-height: 1;
  border-radius: var(--radius);
}

/* A heading rule in the classical manner: one firm line, one hairline under
   it, with the gap doing the work. */
.rule-double {
  border: 0;
  height: 0;
  border-top: 1px solid var(--line-strong);
  box-shadow: 0 3px 0 -2px var(--line);
}

/* ลายไทย — a Thai ornamental rule. One motif, repeated: a lozenge with a
   curl either side of it, which is the bone a kranok flame is drawn on. It is
   a band of gold across the page rather than a border around a box, because
   that is where the ornament sits in a mural: along the edge of the story,
   not around it. Drawn rather than imported so it takes the gold from the
   palette and costs no request. */
.kranok-rule {
  height: 18px;
  border: 0;
  margin: 0;
  background: var(--kranok-band) repeat-x center / auto 18px;
  opacity: .9;
}

/* Half a rule, for the foot of a column: the motif alone, no band. */
.kranok-mark {
  display: block;
  width: 72px;
  height: 18px;
  margin: 0 auto;
  background: var(--kranok-mark) center no-repeat;
}

/* ---------- the same temple after dark ----------------------------------
   Not an inversion. A mural lit by daylight and one lit by candles are not
   the same picture with the brightness turned down: the gold stays gold
   because it is leaf and leaf is what catches a flame, the silk lifts
   because a dark ground swallows a deep magenta, and the ground itself keeps
   its green cast so the page is still this site and not a black rectangle.

   Only the tokens change. Everything drawn from them follows, including the
   lattice, which has to swap its ink for something a dark wall can show.   */
/* Two ways in, one set of values. A media query cannot be asked "unless the
   page says otherwise", so the dark tokens are written twice: once for a
   system that is dark and has not been overruled, once for a page that was
   told to be dark whatever the system thinks. Keep the two in step. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #131815;
    --paper-2: #1a211d;
    --paper-3: #27302a;

    --ink: #e8ece7;
    --ink-2: #c2cac4;
    --ink-3: #8c968f;

    /* Lifted until it reads as the same colour it is in daylight. #be1559 on
       this ground is a bruise; the eye wants more light, not more red. */
    --silk: #e05a86;
    --silk-d: #c23a6a;
    /* The pale washes behind a right or a wrong answer invert outright:
       their job is to be a tint of the ground, and the ground has moved. */
    --silk-l: #3a1424;

    --jade: #3fb6b6;
    --jade-l: #10302f;

    --gold: #dfb551;
    --gold-l: #3a2f12;

    --indigo: #7f9ae0;

    --line: rgba(232, 236, 231, 0.16);
    --line-soft: rgba(232, 236, 231, 0.07);
    --line-strong: rgba(232, 236, 231, 0.30);

    /* The same lattice drawn in light ink. A pattern this faint has to be
       redrawn rather than recoloured: it is a data URI, and the stroke is
       written into it. */
    --lattice: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='44' height='44' viewBox='0 0 44 44'%3E%3Cg fill='none' stroke='%23e8ece7' stroke-opacity='.08' stroke-width='1'%3E%3Cpath d='M22 3 41 22 22 41 3 22Z'/%3E%3Cpath d='M22 13 31 22 22 31 13 22Z'/%3E%3Cpath d='M0 0 3 3M44 0 41 3M0 44 3 41M44 44 41 41'/%3E%3Cpath d='M22 3 22 13M41 22 31 22M22 41 22 31M3 22 13 22'/%3E%3C/g%3E%3Ccircle cx='22' cy='22' r='1.8' fill='%23e8ece7' fill-opacity='.09'/%3E%3C/svg%3E");
    --lattice-firm: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='44' height='44' viewBox='0 0 44 44'%3E%3Cg fill='none' stroke='%23e8ece7' stroke-opacity='.12' stroke-width='1'%3E%3Cpath d='M22 3 41 22 22 41 3 22Z'/%3E%3Cpath d='M22 13 31 22 22 31 13 22Z'/%3E%3Cpath d='M0 0 3 3M44 0 41 3M0 44 3 41M44 44 41 41'/%3E%3Cpath d='M22 3 22 13M41 22 31 22M22 41 22 31M3 22 13 22'/%3E%3C/g%3E%3Ccircle cx='22' cy='22' r='1.8' fill='%23e8ece7' fill-opacity='.13'/%3E%3C/svg%3E");
  }
}
:root[data-theme="dark"] {
    --paper: #131815;
    --paper-2: #1a211d;
    --paper-3: #27302a;

    --ink: #e8ece7;
    --ink-2: #c2cac4;
    --ink-3: #8c968f;

    /* Lifted until it reads as the same colour it is in daylight. #be1559 on
       this ground is a bruise; the eye wants more light, not more red. */
    --silk: #e05a86;
    --silk-d: #c23a6a;
    /* The pale washes behind a right or a wrong answer invert outright:
       their job is to be a tint of the ground, and the ground has moved. */
    --silk-l: #3a1424;

    --jade: #3fb6b6;
    --jade-l: #10302f;

    --gold: #dfb551;
    --gold-l: #3a2f12;

    --indigo: #7f9ae0;

    --line: rgba(232, 236, 231, 0.16);
    --line-soft: rgba(232, 236, 231, 0.07);
    --line-strong: rgba(232, 236, 231, 0.30);

    /* The same lattice drawn in light ink. A pattern this faint has to be
       redrawn rather than recoloured: it is a data URI, and the stroke is
       written into it. */
    --lattice: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='44' height='44' viewBox='0 0 44 44'%3E%3Cg fill='none' stroke='%23e8ece7' stroke-opacity='.08' stroke-width='1'%3E%3Cpath d='M22 3 41 22 22 41 3 22Z'/%3E%3Cpath d='M22 13 31 22 22 31 13 22Z'/%3E%3Cpath d='M0 0 3 3M44 0 41 3M0 44 3 41M44 44 41 41'/%3E%3Cpath d='M22 3 22 13M41 22 31 22M22 41 22 31M3 22 13 22'/%3E%3C/g%3E%3Ccircle cx='22' cy='22' r='1.8' fill='%23e8ece7' fill-opacity='.09'/%3E%3C/svg%3E");
    --lattice-firm: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='44' height='44' viewBox='0 0 44 44'%3E%3Cg fill='none' stroke='%23e8ece7' stroke-opacity='.12' stroke-width='1'%3E%3Cpath d='M22 3 41 22 22 41 3 22Z'/%3E%3Cpath d='M22 13 31 22 22 31 13 22Z'/%3E%3Cpath d='M0 0 3 3M44 0 41 3M0 44 3 41M44 44 41 41'/%3E%3Cpath d='M22 3 22 13M41 22 31 22M22 41 22 31M3 22 13 22'/%3E%3C/g%3E%3Ccircle cx='22' cy='22' r='1.8' fill='%23e8ece7' fill-opacity='.13'/%3E%3C/svg%3E");
  }


/* The theme switch. It lives here rather than in nav.css because the
   lessons page builds its own header and does not load that file, and every
   page loads this one.

   The theme switch: the same square, quiet frame the rest of the header
   uses, with a drawn sun, moon or half-and-half inside it. */
.theme-switch {
  flex: none;
  display: grid;
  place-items: center;
  width: 30px;
  height: 28px;
  padding: 0;
  border: 1px solid var(--line, rgba(0,0,0,.16));
  border-radius: var(--radius, 2px);
  background: transparent;
  color: var(--ink-3, #74837a);
  cursor: pointer;
}
.theme-switch:hover { border-color: var(--silk, #be1559); color: var(--silk, #be1559); }
.theme-ic {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}
