/* Hemmed In — page and interface styles.
   Palette: indigo thread on linen, madder red, mustard, brass. */

@font-face {
  font-family: "Caprasimo";
  src: url("assets/fonts/caprasimo-latin.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Figtree";
  src: url("assets/fonts/figtree-latin.woff2") format("woff2");
  font-weight: 400 800;
  font-style: normal;
  font-display: swap;
}

:root {
  --table: #1b2140;
  --table-2: #252c54;
  --table-line: #39427a;
  --linen: #eee3cc;
  --linen-light: #f8f1e0;
  --linen-shade: #ddcfb0;
  --ink: #2a2433;
  --ink-soft: #564d63;
  --thread: #24408e;
  --thread-light: #9db1f0;
  --madder: #c8402b;
  --madder-dark: #8e2a1b;
  --mustard: #e0a526;
  --bone: #fbf6ea;
  --bone-dim: #cfd3ea;
  --display: "Caprasimo", Georgia, "Times New Roman", serif;
  --body: "Figtree", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --hud-controls-h: max(54px, 2.8rem);
  /* Reserve three hint lines, including at 200% text on a 320px phone.
     Font-relative rows grow with text, independently of hint visibility. */
  --hint-h: calc(3.28125rem + 4px);
  --hud-h: calc(var(--hud-controls-h) + var(--hint-h) + 3px);
}

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

[hidden] {
  display: none !important;
}

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

body {
  margin: 0;
  background: var(--table);
  color: var(--bone);
  font-family: var(--body);
  font-size: 1rem;
  line-height: 1.55;
  overflow-x: hidden;
}

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

.skip {
  position: absolute;
  left: 8px;
  top: -60px;
  z-index: 50;
  padding: 10px 16px;
  background: var(--mustard);
  color: var(--ink);
  font-weight: 700;
  border-radius: 6px;
  text-decoration: none;
}

.skip:focus {
  top: 8px;
}

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

/* ---- masthead ---------------------------------------------------------- */

.masthead {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 2px 16px;
  max-width: 1320px;
  margin: 0 auto;
  padding: 10px max(14px, env(safe-area-inset-right)) 8px max(14px, env(safe-area-inset-left));
}

.brand {
  order: 2;
  margin: 0 0 0 auto;
  font-size: 0.8125rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--bone-dim);
}

.masthead h1 {
  order: 1;
  margin: 0;
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(1.5rem, 1.1rem + 1.6vw, 2.1rem);
  line-height: 1.1;
  color: var(--bone);
}

.kicker {
  order: 1;
  margin: 0;
  color: var(--bone-dim);
  font-size: 0.9375rem;
}

/* ---- stage ------------------------------------------------------------- */

main {
  display: block;
}

.stage {
  position: relative;
  width: min(100% - 16px, 1320px);
  margin: 0 auto;
  border-radius: 14px;
  background: var(--table-2);
  border: 2px solid var(--table-line);
  overflow: hidden;
}

.hud {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  /* Keep the hint row even when empty: no mid-run cloth resize. */
  grid-template-rows: var(--hud-controls-h) var(--hint-h);
  align-items: center;
  gap: 0 8px;
  height: var(--hud-h);
  padding: 0 8px 3px 12px;
  background: var(--table-2);
}

.hud p {
  margin: 0;
}

.hud-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.hearts {
  display: flex;
  gap: 3px;
  flex-shrink: 0;
}

.heart {
  width: 22px;
  height: 20px;
  display: block;
}

.heart path {
  fill: none;
  stroke: var(--bone-dim);
  stroke-width: 1.8;
  stroke-dasharray: 2.6 2.4;
  stroke-linejoin: round;
}

.heart.is-full path {
  fill: var(--madder);
  stroke: #ffd9cf;
  stroke-dasharray: none;
}

.heart.is-shield path {
  stroke: var(--mustard);
  stroke-width: 2.4;
}

.wave {
  font-size: 0.9375rem;
  white-space: nowrap;
  color: var(--bone);
  font-variant-numeric: tabular-nums;
}

.hud-label {
  font-size: 0.6875rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--bone-dim);
}

#wave {
  font-family: var(--display);
  font-size: 1.125rem;
}

.hud-mid {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 8px;
}

.score {
  font-family: var(--display);
  font-size: 1.75rem;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: var(--bone);
}

.score.is-bump {
  animation: bump 0.22s ease-out;
}

