/* Flag Stripe Swap: a notebook page on a CRT. Ink lines, no filled panels. */

@property --fw {
  syntax: '<length>';
  inherits: true;
  initial-value: 12rem;
}

@property --fh {
  syntax: '<length>';
  inherits: true;
  initial-value: 8.7rem;
}

@property --t {
  syntax: '<length>';
  inherits: true;
  initial-value: 3rem;
}

:root {
  --mg: 2rem;
  --pole: 0.9rem;
  --label: 1.9rem;
  --gap: clamp(0.5rem, 2dvh, 1rem);
  --pen: 2px;
  --seam: color-mix(in srgb, var(--ak-accent-2) 80%, transparent);
  --swap-ms: 280ms;
  --tick-step: 170ms;
}

* {
  box-sizing: border-box;
}

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

body {
  overflow: hidden;
  color: var(--ak-ink);
  font-family: var(--ak-font-body);
  background-color: var(--ak-bg);
  background-image: var(--ak-bg-art), var(--ak-backdrop-layer, none);
  background-size: var(--ak-bg-size), cover, cover;
  background-position: center;
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
  color: inherit;
}

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

/* ---------- page layout: upright ---------- */

.page {
  position: relative;
  display: grid;
  grid-template-columns: var(--mg) minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas:
    "margin top"
    "margin board"
    "margin desk";
  width: 100%;
  max-width: 80rem;
  height: 100dvh;
  margin: 0 auto;
  padding:
    env(safe-area-inset-top)
    calc(env(safe-area-inset-right) + 0.5rem)
    calc(env(safe-area-inset-bottom) + 0.5rem)
    env(safe-area-inset-left);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

/* The CRT scanlines breathe behind everything the player reads. */
.page::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background-image: repeating-linear-gradient(
    0deg,
    color-mix(in srgb, var(--ak-bg) 55%, transparent) 0 1px,
    transparent 1px 3px
  );
  opacity: 0.6;
}

.mute {
  position: fixed;
  top: max(0.75rem, env(safe-area-inset-top));
  left: max(0.5rem, env(safe-area-inset-left));
  z-index: 5;
  display: grid;
  place-items: center;
  width: 3rem;
  height: 3rem;
  padding: 0;
  background: var(--ak-bg);
  border: var(--pen) solid var(--ak-accent-2);
  border-radius: 50%;
  cursor: pointer;
}

.mute svg {
  width: 1.6rem;
  height: 1.6rem;
  fill: none;
  stroke: var(--ak-accent-2);
  stroke-width: 2.4;
  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;
  stroke: var(--ak-btn-fill);
}

/* ---------- the margin: red rule and a doodled arrow ---------- */

.margin {
  grid-area: margin;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding-top: 4rem;
  border-right: var(--pen) solid color-mix(in srgb, var(--ak-btn-fill) 75%, transparent);
}

.margin-doodle {
  width: 1.75rem;
  height: 2.6rem;
  fill: none;
  stroke: var(--ak-ink-muted);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.note-extra {
  display: block;
  margin-top: 0.3rem;
  font-size: 0.92em;
  color: var(--ak-ink);
}

.note-extra:empty {
  display: none;
}

.note-report {
  font-family: var(--ak-font-display);
  font-size: 0.8rem;
  line-height: 1.45;
  letter-spacing: 0.02em;
}

/* ---------- top: the small logo ---------- */

.top {
  grid-area: top;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 3.75rem;
  padding: 0.3rem 3.75rem 0.2rem;
}

.logo {
  display: block;
  height: min(7dvh, 3.5rem);
  width: auto;
  max-width: 100%;
}

/* ---------- the board: graph paper with flags ---------- */

/* ---------- status: one small line above the flags ---------- */

.board-col {
  grid-area: board;
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}

.status {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.1rem 0.6rem;
  margin: 0.1rem 0 0 0.5rem;
  font-size: clamp(0.8rem, 3.7vw, 0.875rem);
  line-height: 1.3;
  color: var(--ak-ink);
}

.status-run {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--ak-ink-muted);
}

/* The first-try streak, kept as pen tally marks; a missed first check scribbles them out. */
.tally {
  width: 0.95rem;
  height: 1.35rem;
  fill: none;
  stroke: var(--ak-ink);
  stroke-width: 3.6;
  stroke-linecap: round;
}

.tally:empty {
  display: none;
}

