/* SPDX-License-Identifier: AGPL-3.0-or-later */
/*
 * The site's components. Rules and reasons: docs/design-system.md. Every one of them is shown,
 * in every state, on site/design/preview.html; a new component goes there first.
 *
 * Square corners, hard pixel edges: no border-radius, no blurred shadow, and the sky is the only
 * gradient. Colours and sizes come from tokens.css only.
 */

*, *::before, *::after { box-sizing: border-box; }
html { font-size: 100%; -webkit-text-size-adjust: 100%; }
body { margin: 0; }
img, canvas { image-rendering: pixelated; }
/* Something a page shows only in some states is hidden with the attribute, also where a
   component sets its own display (a plank is inline-flex). */
[hidden] { display: none !important; }
/* Words for screen readers only, such as the head of a ledger's action column. */
.unseen { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* ---- the place: sky, ground line, water ------------------------------------------------ */

.place {
  min-height: 100dvh;
  display: grid;
  grid-template-rows: minmax(var(--horizon), 1fr) auto auto;
  background: var(--water);
  color: var(--bone);
  font: 400 var(--text)/var(--leading) var(--face-text);
}

.sky {
  position: relative;
  display: grid;
  grid-template-columns: var(--menu-width) minmax(0, 1fr);
  gap: var(--space-12);
  align-items: start;
  padding: var(--space-12) var(--space-8) var(--space-16);
  background: linear-gradient(var(--sky-high), var(--sky-low));
}
/* A page with nothing but one column standing on the ground (sign-in, the game's cover). */
.sky--alone {
  grid-template-columns: minmax(0, var(--measure));
  justify-content: center;
  align-items: end;
  padding-bottom: var(--space-8);
}
/* A few stars: 2 px squares, drawn once, never animated. */
.sky::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 2px;
  height: 2px;
  color: var(--bone-dim);
  box-shadow: 9vw 7vh, 23vw 15vh, 31vw 4vh, 47vw 11vh, 58vw 21vh, 66vw 6vh, 74vw 17vh, 83vw 9vh, 91vw 24vh,
    15vw 29vh, 39vw 26vh, 96vw 5vh;
  opacity: 0.7;
  pointer-events: none;
}
.sky > * { position: relative; }

.ground {
  height: calc(4 * var(--px));
  background: var(--ground);
  border-top: var(--px) solid var(--grass);
  box-shadow: inset 0 calc(-1 * var(--px)) 0 var(--outline);
}

.water {
  position: relative;
  min-height: 8rem;
  padding: 56px var(--space-8) var(--space-8);
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-8);
  align-items: end;
  justify-content: space-between;
  color: var(--bone-dim);
  font-size: var(--text-small);
  /* The sky again, upside down and darker, with short dashes of light on it. */
  background:
    linear-gradient(90deg, var(--shimmer) 0 28px, transparent 28px) 6vw 10px / 37vw 2px repeat-x,
    linear-gradient(90deg, var(--shimmer) 0 16px, transparent 16px) 21vw 20px / 29vw 2px repeat-x,
    linear-gradient(90deg, var(--shimmer) 0 36px, transparent 36px) 2vw 30px / 53vw 2px repeat-x,
    linear-gradient(90deg, var(--shimmer) 0 12px, transparent 12px) 33vw 42px / 23vw 2px repeat-x,
    linear-gradient(var(--water-near), var(--water) 5rem);
}
@media (prefers-reduced-motion: no-preference) {
  /* The one thing that moves by itself: the light on the water drifts. */
  .water { animation: drift 48s linear infinite; }
  @keyframes drift {
    to { background-position: calc(6vw + 37vw) 10px, calc(21vw - 29vw) 20px, calc(2vw + 53vw) 30px, calc(33vw - 23vw) 42px, 0 0; }
  }
}
.water p { margin: 0; max-width: var(--measure); }

/* ---- text ------------------------------------------------------------------------------ */

