/*
 * Looseleaf, the encyclopedia arena. Plain CSS, no script: the page is the level.
 *
 * Rules that come from the game engine, so nobody "fixes" them later:
 *  - No text-decoration, text-shadow or gradient text. A destroyed word is hidden by making its glyphs transparent;
 *    an underline or a shadow would stay behind, and gradient text cannot be hidden word by word at all.
 *  - No generated content (list markers, ::before/::after). The engine only sees real nodes, so anything generated
 *    could never be destroyed. Numbers and separators are real text.
 *  - Every box that should shatter has a solid background-color of its own, because its shards are drawn in that
 *    colour. No background images.
 *  - Painted boxes stay well under 60% of the viewport, the engine's limit for a destroyable target. That is why the
 *    infobox is two boxes (plate and facts) that only look like one.
 *  - The page scrolls with the window and nothing is fixed or sticky: the camera is the window's own scroll.
 *  - Pictures are pixel art at 3 CSS px per art pixel. On the desktop layout every image box is an exact multiple
 *    of that (144, 384, 624 px wide), so no pixel is ever stretched unevenly.
 */

:root {
  color-scheme: light;
  --paper: #ffffff;
  --ink: #15171c;
  --ink-2: #4a5160;
  --ink-3: #697182;
  --line: #dde1e8;
  --edge: #c9cfd9;
  --panel: #f0f2f6;
  --panel-blue: #e1e8f8;
  --blue: #2b55c4;
  --amber: #ffd21f;
  --amber-pale: #fff4c2;
  --serif: "Sitka Text", Charter, "Bitstream Charter", "Iowan Old Style", "Noto Serif", Cambria, Georgia, serif;
  --display: "Sitka Display", "Sitka Heading", "Sitka Text", ui-serif, "Iowan Old Style", Charter, "Noto Serif", Georgia, serif;
  --ui: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Roboto, "Noto Sans", Arial, sans-serif;
  --mono: "Cascadia Mono", ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Roboto Mono", monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 16.5px/1.6 var(--serif);
}

p,
h1,
h2,
figure,
ul,
ol {
  margin: 0;
  padding: 0;
}

ul,
ol {
  list-style: none;
}

img {
  display: block;
  width: 100%;
  height: auto;
  image-rendering: pixelated;
}

a {
  color: var(--blue);
  text-decoration: none;
}

a[href]:hover {
  color: #1d3f9c;
}

.btn:hover {
  border-color: #aab2bf;
}

.btn-primary:hover {
  border-color: #2449ad;
  background: #2449ad;
}

a:focus-visible,
button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

sup {
  position: relative;
  top: -0.55em;
  font: 11.5px/0 var(--ui);
  vertical-align: baseline;
}

.needed {
  color: var(--ink-3);
  font-style: italic;
}

cite {
  font-style: italic;
}

.wrap {
  width: min(1072px, calc(100% - 48px));
  margin-inline: auto;
}

.num {
  margin-right: 8px;
  color: var(--ink-3);
  font: 12px/1 var(--mono);
}

/* ------------------------------------------------------------- controls */

.btn {
  flex: none;
  height: 30px;
  padding: 0 12px;
  border: 1px solid var(--edge);
  border-radius: 6px;
  background: #ffffff;
  color: var(--ink);
  font: 500 13px/1 var(--ui);
  cursor: pointer;
}

.btn-primary {
  border-color: var(--blue);
  background: var(--blue);
  color: #ffffff;
}

/* ------------------------------------------------------------ site header */

.site {
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

/* The game's HUD floats over the top centre of the viewport. The search field sits under it; the brand and the
   links stay clear on either side, so a screenshot with the game running shows a tidy header. */
.site-row {
  display: grid;
  grid-template-columns: 1fr minmax(0, 420px) 1fr;
  align-items: center;
  column-gap: 24px;
  height: 55px;
}

.brand {
  display: flex;
  justify-self: start;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font: 600 20px/1 var(--display);
}

.brand-mark {
  width: 27px;
}

.search {
  position: relative;
  min-width: 0;
}

.search-input {
  display: block;
  width: 100%;
  height: 34px;
  margin: 0;
  padding: 0 38px 0 12px;
  border: 1px solid var(--edge);
  border-radius: 6px;
  background: #ffffff;
  color: var(--ink);
  font: 13.5px/1 var(--ui);
  -webkit-appearance: none;
  appearance: none;
}

.search-input::placeholder {
  color: var(--ink-3);
  opacity: 1;
}

.search-key {
  position: absolute;
  top: 7px;
  right: 7px;
  width: 20px;
  height: 20px;
  border: 1px solid var(--edge);
  border-radius: 4px;
  background: var(--panel);
  color: var(--ink-3);
  font: 11.5px/18px var(--mono);
  text-align: center;
}

.site-nav {
  display: flex;
  align-items: center;
  justify-self: end;
  gap: 20px;
  font: 13.5px/1 var(--ui);
}

.site-nav a {
  color: var(--ink-2);
}

/* ------------------------------------------------------------ entry head */

.head,
.sec {
  display: grid;
  grid-template-columns: minmax(0, 624px) 384px;
  justify-content: space-between;
  column-gap: 40px;
}

.head {
  padding-top: 30px;
}

.crumbs {
  display: flex;
  gap: 8px;
  color: var(--ink-3);
  font: 13px/20px var(--ui);
}

.crumbs a {
  color: var(--ink-2);
}

/* A separator the game can destroy: a slash on its own is not a word, so it would be left hanging. */
.crumb-dot {
  align-self: center;
  width: 4px;
  height: 4px;
  background: #9aa2ad;
}

h1 {
  margin-top: 10px;
  font: 400 62px/1 var(--display);
  letter-spacing: -0.012em;
}

.hatnote {
  margin-top: 12px;
  color: var(--ink-2);
  font-size: 15px;
  font-style: italic;
  line-height: 22px;
}

.lead {
  margin-top: 18px;
  font-size: 19px;
  line-height: 29px;
}

.lead-more {
  margin-top: 14px;
}

.habitats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-top: 22px;
}