@keyframes bump {
  0% {
    transform: scale(1.22);
    color: var(--mustard);
  }
  100% {
    transform: scale(1);
  }
}

.chain {
  font-family: var(--display);
  font-size: 1.0625rem;
  line-height: 1;
  padding: 4px 8px 5px;
  border-radius: 999px;
  background: var(--mustard);
  color: var(--ink);
}

.hud-right {
  display: flex;
  justify-content: flex-end;
  gap: 4px;
}

.tool {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--bone);
  cursor: pointer;
}

.tool:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.1);
}

.tool:disabled {
  opacity: 0.35;
  cursor: default;
}

.tool svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tool .i-off,
.tool .i-play {
  display: none;
}

.tool[aria-pressed="true"] .i-on {
  display: none;
}

.tool[aria-pressed="true"] .i-off {
  display: inline;
}

.stage[data-state="paused"] #btn-pause .i-pause {
  display: none;
}

.stage[data-state="paused"] #btn-pause .i-play {
  display: inline;
  fill: currentColor;
}

.chain-bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 4px;
  background: rgba(255, 255, 255, 0.08);
}

.chain-bar span {
  display: block;
  height: 100%;
  width: 100%;
  background: var(--mustard);
  transform-origin: left center;
  transform: scaleX(0);
}

.field {
  position: relative;
  height: clamp(340px, calc(100svh - 200px), 800px);
  background: var(--linen);
}

@supports not (height: 100svh) {
  .field {
    height: clamp(340px, calc(100vh - 200px), 800px);
  }
}

#cloth {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  /* The cloth is the only place where the browser's own gestures are
     switched off; the rest of the page scrolls and zooms normally. */
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  outline-offset: -4px;
}

.stage[data-state="playing"] #cloth {
  cursor: none;
}

/* The cloth's focus ring is thread-blue, not mustard, so it cannot be mistaken
   for the chain bar that runs along its top edge. */
#cloth:focus-visible {
  outline: 3px solid var(--thread);
  outline-offset: -3px;
}

/* Full screen: the real thing where the browser offers it, and a fixed
   full-window layout as the fallback (iPhone Safari has no element API). */
.stage:fullscreen,
.stage.is-max {
  width: 100%;
  max-width: none;
  height: 100%;
  border: 0;
  border-radius: 0;
  display: flex;
  flex-direction: column;
}

.stage.is-max {
  position: fixed;
  inset: 0;
  z-index: 40;
  height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.stage:fullscreen .field,
.stage.is-max .field {
  flex: 1 1 auto;
  height: auto;
  min-height: 0;
}

body.is-max-open {
  overflow: hidden;
}

/* ---- banner and hint ---------------------------------------------------- */

.banner {
  position: absolute;
  left: 50%;
  top: 14%;
  transform: translateX(-50%);
  display: grid;
  justify-items: center;
  gap: 2px;
  width: max-content;
  max-width: calc(100% - 32px);
  padding: 10px 22px 12px;
  text-align: center;
  background: var(--linen-light);
  color: var(--ink);
  border: 2px dashed var(--thread);
  outline: 4px solid var(--linen-light);
  border-radius: 10px;
  pointer-events: none;
  animation: banner-in 0.28s ease-out;
}

.banner strong {
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(1.25rem, 1rem + 1.4vw, 1.9rem);
  line-height: 1.1;
  color: var(--thread);
}

.banner span {
  font-size: 0.9375rem;
  line-height: 1.3;
  color: var(--ink);
}

.banner span:empty {
  display: none;
}

@keyframes banner-in {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

.hint {
  grid-column: 1 / -1;
  align-self: center;
  margin: 0;
  padding: 2px 6px;
  text-align: center;
  font-size: 0.875rem;
  font-weight: 600;
  line-height: 1.25;
  color: var(--bone);
  pointer-events: none;
}

/* ---- overlays and cards ------------------------------------------------- */

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  padding: 14px 12px;
  overflow: auto;
  overscroll-behavior: contain;
  background: rgba(248, 241, 224, 0.5);
}

#screen-ready {
  background: rgba(248, 241, 224, 0.28);
}

.stage:not([data-state="playing"]) .hint,
.stage:not([data-state="playing"]) .banner {
  display: none;
}

.card {
  /* Auto margins centre the card when it fits and let it scroll from the
     top when it does not (plain centring would cut the top off). */
  margin: auto;
  width: min(100%, 420px);
  padding: 20px 22px 18px;
  text-align: center;
  background: var(--linen-light);
  color: var(--ink);
  border-radius: 14px;
  border: 2px dashed var(--thread);
  outline: 5px solid var(--linen-light);
  box-shadow: 0 0 0 7px rgba(27, 33, 64, 0.2), 0 10px 0 2px rgba(27, 33, 64, 0.16);
}