.title {
  margin: 0 0 var(--space-6);
  font: 400 var(--title)/1 var(--face-display);
  color: var(--bone);
}
.title--large { font-size: var(--title-large); margin-bottom: var(--space-8); }
h2, .heading {
  margin: var(--space-8) 0 var(--space-3);
  font: 600 var(--text-large)/1.25 var(--face-text);
}
p { margin: 0 0 var(--space-4); max-width: var(--measure); }
.quiet { color: var(--bone-dim); }
.parchment .quiet { color: var(--ink-soft); }
a { color: var(--coin); text-underline-offset: 3px; }
.parchment a { color: var(--ink); }
:focus-visible { outline: 3px solid var(--coin); outline-offset: 3px; }
/* A region a page moves the keyboard to after an action (its notices) is not itself a control. */
[tabindex="-1"]:focus { outline: none; }
.parchment :focus-visible { outline-color: var(--ink); }

/* ---- plank: everything that is pressed ------------------------------------------------- */

.plank {
  --face: var(--plank);
  --light: var(--plank-light);
  --dark: var(--plank-dark);
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--target);
  /* 16 px at every width: with more, the Kingdoms page's five actions (the most any row has)
     no longer fit one line beside the menu at 1280 px and Delete fell onto a line of its own. */
  padding: 0 var(--space-4);
  border: 0;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  font: 400 var(--plank-text)/1 var(--face-plank);
  text-transform: uppercase;
  color: var(--plank-ink);
  /* a nail in two corners, then the wood */
  background:
    linear-gradient(var(--dark), var(--dark)) 6px calc(100% - 6px) / 4px 4px no-repeat,
    linear-gradient(var(--dark), var(--dark)) calc(100% - 6px) 6px / 4px 4px no-repeat,
    var(--face);
  box-shadow: inset 2px 2px 0 var(--light), inset -2px -2px 0 var(--dark), 0 0 0 2px var(--outline),
    0 4px 0 2px var(--outline);
}
.plank:hover { --face: var(--light); }
.plank:active { transform: translateY(var(--press)); box-shadow: inset 2px 2px 0 var(--light), inset -2px -2px 0 var(--dark), 0 0 0 2px var(--outline), 0 2px 0 2px var(--outline); }
.plank[disabled], .plank[aria-disabled="true"] { opacity: 0.5; cursor: default; transform: none; }
.plank[disabled]:hover, .plank[aria-disabled="true"]:hover { --face: var(--plank); }
/* Where you are: the plank is pressed in and its lettering is gold. */
.plank[aria-current="page"] {
  --face: var(--plank-dark);
  color: var(--coin-light);
  box-shadow: inset 2px 2px 0 var(--outline), inset -2px -2px 0 var(--plank), 0 0 0 2px var(--outline), 0 2px 0 2px var(--outline);
  transform: translateY(var(--press));
}
.plank[aria-current="page"]:hover { --face: var(--plank-dark); }

/* The one thing to do next on a screen. At most one per screen. */
.plank--coin { --face: var(--coin); --light: var(--coin-light); --dark: var(--coin-dark); color: var(--coin-ink); font-weight: 700; }
.plank--coin:hover { --face: var(--coin-light); }
/* What deletes or cannot be undone. */
.plank--banner { --face: var(--banner); --light: var(--banner-light); --dark: var(--banner-dark); color: var(--bone); }
.plank--banner:hover { --face: var(--banner-light); }
.plank--wide { display: flex; width: 100%; justify-content: flex-start; }

.menu { display: grid; gap: var(--space-3); width: var(--menu-width); margin: 0; padding: 0; list-style: none; }
.actions { display: flex; flex-wrap: wrap; gap: var(--space-4); margin-top: var(--space-6); }
/* What a row of buttons opens below itself (earlier copies) keeps clear of their undersides. */
.actions + section { margin-top: var(--space-8); }

