/* Marker Slip Machines: an inventor's notebook left open on a navy desk at night.
   Pen on paper: thin chalk lines, tangerine highlights, pen marks for state, nothing filled but the page. */

:root {
  --msm-red: #F2353B;
  --msm-tape: color-mix(in srgb, var(--ak-link) 30%, var(--ak-ink));
  --msm-wobble: 255px 15px 225px 15px / 15px 225px 15px 255px;
  --msm-wobble-2: 15px 255px 15px 225px / 225px 15px 255px 15px;
  --msm-rule: 26px;
  --msm-margin: 58px;
  --msm-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --msm-out: cubic-bezier(0.22, 1, 0.36, 1);
}

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

html, body { height: 100%; margin: 0; }

body {
  overflow: hidden;
  background-color: var(--ak-bg);
  background-image: var(--ak-bg-art);
  background-size: var(--ak-bg-size);
  color: var(--ak-ink);
  font-family: var(--ak-font-body);
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; color: inherit; }
button:focus-visible, input:focus-visible, canvas:focus-visible { outline: 3px solid var(--ak-focus); outline-offset: 3px; }
[hidden] { display: none !important; }

/* ---- the play screen ---------------------------------------------------------------------- */

.msm {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas: "top" "desk" "dock";
  gap: 6px;
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding:
    calc(var(--ac-status-h, 64px) + 4px)
    max(8px, env(safe-area-inset-right))
    max(6px, env(safe-area-inset-bottom))
    max(8px, env(safe-area-inset-left));
  background-image: var(--ak-backdrop-layer);
  background-size: cover;
  background-position: left top;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

/* The question line: a small logo, the one question, the ring timer. */
.msm-top {
  grid-area: top;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  grid-template-areas: "logo ask ring";
  align-items: center;
  gap: 10px;
  min-height: 52px;
  padding-left: 2px;
}
.msm-logo { grid-area: logo; display: block; width: auto; height: clamp(30px, 5.2dvh, 44px); rotate: -3deg; }
.msm-askbox { grid-area: ask; min-width: 0; }
/* This sitting's brief: a short note in pen under the question, from the second sitting on. */
.msm-brief { margin: 4px 0 0; font-size: 15px; font-weight: 700; line-height: 1.25; color: var(--ak-ink); }
.msm-brief-tag {
  display: inline-block;
  margin-right: 4px;
  padding: 0 6px;
  border: 2px solid var(--ak-accent);
  border-radius: var(--msm-wobble);
  font-family: var(--ak-font-display);
  font-weight: 400;
  font-size: 13px;
  color: var(--ak-ink);
  rotate: -3deg;
}
.msm-toolnote { margin: 0; padding: 0 4px; font-size: 14px; line-height: 1.3; color: var(--ak-ink); }
.msm-toolnote::before { content: ''; display: inline-block; width: 18px; height: 0; margin-right: 6px; border-top: 2px dashed var(--ak-accent); vertical-align: middle; }
.msm-brief-mark { margin: 0; font-size: 15px; font-weight: 700; color: var(--ak-ink); }
.msm-lineup-notes { display: grid; gap: 2px; max-width: 46ch; text-align: center; font-size: 15px; line-height: 1.3; color: var(--ak-ink); }
.msm-lineup-notes p { margin: 0; }
.msm-lineup-notes .msm-teaser { font-family: var(--ak-font-display); font-size: 17px; rotate: -1deg; }
.msm-ask {
  margin: 0;
  font-family: var(--ak-font-display);
  font-weight: var(--ak-title-weight, 400);
  font-size: clamp(18px, 4.6vw, 26px);
  line-height: 1.08;
  color: var(--ak-ink);
}
.msm-ask::after {
  content: '';
  display: block;
  width: min(100%, 15em);
  height: 6px;
  margin-top: 2px;
  background: no-repeat left center / 100% 100% url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 200 6' preserveAspectRatio='none'%3E%3Cpath d='M1 4 C40 1 80 5 120 3 S180 2 199 4' fill='none' stroke='%23FF8A3D' stroke-width='2.4' stroke-linecap='round'/%3E%3C/svg%3E");
}

.msm-ring {
  grid-area: ring;
  position: relative;
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  cursor: pointer;
  touch-action: manipulation;
}
.msm-ring svg { width: 50px; height: 50px; overflow: visible; }
.msm-ring-chalk { fill: none; stroke: var(--ak-ink); stroke-width: 2.6; stroke-linecap: round; opacity: 0.9; }
.msm-ring-arc { fill: none; stroke: var(--ak-accent); stroke-width: 8; stroke-linecap: round; stroke-dasharray: 100; stroke-dashoffset: 100; }
.msm-ring[aria-disabled="true"] { cursor: default; }
.msm-ring[aria-disabled="true"] .msm-ring-chalk { opacity: 0.45; }

/* The desk holds one page torn from the notebook, taped at its four corners. */
.msm-desk { grid-area: desk; position: relative; min-height: 0; padding: 8px 6px 4px; }
.msm-page {
  position: relative;
  display: grid;
  grid-template-columns: var(--msm-margin) minmax(0, 1fr);
  width: 100%;
  height: 100%;
  border: 2px solid var(--ak-ink);
  border-top-width: 0;
  border-radius: 0 0 var(--msm-wobble-2);
  background-color: var(--ak-surface);
  background-image: repeating-linear-gradient(
    to bottom,
    transparent 0 calc(var(--msm-rule) - 1px),
    color-mix(in srgb, var(--ak-ink) 14%, transparent) calc(var(--msm-rule) - 1px) var(--msm-rule)
  );
  background-position: 0 14px;
}
/* The torn top edge. */
.msm-page::before {
  content: '';
  position: absolute;
  left: -2px;
  right: -2px;
  top: -7px;
  height: 8px;
  background:
    linear-gradient(135deg, transparent 50%, var(--ak-surface) 50%) 0 0 / 11px 8px repeat-x,
    linear-gradient(225deg, transparent 50%, var(--ak-surface) 50%) 0 0 / 11px 8px repeat-x;
  pointer-events: none;
}
.msm-tape {
  position: absolute;
  z-index: 3;
  width: 44px;
  height: 16px;
  background: var(--msm-tape);
  clip-path: polygon(3% 8%, 97% 0, 100% 50%, 96% 100%, 2% 92%, 0 45%);
  pointer-events: none;
}
.msm-tape-tl { top: -4px; left: -14px; rotate: -38deg; }
.msm-tape-tr { top: -4px; right: -14px; rotate: 36deg; }
.msm-tape-bl { bottom: -4px; left: -14px; rotate: 34deg; }
.msm-tape-br { bottom: -4px; right: -14px; rotate: -32deg; }

/* The margin: notes in pen beside the double tangerine rule. */
.msm-margin {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 10px 2px 10px 0;
  border-right: 5px double var(--ak-accent);
}
.msm-tally { display: flex; flex-direction: column; gap: 2px; margin: 0; padding: 0; list-style: none; }
.msm-tally li {
  position: relative;
  display: grid;
  place-items: center;
  width: 30px;
  height: 26px;
  font-family: var(--ak-font-display);
  font-size: 16px;
  color: var(--ak-ink-muted);
}
.msm-tally li.is-now { color: var(--ak-ink); }
.msm-tally li.is-now::before {
  content: '';
  position: absolute;
  inset: 0 -1px;
  border: 2px solid var(--ak-accent);
  border-radius: var(--msm-wobble);
  rotate: -8deg;
}
.msm-tally li.is-done { color: var(--ak-ink-muted); text-decoration: line-through 2px var(--ak-ink); }
.msm-tally li.is-done::after {
  content: '';
  position: absolute;
  right: -6px;
  top: 2px;
  width: 9px;
  height: 15px;
  border: solid var(--ak-accent);
  border-width: 0 3px 3px 0;
  rotate: 40deg;
}

.msm-note {
  display: grid;
  place-items: center;
  gap: 1px;
  width: 50px;
  min-height: 54px;
  margin: 0;
  padding: 4px 0 3px;
  border: 2px solid var(--ak-ink);
  border-radius: var(--msm-wobble);
  background: var(--ak-bg);
  color: var(--ak-ink);
  font: 700 12px/1 var(--ak-font-body);
  cursor: pointer;
  touch-action: manipulation;
}
.msm-note:nth-of-type(odd) { rotate: -4deg; }
.msm-note:nth-of-type(even) { rotate: 3deg; }
.msm-note svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.msm-hint { border-color: var(--ak-accent); color: var(--ak-ink); }
.msm-hint svg { stroke: var(--ak-accent); }
.msm-star-spot { position: absolute; left: 50%; bottom: 14px; width: 0; height: 0; }

/* The drawing area: the slip below, the player's ink above. */
.msm-sheetwrap { position: relative; min-width: 0; min-height: 0; overflow: hidden; }
.msm-sheetwrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.msm-ink { touch-action: none; cursor: crosshair; }
.msm.is-resting .msm-ink { cursor: default; }
.msm-cursor {
  position: absolute;
  z-index: 2;
  width: 26px;
  height: 26px;
  margin: -13px 0 0 -13px;
  border: 2px solid var(--ak-accent);
  border-radius: 50%;
  pointer-events: none;
}
.msm-cursor.is-down { background: color-mix(in srgb, var(--ak-accent) 40%, transparent); }
.msm-stamp-layer { position: absolute; inset: 0; pointer-events: none; }
/* The stamp's -8 degrees is painted into its canvas from the machine's own tilt; CSS only animates the drop. */
.msm-stamp { position: absolute; }
.msm-spat { position: absolute; width: 8px; height: 8px; border-radius: 50%; background: var(--ak-accent); opacity: 0.35; }

/* ---- the tool row: tilted paper chips along the bottom edge -------------------------------- */

.msm-dock { grid-area: dock; display: flex; flex-direction: column; gap: 4px; min-width: 0; min-height: 0; }

.msm-tools {
  display: flex;
  flex-wrap: nowrap;
  justify-content: center;
  align-items: center;
  gap: 5px;
  min-width: 0;
  padding: 8px 2px 4px;
  overflow: hidden;
}
.msm-chip {
  --tilt: 0deg;
  position: relative;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 2px;
  min-width: 48px;
  height: 54px;
  margin: 0;
  padding: 3px 7px;
  border: 2px solid var(--ak-ink);
  border-radius: var(--msm-wobble);
  background: var(--ak-bg);
  color: var(--ak-ink);
  font: 700 11px/1.05 var(--ak-font-body);
  text-align: center;
  rotate: var(--tilt);
  cursor: pointer;
  touch-action: manipulation;
}
.msm-chip svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.msm-chip-word { display: block; max-width: 7em; }
.msm-new .msm-chip-word { max-width: 5.2em; }
.msm-chip[aria-pressed="true"]::after,
.msm-chip.is-on::after {
  content: '';
  position: absolute;
  inset: -6px -5px;
  border: 2.5px solid var(--ak-accent);
  border-radius: var(--msm-wobble-2);
  rotate: 5deg;
  pointer-events: none;
}
.msm-chip[aria-disabled="true"] { border-style: dashed; color: var(--ak-ink-muted); border-color: var(--ak-ink-muted); }
.msm-chip[aria-disabled="true"] svg { opacity: 0.6; }

/* Brush sizes are pen strokes of three widths: a different shape from the round colour swatches. */
.msm-chip svg.msm-size-mark { width: 34px; height: 22px; stroke: var(--ak-ink); }
.msm-opt-size[data-size="0"] .msm-size-mark path { stroke-width: 2; }
.msm-opt-size[data-size="1"] .msm-size-mark path { stroke-width: 4.5; }
.msm-opt-size[data-size="2"] .msm-size-mark path { stroke-width: 8; }
.msm-dot-preview { display: block; width: 26px; height: var(--dot, 5px); border-radius: 999px; background: var(--ak-ink); rotate: -12deg; }

.msm-swatch { min-width: 44px; padding: 3px 4px; }
.msm-swatch-dot, .msm-swatch-preview {
  display: block;
  width: 28px;
  height: 28px;
  border: 2px solid var(--ak-ink);
  border-radius: 50% 46% 52% 48% / 48% 52% 46% 50%;
  background: var(--sw, var(--ak-ink));
}
.msm-swatch-preview { width: 22px; height: 22px; }
/* The picked colour gets a pen tick, not just a ring. */
.msm-swatch[aria-pressed="true"]::before {
  content: '';
  position: absolute;
  top: -5px;
  right: 1px;
  z-index: 1;
  width: 9px;
  height: 16px;
  border: solid var(--ak-accent);
  border-width: 0 3.5px 3.5px 0;
  rotate: 40deg;
}

/* Folded row (narrow phones): sizes and colours open in place of the rest of the row. */
.msm-tools[data-mode="all"] .msm-group { display: none; }
.msm-tools[data-mode="folded"][data-open="none"] .msm-opt { display: none; }
.msm-tools[data-mode="folded"][data-open="size"] > :not(.msm-opt-size) { display: none; }
.msm-tools[data-mode="folded"][data-open="colour"] > :not(.msm-swatch) { display: none; }
.msm-tools[data-mode="folded"][data-open="colour"] { gap: 0; padding-inline: 0; }
.msm-tools[data-mode="folded"][data-open="colour"] .msm-swatch { flex: 1 1 0; min-width: 44px; max-width: 64px; }
.msm-tools[data-mode="folded"][data-open="size"] .msm-opt-size { min-width: 64px; }

.msm-tools.is-away { pointer-events: none; }

/* The name field: one ruled line, and a stamp button. */
.msm-namer { display: flex; flex-direction: column; gap: 4px; padding: 4px 4px 0; }
.msm-namer-label { font-family: var(--ak-font-display); font-size: 18px; color: var(--ak-ink); }
.msm-namer-row { display: flex; gap: 10px; align-items: center; }
.msm-name {
  flex: 1 1 auto;
  min-width: 0;
  height: 50px;
  padding: 6px 4px 2px;
  border: 0;
  border-bottom: 3px solid var(--ak-ink);
  border-radius: 0;
  background: transparent;
  color: var(--ak-ink);
  font-family: var(--ak-font-display);
  font-size: 21px;
  user-select: text;
  -webkit-user-select: text;
}
.msm-name::placeholder { color: var(--ak-ink-muted); opacity: 1; }
.msm-name[aria-invalid="true"] { border-bottom-color: var(--ak-accent); border-bottom-style: dashed; }
.msm-namer-note { min-height: 0; margin: 0; font-size: 16px; line-height: 1.3; color: var(--ak-ink); }
.msm-namer-note:empty { display: none; }
.msm-namer-note.is-wrong::before { content: '\2192  '; color: var(--ak-accent); font-weight: 700; }

.msm-btn {
  flex: 0 0 auto;
  min-width: 48px;
  min-height: 50px;
  padding: 6px 18px;
  border: 2.5px solid var(--ak-btn-fill);
  border-radius: var(--msm-wobble);
  background: var(--ak-btn-fill);
  color: var(--ak-btn-ink);
  font-family: var(--ak-font-display);
  font-size: 19px;
  line-height: 1.1;
  rotate: -1.5deg;
  cursor: pointer;
  touch-action: manipulation;
}
.msm-btn-quiet { background: var(--ak-bg); color: var(--ak-ink); border-color: var(--ak-ink); rotate: 1deg; }

.msm-after { display: flex; flex-direction: column; align-items: stretch; gap: 6px; padding: 4px 4px 0; }
.msm-after .msm-btn { align-self: flex-end; }
.msm-says { margin: 0; font-family: var(--ak-font-display); font-size: clamp(16px, 1.6vh + 6px, 19px); line-height: 1.28; letter-spacing: 0.01em; color: var(--ak-ink); }

.msm-kept {
  margin: 0;
  padding: 0 4px;
  overflow: hidden;
  font-size: 13px;
  line-height: 1.3;
  color: var(--ak-ink-muted);
  white-space: nowrap;
  text-overflow: ellipsis;
}
.msm-kept.is-wrong { color: var(--ak-ink); white-space: normal; }
.msm-kept.is-wrong::before { content: '\2192  '; color: var(--ak-accent); font-weight: 700; }

/* ---- the lineup at the end of a sitting ---------------------------------------------------- */

.msm-lineup {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 10px;
  background: var(--ak-surface);
  overflow: hidden auto;
}
.msm-lineup-line { margin: 0; font-family: var(--ak-font-display); font-size: clamp(20px, 3vh + 8px, 30px); text-align: center; rotate: -2deg; }
.msm-lineup-cards {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px 10px;
  width: min(100%, 520px);
  margin: 0;
  padding: 0;
  list-style: none;
}

/* An index card: the painted card, the machine redrawn on it, the name in pen underneath. */
.msm-card {
  --tilt: 0deg;
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 384 / 365;
  margin: 0;
  padding: 0;
  border: 0;
  background: url("art/index-card.png") center / 100% 100% no-repeat;
  rotate: var(--tilt);
}
.msm-card canvas { position: absolute; left: 7%; top: 22%; width: 86%; height: 53%; }
.msm-card-name {
  position: absolute;
  left: 2%;
  right: 2%;
  top: 79%;
  overflow: hidden;
  font-family: var(--ak-font-display);
  font-size: clamp(13px, 1.6vh + 6px, 18px);
  line-height: 1.1;
  text-align: center;
  color: var(--ak-ink);
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}
.msm-star {
  position: absolute;
  left: -26px;
  bottom: 0;
  width: 52px;
  height: 52px;
  pointer-events: none;
}
.msm-star path { fill: none; stroke: var(--ak-accent); stroke-width: 3.2; stroke-linejoin: round; stroke-linecap: round; }
.msm-spark { position: absolute; left: 0; bottom: 24px; width: 3px; height: 12px; border-radius: 2px; background: var(--ak-accent); opacity: 0; pointer-events: none; }
.msm-spark:nth-child(even) { background: var(--ak-ink); }

/* ---- sheets: in-page, never a browser dialog ----------------------------------------------- */

.msm-sheet {
  position: fixed;
  inset: 0;
  z-index: 45;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(14px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--ak-bg) 80%, transparent);
}
.msm-panel {
  position: relative;
  width: min(100%, 440px);
  max-height: 100%;
  overflow: auto;
  padding: 26px 22px 18px;
  border: 2px solid var(--ak-ink);
  border-radius: var(--msm-wobble);
  background-color: var(--ak-bg);
  background-image: repeating-linear-gradient(
    to bottom,
    transparent 0 calc(var(--msm-rule) - 1px),
    color-mix(in srgb, var(--ak-ink) 10%, transparent) calc(var(--msm-rule) - 1px) var(--msm-rule)
  );
  color: var(--ak-ink);
  rotate: -1deg;
}
.msm-panel::before {
  content: '';
  position: absolute;
  top: -1px;
  left: 50%;
  width: 92px;
  height: 20px;
  translate: -50% 0;
  background: var(--msm-tape);
  clip-path: polygon(3% 8%, 97% 0, 100% 50%, 96% 100%, 2% 92%, 0 45%);
  rotate: 3deg;
}
.msm-panel-title { margin: 0 0 8px; font-family: var(--ak-font-display); font-weight: 400; font-size: 24px; line-height: 1.15; }
.msm-panel-text { margin: 0 0 14px; font-size: 17px; line-height: 1.4; }
.msm-panel-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 12px; }
.msm-panel-wide { width: min(100%, 900px); rotate: 0.5deg; }
.msm-panel-card { width: min(100%, 620px); rotate: 0.6deg; }
.msm-drawer-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; }
.msm-drawer-kept { margin: 4px 0 12px; font-size: 14px; color: var(--ak-ink-muted); }
.msm-drawer-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(46%, 150px), 1fr));
  gap: 10px 14px;
  margin: 0;
  padding: 6px 4px 4px;
  list-style: none;
}
.msm-drawer-cards .msm-card { cursor: pointer; }
.msm-drawer-empty { display: grid; justify-items: center; gap: 8px; padding: 10px 0 4px; text-align: center; }
.msm-drawer-empty img { width: min(70%, 240px); height: auto; }
.msm-drawer-empty p { margin: 0; font-size: 17px; }
.msm-card-big { position: relative; width: 100%; aspect-ratio: 4 / 3; max-height: 56dvh; margin: 0 0 10px; border: 2px solid var(--ak-ink); border-radius: var(--msm-wobble-2); background: var(--ak-surface); }
.msm-card-big canvas { position: absolute; inset: 6px; width: calc(100% - 12px); height: calc(100% - 12px); }

