/* Tokens and @font-face copied from public/styles.css (the postcard Worker): keep them in sync. */
:root {
  --terracotta: #b4532e;
  --stone: #ece4d4;
  --ink: #1d1a17;
  --cream: #fbf3ea;
  --font-caption: "Archivo", "Arial Narrow", sans-serif;
  --font-body: "News Cycle", "Arial Narrow", sans-serif;
  /* Trail-only. Sage tones for the cactus rings, darkest innermost; each is at least 3:1 on stone. */
  --sage-1: #5c7a4c;
  --sage-2: #3f5a35;
  --sage-3: #22351e;
  --over: #b3261e;
  --grid-line: rgba(90, 60, 30, 0.16);
  /* Trail line thickness. */
  --bar: 5px;
}

@font-face {
  font-family: "Archivo";
  src: url("/fonts/archivo-latin-wdth-normal.woff2") format("woff2-variations");
  font-weight: 100 900;
  font-stretch: 62% 125%;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "News Cycle";
  src: url("/fonts/news-cycle-latin-400-normal.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}

@font-face {
  font-family: "News Cycle";
  src: url("/fonts/news-cycle-latin-700-normal.woff2") format("woff2");
  font-weight: 700;
  font-display: swap;
}

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

[hidden] {
  display: none !important;
}

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

body {
  margin: 0;
  min-height: 100vh;
  background: var(--terracotta);
  color: var(--cream);
  font: 400 15px/1.5 var(--font-body);
  overflow-wrap: anywhere;
}

main {
  max-width: 608px; /* 576px board + 16px gutters */
  margin: 0 auto;
  padding: 0 16px 56px;
}

a {
  color: inherit;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
}

a:focus-visible,
.button:focus-visible,
.share-text:focus-visible {
  outline: 2px solid var(--cream);
  outline-offset: 3px;
  border-radius: 2px;
}

/* Header: a quiet link back to the postcards */
.site-header {
  padding: 28px 16px 22px;
  text-align: center;
}

.wordmark {
  font: 700 12px/1 var(--font-body);
  letter-spacing: 0.24em;
  text-transform: uppercase;
  text-decoration: none;
}

.wordmark:hover {
  text-decoration: underline;
}

/* Heading: "TRAIL No. 7" in wide Archivo, then the date */
.title {
  margin: 0 2px;
  font: 700 22px/1.15 var(--font-caption);
  font-stretch: 125%;
  letter-spacing: 0.05em;
}

.date {
  margin: 6px 2px 0;
  font: 700 11px/1.4 var(--font-body);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.how {
  margin: 14px 2px 18px;
}

.how p {
  margin: 0 0 0.5em;
}

/* Inline markers in the rules, drawn like the board's trailhead and end. */
.mark {
  display: inline-block;
  width: 0.85em;
  height: 0.85em;
  vertical-align: -0.08em;
}

.mark-start {
  background: linear-gradient(var(--cream), var(--cream)) 50% 50% / 40% 40% no-repeat, var(--ink);
}

.mark-end {
  border: 0.15em solid var(--ink);
  background: var(--stone);
}

/* Board: a stone card of 12x12 cells, grid lines drawn on the card so the trail runs unbroken. */
.board {
  --cell: calc(100% / 12);
  position: relative;
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  grid-template-rows: repeat(12, 1fr);
  /* Fit the viewport's height too, so a whole drag stays on screen (cells never under 22px). */
  width: min(100%, 576px, max(264px, 100svh - 32px));
  aspect-ratio: 1;
  margin: 0 auto;
  background:
    linear-gradient(to right, var(--grid-line) 1px, transparent 1px) 0 0 / var(--cell) 100%,
    linear-gradient(to bottom, var(--grid-line) 1px, transparent 1px) 0 0 / 100% var(--cell),
    var(--stone);
  border-radius: 3px;
  box-shadow: 0 8px 22px rgba(60, 25, 10, 0.4);
  color: var(--ink);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  cursor: pointer;
}

.board:focus-visible {
  outline: 3px solid var(--cream);
  outline-offset: 4px;
}

/*
 * A cell. The trail is up to four ink bars from the centre toward connected sides, as background
 * layers switched on by the client's t-n/t-e/t-s/t-w classes; each bar overshoots the centre by
 * half its width so turns meet squarely. Markers and cacti sit above in ::before/::after.
 */
.cell {
  --tn: none;
  --te: none;
  --ts: none;
  --tw: none;
  --half: calc(50% + var(--bar) / 2);
  position: relative;
  min-width: 0;
  background-image: var(--tn), var(--te), var(--ts), var(--tw);
  background-repeat: no-repeat;
  background-position: 50% 0, 100% 50%, 50% 100%, 0 50%;
  background-size: var(--bar) var(--half), var(--half) var(--bar), var(--bar) var(--half), var(--half) var(--bar);
}

.t-n {
  --tn: linear-gradient(var(--ink), var(--ink));
}

.t-e {
  --te: linear-gradient(var(--ink), var(--ink));
}

.t-s {
  --ts: linear-gradient(var(--ink), var(--ink));
}

.t-w {
  --tw: linear-gradient(var(--ink), var(--ink));
}

.cell::before,
.cell::after {
  position: absolute;
  pointer-events: none;
}

/* Trailhead: an ink square with a cream centre. */
.start::before {
  content: "";
  inset: 20%;
  background: var(--ink);
}

.start::after {
  content: "";
  inset: 37%;
  background: var(--cream);
}

/* Trail end: a hollow ink square; the trail stops at its edge. */
.end::before {
  content: "";
  inset: 20%;
  border: 3px solid var(--ink);
  background: var(--stone);
}

/*
 * Cacti: 1, 2, or 3 concentric squares, outermost lightest, split by thin stone rings.
 * Sizes are in cqw (the cell is a size container) so the rings scale with the cell.
 */
.cactus {
  container-type: size;
}

.cactus::before {
  content: "";
  inset: 14cqw;
  background: var(--sage-1);
}

.c2::after,
.c3::after {
  content: "";
  inset: 31cqw;
  background: var(--sage-2);
  box-shadow: 0 0 0 max(1.5px, 5cqw) var(--stone);
}

/* Three: the middle square becomes a sage-2 band, a stone ring, then a sage-3 core. */
.c3::after {
  inset: 29cqw;
  background: var(--sage-3);
  box-shadow:
    inset 0 0 0 max(1.5px, 6cqw) var(--sage-2),
    inset 0 0 0 max(2.5px, 9.5cqw) var(--stone),
    0 0 0 max(1.5px, 5cqw) var(--stone);
}

/* A cactus cell with more trail neighbours than cacti. */
.cactus.over {
  outline: 2px solid var(--over);
  outline-offset: -2px;
  z-index: 1;
}

.cactus.over::before {
  inset: 18cqw;
}

/* Solved: the board locks; a cream ring marks it done. */
.board.solved {
  cursor: default;
  box-shadow: 0 0 0 3px var(--cream), 0 8px 22px rgba(60, 25, 10, 0.4);
}

/* Below the board */
.status {
  min-height: 1.5em;
  margin: 14px 2px 0;
  font-size: 14px;
}

.controls {
  margin: 6px 2px 0;
}

.button {
  appearance: none;
  min-height: 36px;
  padding: 6px 16px;
  border: 2px solid var(--cream);
  border-radius: 3px;
  background: transparent;
  color: var(--cream);
  font: 700 12px/1.4 var(--font-body);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  cursor: pointer;
}

.button:hover {
  background: rgba(251, 243, 234, 0.12);
}

.solved-panel {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 16px;
  margin: 18px 2px 0;
}

.solved-time {
  margin: 0;
  font: 700 18px/1.2 var(--font-caption);
  font-stretch: 125%;
}

.share-text {
  flex: 1 1 100%;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: 3px;
  background: var(--stone);
  color: var(--ink);
  font: 400 14px/1.4 var(--font-body);
  resize: none;
}

.message {
  margin: 16px 2px 0;
}

/* Notices (before launch, restocking, 404): a small stone card holding the heading. */
.card {
  background: var(--stone);
  border-radius: 3px;
  box-shadow: 0 8px 22px rgba(60, 25, 10, 0.4);
  color: var(--ink);
}

.card-empty {
  padding: 22px 20px 18px;
}

.card-empty .title {
  margin: 0;
}

/* Page links: "Previous trails →", "← Today · Archive" */
.links {
  margin: 28px 2px 0;
  font: 700 12px/1.4 var(--font-body);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.links .sep {
  margin: 0 0.6em;
}

/* Archive */
.page-title {
  margin: 0 2px 18px;
  font: 700 11px/1.4 var(--font-body);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.archive {
  margin: 0;
  padding: 0;
  list-style: none;
}

.archive a {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 2px;
  border-bottom: 1px solid rgba(251, 243, 234, 0.35);
  text-decoration: none;
}

.archive a:hover b {
  text-decoration: underline;
}

.archive b {
  font: 700 14px/1.4 var(--font-caption);
  font-stretch: 125%;
  letter-spacing: 0.05em;
}

@media (max-width: 400px) {
  :root {
    --bar: 4px;
  }

  .end::before {
    border-width: 2px;
  }
}

@media (min-width: 720px) {
  .site-header {
    padding: 40px 16px 30px;
  }

  .title {
    font-size: 26px;
  }
}