/* ---- parchment: everything that is read or typed on ------------------------------------- */

.parchment {
  max-width: 52rem;
  padding: var(--space-6);
  background: var(--parchment);
  color: var(--ink);
  /* paper edge, a wooden frame, and the dark line around both */
  box-shadow: inset 0 0 0 2px var(--parchment-shade), 0 0 0 2px var(--outline), 0 0 0 8px var(--plank-dark),
    0 0 0 10px var(--outline);
  margin: 10px;
}
.parchment > :first-child { margin-top: 0; }
.parchment > :last-child { margin-bottom: 0; }

.ledger { width: 100%; border-collapse: collapse; }
.ledger th {
  padding: 0 var(--space-3) var(--space-2);
  text-align: left;
  font: 600 var(--text-small)/1.25 var(--face-text);
  color: var(--ink-soft);
  border-bottom: 2px solid var(--ink-soft);
}
.ledger td { padding: var(--space-3); vertical-align: baseline; border-bottom: 1px dashed var(--parchment-shade); }
.ledger tr:last-child td { border-bottom: 0; }
.ledger .day { font: 600 1.5rem/1 var(--face-text); white-space: nowrap; }
.ledger tr[aria-selected="true"] td { background: var(--parchment-shade); }
.ledger .act { text-align: right; white-space: nowrap; }
.ledger .act > .plank + .plank { margin-left: var(--space-3); }

/* ---- facts: a few named values, such as an account's name or a file's size --------------- */

.facts {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: var(--space-2) var(--space-6);
  align-items: baseline;
  margin: 0 0 var(--space-4);
  max-width: var(--measure);
}
.facts dt { font: 600 var(--text-small)/var(--leading) var(--face-text); color: var(--bone-dim); }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.parchment .facts dt { color: var(--ink-soft); }
/* A checksum: read by machines, compared by eye now and then. */
.facts .hash { font-size: var(--text-small); }

/* ---- fields ---------------------------------------------------------------------------- */

.field { display: grid; gap: var(--space-1); margin: 0 0 var(--space-4); max-width: var(--measure); }
.field label { font: 600 var(--text-small)/1.25 var(--face-text); }
.field input {
  min-height: var(--target);
  padding: 0 var(--space-3);
  border: 0;
  font: 400 var(--text)/1 var(--face-text);
  color: var(--ink);
  background: var(--parchment);
  box-shadow: inset 2px 2px 0 var(--parchment-shade), 0 0 0 2px var(--outline);
}
.field input:focus-visible { outline: 3px solid var(--coin); outline-offset: 3px; }
.field .wrong { margin: 0; font-size: var(--text-small); color: var(--banner-pale); }
.parchment .field .wrong { color: var(--banner-dark); }
.field input[aria-invalid="true"] { box-shadow: inset 2px 2px 0 var(--parchment-shade), 0 0 0 2px var(--banner); }

/* ---- notice: what just happened, said once ---------------------------------------------- */

.notice {
  max-width: var(--measure);
  margin: 0 0 var(--space-4);
  padding: var(--space-3) var(--space-4);
  background: var(--outline);
  color: var(--bone);
  border-left: 8px solid var(--coin);
}
.notice--failed { border-left-color: var(--banner); }

/* ---- plaque and code -------------------------------------------------------------------- */

.plaque {
  display: inline-grid;
  place-items: center;
  min-width: 7rem;
  padding: var(--space-3) var(--space-6);
  background: var(--plaque);
  color: var(--outline);
  font: 700 2rem/1 var(--face-plank);
  box-shadow: inset 2px 2px 0 var(--plaque-light), inset -2px -2px 0 var(--plaque-dark), 0 0 0 2px var(--outline);
  /* corners cut by one pixel step, as the game cuts its plaques */
  clip-path: polygon(8px 0, calc(100% - 8px) 0, 100% 8px, 100% calc(100% - 8px), calc(100% - 8px) 100%, 8px 100%, 0 calc(100% - 8px), 0 8px);
}
.code { font: 700 2rem/1 var(--face-plank); letter-spacing: 0.2em; color: var(--ink); }
/* A link code is made on the site and typed into the game, never the other way round: a code
   that comes from the signed-in page cannot be a stranger's. Its caption says where to type it. */