/* ---- the guided first round --------------------------------------------------------------- */

.msm-teach { position: fixed; inset: 0; z-index: 33; pointer-events: none; }
.msm-teach-ring {
  position: fixed;
  border: 4px solid var(--ak-accent);
  border-radius: 50%;
}
.msm-teach-arrow { position: fixed; inset: 0; width: 100%; height: 100%; overflow: visible; }
.msm-teach-arrow path { fill: none; stroke: var(--ak-accent); stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; }
.msm-teach-caption {
  position: fixed;
  margin: 0;
  padding: 12px 16px;
  border: 2.5px solid var(--ak-ink);
  border-radius: var(--msm-wobble);
  background: var(--ak-bg);
  color: var(--ak-ink);
  font-size: 18px;
  font-weight: 700;
  line-height: 1.32;
  rotate: -1deg;
}

/* ---- landscape: the page on one side, the question, ring and tools on the other ------------ */

@media (orientation: landscape) {
  .msm {
    grid-template-columns: minmax(0, 1fr) clamp(220px, 33vw, 340px);
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas: "desk top" "desk dock";
    column-gap: 12px;
  }
  .msm-top { grid-template-columns: auto 1fr auto; grid-template-areas: "logo . ring" "ask ask ask"; row-gap: 2px; align-content: start; }
  .msm-ask { font-size: clamp(16px, 2.1vw, 24px); }
  /* Folded tools in landscape: a clear grid of full-size chips, three across, not a squeezed cluster. */
  .msm-tools[data-mode="folded"][data-open="none"] { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; flex: 0 0 auto; }
  .msm-tools[data-mode="folded"][data-open="none"] .msm-chip { width: 100%; min-width: 0; font-size: 12px; }
  .msm-desk { padding: 8px 10px 6px; }
  .msm-dock { justify-content: flex-start; }
  .msm-tools { flex-wrap: wrap; justify-content: flex-start; align-content: flex-start; flex: 1 1 auto; min-height: 0; gap: 8px 6px; padding: 10px 6px 4px; }
  .msm-tools[data-mode="folded"][data-open="colour"] { gap: 6px; padding-inline: 4px; }
  .msm-tools[data-mode="folded"][data-open="colour"] .msm-swatch { flex: 0 0 48px; }
  .msm-namer-row { flex-wrap: wrap; }
  .msm-kept { white-space: normal; }
  .msm-lineup-cards { grid-template-columns: repeat(4, minmax(0, 1fr)); width: min(100%, 760px); }
}