.card-wide {
  width: min(100%, 640px);
}

.card-title {
  width: min(100%, 480px);
  padding-top: 12px;
}

.card h2 {
  margin: 0 0 4px;
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(1.6rem, 1.25rem + 1.6vw, 2.25rem);
  line-height: 1.1;
  color: var(--thread);
}

#over-title {
  color: var(--madder);
}

.card-sub {
  margin: 0 0 14px;
  color: var(--ink-soft);
}

.eyebrow {
  margin: 0 0 2px;
  font-size: 0.8125rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--madder);
}

.wordmark {
  display: block;
  width: min(100%, 400px);
  height: auto;
  margin: 0 auto 12px;
  overflow: visible;
}

.held {
  margin: -6px 0 14px;
  font-size: 0.875rem;
  line-height: 1.4;
  color: var(--thread);
  font-weight: 600;
}

.wordmark text {
  font-family: var(--display);
  font-size: 88px;
}

.wm-patch {
  fill: var(--madder);
  stroke: var(--madder);
  stroke-width: 11;
  stroke-linejoin: round;
}

.wm-fill {
  fill: var(--madder);
}

.wm-stitch {
  fill: none;
  stroke: #ffe3d6;
  stroke-width: 1.7;
  stroke-dasharray: 5 4.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.wm-thread {
  fill: none;
  stroke: var(--thread);
  stroke-width: 4.2;
  stroke-linecap: round;
}

.wm-pin path {
  fill: #cdd2da;
  stroke: #7c8593;
  stroke-width: 0.9;
}

.wm-pin circle {
  fill: var(--madder);
  stroke: var(--madder-dark);
  stroke-width: 1.4;
}

.wm-pin .wm-shine {
  fill: rgba(255, 255, 255, 0.85);
  stroke: none;
}

.steps {
  margin: 4px auto 8px;
  padding: 0;
  list-style: none;
  counter-reset: step;
  display: grid;
  gap: 5px;
  width: fit-content;
  max-width: 100%;
  text-align: left;
}

.steps li {
  counter-increment: step;
  position: relative;
  padding: 1px 0 1px 34px;
  line-height: 1.35;
}

.steps li::before {
  content: counter(step);
  position: absolute;
  left: 0;
  top: 0;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--thread);
  color: var(--bone);
  font-family: var(--display);
  font-size: 0.9375rem;
  line-height: 1;
}

.pitch {
  margin: 0 0 12px;
  font-size: 0.9375rem;
  color: var(--ink-soft);
}

.controls-line {
  margin: 10px 0 0;
  font-size: 0.8125rem;
  line-height: 1.4;
  color: var(--ink-soft);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  min-width: 132px;
  padding: 8px 22px 10px;
  font-family: var(--display);
  font-size: 1.1875rem;
  line-height: 1.1;
  color: var(--thread);
  background: var(--bone);
  border: 2px solid var(--thread);
  border-radius: 12px;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.08s ease-out, background-color 0.12s;
}

.btn:hover {
  background: #fff;
}

.btn:active {
  transform: translateY(2px);
}

.btn-primary {
  min-height: 56px;
  min-width: 190px;
  font-size: 1.5rem;
  color: var(--bone);
  background: var(--madder);
  border-color: var(--madder-dark);
  box-shadow: inset 0 0 0 3px var(--madder), inset 0 0 0 4.5px rgba(255, 227, 214, 0.55), 0 4px 0 var(--madder-dark);
}

.btn-primary:hover {
  background: #d54a33;
}

.btn-primary:active {
  box-shadow: inset 0 0 0 3px var(--madder), inset 0 0 0 4.5px rgba(255, 227, 214, 0.55), 0 2px 0 var(--madder-dark);
}

.btn-quiet {
  border-color: transparent;
  background: transparent;
  text-decoration: underline;
  text-underline-offset: 4px;
}

.btn-quiet:hover {
  background: rgba(36, 64, 142, 0.08);
}

.stack {
  display: grid;
  justify-items: center;
  gap: 10px;
  margin: 4px 0 12px;
}

#touch-style-paused {
  justify-content: center;
  margin: 14px 0 10px;
}

.stack-row {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 4px 6px;
  margin-bottom: 0;
}

