/* Cube Camp: minimal line. One line weight, one accent (gold) only on what can be acted on. */

:root {
  --line: 2px;
  --gold: var(--ak-accent-2);
  --ink: var(--ak-ink);
  --muted: var(--ak-ink-muted);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --grid: min(calc(100dvw - 80px), max(calc(100dvh - 580px - var(--safe-t) - var(--safe-b)), 240px), 460px);
  --ring: 0.095;
  --slow: 520ms;
  /* A second cream wash over the painted tent, so the board, not the backdrop, holds the eye. */
  --quiet: color-mix(in srgb, var(--ak-bg) 62%, transparent);
}

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

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

body {
  min-height: 100dvh;
  background-color: var(--ak-bg);
  background-image: linear-gradient(var(--quiet), var(--quiet)), var(--ak-backdrop-layer, var(--ak-bg-art));
  background-size: var(--ak-bg-size);
  background-size: cover;
  background-position: top center;
  background-repeat: no-repeat;
  color: var(--ink);
  font-family: var(--ak-font-body);
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
  color: inherit;
}

button:focus-visible {
  outline: var(--line) solid var(--ak-focus);
  outline-offset: 3px;
}

[hidden] {
  display: none !important;
}

/* The ending wash: stripes and lights fade back to cream. */
.veil {
  position: fixed;
  inset: 0;
  z-index: 0;
  background: var(--ak-bg);
  opacity: 0;
  pointer-events: none;
}

.lights,
.mute {
  visibility: hidden;
}

body.is-playing .lights,
body.is-playing .mute {
  visibility: visible;
}

.lights {
  position: fixed;
  top: var(--safe-t);
  left: 0;
  z-index: 1;
  width: 100%;
  height: 24px;
  pointer-events: none;
  overflow: visible;
}

.lights .wire {
  fill: none;
  stroke: var(--ink);
  stroke-width: 1;
  opacity: 0.45;
}

.lights .bulb {
  fill: var(--ak-bg);
  stroke: var(--ink);
  stroke-width: 1.25;
}

.lights .bulb.is-lit {
  fill: var(--gold);
  stroke: var(--gold);
}

/* Mute: top left, so the ? corner stays clear. */
.mute {
  position: fixed;
  top: max(12px, var(--safe-t));
  left: max(12px, var(--safe-l));
  z-index: 20;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  padding: 0;
  border: var(--line) solid var(--gold);
  border-radius: 50%;
  background: var(--ak-bg);
  cursor: pointer;
  touch-action: manipulation;
}

.mute svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: var(--ink);
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.mute .mute-off,
.mute[aria-pressed='true'] .mute-on {
  display: none;
}

.mute[aria-pressed='true'] .mute-off {
  display: inline;
}