@media (orientation: landscape) and (max-height: 500px) {
  .msm-logo { height: 28px; }
  .msm-top { min-height: 0; }
  .msm-ring { width: 50px; height: 50px; }
  .msm-ring svg { width: 44px; height: 44px; }
  .msm-tally li { height: 22px; font-size: 14px; }
  .msm-margin { gap: 6px; padding-top: 6px; }
  .msm-note { min-height: 50px; }
  .msm-chip { height: 50px; }
  .msm-lineup { gap: 4px; }
  .msm-lineup-line { font-size: 20px; }
  .msm-brief { font-size: 13px; }
  .msm-toolnote { font-size: 13px; }
  .msm-kept { font-size: 12px; white-space: nowrap; }
  .msm-lineup-notes { font-size: 13px; }
  .msm-lineup-notes .msm-teaser { font-size: 15px; }
}

@media (orientation: portrait) and (max-width: 380px) {
  :root { --msm-margin: 56px; }
  .msm-chip { padding-inline: 5px; }
}

/* ---- motion, only for those who want it --------------------------------------------------- */

@media (prefers-reduced-motion: no-preference) {
  :root:not(.ac-still) .msm-chip,
  :root:not(.ac-still) .msm-note,
  :root:not(.ac-still) .msm-btn,
  :root:not(.ac-still) .msm-ring {
    transition: scale 0.22s var(--msm-spring), rotate 0.22s var(--msm-spring), translate 0.32s var(--msm-out), opacity 0.25s ease;
  }
  :root:not(.ac-still) .msm-chip:active,
  :root:not(.ac-still) .msm-note:active,
  :root:not(.ac-still) .msm-btn:active { scale: 0.88 1.06; }
  :root:not(.ac-still) .msm-ring:active { scale: 0.9; }
  :root:not(.ac-still) .msm-chip.is-tapped { animation: msm-squash 0.36s var(--msm-spring); }
  @media (hover: hover) {
    :root:not(.ac-still) .msm-chip:hover,
    :root:not(.ac-still) .msm-note:hover { translate: 0 -3px; }
    :root:not(.ac-still) .msm-btn:hover { rotate: 1.5deg; scale: 1.04; }
  }

  /* The slip skids in and settles with a wobble. */

  /* The tool chips fold down off the bottom edge like a shuffled deck, and deal back in. */
  :root:not(.ac-still) .msm-tools .msm-chip { transition-delay: calc(var(--i, 0) * 28ms); }
  :root:not(.ac-still) .msm-tools.is-away .msm-chip { translate: 0 150%; rotate: calc(var(--tilt) * -5); opacity: 0; transition-duration: 0.34s; transition-timing-function: cubic-bezier(0.5, -0.4, 0.8, 0.6); }
  :root:not(.ac-still) .msm-tools.is-dealing .msm-chip { animation: msm-deal 0.42s var(--msm-spring) both; animation-delay: calc(var(--i, 0) * 26ms); }
  :root:not(.ac-still) .msm-tools[data-mode="folded"]:not([data-open="none"]) .msm-opt { animation: msm-deal 0.3s var(--msm-spring) both; animation-delay: calc(var(--j, 0) * 22ms); }

  :root:not(.ac-still) .msm-namer:not([hidden]),
  :root:not(.ac-still) .msm-after:not([hidden]) { animation: msm-rise 0.4s var(--msm-spring) both; }

  /* The stamp drops in, thunks at -8 degrees, and leaves a faint ink spatter. */
  :root:not(.ac-still) .msm-stamp.is-pressing { animation: msm-thunk 0.62s cubic-bezier(0.3, 0.9, 0.4, 1.1) both; }
  :root:not(.ac-still) .msm-spat { animation: msm-spat 0.5s ease-out both; animation-delay: 0.36s; }
  :root:not(.ac-still) .msm-sheetwrap.is-thunked { animation: msm-jolt 0.3s ease-out 0.36s; }

  :root:not(.ac-still) .msm-ring.is-closing { animation: msm-ringpop 0.5s var(--msm-spring); }
  :root:not(.ac-still) .msm-ring:not([aria-disabled="true"]) svg { animation: msm-idle-tilt 5s ease-in-out infinite; }
  :root:not(.ac-still) .msm-ask.is-new { animation: msm-pop 0.5s var(--msm-spring); }
  :root:not(.ac-still) .msm-name.is-shaking { animation: msm-shake 0.4s ease; }

  /* Idle: the margin notes bob, the logo sways, the hint glints. */
  :root:not(.ac-still) .msm-note { animation: msm-bob 4.2s ease-in-out infinite; }
  :root:not(.ac-still) .msm-note:nth-of-type(even) { animation-delay: -2.1s; }
  :root:not(.ac-still) .msm-logo { animation: msm-sway 6s ease-in-out infinite; }
  :root:not(.ac-still) .msm-teach-ring { animation: msm-pulse 1.3s ease-in-out infinite; }
  :root:not(.ac-still) .msm-teach-caption { animation: msm-rise 0.4s var(--msm-spring) both; }

  /* Win: the four cards riffle into a row; a doodled star spins into the margin. */
  :root:not(.ac-still) .msm-lineup-cards > li { animation: msm-riffle 0.62s var(--msm-spring) both; animation-delay: calc(var(--i, 0) * 120ms); }
  :root:not(.ac-still) .msm-star { animation: msm-star 0.7s var(--msm-spring) both; animation-delay: 0.7s; }
  :root:not(.ac-still) .msm-spark { animation: msm-spark 0.8s var(--msm-out) both; animation-delay: 0.85s; }
  :root:not(.ac-still) .msm-lineup-line { animation: msm-rise 0.45s var(--msm-spring) both; }

  /* Drawer cards tilt when tapped, then lift out to full size. */
  :root:not(.ac-still) .msm-card.is-lifting { animation: msm-lift 0.34s var(--msm-out) both; }
  :root:not(.ac-still) .msm-drawer-cards > li { animation: msm-riffle 0.5s var(--msm-spring) both; animation-delay: calc(var(--i, 0) * 45ms); }
  :root:not(.ac-still) .msm-sheet:not([hidden]) .msm-panel { animation: msm-drop 0.38s var(--msm-spring) both; }
}

