:root {
  color-scheme: light;

  /* Ink-shop primitives */
  --red-ink: #a94230;
  --red-press: #873326;
  --brown-ink: #33291f;
  --paper-stock: #eee3cc;
  --paper-light: #f8f0df;
  --paper-shadow: #d4c2a0;
  --brass: #dba84e;
  --teal: #9ac9c0;
  --quiet-ink: #665746;
  --rule-ink: #cbbb9d;
  --mono: 'Consolas', 'Courier New', monospace;

  /* Semantic roles */
  --page: var(--paper-stock);
  --surface: var(--paper-light);
  --text: var(--brown-ink);
  --text-muted: var(--quiet-ink);
  --accent: var(--red-ink);
  --focus: var(--red-ink);

  /* Component roles */
  --tile: var(--paper-light);
  --tile-edge: #8b7250;
  --tray: var(--brown-ink);
  --action: var(--red-ink);
  --action-text: var(--paper-light);

  color: var(--text);
  background: var(--page);
  font: 15px/1.5 Arial, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100svh; display: flow-root; }
button, input { font: inherit; }
button { cursor: pointer; min-height: 44px; }
button:disabled { cursor: default; opacity: .5; }
button, a, input { -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
a { color: inherit; }
h1, h2, h3, p { margin-top: 0; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
mark { background: var(--brass); color: var(--brown-ink); }
.overlap-b { background: var(--teal); }
.overlap-both { background: linear-gradient(to bottom, var(--brass) 50%, var(--teal) 50%); }

.masthead { width: min(calc(100% - 48px), 680px); margin: 24px auto 0; padding-bottom: 20px; display: flex; justify-content: space-between; align-items: center; gap: 20px; }
.wordmark { color: var(--red-ink); font: 900 38px/1 Georgia, serif; letter-spacing: -2.2px; text-decoration: none; }
.text-button { background: none; border: 0; color: var(--text-muted); padding: 0 8px; font-size: 13px; }
.text-button:hover:not(:disabled) { color: var(--accent); text-decoration: underline; text-underline-offset: 4px; }
.masthead .text-button { color: var(--text); font-size: 14px; padding-right: 4px; }
main { width: min(calc(100% - 48px), 680px); margin: auto; padding-bottom: 20px; }
.puzzle-meta { display: flex; align-items: center; justify-content: space-between; gap: 10px; font: 11px var(--mono); color: var(--text-muted); padding: 0 0 24px; }
#reset-label { white-space: nowrap; text-decoration: none; }
#reset-label:hover { text-decoration: underline; text-underline-offset: 3px; }
#load-status { padding: 24px 0; line-height: 1.6; }
.endpoints { display: grid; grid-template-columns: minmax(0, 1fr) 36px minmax(0, 1fr); align-items: center; gap: 14px; min-height: 142px; background: var(--red-ink); color: var(--paper-light); padding: 24px 22px; border-radius: 48% 48% 5px 5px / 17% 17% 5px 5px; margin-bottom: 30px; box-shadow: 0 5px 0 var(--red-press); }
.endpoint { min-width: 0; }
.endpoint-target { text-align: right; }
.eyebrow { font: 10px var(--mono); font-weight: 400; letter-spacing: 1.7px; color: inherit; opacity: .88; margin-bottom: 8px; }
.endpoint-word { font: 700 31px/1.1 Georgia, serif; letter-spacing: -.8px; margin: 0; overflow-wrap: anywhere; }
.endpoint-word.long-word { font-size: 23px; }
.connection { font-size: 30px; text-align: center; color: var(--paper-light); }
.chain-heading { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 44px; margin-bottom: 20px; }
.chain-heading h2 { font: 700 17px/1.2 Georgia, serif; margin: 0; }
#chain-count { font: 11px var(--mono); color: var(--text-muted); margin-left: 8px; white-space: nowrap; }
.edit-tools { display: flex; gap: 6px; }
.edit-tools .text-button { font-size: 12px; }
#chain { list-style: none; margin: 0; padding: 8px 0 0; display: flex; flex-direction: column; gap: 23px; }
.chain-step { min-width: 0; position: relative; }
.chain-word { display: flex; align-items: center; gap: 13px; transform: rotate(-1.5deg); transform-origin: left center; padding: 0 4px 0 0; }
.chain-step:nth-child(even) .chain-word { justify-content: flex-end; transform: rotate(1.5deg); transform-origin: right center; padding: 0 0 0 4px; }
.word-number { font: 10px var(--mono); color: var(--text-muted); flex-shrink: 0; }
.word-letters { display: inline-flex; color: var(--brown-ink); font: 700 26px/48px Georgia, serif; box-shadow: 0 4px 0 var(--paper-shadow); min-width: 0; }
.letter-tile { display: inline-block; width: 32px; flex: 0 0 32px; text-align: center; background: var(--tile); border-right: 1px solid var(--tile-edge); border-left: 1px solid #fff8e9; }
.letter-tile mark { display: block; color: inherit; }
.word-tag { display: none; }
.entry-node { position: relative; min-width: 0; margin-top: 16px; }
.rule-strip { font-size: 13px; color: var(--text-muted); margin: 0 0 10px; line-height: 1.5; }
.input-row { display: flex; align-items: center; gap: 10px; background: #e2d3b5; border: 1px solid var(--tile-edge); padding: 10px; }
.input-row:focus-within { border-color: var(--focus); box-shadow: inset 0 0 0 1px var(--focus); }
.input-prefix { display: none; }
.input-field { flex: 1; position: relative; min-width: 0; }
input { width: 100%; min-width: 0; min-height: 44px; padding: 8px; border: 0; outline: 0; background: none; color: var(--text); font: 17px Arial, sans-serif; text-transform: uppercase; }
input::placeholder { color: #655846; font-size: 16px; text-transform: none; opacity: 1; }
input:focus-visible { outline: none; }
.input-mirror { position: absolute; inset: 0; display: flex; align-items: center; padding: 8px; white-space: pre; font: 17px Arial, sans-serif; pointer-events: none; overflow: hidden; }
.input-mirror mark { padding: 1px 0; }
input.has-preview { color: transparent; caret-color: var(--brown-ink); }
.primary { border: 0; background: var(--action); color: var(--action-text); padding: 10px 20px; min-height: 44px; font-size: 13px; }
.primary:hover:not(:disabled) { background: var(--red-press); }
.primary:active:not(:disabled) { translate: 0 1px; }
.primary:focus-visible { outline-color: var(--brown-ink); }
.feedback { font-size: 13px; line-height: 1.45; margin: 10px 0 0; }
.feedback:empty { margin: 0; }
.feedback.error { color: #872c24; font-weight: 600; }
.submit-row { display: flex; margin-top: 16px; }
.submit-row .primary { width: 100%; }
.result { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 8px 16px; background: var(--surface); color: var(--text); padding: 18px; margin-top: 16px; border: 1px solid var(--rule-ink); border-bottom: 4px solid var(--paper-shadow); }
.score-total { grid-column: 1; font-size: 13px; margin: 0; }
.score-number { font: 700 42px/1 Georgia, serif; color: var(--accent); }
.score-detail { grid-column: 1; font-size: 12px; line-height: 1.5; margin: 0; }
.result > button { grid-column: 2; grid-row: 1 / 4; }
.result h2:not(.sr-only) { grid-column: 1; font: 700 25px Georgia, serif; margin: 0; }
.result:focus-visible { outline-color: var(--red-ink); }
.print-footer { display: flex; justify-content: space-between; gap: 16px; margin-top: 30px; padding-top: 16px; border-top: 1px solid var(--rule-ink); color: var(--text-muted); font: 10px var(--mono); }
.print-footer span:last-child { letter-spacing: 1px; }
.storage-warning { color: #872c24; font-size: 13px; line-height: 1.5; margin: 12px 0 0; }
.quiet { color: var(--text-muted); }
dialog .quiet { color: #ddd0b6; }
.secondary { background: transparent; border: 1px solid var(--paper-light); color: var(--paper-light); padding: 10px 14px; font-size: 13px; }
dialog { background: var(--tray); color: var(--paper-light); border: 1px solid #796657; border-bottom: 5px solid #211a15; padding: 26px; width: min(460px, calc(100% - 32px)); max-height: calc(100dvh - 32px); }
dialog::backdrop { background: #211a15b3; }
dialog :focus-visible { outline-color: var(--paper-light); }
dialog h2 { font: 700 30px/1.15 Georgia, serif; margin-bottom: 18px; }
dialog p, dialog li { font-size: 15px; line-height: 1.6; }
dialog ul { padding-left: 20px; margin-bottom: 20px; }
dialog li { margin-bottom: 7px; }
.dialog-top { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.dialog-top h2 { margin-bottom: 12px; }
.icon-button { background: none; border: 0; color: var(--paper-light); min-width: 44px; font-size: 26px; }
.help-example { font: 700 13px var(--mono); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 24px; }
.share-output { display: block; width: 100%; background: var(--paper-light); color: var(--text); padding: 14px; border: 0; border-radius: 0; margin-bottom: 16px; font: 14px/1.6 var(--mono); resize: vertical; }
.noscript { text-align: center; padding: 20px; }
.not-found { padding-top: 48px; }
.not-found h1 { font: 700 36px/1.15 Georgia, serif; }
.not-found .primary { display: inline-block; text-decoration: none; }

/* One composing tray from the first word: adding a word never reflows earlier rows. */
#play-area.dense .endpoints { min-height: 88px; padding: 14px 18px; margin-bottom: 18px; }
#play-area.dense .chain-heading { margin-bottom: 10px; }
#play-area.dense #chain { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 20px; padding-top: 0; }
.dense .chain-step[data-side="left"] { grid-column: 1; }
.dense .chain-step[data-side="right"] { grid-column: 2; }
.dense [data-row="1"] { grid-row: 1; }
.dense [data-row="2"] { grid-row: 2; }
.dense [data-row="3"] { grid-row: 3; }
.dense [data-row="4"] { grid-row: 4; }
.dense [data-row="5"] { grid-row: 5; }
.dense [data-row="6"] { grid-row: 6; }
.dense .chain-word, .dense .chain-step:nth-child(even) .chain-word { transform-origin: left center; justify-content: flex-start; padding: 0; gap: 6px; }
.dense .word-letters { font-size: clamp(12px, 3vw, 22px); line-height: 36px; box-shadow: 0 3px 0 var(--paper-shadow); }
.dense .letter-tile { --tile-width: clamp(11px, calc((100vw - 130px) / 20), 26px); width: var(--tile-width); flex-basis: var(--tile-width); border-left: 0; }
.dense .entry-node { grid-column: 1 / -1; margin-top: 6px; }
.dense .result { padding: 13px; margin-top: 12px; }
.dense .score-number { font-size: 34px; }
@media (max-width: 500px) {
  .endpoint-word { font-size: 24px; }
  .endpoint-word.long-word { font-size: 16px; }
  .letter-tile { width: 28px; flex-basis: 28px; }
  .word-letters { font-size: 24px; }
  .dense .word-letters { font-size: 13px; }
  .dense .letter-tile { width: 13px; flex-basis: 13px; }
}
@media (max-width: 360px) {
  .masthead, main { width: calc(100% - 32px); }
  .endpoint-word.long-word { font-size: 14px; }
  .letter-tile { width: 25px; flex-basis: 25px; }
  .word-letters { font-size: 22px; }
  .edit-tools { gap: 0; }
  .edit-tools .text-button { padding-left: 5px; padding-right: 5px; font-size: 11px; }
  .dense .letter-tile { width: 11px; flex-basis: 11px; }
  #play-area.dense #chain { column-gap: 14px; }
}
@media (max-height: 800px) {
  .masthead { margin-top: 16px; padding-bottom: 14px; }
  .puzzle-meta { padding-bottom: 18px; }
  .endpoints { min-height: 120px; }
  #play-area.dense .endpoints { min-height: 78px; margin-bottom: 12px; }
  #play-area.dense .chain-heading { margin-bottom: 6px; }
  #play-area.dense #chain { row-gap: 10px; }
  .dense .word-letters { line-height: 28px; }
  .dense .result { padding: 10px; }
  main:has(.dense) .print-footer { margin-top: 10px; padding-top: 10px; }
}
@media (max-height: 600px) {
  main { padding-bottom: 6px; }
  .masthead { margin-top: 8px; padding-bottom: 8px; }
  .wordmark { font-size: 32px; }
  .puzzle-meta { padding-bottom: 12px; }
  .endpoints, #play-area.dense .endpoints { min-height: 70px; padding-top: 10px; padding-bottom: 10px; margin-bottom: 14px; }
  .chain-heading, #play-area.dense .chain-heading { margin-bottom: 6px; }
  #play-area.dense #chain { row-gap: 8px; }
  .dense .word-letters { line-height: 23px; }
  .entry-node { margin-top: 10px; }
  .rule-strip { margin-bottom: 6px; }
  .input-row { padding: 5px; }
  .dense .result { padding: 8px 10px; margin-top: 8px; }
  .dense .score-number { font-size: 28px; }
  .submit-row { margin-top: 8px; }
  .print-footer, main:has(.dense) .print-footer { margin-top: 12px; padding-top: 8px; }
  .feedback { margin-top: 6px; }
}
@media (prefers-reduced-motion: no-preference) {
  @keyframes set-type { from { opacity: .5; translate: 0 -4px; } to { opacity: 1; translate: 0 0; } }
  .latest-step { animation: set-type 160ms ease-out; }
}
