:root {
  --paper: #f3eee3;
  --paper-2: #ebe4d4;
  --ink: #221d17;
  --muted: #6d6456;
  --rule: #cdc3b0;
  --accent: #b83a22;
  --accent-ink: #fff8ef;
  --ok: #3f6a3a;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --mono: ui-monospace, "Cascadia Code", "SF Mono", Menlo, Consolas, monospace;
  --measure: 30rem;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #1a1612;
    --paper-2: #242019;
    --ink: #eee6d6;
    --muted: #a39984;
    --rule: #3d362b;
    --accent: #e0694d;
    --accent-ink: #1a1612;
    --ok: #8fbf86;
  }
}

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

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

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--paper);
  color: var(--ink);
  font: 1.0625rem/1.5 var(--serif);
  padding: 0 1rem 4rem;
}

h1, h2, h3, p { margin: 0; }

.masthead, main {
  width: min(100%, var(--measure));
  margin-inline: auto;
}

.masthead {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.25rem 0 0.75rem;
  border-bottom: 2px solid var(--ink);
}

.masthead__title { display: flex; align-items: baseline; gap: 0.75rem; }

h1 {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1;
}

.masthead__issue {
  font: 0.8125rem var(--mono);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.masthead__tools { display: flex; gap: 1rem; }

.textbtn {
  appearance: none;
  background: none;
  border: 0;
  padding: 0.25rem 0;
  color: var(--ink);
  font: inherit;
  font-size: 0.9375rem;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.25em;
  cursor: pointer;
}
.textbtn:disabled { color: var(--muted); text-decoration: none; cursor: default; }
.textbtn:not(:disabled):hover { color: var(--accent); }

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

.solid {
  appearance: none;
  border: 2px solid var(--ink);
  background: var(--ink);
  color: var(--paper);
  font: 600 0.9375rem var(--serif);
  padding: 0.5rem 1rem;
  border-radius: 0;
  cursor: pointer;
}
.solid:hover { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

.brief {
  margin: 1.5rem 0 1.25rem;
  font-size: 1.125rem;
}
.brief strong { font-weight: 700; border-bottom: 2px solid var(--accent); }

/* ---- the chain ---- */

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

.trail > li { position: relative; padding-left: 2.25rem; }

/* the thread running down the left, joining every item */
.trail > li::before {
  content: "";
  position: absolute;
  left: 0.6875rem;
  top: 0;
  bottom: 0;
  border-left: 2px solid var(--ink);
}
.trail > li:first-child::before { top: 50%; }
.trail > li:last-child::before { bottom: 50%; }

/* the knot on the thread */
.word::after {
  content: "";
  position: absolute;
  left: 0.25rem;
  top: 50%;
  width: 0.875rem;
  height: 0.875rem;
  margin-top: -0.4375rem;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: var(--paper);
}
.word--placed::after { background: var(--ink); }
.word--given::after { border-color: var(--accent); }

.word {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.5rem 0;
}
.word__text { font-size: 1.5rem; line-height: 1.2; }
.word--given .word__text { font-weight: 700; }
.word__tag {
  font: 0.6875rem var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent);
}

/* the unfinished stretch is drawn dashed until the two ends meet */
.gap { padding-block: 0.25rem; }
.gap::before { border-left-style: dashed !important; border-color: var(--accent) !important; }

.entry {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.5rem;
  margin: 0.25rem 0;
  padding: 0.5rem 0;
}
.entry input {
  min-width: 0;
  padding: 0.5rem 0.25rem;
  font: 1.25rem var(--serif);
  color: var(--ink);
  background: transparent;
  border: 0;
  border-bottom: 2px solid var(--ink);
  border-radius: 0;
}
.entry input::placeholder { color: var(--muted); font-style: italic; }
.entry input:focus-visible { outline: 0; border-bottom-color: var(--accent); }
.entry__note {
  grid-column: 1 / -1;
  min-height: 1.5em;
  font-size: 0.9375rem;
  color: var(--accent);
}

.trail--done > li::before { border-color: var(--ok); }
.trail--done .word--given::after { border-color: var(--ok); }
.trail--done .word__tag { color: var(--ok); }

.actions {
  display: flex;
  gap: 1.5rem;
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--rule);
}

/* ---- result ---- */

.result {
  margin-top: 2rem;
  padding-top: 1.25rem;
  border-top: 2px solid var(--ink);
}
.result[hidden] { display: none; }
.result h2 { font-size: 1.75rem; line-height: 1.15; margin-bottom: 0.5rem; }
.result__route { margin-top: 0.5rem; color: var(--muted); font-style: italic; }
.result__card {
  margin: 1.25rem 0;
  padding: 1rem;
  background: var(--paper-2);
  border-left: 4px solid var(--accent);
  font: 0.9375rem/1.6 var(--mono);
  white-space: pre-wrap;
}
.result__row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.result__next { font: 0.8125rem var(--mono); color: var(--muted); }

/* ---- dialogs ---- */

dialog {
  width: min(92vw, 28rem);
  max-height: 88dvh;
  padding: 1.5rem;
  border: 2px solid var(--ink);
  border-radius: 0;
  background: var(--paper);
  color: var(--ink);
}
dialog::backdrop { background: rgb(20 16 10 / 0.55); }
dialog h2 { font-size: 1.5rem; margin-bottom: 0.75rem; }
dialog h3 {
  margin: 1.5rem 0 0.5rem;
  font: 0.75rem var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
}
dialog p + p, dialog p + ul { margin-top: 0.75rem; }
dialog ul, dialog ol { padding-left: 1.25rem; margin: 0; }
dialog li + li { margin-top: 0.375rem; }
.dialog__note { color: var(--muted); font-style: italic; }
.dialog__close {
  float: right;
  appearance: none;
  background: none;
  border: 0;
  padding: 0.25rem 0;
  color: var(--ink);
  font: 0.9375rem var(--serif);
  text-decoration: underline;
  cursor: pointer;
}

.record { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.5rem; margin: 0; }
.record div { display: flex; flex-direction: column-reverse; }
.record dd { margin: 0; font-size: 2rem; line-height: 1.1; font-weight: 700; }
.record dt { font-size: 0.8125rem; color: var(--muted); }

.spread__row { display: grid; grid-template-columns: 2rem 1fr; align-items: center; gap: 0.5rem; margin-top: 0.25rem; }
.spread__label { font: 0.8125rem var(--mono); color: var(--muted); }
.spread__bar {
  display: block;
  width: var(--w);
  padding: 0 0.5rem;
  background: var(--ink);
  color: var(--paper);
  font: 0.8125rem/1.5 var(--mono);
  text-align: right;
}

@media (prefers-reduced-motion: no-preference) {
  .word { animation: settle 0.25s ease-out; }
  @keyframes settle { from { opacity: 0; transform: translateY(-4px); } }
}

@media (max-width: 26rem) {
  h1 { font-size: 1.75rem; }
  .word__text { font-size: 1.375rem; }
}