@keyframes msm-deal {
  0% { translate: 0 120%; rotate: calc(var(--tilt) * 4); opacity: 0; }
  70% { translate: 0 -8%; opacity: 1; }
  100% { translate: 0 0; rotate: var(--tilt); opacity: 1; }
}
@keyframes msm-squash {
  0% { scale: 1; }
  30% { scale: 1.12 0.86; }
  60% { scale: 0.94 1.08; }
  100% { scale: 1; }
}
@keyframes msm-rise {
  from { translate: 0 18px; opacity: 0; }
  to { translate: 0 0; opacity: 1; }
}
@keyframes msm-thunk {
  0% { scale: 2.4; rotate: -12deg; opacity: 0; }
  58% { scale: 0.9; rotate: 0deg; opacity: 1; }
  76% { scale: 1.06 0.96; }
  100% { scale: 1; rotate: 0deg; opacity: 1; }
}
@keyframes msm-spat {
  from { scale: 0; opacity: 0; }
  40% { scale: 1.3; opacity: 0.9; }
  to { scale: 1; opacity: 0.35; }
}
@keyframes msm-jolt {
  0%, 100% { translate: 0 0; }
  35% { translate: 0 3px; }
  70% { translate: 0 -1px; }
}
@keyframes msm-ringpop {
  0% { scale: 1; }
  40% { scale: 1.3; rotate: 12deg; }
  100% { scale: 1; rotate: 0deg; }
}
@keyframes msm-idle-tilt {
  0%, 100% { rotate: -3deg; }
  50% { rotate: 3deg; }
}
@keyframes msm-pop {
  0% { scale: 1; }
  40% { scale: 1.08 0.94; }
  100% { scale: 1; }
}
@keyframes msm-shake {
  0%, 100% { translate: 0 0; }
  20% { translate: -7px 0; }
  45% { translate: 6px 0; }
  70% { translate: -3px 0; }
}
@keyframes msm-bob {
  0%, 100% { translate: 0 0; }
  50% { translate: 0 -3px; }
}
@keyframes msm-sway {
  0%, 100% { rotate: -3deg; }
  50% { rotate: -1deg; }
}
@keyframes msm-pulse {
  0%, 100% { scale: 1; opacity: 1; }
  50% { scale: 1.14; opacity: 0.65; }
}
@keyframes msm-riffle {
  0% { translate: var(--from-x, -40%) 90%; rotate: -24deg; opacity: 0; }
  65% { translate: 0 -7%; rotate: calc(var(--tilt, 0deg) + 4deg); opacity: 1; }
  100% { translate: 0 0; rotate: var(--tilt, 0deg); opacity: 1; }
}
@keyframes msm-star {
  0% { scale: 0; rotate: -220deg; opacity: 0; }
  65% { scale: 1.3; rotate: 18deg; opacity: 1; }
  100% { scale: 1; rotate: 0deg; opacity: 1; }
}
@keyframes msm-spark {
  0% { translate: 0 0; scale: 0.4; opacity: 1; }
  100% { translate: var(--dx) var(--dy); scale: 1; opacity: 0; }
}
@keyframes msm-lift {
  0% { rotate: var(--tilt); scale: 1; }
  45% { rotate: calc(var(--tilt) + 6deg); scale: 1.04; }
  100% { rotate: 0deg; scale: 1.18; opacity: 0.2; }
}
@keyframes msm-drop {
  from { translate: 0 -26px; rotate: -5deg; opacity: 0; }
}