.tally .scribble {
  stroke: var(--ak-btn-fill);
  stroke-width: 3.4;
}

.board-wrap {
  flex: 1;
  container-type: size;
  padding-top: 0.55rem;
  min-height: 0;
  min-width: 0;
  margin: 0 0 0.25rem 0.5rem;
  background-image:
    repeating-linear-gradient(0deg, color-mix(in srgb, var(--ak-accent) 9%, transparent) 0 1px, transparent 1px 1.5rem),
    repeating-linear-gradient(90deg, color-mix(in srgb, var(--ak-accent) 9%, transparent) 0 1px, transparent 1px 1.5rem);
}

.board {
  --cols: 1;
  --rows: 3;
  --colw: calc((100cqw - (var(--cols) - 1) * var(--gap)) / var(--cols));
  --rowh: calc((100cqh - (var(--rows) - 1) * var(--gap)) / var(--rows));
  --fw: min(calc(var(--colw) - var(--pole)), calc((var(--rowh) - var(--label)) * 1.5), 22rem);
  --fh: min(max(calc(var(--fw) / 1.5), 8.7rem), calc(var(--rowh) - var(--label)));
  display: grid;
  grid-template-columns: repeat(var(--cols), auto);
  gap: var(--gap);
  place-content: center;
  width: 100%;
  height: 100%;
}

.board[data-count="4"] {
  --cols: 2;
  --rows: 2;
}

.board[data-count="6"] {
  --cols: 2;
  --rows: 3;
}

.board.is-teaching {
  pointer-events: none;
}

.flag {
  position: relative;
  display: grid;
  grid-template-rows: var(--fh) var(--label);
  width: calc(var(--fw) + var(--pole));
  margin: 0;
  padding-left: var(--pole);
}

.frame {
  position: relative;
  width: var(--fw);
  height: var(--fh);
}

/* The pen outline of the flag sits over the stripe edges, never across them. */
.frame::after {
  content: "";
  position: absolute;
  inset: calc(var(--pen) * -1);
  z-index: 3;
  pointer-events: none;
  border: var(--pen) solid var(--ak-accent-2);
  border-radius: 1px;
}

.pole {
  position: absolute;
  top: 0.1rem;
  bottom: calc(var(--label) * -0.2);
  left: calc(var(--pole) * -0.7);
  width: 3px;
  background: var(--ak-accent-2);
}

.pole::before {
  content: "";
  position: absolute;
  top: -0.6rem;
  left: -0.3rem;
  width: 0.7rem;
  height: 0.7rem;
  border: var(--pen) solid var(--ak-accent-2);
  border-radius: 50%;
}

.seams {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
}

.seams::before,
.seams::after {
  content: "";
  position: absolute;
}

[data-dir="h"] .seams::before,
[data-dir="h"] .seams::after {
  left: 0;
  right: 0;
  height: 0;
  border-top: var(--pen) dashed var(--seam);
}

[data-dir="h"] .seams::before { top: 33.333%; }
[data-dir="h"] .seams::after { top: 66.666%; }

[data-dir="v"] .seams::before,
[data-dir="v"] .seams::after {
  top: 0;
  bottom: 0;
  width: 0;
  border-left: var(--pen) dashed var(--seam);
}

[data-dir="v"] .seams::before { left: 33.333%; }
[data-dir="v"] .seams::after { left: 66.666%; }

/* ---------- stripes: cut from the painted marker sheet ---------- */

.stripe {
  position: absolute;
  z-index: 1;
  display: block;
  padding: 0;
  margin: 0;
  overflow: hidden;
  background: var(--ak-bg);
  border: 0;
  border-radius: 0;
  cursor: grab;
  touch-action: none;
}

.flag[data-dir="h"] .stripe,
.mini[data-dir="h"] .stripe {
  --t: calc(var(--fh) / 3);
  left: 0;
  top: calc(var(--slot) * var(--fh) / 3);
  width: 100%;
  height: calc(var(--fh) / 3);
}

.flag[data-dir="v"] .stripe,
.mini[data-dir="v"] .stripe {
  --t: calc(var(--fw) / 3);
  top: 0;
  left: calc(var(--slot) * var(--fw) / 3);
  width: calc(var(--fw) / 3);
  height: 100%;
}

/* Flat flag colours from the painted marker sheet, each with one small pen mark
   so a stripe reads by shape as well as colour. */
