/* Knotwick web design system: base and components.
 * Needs tokens.css first. Page layouts live in each page's own stylesheet.
 */

/* ---------- Base ---------- */

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: var(--s8);
}

body {
  margin: 0;
  background: var(--bench);
  color: var(--text);
  font-family: var(--font-text);
  font-size: var(--text-body);
  line-height: var(--leading-body);
  font-variant-numeric: lining-nums;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

[hidden] { display: none !important; }

img, picture, canvas { display: block; max-width: 100%; }
img { height: auto; }

h1, h2, h3, h4, p, ul, ol, figure, blockquote { margin: 0; }
ul, ol { padding: 0; list-style: none; }

h1, h2, h3 {
  font-family: var(--font-display);
  font-weight: 700;
  line-height: var(--leading-tight);
  text-wrap: balance;
}
h1 { font-size: var(--text-h1); }
h2 { font-size: var(--text-h2); }
h3 { font-size: var(--text-h3); }

p { text-wrap: pretty; }

a { color: inherit; }

:focus-visible {
  outline: 2px solid var(--paper);
  outline-offset: 3px;
  border-radius: 2px;
}

::selection { background: var(--nightshade); color: var(--paper); }

.wrap {
  width: 100%;
  max-width: var(--page);
  margin-inline: auto;
  padding-left: var(--gutter-left);
  padding-right: var(--gutter-right);
}

.measure { max-width: var(--measure); }

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* ---------- Type roles ---------- */

/* Spaced capitals: room names, HUD labels, eyebrows. */
.label {
  font-family: var(--font-text);
  font-weight: 700;
  font-size: var(--text-label);
  letter-spacing: var(--track-label);
  text-transform: uppercase;
  line-height: 1.2;
}

.lead { font-size: var(--text-lead); line-height: 1.45; }
.dim { color: var(--text-dim); }

/* Nell's voice and the tagline: Cochin italic. */
.voice {
  font-family: var(--font-display);
  font-style: italic;
  font-size: var(--text-lead);
  line-height: 1.3;
}

/* The game's own link style: paper, underlined. */
.link {
  color: var(--paper);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.22em;
  transition: color var(--t-fade) linear, text-decoration-color var(--t-fade) linear;
}
.link:hover { color: var(--brass-hi); }
.on-paper .link, .leaf .link { color: var(--text-ink); }
.on-paper .link:hover, .leaf .link:hover { color: var(--oxblood); }

/* ---------- Skins ----------
 * The game's painted panels, stretched nine-slice style. Each sets a
 * transparent border the size of the art's caps, and paints through it.
 */

/* Parchment leaf: stitched at the left, a wax seal at its top corner. */
.leaf {
  --pad: var(--s5);
  border-style: solid;
  border-color: transparent;
  border-width: calc(32px * var(--skin)) calc(12px * var(--skin)) calc(12px * var(--skin)) calc(32px * var(--skin));
  border-image: var(--skin-parchment) 96 36 36 96 fill / calc(32px * var(--skin)) calc(12px * var(--skin)) calc(12px * var(--skin)) calc(32px * var(--skin)) stretch;
  padding: calc(var(--pad) - 8px) var(--pad) var(--pad) calc(var(--pad) - 8px);
  color: var(--text-ink);
  filter: drop-shadow(0 14px 22px rgb(4 10 14 / 0.5));
}
.leaf .dim { color: var(--text-ink-dim); }
.leaf h2, .leaf h3 { color: var(--text-ink); }

/* Slate plate in an oak frame. */
.plate {
  border-style: solid;
  border-color: transparent;
  border-width: calc(8px * var(--skin));
  border-image: var(--skin-slate) 18 fill / calc(8px * var(--skin)) stretch;
  padding: var(--s3) var(--s5);
  color: var(--paper);
}

/* Paper tag on a string: short single lines. */
.tag {
  display: inline-block;
  border-style: solid;
  border-color: transparent;
  border-width: calc(5px * var(--skin)) calc(8px * var(--skin)) calc(5px * var(--skin)) calc(22px * var(--skin));
  border-image: var(--skin-callout) 12 18 12 54 fill / calc(5px * var(--skin)) calc(8px * var(--skin)) calc(5px * var(--skin)) calc(22px * var(--skin)) stretch;
  padding: 0.15em 0.9em 0.15em 0.7em;
  color: var(--text-ink);
}

/* HUD tag: a label over a number. */
.hud-tag {
  display: inline-grid;
  gap: 1px;
  min-width: 6.5rem;
  border-style: solid;
  border-color: transparent;
  border-width: calc(7px * var(--skin)) calc(7px * var(--skin)) calc(7px * var(--skin)) calc(26px * var(--skin));
  border-image: var(--skin-hud-tag) 18 18 18 66 fill / calc(7px * var(--skin)) calc(7px * var(--skin)) calc(7px * var(--skin)) calc(26px * var(--skin)) stretch;
  padding: 0 var(--s3) 2px 4px;
  color: var(--text-ink);
}
.hud-tag .label { font-size: 0.6875rem; }
.hud-tag__value {
  font-family: var(--font-text);
  font-weight: 700;
  font-size: 1.5rem;
  line-height: 1;
  font-variant-numeric: lining-nums tabular-nums;
}

/* ---------- Buttons ---------- */

.btn {
  --press: 0px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5em;
  min-height: 3.25rem;
  border-style: solid;
  border-color: transparent;
  border-width: calc(9px * var(--skin));
  border-image: var(--skin-brass) 24 fill / calc(9px * var(--skin)) stretch;
  padding: 0.2em 1.4em 0.3em;
  background: none;
  color: var(--text-ink);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.3rem;
  line-height: 1.1;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  transform: translateY(var(--press));
  transition: transform var(--t-press) linear, filter var(--t-press) linear;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { filter: brightness(1.07); }
.btn:active { --press: 1px; filter: brightness(0.8); }

.btn--slate {
  border-width: calc(7px * var(--skin));
  border-image: var(--skin-slate-action) 18 fill / calc(7px * var(--skin)) stretch;
  color: var(--paper);
}
.btn--small { min-height: 2.75rem; font-size: 1.1rem; padding-inline: 1em; }

/* Where the game can be had. A plate, not a button, until there is a store
   page to link to; then it becomes a link with the same look. */
.store {
  display: inline-grid;
  gap: 2px;
  margin: 0;
  padding: 0.3em 1.2em 0.4em;
  line-height: 1.1;
  text-decoration: none;
}
.store .label { font-size: 0.6875rem; color: var(--text-dim); }
.store__when { font-family: var(--font-display); font-weight: 700; font-size: 1.25rem; }

/* Oak key: the game's touch controls. Holds one glyph. */
.key {
  display: inline-grid;
  place-items: center;
  width: 3.25rem;
  height: 3.25rem;
  border-style: solid;
  border-color: transparent;
  border-width: 7px;
  border-image: var(--skin-key) 18 fill / 7px stretch;
  padding: 0;
  background: none;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.key img { width: 1.5rem; height: 1.5rem; }
.key:active { border-image-source: var(--skin-key-pressed); }
.key:active img { transform: translateY(1px); }

/* ---------- Pieces ---------- */

/* An ink and its mark, side by side, for legends. */
.ink {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
}
.ink img { width: 2.25rem; height: 2.25rem; }

/* A charm on its own: bracelet charms, map stops, tinctures. */
.token {
  display: grid;
  justify-items: center;
  gap: var(--s2);
  text-align: center;
}
.token img { width: 4rem; height: 4rem; }

/* Nell saying a line: her portrait in its frame, then the words. */
.nell-line {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: var(--s4);
}
.nell-face {
  position: relative;
  width: 4.5rem;
  height: 4.5rem;
  flex: none;
}
.nell-face img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
.nell-face__portrait { border-radius: 50%; transform: scale(0.89); }

/* A painting from the story, with the pan the opening uses. */
.painting {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius-painting);
  background: var(--dusk-deep);
  box-shadow: var(--shadow-bench);
}
.painting img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.painting--pan img {
  animation: pan var(--pan) var(--ease-drift) infinite alternate;
  will-change: transform;
}
@keyframes pan {
  from { transform: scale(1.02) translate3d(-1%, 0.5%, 0); }
  to { transform: scale(1.12) translate3d(1.5%, -1.5%, 0); }
}

/* A phone showing a screen from the game. */
.phone {
  position: relative;
  aspect-ratio: 1206 / 2622;
  border-radius: 13% / 6%;
  padding: 2.6%;
  background: linear-gradient(145deg, #3a3f45, #14181c 40%, #0b0e11);
  box-shadow: var(--shadow-lift), inset 0 0 0 1px rgb(255 255 255 / 0.08);
}
.phone img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 11% / 5.1%;
}

/* The bracelet's cord as a rule between sections. */
.cord-rule {
  height: 3rem;
  background: url("../img/ui/bracelet-cord.webp") center / contain no-repeat;
  opacity: 0.9;
}

/* ---------- Arriving ----------
 * Things ease up a little as they come into view. They are always visible:
 * without scripts, or with reduced motion, nothing is hidden.
 */
.js .arrive {
  transform: translateY(18px);
  opacity: 0.001;
  transition: transform var(--t-settle) var(--ease-set), opacity var(--t-settle) linear;
  transition-delay: calc(var(--i, 0) * 70ms);
}
.js .arrive.is-in { transform: none; opacity: 1; }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .js .arrive { transform: none; opacity: 1; transition: none; }
  .painting--pan img { animation: none; transform: scale(1.06); }
  .btn, .key img { transition: none; }
}