.options {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px 16px;
  margin-top: 12px;
  font-size: 0.875rem;
}

.seg {
  display: flex;
  align-items: center;
  gap: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.seg legend {
  float: left;
  margin-right: 8px;
  padding: 0;
  color: var(--ink-soft);
}

.seg label {
  position: relative;
  cursor: pointer;
}

.seg input {
  position: absolute;
  inset: 0;
  opacity: 0;
  margin: 0;
  cursor: pointer;
}

.seg span {
  display: block;
  padding: 7px 12px;
  min-height: 36px;
  border: 2px solid var(--thread);
  color: var(--thread);
  font-weight: 600;
  background: transparent;
}

.seg label:first-of-type span {
  border-radius: 9px 0 0 9px;
  border-right-width: 1px;
}

.seg label:last-of-type span {
  border-radius: 0 9px 9px 0;
  border-left-width: 1px;
}

.seg input:checked + span {
  background: var(--thread);
  color: var(--bone);
}

.seg input:focus-visible + span {
  outline: 3px solid var(--mustard);
  outline-offset: 2px;
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  color: var(--ink);
  cursor: pointer;
  font-size: 0.875rem;
}

.check input {
  width: 20px;
  height: 20px;
  margin: 0;
  accent-color: var(--thread);
}

.best {
  margin: 10px 0 0;
  font-size: 0.875rem;
  color: var(--ink);
}

.best b {
  font-family: var(--display);
  font-weight: 400;
  font-size: 1rem;
  color: var(--thread);
}

/* ---- notion choice ------------------------------------------------------ */

.notions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 4px;
}

.notion {
  position: relative;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  justify-items: center;
  gap: 4px;
  min-height: 150px;
  padding: 12px 10px 10px;
  text-align: center;
  font: inherit;
  color: var(--ink);
  background: var(--bone);
  border: 2px solid var(--thread);
  border-radius: 12px;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.08s ease-out, background-color 0.12s;
}

.notion:hover {
  background: #fff;
  transform: translateY(-2px);
}

.notion:active {
  transform: translateY(1px);
}

.notion svg {
  width: 38px;
  height: 38px;
  fill: none;
  stroke: var(--madder);
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.notion-name {
  font-family: var(--display);
  font-size: 1.125rem;
  line-height: 1.15;
  color: var(--thread);
}

.notion-text {
  font-size: 0.875rem;
  line-height: 1.35;
}

.notion-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.75rem;
  color: var(--ink-soft);
}

.notion-key {
  display: inline-grid;
  place-items: center;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border: 1.5px solid var(--ink-soft);
  border-radius: 5px;
  font-weight: 700;
  line-height: 1;
}

@media (hover: none) and (pointer: coarse) {
  .notion-key {
    display: none;
  }
}

/* ---- results ------------------------------------------------------------ */

.stats {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  margin: 0 0 10px;
}

.stat {
  display: grid;
  gap: 1px;
  padding: 8px 4px;
  background: rgba(36, 64, 142, 0.08);
  border-radius: 9px;
}

.stat-big {
  grid-column: 1 / -1;
  background: var(--thread);
  color: var(--bone);
}