/* ---- the drawer on the start screen: the last twelve machines, filed under the brief ---------- */

.msm-start-drawer {
  margin: 28px 0 8px;
  padding: 16px 4px 4px;
  border-top: 2px dashed var(--ak-ink-muted);
  text-align: left;
}
.msm-start-drawer h2 { margin: 0 0 2px; font-family: var(--ak-font-display); font-weight: 400; font-size: 24px; color: var(--ak-ink); rotate: -1.5deg; }
.msm-start-drawer p { margin: 0 0 10px; font-family: var(--ak-font-body); font-size: 14px; color: var(--ak-ink-muted); }
.msm-start-drawer ol {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(30%, 128px), 1fr));
  gap: 8px 12px;
  margin: 0;
  padding: 4px 2px;
  list-style: none;
}
.msm-start-drawer .msm-card { cursor: pointer; }
.msm-start-drawer .msm-card-name { font-size: 13px; }

/* An empty page at the ring: what the red scribble is, and a way to move on. */
.msm-namer-empty { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; }
.msm-namer-empty p { flex: 1 1 16em; margin: 0; font-size: 15px; line-height: 1.3; color: var(--ak-ink); }
.msm-namer-empty .msm-btn { font-size: 16px; min-height: 48px; }
.msm-start-streak { color: var(--ak-ink) !important; font-weight: 700; }
@media (prefers-reduced-motion: no-preference) {
  :root:not(.ac-still) .msm-brief.is-new { animation: msm-brief-in 0.6s var(--msm-spring) both; }
}
@keyframes msm-brief-in {
  0% { translate: -14px 0; scale: 0.9; opacity: 0; }
  60% { translate: 2px 0; scale: 1.04; opacity: 1; }
  100% { translate: 0 0; scale: 1; opacity: 1; }
}