/* Layout: upright, the board sits above the controls. */
.app {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-areas:
    'head'
    'stage'
    'side';
  grid-template-rows: auto auto 1fr;
  justify-items: center;
  min-height: 100dvh;
  padding:
    var(--safe-t)
    max(12px, var(--safe-r))
    max(12px, var(--safe-b))
    max(12px, var(--safe-l));
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.head {
  grid-area: head;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 2px;
  padding: 22px 60px 0;
}

.logo {
  display: block;
  height: 38px;
  width: auto;
  max-width: 100%;
}

.stage {
  grid-area: stage;
  padding: calc(var(--grid) * var(--ring));
}

.board {
  --n: 5;
  position: relative;
  width: var(--grid);
  height: var(--grid);
}

.ring {
  position: absolute;
  inset: calc(var(--ring) * -100%);
  width: calc(100% + var(--ring) * 200%);
  height: calc(100% + var(--ring) * 200%);
  overflow: visible;
  pointer-events: none;
}

/* The sawdust ring: a faint chalk line, so the squares lead. */
.ring circle {
  fill: none;
  stroke: var(--ink);
  stroke-width: 1px;
  vector-effect: non-scaling-stroke;
  opacity: 0.28;
}

.marks {
  position: absolute;
  inset: 0;
  z-index: 2;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}

.marks * {
  vector-effect: non-scaling-stroke;
  fill: none;
  stroke-width: var(--line);
  stroke-linecap: round;
  stroke-linejoin: round;
}

.marks .gridline {
  stroke: var(--ink);
  opacity: 0.7;
}

.marks .blocker {
  stroke: var(--ink);
}

.marks .invite {
  stroke: var(--gold);
  stroke-dasharray: 5 5;
}

.marks .flag {
  stroke: var(--gold);
  stroke-width: 3px;
}

.marks .flag.is-lonely {
  stroke-dasharray: 4 4;
}

/* A spark: a zigzag in a small circle on the side a campfire and a cabin share. */
.marks .spark {
  fill: var(--ak-bg);
  stroke: var(--ink);
}

.marks .spark-bolt {
  stroke: var(--ink);
  stroke-width: 2.4px;
}

.marks .flag-edge {
  stroke: var(--ink);
  stroke-width: 1px;
}

.marks .stitch {
  stroke: var(--gold);
}

.marks .stitch.is-flash {
  opacity: 0;
}

.grid {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(var(--n), 1fr);
  grid-template-rows: repeat(var(--n), 1fr);
}

.cell {
  position: relative;
  display: block;
  min-width: 0;
  min-height: 0;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  touch-action: none;
}

.cell.is-blocked {
  cursor: not-allowed;
}

.cell:focus-visible {
  outline-offset: -6px;
}

/* The square under a dragged cube. */
.cell.is-target::after {
  content: '';
  position: absolute;
  inset: 7%;
  border: var(--line) solid var(--gold);
  pointer-events: none;
}

.cube {
  position: absolute;
  inset: 14%;
  display: block;
  pointer-events: none;
}

.cube img,
.cube .cube-line {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  -webkit-user-drag: none;
}

.cube .cube-line {
  opacity: 0;
  fill: none;
  stroke: var(--ink);
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.cell.is-held .cube {
  opacity: 0.3;
}

.cell.is-picked .cube::after,
.slot.is-picked .slot-cube::after {
  content: '';
  position: absolute;
  inset: -6px;
  border: var(--line) solid var(--gold);
}

.cell.is-picked .cube {
  transform: translateY(-3px);
}

/* The worked step's cubes: shown, not playable. */
.cube.is-example {
  opacity: 0.85;
}

.cube.is-ghost {
  opacity: 0.55;
}

.cube.is-ghost::after {
  content: '';
  position: absolute;
  inset: -6px;
  border: var(--line) dashed var(--gold);
}

/* The plan: where a kind not yet down will start. Fainter than the worked step's ghost. */
.cube.is-plan {
  opacity: 0.4;
}

/* The controls side. */
.side {
  grid-area: side;
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: min(100%, 440px);
  padding-bottom: 4px;
}

.status {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.plot-score {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

/* Each stays on one line; on a narrow side column the score drops below the plot label instead. */
.plot-label,
.plot-score {
  white-space: nowrap;
}

.plot-label,
.teach-label,
.slot-label {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.rules {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.rules li {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  color: var(--ink);
  font-size: 16px;
  line-height: 1.3;
}

.rules b {
  font-weight: 700;
}

.app.is-teaching .status {
  display: none;
}

.rules svg {
  flex: none;
  width: 52px;
  height: 20px;
  fill: none;
  stroke: var(--ink);
  stroke-width: 1.4;
  stroke-linejoin: round;
}

.rules .blocked-icon {
  height: 22px;
  overflow: visible;
}

.rules .blocked-icon * {
  vector-effect: non-scaling-stroke;
  stroke-width: 1.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.rule-pics {
  display: flex;
  flex: none;
  align-items: center;
  width: 62px;
  height: 28px;
}

.rule-pics img {
  display: block;
  width: 28px;
  height: 28px;
}

.rule-pics .pic-link {
  flex: 1;
  height: 0;
  border-top: var(--line) solid var(--gold);
}

/* The same spark the board draws, set on the side the two cubes share. */
.rules .rule-pics .pic-spark {
  position: relative;
  z-index: 1;
  width: 16px;
  height: 16px;
  margin: 0 -5px;
  overflow: visible;
}

.rules .pic-spark circle {
  fill: var(--ak-bg);
  stroke: var(--ink);
  stroke-width: 0.14;
}

.rules .pic-spark path {
  stroke: var(--ink);
  stroke-width: 0.24;
  stroke-linecap: round;
}

.rule-text {
  min-width: 0;
}

/*
 * After a failed check: a kept rule gets a tick; a broken one swaps its picture for the mark the
 * board uses (dashed ring: no buddy, spark: campfire touching cabin) and says how to fix it.
 */
.rules .rule-mark,
.rules .rule-flag {
  display: none;
  flex: none;
}

.rules .rule-mark {
  width: 20px;
  height: 20px;
  margin: 4px -2px 0;
  stroke: var(--ink);
  stroke-width: 2.4;
  stroke-linecap: round;
}

.rule.is-kept .rule-mark,
.rule.is-broken .rule-flag {
  display: block;
}

.rule.is-broken .rule-pics {
  display: none;
}

.rules .rule-flag {
  width: 30px;
  height: 30px;
  overflow: visible;
}

.rule-flag .flag-ring {
  stroke: var(--gold);
  stroke-width: 2;
  stroke-dasharray: 3 3;
}

.rule-flag .flag-cube {
  stroke: var(--ink);
  stroke-width: 1.4;
}

.rule-flag .spark-ring {
  fill: var(--ak-bg);
  stroke: var(--ink);
  stroke-width: 0.1;
}

.rule-flag .spark-bolt {
  stroke: var(--ink);
  stroke-width: 0.2;
  stroke-linecap: round;
}

.rule.is-kept {
  color: var(--muted);
}

.say.is-quiet {
  position: absolute;
  width: 1px;
  height: 1px;
  min-height: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.rule.is-broken .rule-text {
  font-weight: 600;
}

/* While a cube is in hand: a gold square holding a faded copy of it = a buddy next door,
   x = it would touch the wrong kind. Nothing is marked until a cube is picked. */
.marks .hint-ghost {
  opacity: 0.42;
}

.marks .hint-link {
  stroke: var(--gold);
  stroke-width: 2.5px;
}

.marks .hint-open {
  stroke: var(--gold);
  stroke-width: 1.5px;
}

/* A buddy square is the one to use: bold. Any other free square stays faint. */
.marks .hint-open.is-buddy {
  stroke-width: 3px;
}

.marks .hint-open.is-quiet {
  stroke-width: 1px;
  opacity: 0.4;
}

.marks .hint-clash {
  stroke: var(--ink);
  stroke-width: var(--line);
}

.rules svg .gold {
  stroke: var(--gold);
  stroke-width: 2;
}

.say {
  display: flex;
  gap: 8px;
  min-height: 2.8em;
  margin: 0;
  color: var(--ink);
  font-size: 16px;
  line-height: 1.4;
}

/* Undo, offered inside the sentence that explains a move worth taking back. */
.say-undo {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  margin: 0 2px;
  padding: 0 10px;
  border: var(--line) solid var(--gold);
  border-radius: 2px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-weight: 700;
  vertical-align: middle;
  cursor: pointer;
  touch-action: manipulation;
}

.say.is-wrong::before {
  content: '';
  flex: none;
  width: 14px;
  height: 14px;
  margin-top: 0.2em;
  border: var(--line) solid var(--ak-accent);
  border-radius: 50%;
  background:
    linear-gradient(var(--ak-accent), var(--ak-accent)) center 3px / 2px 5px no-repeat,
    linear-gradient(var(--ak-accent), var(--ak-accent)) center 9px / 2px 2px no-repeat;
}

/* Worked example caption: solid backing, big Got it. */
.teach {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px;
  border: var(--line) solid var(--ink);
  background: var(--ak-bg);
}

.teach-text {
  margin: 0;
  color: var(--ink);
  font-size: 19px;
  line-height: 1.4;
}

/* The board marks, small, so words can point at them. */
.ico {
  display: inline-block;
  width: 1.45em;
  height: 1.2em;
  vertical-align: -0.22em;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  overflow: visible;
}

.ico-free rect,
.ico-dot rect,
.ico-start rect {
  stroke: var(--gold);
  stroke-width: 1.5;
}

.ico-dot rect {
  stroke-width: 2.4;
}

.ico-free rect {
  stroke-width: 1;
  opacity: 0.5;
}

.ico-start rect {
  stroke-dasharray: 3 3;
}

.ico-dot .ico-ghost {
  fill: var(--ak-accent);
  stroke: none;
  opacity: 0.4;
}

.ico-dot path {
  stroke: var(--gold);
  stroke-width: 2.4;
}

.ico-x path {
  stroke: var(--ink);
  stroke-width: 2.2;
}

.ico-wrap {
  white-space: nowrap;
}

.ico-name {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* The four rules, each a tiny board beside one plain sentence: buddies, corners, sparks, gardens. */
.teach-rules {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.teach-rules li {
  display: grid;
  grid-template-columns: 84px 1fr;
  align-items: center;
  gap: 10px;
}

.rule-say {
  color: var(--ink);
  font-size: 17px;
  line-height: 1.3;
}

.rule-say b {
  font-weight: 700;
}

.mini {
  position: relative;
  justify-self: start;
  display: grid;
  grid-template-columns: repeat(2, 26px);
  grid-template-rows: repeat(2, 26px);
  border: 1px solid var(--ink);
  background:
    linear-gradient(var(--ink), var(--ink)) center / 1px 100% no-repeat,
    linear-gradient(var(--ink), var(--ink)) center / 100% 1px no-repeat;
}

.mini img {
  display: block;
  width: 22px;
  height: 22px;
  margin: 2px;
}

.mini-link {
  grid-area: 1 / 1 / 2 / 3;
  align-self: center;
  justify-self: center;
  z-index: 1;
  width: 8px;
  border-top: 2.5px solid var(--gold);
}

.mini-spark {
  position: absolute;
  top: 6px;
  left: 18px;
  width: 16px;
  height: 16px;
  overflow: visible;
}

.mini-spark circle {
  fill: var(--ak-bg);
  stroke: var(--ink);
  stroke-width: 0.14;
}

.mini-spark path {
  fill: none;
  stroke: var(--ink);
  stroke-width: 0.24;
  stroke-linecap: round;
}

.mini-mark {
  position: absolute;
  right: -26px;
  bottom: -2px;
  width: 22px;
  height: 22px;
  fill: none;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.mini-mark.is-yes {
  stroke: var(--ink);
}

.mini-mark.is-no {
  stroke: var(--ak-accent);
}

.teach-text .ico-slot {
  font-size: 20px;
}

.got-it {
  min-height: 56px;
  border: var(--line) solid var(--ink);
  background: var(--gold);
  color: var(--ink);
  font-size: 20px;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}

.play {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* The three steps of a move, always shown; the one to do now is in ink, the others fade back. */
.steps {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  margin: 0 0 -6px;
  padding: 0;
  list-style: none;
  counter-reset: step;
}

.steps li {
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  counter-increment: step;
}

.steps li::before {
  content: counter(step);
  display: grid;
  place-items: center;
  width: 17px;
  height: 17px;
  border: 1px solid currentColor;
  border-radius: 50%;
  font-size: 10px;
  letter-spacing: 0;
}

.steps li.is-now {
  color: var(--ink);
}

.steps li.is-now::before {
  border-width: 2px;
}

/* What each mark on the plot means, kept in view the whole time. */
.key {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 12px;
  margin: 0;
  padding: 0;
  list-style: none;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.key li {
  display: flex;
  align-items: center;
  gap: 4px;
}

.key .ico-slot {
  font-size: 14px;
}

.key-plan {
  width: 15px;
  height: 15px;
  opacity: 0.4;
}

/* The ending's three stars: solid navy when won, a dashed outline when missed. Gold stays for buttons. */
.end-stars {
  display: flex;
  justify-content: center;
  gap: 14px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.end-stars li {
  display: flex;
  flex: 0 1 8.5em;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.2;
  text-align: center;
}

.end-stars svg {
  width: 30px;
  height: 30px;
  fill: var(--ink);
  stroke: var(--ink);
  stroke-width: 1.2;
  stroke-linejoin: round;
}

.end-stars li.is-missed {
  color: var(--muted);
}

.end-stars li.is-missed svg {
  fill: none;
  stroke: var(--muted);
  stroke-dasharray: 2 2;
}

.tray {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 6px 0;
  border-top: 1px solid color-mix(in srgb, var(--ink) 35%, transparent);
  border-bottom: 1px solid color-mix(in srgb, var(--ink) 35%, transparent);
}

.tray.is-target {
  outline: var(--line) dashed var(--gold);
  outline-offset: 2px;
}

.slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-height: 48px;
  padding: 6px 4px 4px;
  border: 0;
  background: transparent;
  cursor: pointer;
  touch-action: none;
}

.slot-cube {
  position: relative;
  display: block;
  width: 48px;
  height: 48px;
}

.slot-cube img {
  display: block;
  width: 100%;
  height: 100%;
  -webkit-user-drag: none;
  pointer-events: none;
}

/* A cube that can be picked up wears a thin gold outline. */
.slot.has-cubes .slot-cube::before {
  content: '';
  position: absolute;
  inset: -4px;
  border: 1px solid var(--gold);
}

/* The cube the hint wants picked next: a bolder gold outline, breathing where motion is fine. */
.slot.is-invite .slot-cube::before {
  border-width: 2.5px;
}

.slot.is-out .slot-cube {
  border: var(--line) dashed color-mix(in srgb, var(--ink) 40%, transparent);
}

.slot.is-out .slot-cube img {
  display: none;
}

/* The picked cube: a thick gold frame, lifted, named; the others step back. */
.slot.is-picked .slot-cube {
  transform: translateY(-5px);
}

.slot.is-picked .slot-cube::after {
  inset: -7px;
  border-width: 3px;
}

.tray.has-pick .slot:not(.is-picked) {
  opacity: 0.5;
}

.slot.is-picked .slot-label .kind {
  color: var(--ink);
}

.slot-label b {
  color: var(--ink);
  font-size: 15px;
  font-weight: 700;
}

/* Pinned: Undo and Check on the bottom edge, under the side column, when their own spot is off screen. */
.app.is-pinned .acts {
  position: fixed;
  bottom: 0;
  left: var(--acts-x, 0px);
  z-index: 30;
  width: var(--acts-w, 100%);
  padding: 8px 0 max(8px, var(--safe-b));
  border-top: 1px solid color-mix(in srgb, var(--ink) 35%, transparent);
  background: var(--ak-bg);
}

.app.is-pinned .side {
  padding-bottom: calc(var(--acts-h, 64px) + 8px);
}

.acts,
.end-acts {
  display: flex;
  gap: 10px;
}

.act {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 48px;
  padding: 0 16px;
  border: var(--line) solid var(--gold);
  border-radius: 2px;
  background: transparent;
  color: var(--ink);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}

.act svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.act:disabled,
.act[aria-disabled='true'] {
  border-style: dashed;
  border-color: color-mix(in srgb, var(--ink) 35%, transparent);
  color: var(--muted);
}

.act:disabled {
  cursor: default;
}

.act.check {
  flex: 1;
}

.act.check:not([aria-disabled='true']) {
  background: var(--gold);
  border-color: var(--ink);
}

.end {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 8px 0;
}

/* What this plot came to, in tiny caps above the one sentence that stays. */
.end-tag {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.16em;
  line-height: 1.5;
  text-align: center;
  text-transform: uppercase;
  white-space: pre-line;
}

.end-line {
  margin: 0;
  color: var(--ink);
  font-size: 22px;
  line-height: 1.35;
  text-align: center;
}

.end-acts {
  flex-wrap: wrap;
}

.end-acts .act {
  flex: 1 1 8em;
}

.drag-ghost {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 50;
  pointer-events: none;
}

.drag-ghost img {
  display: block;
  width: 100%;
  height: 100%;
}

/* The ending: everything fades to lines and one sentence remains. */
body.is-lines .veil {
  opacity: 0.94;
}

body.is-lines .lights .bulb {
  fill: var(--ak-bg);
  stroke: var(--ink);
}

body.is-lines .cube img {
  opacity: 0;
}

body.is-lines .cube .cube-line {
  opacity: 1;
}

body.is-lines .marks .stitch {
  stroke: var(--ink);
}

body.is-lines .status,
body.is-lines .play {
  display: none;
}

body.is-lines .logo {
  opacity: 0.4;
}

/* Sideways, the board sits on one side and the controls on the other. */
@media (orientation: landscape) {
  :root {
    --grid: min(calc(100dvh - 76px), 46dvw, 460px);
    /* Sideways the tent folds away to a whisper: two columns on plain cream. */
    --quiet: color-mix(in srgb, var(--ak-bg) 84%, transparent);
  }

  .app {
    grid-template-areas:
      'stage head'
      'stage side';
    grid-template-columns: auto minmax(0, 420px);
    grid-template-rows: auto 1fr;
    justify-content: center;
    align-content: safe center;
    column-gap: clamp(28px, 5dvw, 56px);
    padding-left: max(60px, calc(var(--safe-l) + 52px));
    padding-right: max(12px, var(--safe-r));
  }

  .stage {
    align-self: center;
    padding-top: max(calc(var(--grid) * var(--ring)), 22px);
  }

  .head {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: flex-start;
    justify-self: stretch;
    gap: 2px 14px;
    min-height: calc(64px + var(--safe-t));
    padding: max(18px, var(--safe-t)) 60px 4px 0;
  }

  .logo {
    height: 30px;
  }

  .plot-label,
  .plot-score {
    padding-bottom: 3px;
  }

  .side {
    align-self: start;
    width: 100%;
    gap: 10px;
  }

  .side:has(.end:not([hidden])) {
    align-self: center;
  }

  .slot {
    flex-direction: row;
    justify-content: center;
    gap: 8px;
    padding: 6px 2px;
  }

  .slot-cube {
    width: 44px;
    height: 44px;
  }

  .slot-label {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    letter-spacing: 0.1em;
  }

  .slot-label b {
    font-size: 18px;
    letter-spacing: 0;
  }

  .say {
    min-height: 2.6em;
    font-size: 16px;
    line-height: 1.35;
  }

  .act {
    font-size: 17px;
  }
}

@media (orientation: landscape) and (max-height: 400px) {
  :root {
    --grid: min(calc(100dvh - 90px), 44dvw, 460px);
  }

  .side,
  .play {
    gap: 8px;
  }

  .rules li {
    font-size: 15px;
    line-height: 1.25;
  }

  .say {
    font-size: 15px;
  }

  .app {
    padding-bottom: max(4px, var(--safe-b));
  }

  .teach {
    gap: 6px;
    padding: 10px 12px;
  }

  .teach-text {
    font-size: 18px;
    line-height: 1.3;
  }

  .got-it {
    min-height: 48px;
  }
}

/* A narrow sideways phone: the cube picture names the kind, the big count says how many. */
@media (orientation: landscape) and (max-width: 799px) {
  .slot-label .kind {
    display: none;
  }

  .slot-label b {
    font-size: 20px;
  }

  .slot-label b::before {
    content: '\00D7';
    margin-right: 2px;
    font-weight: 400;
  }
}

@media (orientation: portrait) and (max-height: 760px) {
  .logo {
    height: 32px;
  }

  .teach {
    gap: 6px;
    padding: 10px 14px;
  }

  .teach-text {
    line-height: 1.3;
  }

  .got-it {
    min-height: 50px;
  }

  .side,
  .play {
    gap: 10px;
  }
}

@media (orientation: landscape) and (min-height: 600px) {
  .slot-cube {
    width: 60px;
    height: 60px;
  }
}

@media (orientation: portrait) and (min-height: 900px) {
  .slot-cube {
    width: 60px;
    height: 60px;
  }
}

@media (prefers-reduced-motion: no-preference) {
  .veil,
  .lights .bulb,
  .cube img,
  .cube .cube-line,
  .marks .stitch,
  .logo {
    transition: opacity 1400ms ease, fill 600ms ease, stroke 600ms ease;
  }

  .lights .bulb {
    transition-delay: calc(var(--i, 0) * 70ms);
  }

  body.is-lines .lights .bulb {
    transition-delay: 0ms;
  }

  .slot-cube,
  .cell .cube {
    transition: transform 260ms ease, opacity 260ms ease;
  }

  .cube.is-landing {
    animation: settle var(--slow) cubic-bezier(0.2, 0.7, 0.3, 1) both;
  }

  .cube.is-settling {
    animation: settle var(--slow) cubic-bezier(0.2, 0.7, 0.3, 1) both;
    animation-delay: calc(var(--i, 0) * 90ms);
  }

  .marks .stitch.is-flash {
    animation: stitch 1500ms ease both;
  }

  .marks .stitch.is-drawn {
    stroke-dasharray: 1;
    animation: draw 700ms ease both;
    animation-delay: calc(var(--i, 0) * 60ms);
  }

  .marks .invite,
  .cube.is-next::after,
  .slot.is-invite .slot-cube {
    animation: breathe 2400ms ease-in-out infinite;
  }

  .marks .flag {
    animation: breathe 2400ms ease-in-out infinite;
  }

  .tray.is-nudge,
  .steps.is-nudge {
    animation: nudge 520ms ease both;
  }

  .end:not([hidden]) {
    animation: rise 900ms ease both;
  }

  .drag-ghost {
    transition: none;
  }
}

@keyframes settle {
  0% {
    transform: translateY(-4px) scale(1.05);
    opacity: 0.75;
  }

  100% {
    transform: none;
    opacity: 1;
  }
}

@keyframes stitch {
  0% {
    opacity: 0;
  }

  25%,
  65% {
    opacity: 1;
  }

  100% {
    opacity: 0;
  }
}

@keyframes draw {
  from {
    stroke-dashoffset: 1;
  }

  to {
    stroke-dashoffset: 0;
  }
}

@keyframes nudge {
  0%,
  100% {
    transform: none;
    outline-color: transparent;
  }

  20%,
  60% {
    transform: translateX(-4px);
    outline: var(--line) solid var(--gold);
    outline-offset: 3px;
  }

  40%,
  80% {
    transform: translateX(4px);
    outline: var(--line) solid var(--gold);
    outline-offset: 3px;
  }
}

@keyframes breathe {
  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.45;
  }
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(6px);
  }

  to {
    opacity: 1;
    transform: none;
  }
}

/*
 * The opening screen is start.js's own; these rules only arrange what it draws. The doubled id
 * outranks its layout rules but not its sideways-phone ones, which already lift Play up.
 */

/* The logo, tagline and goal are there from the first frame, never fading in from nothing. */
#activity-start#activity-start.is-instructions,
#activity-start#activity-start .ak-title,
#activity-start#activity-start .ak-logo,
#activity-start#activity-start .ak-section {
  animation: none;
}

#activity-start#activity-start .ak-tagline {
  color: var(--ak-ink);
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.14em;
}

/* Upright: logo, goal, Start here, then Play right under them; controls and tip follow. */
@media (orientation: portrait) {
  #activity-start#activity-start.layout-steps.is-instructions .ak-sheet {
    display: flex;
    flex-direction: column;
    align-items: center;
  }

  #activity-start#activity-start.layout-steps.is-instructions .ak-howto {
    display: contents;
  }

  #activity-start#activity-start.layout-steps.is-instructions .ak-section {
    width: min(100%, 480px);
    text-align: left;
  }

  #activity-start#activity-start.layout-steps.is-instructions .ak-goal {
    order: 1;
    margin-top: var(--ak-space-5);
  }

  #activity-start#activity-start.layout-steps.is-instructions .ak-goal::after {
    display: none;
  }

  #activity-start#activity-start.layout-steps.is-instructions .ak-first {
    order: 2;
    width: min(100%, 480px);
    margin-top: var(--ak-space-5);
  }

  #activity-start#activity-start.layout-steps.is-instructions .ak-go {
    order: 3;
    position: static;
    width: min(100%, 480px);
    margin-top: var(--ak-space-4);
  }

  #activity-start#activity-start.layout-steps.is-instructions .ak-controls-block {
    order: 4;
    margin-top: var(--ak-space-7);
  }

  #activity-start#activity-start.layout-steps.is-instructions .ak-tip {
    order: 5;
    margin-top: var(--ak-space-6);
  }
}