.stat dt {
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.stat-big dt {
  color: var(--thread-light);
}

.stat dd {
  margin: 0;
  font-family: var(--display);
  font-size: 1.375rem;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.stat-big dd {
  font-size: clamp(2rem, 1.5rem + 2.4vw, 2.9rem);
}

.record {
  display: inline-block;
  margin: 0 0 8px;
  padding: 4px 14px 5px;
  font-family: var(--display);
  font-size: 1.0625rem;
  border-radius: 999px;
  background: var(--mustard);
  color: var(--ink);
}

.tip {
  margin: 0 auto 14px;
  max-width: 46ch;
  font-size: 0.9375rem;
  line-height: 1.4;
  color: var(--ink);
}

.tip:empty {
  display: none;
}

.cause {
  margin-bottom: 10px;
}

/* "See the cloth": the card steps aside so the finished embroidery shows. */
.overlay.is-peek {
  background: transparent;
  overflow: hidden;
  justify-content: center;
}

.overlay.is-peek .card {
  display: none;
}

.unpeek {
  position: absolute;
  top: 12px;
  right: 12px;
  margin: 0;
  box-shadow: 0 0 0 4px var(--linen-light);
}

.stack-row {
  flex-wrap: wrap;
}

.stack-row .btn-quiet {
  min-width: 0;
  padding-left: 12px;
  padding-right: 12px;
  font-size: 1.0625rem;
}

.noscript {
  margin: 0;
  padding: 14px 16px;
  background: var(--mustard);
  color: var(--ink);
  font-weight: 600;
}

/* ---- information below the game ------------------------------------------ */

.info {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  width: min(100% - 16px, 1320px);
  margin: 18px auto 0;
}

.panel {
  padding: 18px 20px 20px;
  background: var(--table-2);
  border: 1px solid var(--table-line);
  border-radius: 14px;
}

.panel h2 {
  margin: 0 0 8px;
  font-family: var(--display);
  font-weight: 400;
  font-size: 1.5rem;
  line-height: 1.15;
  color: var(--bone);
}

.panel h3 {
  margin: 0;
  font-family: var(--display);
  font-weight: 400;
  font-size: 1.0625rem;
  color: var(--bone);
}

.panel p,
.panel li,
.panel dd {
  color: #dfe2f3;
}

.panel p {
  margin: 0 0 10px;
  max-width: 68ch;
}

.panel p:last-child {
  margin-bottom: 0;
}

.panel b {
  color: var(--bone);
}

.howto,
.plain {
  margin: 0 0 12px;
  padding-left: 1.25em;
  display: grid;
  gap: 6px;
  max-width: 68ch;
}

.aside {
  padding: 10px 14px;
  border-left: 4px solid var(--mustard);
  background: rgba(224, 165, 38, 0.1);
  border-radius: 0 8px 8px 0;
}

.table-wrap {
  overflow-x: auto;
  margin: 0 0 12px;
  border-radius: 8px;
}

table {
  width: 100%;
  min-width: 460px;
  border-collapse: collapse;
  font-size: 0.9375rem;
}

th,
td {
  padding: 7px 10px;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--table-line);
  color: #dfe2f3;
}

thead th {
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--bone-dim);
}

tbody th {
  color: var(--bone);
  white-space: nowrap;
}

.cast {
  margin: 0 0 12px;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 10px;
}

.cast li {
  display: grid;
  grid-template-columns: 64px 1fr;
  gap: 12px;
  align-items: center;
}

.cast p {
  margin: 0;
  font-size: 0.9375rem;
}

.portrait {
  width: 64px;
  height: 64px;
  border-radius: 12px;
  background: var(--linen);
}

.glossary {
  margin: 0;
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 6px 14px;
}

.glossary dt {
  font-family: var(--display);
  color: var(--bone);
}

.glossary dd {
  margin: 0;
  font-size: 0.9375rem;
}

.more span {
  color: var(--bone);
  font-weight: 600;
}

.foot {
  width: min(100% - 16px, 1320px);
  margin: 18px auto 0;
  padding: 0 4px calc(22px + env(safe-area-inset-bottom));
  font-size: 0.8125rem;
  color: var(--bone-dim);
}

.foot p {
  margin: 0;
}

/* ---- smaller screens ----------------------------------------------------- */