.link-code { display: grid; gap: var(--space-3); justify-items: start; margin: 0; }
.link-code figcaption { font: 600 var(--text-small)/1.25 var(--face-text); max-width: var(--measure); }

/* ---- state of a kingdom: always a word, the square only repeats it ----------------------- */

.state { display: inline-flex; align-items: center; gap: var(--space-2); white-space: nowrap; }
.state::before { content: ""; width: 8px; height: 8px; background: var(--grass); box-shadow: 0 0 0 2px var(--outline); }
.state--waiting::before { background: var(--coin); }
.state--differs::before { background: var(--banner); }

/* ---- dialog ----------------------------------------------------------------------------- */

dialog.parchment { border: 0; width: min(30rem, calc(100vw - 2 * var(--space-8))); margin: auto; }
dialog.parchment::backdrop { background: rgb(8 13 16 / 0.72); }
dialog.parchment h2 { margin-top: 0; }
dialog.parchment .actions { justify-content: flex-end; }

/* ---- the game's page -------------------------------------------------------------------- */

.stage { position: fixed; inset: 0; background: #000; }
.stage canvas { display: block; width: 100%; height: 100%; }
.progress { height: calc(3 * var(--px)); max-width: var(--measure); background: var(--outline); box-shadow: 0 0 0 2px var(--outline), 0 0 0 4px var(--plank-dark); }
.progress > i { display: block; height: 100%; background: var(--coin); }

/* ---- narrow screens --------------------------------------------------------------------- */

@media (max-width: 46rem) {
  .sky { grid-template-columns: minmax(0, 1fr); gap: var(--space-8); padding: var(--space-6) var(--space-4) var(--space-12); }
  .menu { width: auto; grid-template-columns: 1fr 1fr; }
  .plank--wide { justify-content: center; }
  .title { font-size: 2.25rem; }
  .title--large { font-size: 3.25rem; }
  /* the top stays clear of the dashes of light on the water */
  .water { padding: 56px var(--space-4) var(--space-6); }
  .parchment { padding: var(--space-4); }
  /* A ledger row becomes a block: the day at the left, the rest stacked beside it. The column
     heads are kept for screen readers only. */
  .ledger thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .ledger, .ledger tbody { display: block; }
  .ledger tr { display: grid; grid-template-columns: 4.5rem minmax(0, 1fr); padding: var(--space-3) 0; border-bottom: 1px dashed var(--parchment-shade); }
  .ledger tr:last-child { border-bottom: 0; }
  .ledger td { display: block; padding: 0 var(--space-2); border: 0; grid-column: 2; }
  .ledger td:first-child { grid-column: 1; grid-row: 1 / span 5; }
  .ledger .act { text-align: left; padding-top: var(--space-2); }
  /* A ledger whose rows do not start with a day (devices, sign-ins, people): each row is a
     column of lines, the first one in bold. */
  .ledger--plain tr { grid-template-columns: minmax(0, 1fr); }
  .ledger--plain td, .ledger--plain td:first-child { grid-column: 1; grid-row: auto; }
  .ledger--plain td:first-child { font-weight: 600; }
  /* Without its column heads a cell that could be misread (two times in one row) says what it is. */
  .ledger td[data-label]::before { content: attr(data-label) " "; font-weight: 600; color: var(--ink-soft); }
  .ledger .act > .plank + .plank { margin-left: 0; }
  .ledger .act { display: flex; flex-wrap: wrap; gap: var(--space-3); }
  .state { white-space: normal; }
}