/* Each card fills its grid cell, so the four stay the same height when a caption wraps. */
.habitats li {
  display: grid;
}

.tile,
.fig {
  border-radius: 3px;
  background: var(--panel);
}

.tile img,
.fig img {
  border-radius: 3px 3px 0 0;
}

.tile figcaption {
  padding: 7px 10px 8px;
  color: var(--ink-2);
  font: 12.5px/17px var(--ui);
}

.actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.rev {
  margin-left: auto;
  color: var(--ink-3);
  font: 12.5px/1 var(--ui);
}

.infobox {
  margin-top: 16px;
}

.infobox-card {
  border-radius: 3px 3px 0 0;
  background: var(--panel);
}

.infobox-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 9px 12px;
  border-radius: 3px 3px 0 0;
  background: var(--panel-blue);
  font: 600 14px/18px var(--ui);
}

.infobox-no {
  color: var(--ink-3);
  font: 400 12.5px/1 var(--ui);
}

.plate figcaption,
.fig figcaption {
  padding: 9px 12px 11px;
  color: var(--ink-2);
  font: 12.5px/18px var(--ui);
}

.facts {
  width: 100%;
  border-spacing: 0;
  border-radius: 0 0 3px 3px;
  background: var(--panel);
  font: 13px/18px var(--ui);
}

.facts th,
.facts td {
  padding: 6px 12px;
  border-top: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.facts th {
  width: 37%;
  color: var(--ink-3);
  font-weight: 400;
}

/* --------------------------------------------------------------- contents */

.contents {
  display: flex;
  align-items: center;
  gap: 26px;
  min-height: 44px;
  margin-top: 26px;
  padding: 0 14px;
  border-radius: 3px;
  background: var(--panel);
  font: 13.5px/20px var(--ui);
}

.contents-label {
  font-weight: 600;
}

.contents ol {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 28px;
}

/* --------------------------------------------------------------- sections */

/* Rows: rule, heading, text. The figure sits in the margin beside heading and text; the last row takes any slack
   so a tall figure never pushes the heading away from its paragraphs. */
.sec {
  grid-template-rows: auto auto 1fr;
  margin-top: 34px;
}

hr {
  width: 100%;
  height: 0;
  margin: 0 0 22px;
  border: 0;
  border-top: 1px solid var(--line);
}

.sec > hr {
  grid-column: 1 / -1;
  grid-row: 1;
}

h2 {
  font: 400 31px/36px var(--display);
  letter-spacing: -0.005em;
}

h2 .num {
  margin-right: 12px;
  font-size: 13px;
}

.sec > h2 {
  grid-column: 1;
  grid-row: 2;
}

.sec > .fig {
  grid-column: 2;
  grid-row: 2 / span 2;
  align-self: start;
  margin-top: 6px;
}

.sec > .prose {
  grid-column: 1;
  grid-row: 3;
}

.sec > .wide {
  grid-column: 1 / -1;
  grid-row: 4;
}

.prose {
  margin-top: 14px;
}

.prose > * + * {
  margin-top: 14px;
}

.prose > .strip {
  margin-top: 18px;
  margin-bottom: 18px;
}

.notice {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 8px 8px 12px;
  border-left: 3px solid var(--amber);
  border-radius: 3px;
  background: var(--amber-pale);
  font: 13px/18px var(--ui);
}

.variants {
  width: 100%;
  margin-top: 28px;
  border-spacing: 0;
  font: 13.5px/20px var(--ui);
}

.variants caption {
  padding-bottom: 10px;
  font-weight: 600;
  text-align: left;
}

.variants th,
.variants td {
  padding: 9px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.variants thead th {
  border-bottom: 0;
  background: var(--panel);
  color: var(--ink-2);
  font-size: 12.5px;
  font-weight: 600;
}

.variants thead th:first-child {
  border-radius: 3px 0 0 3px;
}

.variants thead th:last-child {
  border-radius: 0 3px 3px 0;
}

.variants tbody th {
  font-weight: 600;
}

.variants .numcol {
  width: 84px;
  text-align: right;
}

.variants td.numcol {
  font-family: var(--mono);
  font-size: 13px;
}

.variants thead th:first-child {
  width: 150px;
}

.variants .found {
  width: 300px;
  padding-left: 40px;
}

.variants td:last-child {
  color: var(--ink-2);
}

/* ------------------------------------------------------------ back matter */

.back {
  margin-top: 34px;
}

.also {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 16px;
}

.also li {
  padding: 10px 14px 12px;
  border-radius: 3px;
  background: var(--panel);
}

.also a {
  display: block;
  font-size: 17px;
  line-height: 24px;
}

.also span {
  display: block;
  color: var(--ink-2);
  font: 12.5px/18px var(--ui);
}

.refs {
  columns: 2;
  column-gap: 40px;
  margin-top: 16px;
  color: var(--ink-2);
  font: 13px/19px var(--ui);
}

.refs li {
  display: flex;
  gap: 4px;
  padding-bottom: 9px;
  break-inside: avoid;
}

.refs .num {
  flex: none;
  width: 14px;
  line-height: 19px;
}

.tail {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  margin-top: 26px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
  font: 13px/20px var(--ui);
}

.cats {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.cats-label {
  margin-right: 4px;
  color: var(--ink-3);
}

.cats a {
  display: block;
  padding: 3px 10px;
  border-radius: 12px;
  background: var(--panel);
  color: var(--ink);
  font-size: 12.5px;
}

.poll {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink-2);
}

.poll p {
  margin-right: 4px;
}

.foot {
  margin-top: 36px;
  padding: 20px 0 28px;
  border-top: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink-3);
  font: 12.5px/19px var(--ui);
}

.foot-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 28px;
}