/* The lineup carries more notes now: tighter type and cards so the whole of it fits the page unscrolled. */
.msm-lineup { gap: 6px; padding: 8px; }
.msm-lineup-line { font-size: clamp(17px, 1.6vh + 8px, 24px); line-height: 1.15; max-width: 24ch; }
.msm-lineup-cards { width: min(100%, 52dvh, 460px); gap: 2px 10px; }
.msm-lineup-notes { font-size: 14px; line-height: 1.25; }
.msm-lineup-notes .msm-teaser { font-size: 15px; }
.msm-lineup .msm-btn { min-height: 48px; font-size: 18px; }
@media (orientation: landscape) {
  .msm-lineup-cards { width: min(100%, 92dvh, 700px); }
  .msm-lineup-line { max-width: none; }
}
@media (orientation: landscape) {
  /* Sideways: the four cards two by two on the left; the notes and Start another four on the right. */
  .msm-lineup {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-rows: auto 1fr auto;
    grid-template-areas: "line line" "cards notes" "cards again";
    align-content: center;
    column-gap: 16px;
    row-gap: 6px;
  }
  .msm-lineup-line { grid-area: line; justify-self: center; }
  .msm-lineup-cards { grid-area: cards; grid-template-columns: repeat(2, minmax(0, 1fr)); width: min(100%, 60dvh, 420px); justify-self: center; align-self: center; }
  .msm-lineup-notes { grid-area: notes; align-self: end; text-align: left; max-width: 34ch; font-size: 13px; }
  .msm-lineup-notes .msm-teaser { font-size: 14px; }
  .msm-lineup .msm-again { grid-area: again; justify-self: start; align-self: start; }
}