@media (max-width: 900px) {
  .info {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  :root {
    --hud-controls-h: max(50px, 2.4rem);
  }

  .masthead {
    padding-top: 6px;
    padding-bottom: 5px;
  }

  .kicker {
    display: none;
  }

  .stage {
    width: 100%;
    border-radius: 0;
    border-left: 0;
    border-right: 0;
  }

  .field {
    height: clamp(330px, calc(100svh - 108px), 860px);
  }

  .hud {
    padding-left: 8px;
    padding-right: 2px;
    gap: 0 4px;
  }

  .hud-left {
    flex-direction: column;
    align-items: flex-start;
    gap: 1px;
  }

  .heart {
    width: 18px;
    height: 16px;
  }

  .wave {
    font-size: 0.8125rem;
    line-height: 1.1;
  }

  #wave {
    font-size: 0.9375rem;
  }

  .score {
    font-size: 1.5rem;
  }

  .tool {
    width: 40px;
  }

  .card {
    padding: 14px 14px 14px;
  }

  .card-title {
    padding-top: 8px;
  }

  .notions {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .notion {
    grid-template-columns: 44px 1fr;
    grid-template-rows: auto auto;
    justify-items: start;
    align-items: center;
    column-gap: 10px;
    row-gap: 1px;
    min-height: 68px;
    padding: 9px 12px;
    text-align: left;
  }

  .notion svg {
    grid-row: 1 / span 2;
  }

  .notion-meta {
    display: none;
  }

  .stats {
    grid-template-columns: repeat(3, 1fr);
  }

  .stat:nth-child(5),
  .stat:nth-child(6) {
    grid-column: span 1;
  }

  .stats .stat:nth-child(2) {
    grid-column: span 1;
  }

  .panel {
    padding: 16px 14px 18px;
    border-radius: 0;
    border-left: 0;
    border-right: 0;
  }

  .info {
    width: 100%;
    gap: 8px;
  }

  .glossary {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .glossary dd {
    margin-bottom: 8px;
  }
}

@media (max-width: 380px) {
  .tool {
    width: 36px;
  }

  .score {
    font-size: 1.3125rem;
  }

  .btn-primary {
    min-width: 160px;
  }

  .steps {
    font-size: 0.9375rem;
  }

  .seg legend {
    float: none;
    display: block;
    width: 100%;
    margin: 0 0 4px;
    text-align: center;
  }

  .seg {
    flex-wrap: wrap;
    justify-content: center;
  }
}

/* Short phones (an iPhone SE is 568 tall): the title card must fit the cloth
   without scrolling, so it drops its secondary lines. */
@media (max-width: 720px) and (max-height: 700px) {
  .wordmark {
    width: min(100%, 250px);
  }

  .card-title {
    padding: 6px 12px 10px;
  }

  .steps {
    gap: 2px;
    margin: 2px auto 8px;
    font-size: 0.9375rem;
  }

  .pitch {
    display: none;
  }

  .btn-primary {
    min-height: 50px;
  }

  /* The first run shows this same advice on the cloth itself. */
  .card-title .controls-line {
    display: none;
  }

  .options {
    margin-top: 10px;
    gap: 6px 14px;
  }

  /* ...and so must the results card. */
  .card {
    padding: 8px 12px 10px;
  }

  .card h2 {
    font-size: 1.375rem;
    margin-bottom: 2px;
  }

  .card-sub {
    margin-bottom: 6px;
    font-size: 0.9375rem;
    line-height: 1.3;
  }

  .stats {
    gap: 4px;
    margin-bottom: 8px;
  }

  .stat {
    padding: 4px 2px 5px;
  }

  .stat dd {
    font-size: 1.125rem;
  }

  .stat-big dd {
    font-size: 1.5rem;
  }

  .stat-big {
    padding-top: 3px;
    padding-bottom: 4px;
  }

  .record {
    margin-bottom: 6px;
    font-size: 0.9375rem;
  }

  .tip {
    margin-bottom: 8px;
    font-size: 0.875rem;
    line-height: 1.3;
  }

  .stack-row .btn-primary {
    min-width: 140px;
    min-height: 46px;
    font-size: 1.25rem;
  }

  .stack-row .btn-quiet {
    min-height: 40px;
    font-size: 0.9375rem;
    padding-left: 8px;
    padding-right: 8px;
  }
}

/* Wide desktops: let the cloth grow. */
@media (min-width: 1700px) and (min-height: 960px) {
  .masthead,
  .stage,
  .info,
  .foot {
    max-width: 1560px;
  }

  .stage {
    width: min(100% - 16px, 1560px);
  }

  .info,
  .foot {
    width: min(100% - 16px, 1560px);
  }

  .field {
    height: clamp(340px, calc(100svh - 200px), 900px);
  }
}

/* Short landscape phones: let the cloth use the height it has. */
@media (max-height: 520px) and (orientation: landscape) {
  .masthead {
    display: none;
  }

  .field {
    height: clamp(240px, calc(100svh - 58px), 800px);
  }

  .card {
    padding: 10px 16px;
  }

  .wordmark {
    width: min(100%, 250px);
  }

  .steps {
    gap: 2px;
    margin-bottom: 4px;
    font-size: 0.875rem;
  }

  .pitch,
  .controls-line {
    display: none;
  }

  .options {
    margin-top: 6px;
  }
}

/* ---- preferences --------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

.reduce-motion *,
.reduce-motion *::before,
.reduce-motion *::after {
  animation-duration: 0.001ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.001ms !important;
}

@media (forced-colors: active) {
  .card,
  .notion,
  .btn,
  .stat,
  .panel,
  .banner,
  .hint,
  .chain {
    border: 2px solid CanvasText;
  }

  .chain-bar span {
    background: Highlight;
  }

  .heart.is-full path {
    fill: CanvasText;
  }

  .seg input:checked + span {
    background: Highlight;
    color: HighlightText;
  }
}
