/* Instruction booklet — the manual as the stapled booklet a game cartridge used to come with, made for the Slopbox
   (codex: slopbox, cartridge), whose cartridges are text files and never needed one: ink-black cover, acid edges,
   chunky pixel borders. Shows off cascade layers. The sheet declares
   its layers once, in order (reset, booklet, pages, warnings), and a rule in a later layer beats any rule in an earlier
   one whatever its specificity: the warning in chapter 3 is styled by a plain .note in the warnings layer, and it wins
   over #lamp .note in the pages layer, an id selector. A browser without @layer skips every layered block and shows the
   manual in its own plain style. Nothing moves.
   Designed by machine for the Slopwright. */
@layer reset, booklet, pages, warnings;

@layer reset {
  * { box-sizing: border-box; }
  html { overflow-x: clip; scroll-behavior: smooth; }
  body { min-width: 320px; margin: 0; }
  img { max-width: 100%; height: auto; }
  .extra { display: none; }
  .main:focus { outline: none; }
  @media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
}

@layer booklet {
  :root {
    color-scheme: light;
    --ink: #111210; --acid: #e3ff59; --paper: #fbfaf3; --paper-2: #eeecdf; --dim: #4f4f47; --link: #1d4fb8;
    --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;
    /* a pixel border: four hard shadows, two pixels each, that step round the corner */
    --pixels: 0 -4px 0 0 var(--ink), 0 4px 0 0 var(--ink), -4px 0 0 0 var(--ink), 4px 0 0 0 var(--ink);
  }
  body { color: var(--ink); font: 17px/1.6 Verdana, Geneva, "DejaVu Sans", sans-serif;
    background: repeating-linear-gradient(45deg, #1b1c19 0 6px, var(--ink) 6px 12px); }
  a { color: var(--link); text-underline-offset: 3px; }
  :where(a, [tabindex]):focus-visible { outline: 4px solid var(--acid); outline-offset: 2px; box-shadow: 0 0 0 8px var(--ink); }
  .skip { position: absolute; left: 12px; top: -80px; z-index: 10; padding: 10px 16px; background: var(--acid); color: var(--ink); font-weight: 700; }
  .skip:focus { top: 12px; }
  /* the booklet: one column of pages on the cartridge box's inside */
  .page { max-width: 760px; margin: 0 auto; padding: 0 16px 30px; }
  .site-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 4px 16px; margin: 0 -16px; padding: 12px 20px; background: var(--ink); border-bottom: 4px solid var(--acid); font-family: var(--mono); }
  .masthead { display: flex; align-items: center; }
  .masthead .brand { padding: 4px 8px; background: var(--paper); }
  .masthead .brand img { display: block; height: 22px; width: auto; }
  .site-name { margin-left: 12px; color: var(--acid); font-weight: 700; letter-spacing: .1em; text-decoration: none; }
  .site-nav { display: flex; flex-wrap: wrap; gap: 0 18px; font-size: 14px; text-transform: uppercase; }
  .site-nav a { color: var(--paper); text-decoration: none; }
  .site-nav a:hover { color: var(--acid); text-decoration: underline; }
  h1, h2 { margin: 0; font-family: var(--mono); font-weight: 800; }
}

@layer pages {
  /* every page of the booklet is a sheet with a pixel border */
  .title-block, .contents, .chapter, .outfits, .site-foot { margin: 34px 4px 0; padding: 26px clamp(18px, 4vw, 34px); background: var(--paper); box-shadow: var(--pixels), 8px 8px 0 4px var(--acid); }
  .title-block { margin-top: 40px; padding-block: 40px; text-align: center; background: linear-gradient(var(--ink), var(--ink)) 0 0 / 100% 14px no-repeat, linear-gradient(var(--acid), var(--acid)) 0 14px / 100% 6px no-repeat, var(--paper); }
  .edition { margin: 18px 0 0; font: 700 12px/1.4 var(--mono); letter-spacing: .2em; text-transform: uppercase; }
  .title { margin: 18px 0 0; font-size: clamp(36px, 7vw, 64px); line-height: 1; letter-spacing: -.02em; text-transform: uppercase; }
  .title::before, .title::after { content: "\25B8"; margin: 0 .3em; color: var(--dim); font-size: .5em; vertical-align: .35em; }
  .title::before { content: "\25C2"; }
  .subtitle { max-width: 30em; margin: 18px auto 0; color: var(--dim); }
  .contents-title { margin: 0 0 12px; font-size: 16px; letter-spacing: .15em; text-transform: uppercase; }
  .contents-list { margin: 0; padding: 0; list-style: none; counter-reset: c; font-family: var(--mono); }
  .contents-list li { counter-increment: c; display: flex; align-items: center; gap: 8px; border-bottom: 2px dotted var(--paper-2); }
  .contents-list li::after { content: "P." counter(c); margin-left: auto; color: var(--dim); font-size: 14px; }
  .contents-list a { justify-content: flex-start; color: var(--ink); font-weight: 700; text-decoration: none; }
  .contents-list a::before { content: "\25B8"; margin-right: 10px; color: var(--paper-2); }
  .contents-list a:hover::before, .contents-list a:focus-visible::before { color: var(--ink); }
  .chapter { scroll-margin-top: 16px; }
  .chapter-title { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 14px; margin-bottom: 16px; font-size: clamp(22px, 3.4vw, 30px); line-height: 1.15; text-transform: uppercase; }
  .chapter-num { padding: 2px 8px; background: var(--ink); color: var(--acid); font-size: 14px; }
  .chapter-num::before { content: "P."; }
  .chapter-body > :first-child { margin-top: 0; }
  .first { font-size: 18px; }
  .plate { margin: 22px 0 0; padding: 6px; background: var(--ink); }
  .plate img { display: block; width: 100%; image-rendering: pixelated; }
  .plate figcaption { padding: 6px 2px 0; color: var(--paper); font: 13px var(--mono); }
  .tools, .rules { padding-left: 0; list-style: none; }
  .tools li, .rules li { position: relative; padding: 8px 0 8px 2em; border-top: 2px dotted var(--paper-2); }
  .tools li::before { content: "\25AA"; position: absolute; left: .4em; }
  .rules { counter-reset: r; }
  .rules li { counter-increment: r; }
  .rules li::before { content: counter(r); position: absolute; left: 0; width: 1.5em; background: var(--ink); color: var(--acid); font: 700 14px/1.6 var(--mono); text-align: center; }
  /* an id selector: in an earlier layer, so the warnings layer's plain .note still beats it */
  #lamp .note { margin: 20px 0; padding: 14px 18px; background: var(--paper-2); }
  .note p { margin: 0; }
  .saying { margin: 24px 0 0; padding: 16px 18px; background: var(--ink); color: var(--paper); }
  .saying p { margin: 0; font: 700 20px/1.4 var(--mono); }
  .saying footer { margin-top: 8px; color: var(--acid); font: 13px var(--mono); }
  .table-wrap { overflow-x: auto; }
  table { width: 100%; border-collapse: collapse; font-size: 15px; }
  caption { padding-bottom: 8px; font: 700 13px var(--mono); letter-spacing: .1em; text-align: left; text-transform: uppercase; }
  th, td { padding: 8px 10px 8px 0; border-top: 2px dotted var(--paper-2); text-align: left; vertical-align: top; }
  thead th { border-top: 0; border-bottom: 4px solid var(--ink); font-family: var(--mono); font-size: 13px; text-transform: uppercase; }
  .hazards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin: 0; }
  .hazard { padding: 12px 14px; box-shadow: var(--pixels); background: var(--paper); }
  .hazard dt { font: 700 15px var(--mono); text-transform: uppercase; }
  .hazard dd { margin: 4px 0 0; font-size: 15px; }
  .glossary { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; }
  .glossary dt { font: 700 15px/1.6 var(--mono); }
  .glossary dd { margin: 0; }
  .sign-off { margin-top: 20px; font-weight: 700; }
  .outfits-title { font-size: clamp(22px, 3.4vw, 28px); text-transform: uppercase; }
  .outfits-lede { color: var(--dim); }
  .outfit-list { margin: 14px 0 0; padding: 0; list-style: none; columns: 2 220px; column-gap: 24px; font-size: 14px; }
  .outfit { break-inside: avoid; padding: 4px 0; border-bottom: 2px dotted var(--paper-2); }
  .outfit-link { color: var(--ink); font: 700 15px var(--mono); text-decoration: none; }
  .outfit-link:hover { text-decoration: underline; }
  .outfit-by, .outfit-note { display: none; }
  .outfit-technique { display: block; color: var(--dim); }
  #th-booklet { padding: 4px 10px; background: var(--ink); }
  #th-booklet .outfit-link, #th-booklet .outfit-technique { color: var(--acid); }
  #th-booklet .outfit-link::after { content: " \25C0 in the slot"; margin-left: .3em; }
  .site-foot { margin-bottom: 10px; font-size: 14px; color: var(--dim); }
  .site-foot p { margin: 0 0 6px; }
  @media (max-width: 640px) {
    .title-block, .contents, .chapter, .outfits, .site-foot { margin-inline: 4px; box-shadow: var(--pixels), 6px 6px 0 4px var(--acid); }
    .glossary { grid-template-columns: 1fr; gap: 2px; }
    .glossary dd { margin-bottom: 8px; }
  }
}