.foot-note {
  flex: 1 0 100%;
  color: var(--ink-2);
}

.foot-nav {
  display: flex;
  gap: 18px;
  margin-left: auto;
}

.foot-nav a {
  color: var(--ink-2);
}

/* ------------------------------------------------------------------ phone */

@media (max-width: 880px) {
  body {
    font-size: 15.5px;
    line-height: 24px;
  }

  /* The phone edition is shorter: a few paragraphs and one table row are desktop only. */
  .wide-only {
    display: none;
  }

  .wrap {
    width: min(560px, calc(100% - 32px));
  }

  .site-row {
    grid-template-columns: auto minmax(0, 1fr) auto;
    column-gap: 10px;
    height: 51px;
  }

  .brand {
    font-size: 19px;
  }

  .search-input {
    padding-right: 10px;
    font-size: 16px; /* below 16px, iOS zooms the page when the field is focused */
  }

  .site-nav a,
  .search-key,
  .rev {
    display: none;
  }

  .head,
  .sec {
    display: block;
  }

  .head {
    padding-top: 18px;
  }

  h1 {
    font-size: 42px;
  }

  .hatnote {
    font-size: 14.5px;
    line-height: 21px;
  }

  .lead {
    margin-top: 14px;
    font-size: 17px;
    line-height: 26px;
  }

  /* Pictures before the second paragraph, so the first phone screen has all three kinds of target. */
  .head-main {
    display: flex;
    flex-direction: column;
  }

  .habitats {
    order: 1;
    gap: 8px;
    margin-top: 18px;
  }

  .lead-more {
    order: 2;
    margin-top: 18px;
  }

  .tile figcaption {
    padding: 5px 6px 6px;
    font-size: 11px;
    line-height: 14px;
  }

  .head-side {
    margin-top: 22px;
  }

  .contents {
    display: block;
    padding: 11px 14px 13px;
  }

  .contents ol {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px 16px;
    margin-top: 6px;
  }

  .sec,
  .back {
    margin-top: 28px;
  }

  hr {
    margin-bottom: 18px;
  }

  h2 {
    font-size: 28px;
    line-height: 34px;
  }

  /* The figure follows the heading and leads into the text. */
  .sec > .fig {
    margin-top: 14px;
  }

  .notice {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
    padding: 10px 12px;
  }

  .variants {
    margin-top: 22px;
    font-size: 13px;
    line-height: 18px;
  }

  .variants .found {
    display: none;
  }

  .variants .numcol {
    width: 52px;
  }

  .variants thead th:first-child {
    width: 92px;
  }

  .variants th,
  .variants td {
    padding: 8px 8px;
  }

  .also {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .also li {
    padding: 9px 11px 10px;
  }

  .refs {
    columns: 1;
    font-size: 12.5px;
    line-height: 18px;
  }

  .refs li {
    padding-bottom: 7px;
  }

  .tail {
    display: block;
  }

  .poll {
    flex-wrap: wrap;
    margin-top: 18px;
  }

  .poll p {
    flex: 1 0 100%;
  }

  /* Room at the end of the page: the joystick sits bottom-left and a HUD bar may sit along an edge, so the last
     lines must be able to scroll clear of both. */
  .foot {
    padding-bottom: 168px;
  }

  .foot-nav {
    margin-left: 0;
  }
}