.ink {
  position: absolute;
  inset: 0;
  background-color: var(--fill);
  background-image: var(--mark);
  background-repeat: no-repeat;
  background-position: center;
  background-size: min(calc(var(--t) * 0.46), 1.5rem);
}

[data-color="red"] {
  --fill: #FA080C;
  --mark: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23F8F8F7' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 19 L11 5 M13 19 L20 5'/%3E%3C/svg%3E");
}

[data-color="white"] {
  --fill: #F8F8F7;
  --mark: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2307080F' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='6.5'/%3E%3C/svg%3E");
}

[data-color="blue"] {
  --fill: #006CFE;
  --mark: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23F8F8F7' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 6 L18 18 M18 6 L6 18'/%3E%3C/svg%3E");
}

[data-color="green"] {
  --fill: #10E12F;
  --mark: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2307080F' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M2 12 C5 6 8 6 12 12 C16 18 19 18 22 12'/%3E%3C/svg%3E");
}

[data-color="yellow"] {
  --fill: #FEFB03;
  --mark: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2307080F' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M2 16 L7 8 L12 16 L17 8 L22 16'/%3E%3C/svg%3E");
}

[data-color="orange"] {
  --fill: #FC8D02;
  --mark: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2307080F' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M2 12 H8 M16 12 H22'/%3E%3C/svg%3E");
}

[data-color="black"] {
  --fill: #161615;
  --mark: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23F8F8F7' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 7 H19 M5 12 H19 M5 17 H19'/%3E%3C/svg%3E");
}

/* A ring readable on every stripe: light dashes between two dark rings. */
.stripe::after {
  content: "";
  position: absolute;
  inset: 5px;
  z-index: 1;
  pointer-events: none;
  border: 3px dashed transparent;
  border-radius: 2px;
}

.stripe.is-picked,
.stripe.is-target,
.stripe.is-invite {
  z-index: 2;
}

.stripe.is-picked::after,
.stripe.is-invite::after {
  border-color: var(--ak-ink);
  box-shadow: 0 0 0 3px var(--ak-bg), inset 0 0 0 3px var(--ak-bg);
}

.stripe.is-target::after {
  border-style: solid;
  border-color: var(--ak-accent-2);
  box-shadow: 0 0 0 3px var(--ak-bg), inset 0 0 0 3px var(--ak-bg);
}

.stripe.is-lifted .ink {
  opacity: 0.3;
}

.stripe:focus-visible {
  outline: 3px solid var(--ak-focus);
  outline-offset: -3px;
  z-index: 2;
}

.ghost {
  position: fixed;
  z-index: 60;
  pointer-events: none;
  overflow: hidden;
  border: var(--pen) solid var(--ak-accent-2);
  background: var(--ak-bg);
  transform: translate(-50%, -50%) rotate(-2deg);
}

/* ---------- the country name, written under each flag ---------- */

.name {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  min-width: 0;
  padding-top: 0.3rem;
  font-size: clamp(0.95rem, 2.2dvh, 1.15rem);
  line-height: 1.1;
  color: var(--ak-ink);
  white-space: nowrap;
}

.name-text {
  overflow: hidden;
  text-overflow: ellipsis;
  border-bottom: var(--pen) solid color-mix(in srgb, var(--ak-accent) 70%, transparent);
  transform: rotate(-1deg);
}

/* Long names shrink to fit the flag width instead of being cut off. */
.name.is-long .name-text {
  font-size: min(1em, calc(var(--fw) / 9.5));
  letter-spacing: -0.03em;
}

.flag:nth-child(even) .name-text {
  transform: rotate(0.8deg);
}

.mark {
  flex: none;
  width: 1.6rem;
  height: 1.6rem;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  display: none;
}

.tick {
  stroke: var(--ak-accent);
  stroke-width: 4;
}

.cross {
  stroke: var(--ak-btn-fill);
  stroke-width: 3.5;
}

.flag.is-right .tick,
.flag.is-wrong .cross {
  display: block;
}

.strike {
  position: absolute;
  inset: -4%;
  z-index: 4;
  width: 108%;
  height: 108%;
  pointer-events: none;
  fill: none;
  stroke-linecap: round;
  display: none;
}

.strike .under {
  stroke: var(--ak-bg);
  stroke-width: 7;
}

.strike .over {
  stroke: var(--ak-btn-fill);
  stroke-width: 3.5;
}

.flag.is-wrong .strike {
  display: block;
}

.flag.is-wrong .frame::after {
  border-color: var(--ak-btn-fill);
  border-style: dashed;
}