@layer warnings {
  /* a later layer: these win over anything in pages, id selectors included */
  .note { padding: 14px 18px 14px 56px; background: var(--acid) linear-gradient(var(--ink), var(--ink)) 16px 50% / 24px 24px no-repeat; box-shadow: var(--pixels); }
  .note::before { content: "!"; position: absolute; margin: 0 0 0 -40px; width: 24px; color: var(--acid); font: 800 18px/24px var(--mono); text-align: center; }
  .warning { position: relative; }
  @media (forced-colors: active) { .note { border: 4px solid CanvasText; } }
}

/* outside every layer, so these beat all of the above: moving between outfits, and the targets */
@view-transition { navigation: auto; }
.masthead { view-transition-name: masthead; }
.title { view-transition-name: manual-title; }
@media (prefers-reduced-motion: reduce) { @view-transition { navigation: none; } }

/* targets: every link outside running text is at least 44 px tall (the accessibility skill). The display goes in the
   first layer, so every later layer's own wins; the minimum size stays outside the layers, so it sticks */
@layer reset { :where(.masthead, .site-nav, .contents-list) :where(a), :where(.outfit-link) { display: inline-flex; align-items: center; justify-content: center; } }
:root:root body :is(.masthead, .site-nav, .contents-list) a, :root:root body .outfit-link { min-width: 44px; min-height: 44px; }
