  /* Registered so the colours themselves animate: every text, sheet and piece turns with the sky. */
  @property --sky { syntax: '<color>'; inherits: true; initial-value: #F3E8D2; }
  @property --paper { syntax: '<color>'; inherits: true; initial-value: #EBCB7C; }
  @property --on-paper { syntax: '<color>'; inherits: true; initial-value: #3B2F26; }
  @property --on-paper-muted { syntax: '<color>'; inherits: true; initial-value: #5C4636; }
  @property --piece-strong { syntax: '<color>'; inherits: true; initial-value: #4A3428; }
  @property --on-piece-strong { syntax: '<color>'; inherits: true; initial-value: #FBF6EC; }
  @property --cast { syntax: '<color>'; inherits: true; initial-value: rgb(90 64 32 / 0.25); }
  :root {
    transition: --sky var(--night-fade), --paper var(--night-fade), --on-paper var(--night-fade), --on-paper-muted var(--night-fade), --piece-strong var(--night-fade), --on-piece-strong var(--night-fade), --cast var(--night-fade);
    --sky: #F3E8D2;
    --paper: #EBCB7C; /* the episode cover */
    --on-paper: #3B2F26;
    --on-paper-muted: #5C4636;
    --piece: #FBF6EC; /* cut-out pieces: buttons and links */
    --piece-strong: #4A3428;
    --on-piece-strong: #FBF6EC;
    --ink: #4A3428;
    --edge: #FFFFFF;
    --cast: rgb(90 64 32 / 0.25);
    --night-fade: 3s cubic-bezier(0.37, 0, 0.63, 1); /* easeInOutSine, same as the set */
    --title: 'Fredoka', 'Noto Sans', sans-serif;
    --text: 'Nunito', 'Noto Sans', sans-serif;
  }
  /* Night: the cover becomes a sheet of night-sky paper; the lit window gives the main button. */
  :root[data-theme="night"] {
    --sky: #343D66;
    --paper: #4A5582;
    --on-paper: #F6ECDC;
    --on-paper-muted: #D9D3E8;
    --piece-strong: #FFD36A;
    --on-piece-strong: #4A3428;
    --cast: rgb(10 14 40 / 0.35);
  }
  * { box-sizing: border-box; margin: 0; }
  body {
    min-height: 100vh;
    background: var(--sky);
    color: var(--on-paper);
    font: 700 1rem/1.4 var(--text);
  }

  header {
    position: relative;
    display: flex; justify-content: flex-end; align-items: stretch; gap: 14px;
    padding: 14px 18px 0;
  }

  /* A paper piece: ink outline, white cut edge, soft cast shadow, stuck on slightly crooked. */
  .piece {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    min-height: 44px; padding: 0.45rem 1.1rem;
    font: inherit; color: var(--ink); text-decoration: none;
    background: var(--piece);
    border: 2.5px solid var(--ink);
    border-radius: 16px;
    box-shadow: 0 0 0 5px var(--edge), 0 4px 6px 5px var(--cast);
    rotate: -1deg;
    cursor: pointer;
    transition: translate 0.3s, box-shadow 0.3s;
  }
  .piece:nth-child(even) { rotate: 1.2deg; }
  .piece:hover { translate: 0 -2px; box-shadow: 0 0 0 5px var(--edge), 0 7px 8px 5px var(--cast); }
  .piece:active { translate: 0 1px; }
  .piece.strong { background: var(--piece-strong); color: var(--on-piece-strong); }

  /* Sun and moon: the pieces from the set (Huerto.tsx) in a round window of sky. The button shows
     where it takes you: the moon by day, the sun by night. On a switch the old piece sets and the
     new one comes down, in step with the set. */
  #theme { position: relative; height: auto; aspect-ratio: 1; padding: 0; border-radius: 50%; overflow: hidden; background: var(--sky); }
  #theme svg { position: absolute; inset: 0; width: 100%; height: 100%; transition: translate var(--night-fade); }
  #theme .sun { translate: 0 -110%; }
  [data-theme="night"] #theme .moon { translate: 0 110%; }
  [data-theme="night"] #theme .sun { translate: 0 0; }
  /* A sheet of paper cut like a sticker, as in the cover of each episode. */
  .card {
    background: var(--paper);
    border: 2.5px solid var(--ink);
    border-radius: 28px;
    box-shadow: 0 0 0 6px var(--edge), 0 4px 8px 6px var(--cast);
    padding: 8px 22px 24px;
  }
  .title { display: block; width: min(100%, 22rem, 34vh); margin: 0 auto; overflow: visible; }
  .title text {
    font-family: var(--title); font-weight: 600; text-anchor: middle;
    fill: var(--ink); stroke: var(--edge); stroke-linejoin: round; paint-order: stroke;
    filter: drop-shadow(0 3px 3px rgb(90 64 32 / 0.25));
  }
  .links { display: flex; flex-wrap: wrap; gap: 16px; justify-content: center; margin-top: 1.1rem; }
  :focus-visible { outline: 3px solid var(--on-paper); outline-offset: 7px; }
  /* Keyboard focus on a piece: its cut edge turns yellow instead of an outline around it. */
  .piece:focus-visible { outline: none; box-shadow: 0 0 0 5px #FFD36A, 0 4px 6px 5px var(--cast); }

  /* Language sheet: covers the screen, all languages at once. */
  dialog {
    width: 100%; height: 100%; max-width: none; max-height: none;
    margin: 0; padding: 24px 18px;
    background: var(--paper); color: var(--on-paper);
    border: 0;
  }
  dialog[open] { display: flex; flex-direction: column; align-items: center; justify-content: safe center; overflow-y: auto; } /* safe: 16 languages scroll on short phones */
  dialog > * { width: min(100%, 36rem); }
  dialog .title { width: min(100%, 18rem); }
  dialog ul { list-style: none; padding: 0; display: grid; gap: 16px; margin-top: 12px; }
  @media (min-width: 640px) { dialog ul { grid-template-columns: 1fr 1fr; } }
  dialog li .piece { width: 100%; rotate: -0.4deg; } /* long pieces: a smaller tilt reads the same */
  dialog li:nth-child(even) .piece { rotate: 0.5deg; }
  dialog li .piece[aria-current="true"] { background: var(--piece-strong); color: var(--on-piece-strong); }
  dialog > .close { position: absolute; top: 14px; right: 18px; width: 44px; padding: 0; font-size: 1.4rem; }
  .sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }

  @media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