.board.is-solved .frame::after {
  border-color: var(--ak-accent);
  box-shadow: 0 0 0.6rem color-mix(in srgb, var(--ak-glow) 60%, transparent);
}

/* ---------- the desk: notes and the two arcade buttons ---------- */

.desk {
  grid-area: desk;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 0.3rem 0 0 0.75rem;
}

.note {
  position: relative;
  display: flex;
  align-items: center;
  min-width: 0;
  min-height: 3.9em;
  font-size: 0.95rem;
}

.note-text {
  margin: 0;
  font-size: 0.95rem;
  line-height: 1.3;
  color: var(--ak-ink);
}

.note.is-wrong .note-text {
  text-decoration: underline wavy var(--ak-btn-fill);
  text-decoration-thickness: 2px;
  text-underline-offset: 0.3em;
}

.note.is-result {
  padding-left: 2.4rem;
}

/* The star lands on the margin rule beside the result; the stamp thumps down next to it. */
.note-marks {
  position: absolute;
  left: calc(-1 * var(--mg) - 1rem);
  top: 50%;
  width: 5.4rem;
  height: 4.4rem;
  margin-top: -2.2rem;
  pointer-events: none;
  display: none;
}

.note.is-result .note-marks {
  display: block;
}

.star {
  filter: drop-shadow(0 0 1.5px var(--ak-bg)) drop-shadow(0 0 1.5px var(--ak-bg));
  position: absolute;
  left: 0;
  top: 0;
  width: 3.4rem;
  height: 3.4rem;
  fill: none;
  stroke: var(--ak-btn-fill);
  stroke-width: 3.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.stamp {
  --s: 2.9rem;
  position: absolute;
  right: 0;
  bottom: 0;
  width: var(--s);
  height: var(--s);
  background-image: url("art/check-marks.png");
  background-repeat: no-repeat;
  background-size: calc(var(--s) * 313 / 156) calc(var(--s) * 384 / 156);
  background-position: calc(var(--s) * -128 / 156) calc(var(--s) * -180 / 156);
  clip-path: circle(50%);
  transform: rotate(-12deg);
}

.pads {
  flex: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}

.pad {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 3.5rem;
  padding: 0.2rem;
  background: none;
  border: 0;
  cursor: pointer;
}

.pad-cap {
  flex: none;
  display: grid;
  place-items: center;
  width: clamp(3rem, 6.5dvh, 3.75rem);
  height: clamp(3rem, 6.5dvh, 3.75rem);
  border-radius: 50%;
  background: radial-gradient(circle at 38% 32%, var(--ak-btn-fill) 0 45%, var(--ak-btn-active) 100%);
  box-shadow:
    0 0 0 3px var(--ak-outline),
    0 0 0 6px color-mix(in srgb, var(--ak-accent-2) 45%, var(--ak-bg)),
    inset 0 -5px 0 color-mix(in srgb, var(--ak-outline) 55%, transparent);
}

.pad-main {
  flex-direction: row-reverse;
}

.pad-main .pad-cap {
  width: clamp(3.25rem, 7.5dvh, 4.25rem);
  height: clamp(3.25rem, 7.5dvh, 4.25rem);
}

.pad:active .pad-cap {
  transform: translateY(2px);
  background: radial-gradient(circle at 38% 32%, var(--ak-btn-hover) 0 40%, var(--ak-btn-active) 100%);
  box-shadow:
    0 0 0 3px var(--ak-outline),
    0 0 0 6px color-mix(in srgb, var(--ak-accent-2) 45%, var(--ak-bg)),
    inset 0 -2px 0 color-mix(in srgb, var(--ak-outline) 55%, transparent);
}

.pad-main .pad-label {
  text-align: right;
}

.pad:disabled {
  cursor: default;
}

.pad:disabled .pad-cap {
  opacity: 0.4;
}

.pad:disabled .pad-label {
  color: var(--ak-ink-muted);
}

.pad svg {
  width: 52%;
  height: 52%;
  fill: none;
  stroke: var(--ak-btn-ink);
  stroke-width: 3.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.pad .icon-settings,
.pad .icon-next,
.pads.is-result .icon-undo,
.pads.is-result .icon-check {
  display: none;
}

.pads.is-result .icon-settings,
.pads.is-result .icon-next {
  display: inline;
}

.pad-label {
  max-width: 7.5rem;
  font-family: var(--ak-font-display);
  font-size: 0.78rem;
  line-height: 1.2;
  text-align: left;
  color: var(--ak-ink);
}

/* ---------- the worked example, before the first round ---------- */

.teach {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  padding: 0.75rem;
  background: var(--ak-bg);
  border: var(--pen) dashed var(--ak-accent-2);
}

.teach[hidden],
.note[hidden],
.pads[hidden] {
  display: none;
}

.teach-caption {
  margin: 0;
  font-size: 1.15rem;
  line-height: 1.35;
  color: var(--ak-ink);
}

.teach-demo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
}

.mini {
  --fw: 4.8rem;
  --fh: 3.3rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  margin: 0;
}

.mini .frame::after {
  border-width: 2px;
}

.mini .stripe {
  cursor: default;
}

.mini figcaption {
  font-size: 0.85rem;
  color: var(--ak-ink-muted);
}

.demo-arrow {
  width: 2.6rem;
  height: 1.6rem;
  fill: none;
  stroke: var(--ak-accent-2);
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.got-it {
  min-height: 3.5rem;
  padding: 0.5rem 1rem;
  font-family: var(--ak-font-display);
  font-size: 1.2rem;
  color: var(--ak-btn-ink);
  background: var(--ak-btn-fill);
  border: 0;
  border-radius: var(--ak-radius);
  border-bottom: 4px solid var(--ak-btn-active);
  cursor: pointer;
}

.got-it:active {
  background: var(--ak-btn-active);
}

/* ---------- sideways: board on the left, notes and buttons on the right ---------- */

@media (orientation: landscape) {
  .page {
    grid-template-columns: var(--mg) minmax(0, 1fr) clamp(13rem, 32vw, 20rem);
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas:
      "margin board top"
      "margin board desk";
    column-gap: 0.75rem;
    padding-top: calc(env(safe-area-inset-top) + 0.5rem);
  }

  .top {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.2rem;
    justify-content: flex-start;
    min-height: 3.5rem;
    padding: 0 3.75rem 0 0;
  }

  .logo {
    height: min(13dvh, 3.75rem);
  }

  .margin-doodle {
    display: none;
  }

  .status {
    padding-left: 1.75rem;
  }

  .desk {
    flex-direction: column;
    align-items: stretch;
    justify-content: center;
    gap: 1rem;
    padding: 0 0 0.5rem;
  }

  .note {
    flex: none;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.4rem;
    min-height: 0;
  }

  .note.is-result {
    padding-left: 0;
  }

  .note-text {
    font-size: 1.05rem;
  }

  .note-marks {
    position: relative;
    left: 0;
    top: 0;
    margin-top: 0;
  }

  .pads {
    justify-content: space-around;
    gap: 0.5rem;
  }

  .pad,
  .pad-main {
    flex-direction: column;
    width: 6rem;
    gap: 0.35rem;
  }

  .pad-label,
  .pad-main .pad-label {
    text-align: center;
  }

  .pad-cap {
    width: clamp(3rem, 15dvh, 4.25rem);
    height: clamp(3rem, 15dvh, 4.25rem);
  }

  .pad-main .pad-cap {
    width: clamp(3.4rem, 17dvh, 5rem);
    height: clamp(3.4rem, 17dvh, 5rem);
  }

  .teach {
    flex: 1;
    min-height: 0;
    overflow: auto;
    gap: 0.45rem;
    padding: 0.6rem;
  }

  .teach-caption {
    font-size: 1.125rem;
  }

  .mini {
    --fw: 4.2rem;
    --fh: 2.9rem;
  }

  .got-it {
    min-height: 3rem;
  }

  .board[data-count="3"] {
    --cols: 3;
    --rows: 1;
  }

  .board[data-count="6"] {
    --cols: 3;
    --rows: 2;
  }
}

/* Short upright screens: the six-flag page keeps its stripes big and lets the tip go. */
@media (orientation: portrait) and (max-height: 800px) {
  :root {
    --label: 1.75rem;
    --gap: 0.6rem;
  }

  .page[data-count="6"] .note-tip {
    display: none;
  }
}

/* Short upright screens: three flags go two across so every stripe stays big enough. */
@media (orientation: portrait) and (max-height: 720px) {
  .board[data-count="3"] {
    --cols: 2;
    --rows: 2;
  }

  .board[data-count="3"] .flag:last-child {
    grid-column: 1 / -1;
    justify-self: center;
  }
}

/* Short sideways phones: tighter names and notes so the board keeps its room. */
@media (orientation: landscape) and (max-height: 500px) {
  .note-text {
    font-size: 1rem;
  }

  .pad-label {
    font-size: 0.75rem;
  }
}

/* ---------- motion ---------- */

@media (prefers-reduced-motion: no-preference) {
  .page::before {
    animation: breathe 7s ease-in-out infinite;
  }

  .board .stripe {
    transition: transform var(--swap-ms) cubic-bezier(0.3, 0.9, 0.4, 1);
  }

  .stripe.is-swapping {
    z-index: 2;
  }

  .stripe.is-settling {
    animation: pen-wiggle 340ms ease-out;
  }

  .stripe.is-invite::after {
    animation: invite 1.3s ease-in-out infinite;
  }

  .flag.is-right .tick path,
  .flag.is-wrong .cross path,
  .flag.is-wrong .strike path {
    stroke-dasharray: 120;
    animation: draw 420ms ease-out both;
  }

  .board.is-solved .flag .tick path {
    animation-delay: calc(var(--i) * var(--tick-step));
  }

  .board.is-solved .stripe {
    animation: settle 380ms cubic-bezier(0.34, 1.56, 0.64, 1) both;
    animation-delay: calc(var(--i) * var(--tick-step) + var(--slot) * 70ms);
  }

  .note.is-result .star path {
    stroke-dasharray: 260;
    animation: draw-star 700ms ease-out both;
  }

  .note.is-result .star .star-spark {
    animation-delay: 600ms;
  }

  .note.is-result .stamp {
    animation: thump 380ms cubic-bezier(0.2, 1.6, 0.5, 1) 650ms both;
  }

  .note.is-result .note-text {
    animation: ink-in 320ms ease-out both;
  }

  .tally .is-new,
  .tally .scribble {
    stroke-dasharray: 80;
    animation: draw 420ms ease-out both;
  }

  .ghost {
    animation: lift 160ms ease-out both;
  }
}

@keyframes breathe {
  0%, 100% { opacity: 0.45; }
  50% { opacity: 0.85; }
}

@keyframes pen-wiggle {
  0% { transform: rotate(0); }
  30% { transform: rotate(-1.6deg); }
  60% { transform: rotate(1.1deg); }
  100% { transform: rotate(0); }
}

@keyframes invite {
  0%, 100% { inset: 5px; }
  50% { inset: 9px; }
}

@keyframes draw {
  from { stroke-dashoffset: 120; }
  to { stroke-dashoffset: 0; }
}

@keyframes draw-star {
  from { stroke-dashoffset: 260; }
  to { stroke-dashoffset: 0; }
}

@keyframes settle {
  0% { transform: translateY(0); }
  40% { transform: translateY(-8%); }
  100% { transform: translateY(0); }
}

@keyframes thump {
  0% { opacity: 0; transform: scale(1.9) rotate(-28deg); }
  100% { opacity: 1; transform: scale(1) rotate(-12deg); }
}

@keyframes ink-in {
  from { opacity: 0; clip-path: inset(0 100% 0 0); }
  to { opacity: 1; clip-path: inset(0 0 0 0); }
}

@keyframes lift {
  from { transform: translate(-50%, -50%) rotate(0) scale(1); }
  to { transform: translate(-50%, -50%) rotate(-2deg) scale(1.04); }
}

/* ---------- the start screen: a sample shuffled flag, and Play on a solid backing ---------- */

.fss-sample {
  --fw: min(11rem, 42vw);
  --fh: min(7.3rem, 28vw);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  margin: 1rem auto 0.25rem;
  padding-left: var(--pole);
}

.fss-sample .name {
  justify-content: center;
  font-size: 1.1rem;
}

.fss-sample-note {
  margin: 0;
  font-size: 1rem;
  color: var(--ak-ink-muted);
}

/* A solid band from just above Play to the bottom edge, so no text runs behind it. */
html body #activity-start .ak-go {
  z-index: 2;
  box-shadow: var(--ak-shadow), 0 0 0 100vmax var(--ak-bg);
  clip-path: inset(-0.9rem -100vmax -100vmax -100vmax);
  font-size: 1.35rem;
}

@media (orientation: landscape) and (max-height: 500px) {
  .fss-sample {
    --fw: 8.4rem;
    --fh: 5.6rem;
    margin-top: 0.6rem;
  }
}