/* Time's up: a pen-written note pinned at the top of the page until the machine is stamped. */
.msm-pensdown {
  position: absolute;
  z-index: 3;
  top: 10px;
  left: 50%;
  margin: 0;
  padding: 6px 16px;
  border: 2.5px solid var(--ak-accent);
  border-radius: var(--msm-wobble);
  background: var(--ak-bg);
  color: var(--ak-ink);
  font-family: var(--ak-font-display);
  font-size: clamp(18px, 2vh + 8px, 24px);
  white-space: nowrap;
  translate: -50% 0;
  rotate: -3deg;
  pointer-events: none;
}
.msm-progress-note { margin: 0; font-size: 15px; line-height: 1.3; color: var(--ak-ink-muted); }
.msm-progress-note.is-title { color: var(--ak-ink); font-weight: 700; }
.msm-progress-note.is-title::before { content: ''; display: inline-block; width: 12px; height: 12px; margin-right: 6px; border: 2.5px solid var(--ak-accent); rotate: 45deg; vertical-align: -1px; }
@media (prefers-reduced-motion: no-preference) {
  :root:not(.ac-still) .msm-pensdown:not([hidden]) { animation: msm-pens 0.5s var(--msm-spring) both; }
  :root:not(.ac-still) .msm-ring.is-late svg { animation: msm-late 0.9s ease-in-out infinite; }
  :root:not(.ac-still) .msm-namer:not([hidden]) .msm-stamp-it { animation: msm-nudge 2.4s ease-in-out 1.2s infinite; }
}
/* Without motion the late ring still reads: its chalk circle turns tangerine. */
.msm-ring.is-late .msm-ring-chalk { stroke: var(--ak-accent); }
@keyframes msm-pens {
  0% { scale: 1.8; opacity: 0; rotate: -12deg; }
  60% { scale: 0.94; opacity: 1; rotate: -2deg; }
  100% { scale: 1; rotate: -3deg; }
}
@keyframes msm-late {
  0%, 100% { scale: 1; }
  50% { scale: 1.14; }
}
@keyframes msm-nudge {
  0%, 80%, 100% { translate: 0 0; }
  86% { translate: 0 -4px; }
  92% { translate: 0 1px; }
}