/* Wide: the logo, Start here and Play fill the open left side; the steps sit on the right. */
@media (min-width: 900px) and (min-height: 560px) {
  #activity-start#activity-start.layout-steps.is-instructions .ak-sheet {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-rows: 1fr auto auto auto 1fr;
    grid-template-areas:
      '. howto'
      'head howto'
      'first howto'
      'go howto'
      '. howto';
    column-gap: var(--ak-space-8);
    align-items: center;
    width: min(100%, 1040px);
    min-height: calc(100dvh - 2 * var(--ak-space-6));
  }

  #activity-start#activity-start.layout-steps.is-instructions .ak-head {
    grid-area: head;
  }

  #activity-start#activity-start.layout-steps.is-instructions .ak-logo {
    max-height: 220px;
  }

  #activity-start#activity-start.layout-steps.is-instructions .ak-first {
    grid-area: first;
    margin-top: var(--ak-space-5);
  }

  #activity-start#activity-start.layout-steps.is-instructions .ak-go {
    grid-area: go;
    position: static;
    justify-self: center;
    margin-top: var(--ak-space-5);
  }

  #activity-start#activity-start.layout-steps.is-instructions .ak-howto {
    grid-area: howto;
    width: 100%;
    margin: 0;
  }
}

/* A sideways phone: Play sits right under Start here instead of floating over the goal. */
@media (orientation: landscape) and (max-height: 500px) {
  #activity-start#activity-start.layout-steps.is-instructions .ak-go {
    order: 0;
    position: static;
    align-self: center;
  }
}

/* A sideways phone: the four rules shrink so all of them and Got it fit on one screen. */
@media (orientation: landscape) and (max-height: 500px) {
  .teach {
    gap: 6px;
  }

  .teach-rules {
    gap: 4px;
  }

  .teach-rules li {
    grid-template-columns: 62px 1fr;
    gap: 8px;
  }

  .teach-rules .mini {
    grid-template-columns: repeat(2, 19px);
    grid-template-rows: repeat(2, 19px);
  }

  .teach-rules .mini img {
    width: 16px;
    height: 16px;
    margin: 1.5px;
  }

  .teach-rules .mini-spark {
    top: 4px;
    left: 13px;
    width: 12px;
    height: 12px;
  }

  .teach-rules .mini-mark {
    right: -22px;
    width: 18px;
    height: 18px;
  }

  .rule-say,
  .teach .teach-text {
    font-size: 15px;
    line-height: 1.25;
  }

  .steps {
    gap: 2px 10px;
  }

  .steps li {
    letter-spacing: 0.08em;
  }

  .key {
    gap: 0 10px;
    font-size: 12px;
  }
}