/* Before the brief has been read, nothing of the play screen shows: the opening comes first. */
html.msm-waiting .msm { visibility: hidden; }

/* The ring is a countdown: the tangerine arc is the time left, and the word says what the ring is. */
.msm-ring-word { fill: var(--ak-ink); font-family: var(--ak-font-display); font-size: 21px; }
.msm-ring[aria-disabled="true"] .msm-ring-word { fill: var(--ak-ink-muted); }

/* Secondary controls step back: the margin notes are pen marks, not paper chips, and the tape is small. */
.msm-note {
  border: 2px dashed color-mix(in srgb, var(--ak-ink) 55%, transparent);
  background: transparent;
  font-weight: 700;
}
.msm-hint { border-color: var(--ak-accent); border-style: dashed; }
.msm-tape { width: 34px; height: 13px; }
.msm-tape-tl { top: -3px; left: -10px; }
.msm-tape-tr { top: -3px; right: -10px; }
.msm-tape-bl { bottom: -3px; left: -10px; }
.msm-tape-br { bottom: -3px; right: -10px; }

/* A stamped machine is a print on the wall: the page tilts a little, a pin goes in, its name is lettered on it. */
.msm-page { transition: rotate 0.45s var(--msm-spring); }
.msm-page.is-print { rotate: -1.2deg; }
.msm-page.is-print::after {
  content: '';
  position: absolute;
  z-index: 5;
  top: -9px;
  left: 50%;
  width: 18px;
  height: 18px;
  border: 2px solid var(--ak-ink);
  border-radius: 50%;
  background: var(--ak-accent);
  translate: -50% 0;
}
.msm-print-name {
  position: absolute;
  z-index: 3;
  top: 8px;
  left: 10px;
  right: 10px;
  margin: 0;
  pointer-events: none;
  font-family: var(--ak-font-display);
  font-size: clamp(20px, 2.4vh + 6px, 28px);
  line-height: 1.1;
  color: var(--ak-ink);
  rotate: -1.5deg;
  transform-origin: left top;
}
.msm-print-name::after {
  content: '';
  display: block;
  width: min(100%, 12em);
  height: 3px;
  margin-top: 3px;
  border-radius: 2px;
  background: var(--ak-accent);
}
.msm-print-date { font-family: var(--ak-font-body); font-size: 14px; font-weight: 700; color: var(--ak-ink-muted); }
@media (prefers-reduced-motion: no-preference) {
  :root:not(.ac-still) .msm-print-name:not([hidden]) { animation: msm-letter 0.6s var(--msm-out) 0.5s both; }
}
:root.ac-still .msm-page { transition: none; }
@keyframes msm-letter {
  from { clip-path: inset(0 100% 0 0); }
  to { clip-path: inset(0 0 0 0); }
}
