/* Labyrinth — base layout, tokens and screens. */

:root {
  --ink: #3b2d4f;
  --ink-soft: #6a5a80;
  --paper: #fffaf0;
  --sky-top: #7ec8f2;
  --sky-bottom: #c9f0ff;
  --grass: #8fdc6a;
  --sun: #ffd23f;
  --pink: #ff5d8f;
  --orange: #ff9f1c;
  --green: #3ccf6e;
  --green-dark: #23a052;
  --blue: #3fa7f5;
  --blue-dark: #1f7fd0;
  --purple: #9b6bff;
  --purple-dark: #6f43d6;
  --red: #ff6b6b;
  --red-dark: #d94848;
  --radius: 28px;
  --btn: 72px;
  --gap: clamp(10px, 2.2vmin, 24px);
  --font: ui-rounded, "SF Pro Rounded", "Nunito", "Varela Round", "Arial Rounded MT Bold", "Comic Sans MS", system-ui, sans-serif;
  --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);
}

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

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  user-select: none;
  -webkit-user-select: none;
}

body {
  font-family: var(--font);
  color: var(--ink);
  background: linear-gradient(180deg, var(--sky-top), var(--sky-bottom) 70%, #e9fbd9);
  font-weight: 800;
}

/* Soft drifting clouds behind the menus. */
body::before, body::after {
  content: "";
  position: fixed;
  pointer-events: none;
  width: 340px; height: 120px;
  background:
    radial-gradient(circle at 30% 60%, #fff 0 38px, transparent 39px),
    radial-gradient(circle at 52% 40%, #fff 0 52px, transparent 53px),
    radial-gradient(circle at 72% 62%, #fff 0 40px, transparent 41px),
    radial-gradient(ellipse at 50% 80%, #fff 0 110px, transparent 111px);
  opacity: .85;
  z-index: 0;
  animation: drift 60s linear infinite;
}
body::before { top: 6vh; left: -360px; }
body::after { top: 58vh; left: -360px; transform: scale(.7); animation-duration: 85s; animation-delay: -40s; }
@keyframes drift { to { translate: calc(100vw + 720px) 0; } }

#app {
  position: fixed;
  inset: 0;
  z-index: 1;
  padding: calc(var(--safe-t) + var(--gap)) calc(var(--safe-r) + var(--gap)) calc(var(--safe-b) + var(--gap)) calc(var(--safe-l) + var(--gap));
  display: flex;
}

button {
  font: inherit;
  color: inherit;
  border: 0;
  background: none;
  padding: 0;
  cursor: pointer;
  touch-action: manipulation;
}
button:focus-visible { outline: 5px solid var(--sun); outline-offset: 4px; }

svg { display: block; }

/* ---------- Screens ---------- */

.screen {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  position: relative;
  z-index: 1;
  animation: pop-in .35s cubic-bezier(.2, 1.4, .4, 1) both;
}
@keyframes pop-in { from { opacity: 0; transform: scale(.94); } }

.topbar, .playbar {
  display: flex;
  align-items: center;
  gap: var(--gap);
  flex: none;
}
.screen-title {
  margin: 0;
  font-size: clamp(28px, 5vmin, 48px);
  display: flex;
  align-items: center;
  gap: 12px;
  text-shadow: 0 3px 0 #fff;
}
.screen-title svg { width: 1.3em; height: 1.3em; }

/* Chunky candy buttons */
.icon-btn, .mode-btn, .level-tile, .choice, .play-btn {
  --c: var(--blue);
  --cd: var(--blue-dark);
  background: var(--c);
  border: 4px solid var(--ink);
  border-radius: var(--radius);
  box-shadow: 0 8px 0 var(--cd), 0 10px 0 var(--ink), 0 16px 18px rgba(59, 45, 79, .25);
  transition: transform .08s, box-shadow .08s;
}
.icon-btn:active, .mode-btn:active, .level-tile:active, .choice:active, .play-btn:active {
  transform: translateY(6px);
  box-shadow: 0 2px 0 var(--cd), 0 4px 0 var(--ink), 0 6px 8px rgba(59, 45, 79, .25);
}

.icon-btn {
  width: var(--btn);
  height: var(--btn);
  min-width: 64px;
  min-height: 64px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  flex: none;
  color: #fff;
}
.icon-btn svg { width: 58%; height: 58%; }
.icon-btn.home { --c: var(--orange); --cd: #d97c00; }
.icon-btn.reset { --c: var(--purple); --cd: var(--purple-dark); }
.icon-btn.go { --c: var(--green); --cd: var(--green-dark); }
.icon-btn.big { width: 104px; height: 104px; }

/* ---------- Main menu ---------- */

.menu { align-items: center; justify-content: center; }
.logo {
  margin: 0;
  font-size: clamp(48px, 11vmin, 120px);
  letter-spacing: .02em;
  line-height: 1;
  display: flex;
  gap: .02em;
}
.logo span {
  display: inline-block;
  color: var(--c);
  -webkit-text-stroke: .06em var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 .07em 0 var(--ink);
  animation: bob 2.4s ease-in-out infinite;
  animation-delay: calc(var(--i) * -.18s);
}
@keyframes bob { 50% { transform: translateY(-.08em) rotate(-3deg); } }

.mode-grid {
  display: flex;
  gap: calc(var(--gap) * 1.5);
  flex-wrap: wrap;
  justify-content: center;
  margin-top: var(--gap);
}
.mode-btn {
  width: clamp(150px, 26vmin, 260px);
  aspect-ratio: 4 / 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 14px 10px 16px;
  color: #fff;
}
.mode-btn.levels { --c: var(--pink); --cd: #d9356b; }
.mode-btn.free { --c: var(--green); --cd: var(--green-dark); }
.mode-btn.endless { --c: var(--purple); --cd: var(--purple-dark); }
.mode-art {
  width: 100%;
  flex: 1;
  min-height: 0;
  background: rgba(255, 255, 255, .9);
  border: 3px solid var(--ink);
  border-radius: 20px;
  display: grid;
  place-items: center;
  padding: 6px;
  margin-bottom: 10px;
}
.mode-art svg { width: 100%; height: 100%; }
.mode-label {
  font-size: clamp(20px, 3.8vmin, 34px);
  -webkit-text-stroke: 5px var(--ink);
  paint-order: stroke fill;
}

/* Landscape phones: keep the menu on one row */
@media (max-height: 520px) and (orientation: landscape) {
  .mode-btn { width: clamp(130px, 22vw, 210px); aspect-ratio: 1; }
  .logo { font-size: 13vmin; }
}

/* ---------- Level picker ---------- */

.level-grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(clamp(140px, 17vw, 230px), 1fr));
  grid-auto-rows: clamp(112px, 12.5vw, 180px);
  align-content: start;
  gap: calc(var(--gap) * 1.4);
  padding: 20px 16px 28px;
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
  scroll-padding: 24px;
}
.level-tile {
  --c: #fff;
  --cd: #d6cbe8;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 0;
  overflow: visible;
  padding: 8px;
  background: var(--tile-bg, #fff);
}
.level-tile .tile-art { width: 100%; flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; gap: 4%; }
.level-tile .tile-art img { width: 46%; height: auto; max-height: 100%; object-fit: contain; }
.tile-num {
  position: absolute;
  top: -14px; left: -12px;
  width: 48px; height: 48px;
  border-radius: 50%;
  background: var(--sun);
  border: 4px solid var(--ink);
  display: grid;
  place-items: center;
  font-size: 24px;
}
.tile-star {
  position: absolute;
  top: -16px; right: -14px;
  width: 52px; height: 52px;
  filter: drop-shadow(0 3px 0 var(--ink));
  animation: twinkle 2s ease-in-out infinite;
}
@keyframes twinkle { 50% { transform: rotate(12deg) scale(1.08); } }

/* ---------- Setup screens ---------- */

.setup-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: calc(var(--gap) * 1.4);
  overflow-y: auto;
  padding-bottom: 18px;
}
.choice-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--gap);
}
.choice {
  --c: #fff;
  --cd: #d6cbe8;
  min-width: clamp(96px, 13vmin, 150px);
  min-height: clamp(96px, 13vmin, 150px);
  padding: 10px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 18px;
}
.choice[aria-pressed="true"] { --c: #9fdcff; --cd: #4fa8dc; transform: scale(1.08); }
.choice[aria-pressed="true"]:active { transform: translateY(6px) scale(1.06); }
.stars { display: flex; gap: 2px; }
.choice .stars svg { width: clamp(30px, 4.5vmin, 48px); height: clamp(30px, 4.5vmin, 48px); }
.choice img { width: clamp(64px, 10vmin, 110px); height: clamp(64px, 10vmin, 110px); object-fit: contain; }
.choice.theme { min-width: 0; min-height: 0; padding: 8px; }
.choice { font-size: clamp(18px, 2.6vmin, 26px); }

.play-btn {
  --c: var(--green);
  --cd: var(--green-dark);
  width: 148px;
  height: 104px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  color: #fff;
  flex: none;
}
.play-btn svg { width: 56px; height: 56px; }

/* ---------- Play screen ---------- */

.play { gap: calc(var(--gap) * .8); }
.playbar { justify-content: space-between; }
.playbar .middle { flex: 1; display: flex; justify-content: center; gap: var(--gap); min-width: 0; }
.pill {
  background: #fff;
  border: 4px solid var(--ink);
  border-radius: 999px;
  padding: 6px 22px;
  font-size: clamp(26px, 5vmin, 44px);
  min-height: 64px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 6px 0 rgba(59, 45, 79, .25);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.pill svg { width: 1.1em; height: 1.1em; }
.timer.running svg { animation: tick 1s steps(2) infinite; }
@keyframes tick { 50% { transform: rotate(15deg); } }

.board-wrap {
  flex: 1;
  min-height: 0;
  position: relative;
  border-radius: calc(var(--radius) + 6px);
  overflow: hidden;
  border: 5px solid var(--ink);
  box-shadow: 0 10px 0 rgba(59, 45, 79, .35);
  background: #fff;
}
.board {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
}

/* Landscape phones: put the controls in a side column to give the maze height. */
@media (max-height: 520px) and (orientation: landscape) {
  .play { flex-direction: row; }
  .playbar { flex-direction: column; justify-content: space-between; }
  .playbar .middle { flex-direction: column; justify-content: center; align-items: center; }
  .pill { padding: 4px 12px; font-size: 24px; }
}

/* ---------- Celebration overlay ---------- */

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 5;
  pointer-events: none;
}
.celebrate-card {
  pointer-events: auto;
  background: #fff;
  border: 5px solid var(--ink);
  border-radius: 36px;
  padding: 18px 28px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  box-shadow: 0 12px 0 rgba(59, 45, 79, .35);
  animation: card-in .5s cubic-bezier(.2, 1.6, .4, 1) both;
  max-width: calc(100% - 24px);
}
@keyframes card-in { from { transform: scale(.3) rotate(-8deg); opacity: 0; } }
.big-star { width: clamp(90px, 18vmin, 150px); height: clamp(90px, 18vmin, 150px); animation: spin-in 1s ease-out both; }
@keyframes spin-in { from { transform: rotate(-200deg) scale(.2); } }
.result-time { font-size: clamp(36px, 8vmin, 64px); display: flex; align-items: center; gap: 12px; font-variant-numeric: tabular-nums; }
.result-time svg { width: .9em; height: .9em; }
.actions { display: flex; gap: 18px; flex-wrap: wrap; justify-content: center; }
.countdown { position: absolute; inset: -8px; pointer-events: none; }
.countdown circle { fill: none; stroke: #fff; stroke-width: 6; stroke-linecap: round; transform: rotate(-90deg); transform-origin: center; animation: countdown var(--dur, 4s) linear forwards; }
@keyframes countdown { from { stroke-dashoffset: 0; } to { stroke-dashoffset: var(--len); } }
.icon-btn { position: relative; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}

.mode-art img { width: 100%; height: 100%; object-fit: contain; }
.choice .dice { display: block; width: clamp(64px, 10vmin, 110px); height: clamp(64px, 10vmin, 110px); color: var(--purple); }
.choice .dice svg { width: 100%; height: 100%; }
.pill .stars svg { width: 1em; height: 1em; }

/* ---------- Accounts: menu corner, grown-ups area, forms, dialogs ---------- */

input, textarea { user-select: text; -webkit-user-select: text; -webkit-touch-callout: default; }

.menu-corner {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  pointer-events: none;
}
.menu-corner > * { pointer-events: auto; }

.avatar-btn {
  width: 84px; height: 84px;
  border-radius: 50%;
  background: #fff;
  border: 4px solid var(--ink);
  box-shadow: 0 6px 0 rgba(59, 45, 79, .3);
  display: grid; place-items: center;
  padding: 6px;
  flex: none;
}
.avatar-btn.small { width: 68px; height: 68px; margin-left: auto; }
.avatar-btn img, .avatar-btn svg { width: 100%; height: 100%; }
.avatar-btn .who-icon { width: 70%; height: 70%; color: var(--purple); }
.avatar-img { display: block; object-fit: contain; }

.icon-btn.lock-btn { --c: #efe9f7; --cd: #cfc6df; color: var(--ink-soft); }
.icon-btn.lock-btn svg { width: 44%; height: 44%; }
.icon-btn.no { --c: var(--red); --cd: var(--red-dark); }

.scroll-body {
  flex: 1; min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex; justify-content: center; align-items: flex-start;
  padding: 4px 4px 24px;
}
.panel {
  width: 100%; max-width: 560px;
  background: #fff;
  border: 4px solid var(--ink);
  border-radius: var(--radius);
  box-shadow: 0 8px 0 rgba(59, 45, 79, .25);
  padding: clamp(16px, 3vmin, 28px);
  display: flex; flex-direction: column; gap: 16px;
}
.panel h3 { margin: 6px 0 0; font-size: 22px; }
.panel-text { margin: 0; font-size: 18px; font-weight: 600; line-height: 1.45; }
.privacy .panel-text { font-size: 17px; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 18px; }
.field-hint { font-size: 14px; font-weight: 600; color: var(--ink-soft); }
.field input {
  font: inherit; font-size: 18px; font-weight: 700; color: var(--ink);
  min-height: 56px; padding: 0 14px;
  border: 3px solid var(--ink); border-radius: 14px; background: #fbf9ff;
}
.field input:focus { outline: 4px solid var(--sun); outline-offset: 1px; }
.check { display: flex; align-items: center; gap: 12px; font-size: 17px; font-weight: 700; line-height: 1.3; cursor: pointer; }
.check input { width: 28px; height: 28px; flex: none; accent-color: var(--green); }

.text-btn {
  min-height: 56px; padding: 0 20px;
  border: 3px solid var(--ink); border-radius: 16px;
  background: #fff; font-size: 18px;
  box-shadow: 0 4px 0 var(--ink);
}
.text-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.text-btn.primary { background: var(--green); color: #fff; }
.text-btn.danger { background: var(--red); color: #fff; }
.text-btn.big { min-height: 64px; font-size: 20px; }
.text-btn:disabled { opacity: .5; cursor: default; }
.link-btn { align-self: center; padding: 10px; font-size: 16px; text-decoration: underline; color: var(--blue-dark); min-height: 44px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.stack.spaced { margin-top: 12px; }
.form-error { margin: 0; padding: 10px 14px; border-radius: 12px; background: #ffe1e1; color: #a12a2a; font-weight: 700; }
.form-actions { display: flex; justify-content: flex-end; gap: 12px; }

.dialog-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(59, 45, 79, .45);
  display: grid; place-items: center;
  padding: 16px;
}
.dialog {
  width: min(440px, 100%);
  background: #fff; border: 4px solid var(--ink); border-radius: var(--radius);
  padding: 22px; display: flex; flex-direction: column; gap: 16px;
  animation: card-in .35s cubic-bezier(.2, 1.6, .4, 1) both;
}
.dialog-icon { width: 56px; height: 56px; align-self: center; color: var(--purple); }
.dialog-icon svg { width: 100%; height: 100%; }
.shake { animation: shake .4s; }
@keyframes shake { 20%, 60% { transform: translateX(-10px); } 40%, 80% { transform: translateX(10px); } }

.player-list { display: flex; flex-direction: column; gap: 8px; }
.player-row {
  display: flex; align-items: center; gap: 12px;
  min-height: 68px; padding: 6px 14px;
  border: 3px solid var(--ink); border-radius: 18px; background: #fbf9ff; text-align: left;
}
.player-row .avatar-img { width: 54px; height: 54px; }
.player-name { flex: 1; font-size: 20px; }
.row-icon { width: 26px; height: 26px; color: var(--ink-soft); }
.row-icon svg { width: 100%; height: 100%; }

.avatar-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 10px; }
.avatar-choice { border: 3px solid var(--ink); border-radius: 18px; background: #fff; padding: 6px; aspect-ratio: 1; min-height: 64px; }
.avatar-choice img { width: 100%; height: 100%; }
.avatar-choice[aria-pressed="true"] { background: #9fdcff; transform: scale(1.06); box-shadow: 0 0 0 4px var(--sun); }
.avatar-choice:disabled { opacity: .25; cursor: not-allowed; }

.who-grid { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-wrap: wrap; align-content: center; justify-content: center; gap: calc(var(--gap) * 1.4); padding: 12px; }
.who-tile {
  --c: #fff; --cd: #d6cbe8;
  width: clamp(130px, 22vmin, 220px); aspect-ratio: 1;
  background: var(--c); border: 4px solid var(--ink); border-radius: var(--radius);
  box-shadow: 0 8px 0 var(--cd), 0 10px 0 var(--ink);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; padding: 10px;
}
.who-tile:active { transform: translateY(6px); box-shadow: 0 2px 0 var(--cd), 0 4px 0 var(--ink); }
.who-tile .avatar-img { width: 78%; height: auto; flex: 1; min-height: 0; }
.who-name { font-size: clamp(16px, 2.4vmin, 22px); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.note-card {
  align-self: center; background: #fff; border: 4px solid var(--ink); border-radius: var(--radius);
  padding: 16px 24px; display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; font-size: 20px;
  box-shadow: 0 6px 0 rgba(59, 45, 79, .25);
}
.note-card p { margin: 0; }
.note-art { display: flex; gap: 8px; }
.note-art .avatar-img { width: 56px; height: 56px; }

/* ---------- Completion: leaderboard and notes ---------- */

.celebrate-card { max-height: calc(100% - 16px); overflow-y: auto; }
.result-extra { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.result-extra:empty { display: none; }
.leaderboard { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; width: min(440px, 78vw); }
.leaderboard li {
  display: grid; grid-template-columns: 40px 44px 1fr auto; align-items: center; gap: 10px;
  padding: 4px 12px; border-radius: 14px; background: #f6f2fb; font-size: 20px; min-height: 52px;
}
.leaderboard li.mine { background: #fff1b8; box-shadow: inset 0 0 0 3px #ffb703; animation: pop-in .5s .3s both; }
.leaderboard .medal { width: 36px; height: 36px; }
.leaderboard .medal svg { width: 100%; height: 100%; }
.leaderboard .rank { text-align: center; color: var(--ink-soft); }
.leaderboard .avatar-img { width: 44px; height: 44px; }
.lb-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-time { font-variant-numeric: tabular-nums; }
.result-note { display: flex; align-items: center; gap: 10px; font-size: 18px; padding: 8px 16px; border-radius: 14px; background: #eef6ff; }
.result-note svg { width: 28px; height: 28px; }
.result-note.muted { background: #f1eef6; color: var(--ink-soft); }
.result-note.cheer { background: #e8fbe0; }

.import .import-art { display: flex; align-items: center; justify-content: center; gap: 14px; }
.import-star { width: 84px; height: 84px; }
.import-star svg { width: 100%; height: 100%; }
.import-arrow { width: 44px; height: 44px; color: var(--ink-soft); }
.import-arrow svg { width: 100%; height: 100%; }
.import .avatar-img { width: 96px; height: 96px; }
.import .actions { justify-content: center; }
.tile-art img.face-right { transform: scaleX(-1); }

/* ---------- Sound toggles ---------- */

.corner-right { display: flex; gap: var(--gap); align-items: flex-start; }
.sound-toggles { display: flex; gap: calc(var(--gap) * .8); flex: none; }
.icon-btn.sound-btn { --c: #fff; --cd: #d6cbe8; color: var(--ink); }
.icon-btn.sound-btn svg { width: 46%; height: 46%; }
.icon-btn.sound-btn.off { --c: #efe9f7; color: var(--ink-soft); }
.icon-btn.sound-btn.off::after {
  content: "";
  position: absolute;
  left: 18%; right: 18%; top: 50%;
  height: 5px; border-radius: 3px;
  background: var(--red);
  transform: rotate(-40deg);
  box-shadow: 0 0 0 2px #fff;
}

/* Narrow portrait screens: the toggles get their own row above the board. */
@media (max-width: 600px) and (orientation: portrait) {
  .playbar { flex-wrap: wrap; row-gap: 10px; }
  .playbar .sound-toggles { order: 5; width: 100%; justify-content: center; }
}

/* Landscape phones: a compact 2-column side panel. */
@media (max-height: 520px) and (orientation: landscape) {
  .playbar {
    display: grid;
    grid-template-columns: repeat(2, 64px);
    grid-template-areas: "back reset" "mid mid" "snd snd";
    align-content: space-between;
    justify-content: center;
  }
  .playbar > .home { grid-area: back; }
  .playbar > .reset { grid-area: reset; }
  .playbar > .middle { grid-area: mid; }
  .playbar > .sound-toggles { grid-area: snd; gap: 0; justify-content: space-between; }
  .playbar .icon-btn { width: 64px; height: 64px; }
}

/* ---------- Four modes on the menu ---------- */

.mode-btn.tangles { --c: var(--orange); --cd: #d97c00; }
.mode-btn { width: clamp(140px, 21vmin, 230px); }
/* Narrow or short screens: a 2×2 grid of mode buttons. */
@media (max-aspect-ratio: 1/1) {
  .mode-grid { display: grid; grid-template-columns: repeat(2, auto); }
  .mode-btn { width: clamp(130px, 40vw, 220px); }
}
@media (max-height: 520px) and (orientation: landscape) {
  /* Leave the top strip to the corner buttons (avatar, sound, padlock). */
  .menu { justify-content: center; padding-top: 70px; }
  .menu .logo { font-size: 8vmin; }
  .mode-grid { margin-top: 2px; }
  .mode-btn { width: clamp(100px, 17vw, 150px); aspect-ratio: 5 / 6; padding: 8px 8px 10px; }
  .mode-btn .mode-art { margin-bottom: 6px; }
  .mode-btn .mode-label { font-size: clamp(14px, 4.2vh, 20px); white-space: nowrap; -webkit-text-stroke-width: 4px; }
}

/* ---------- Five modes on the menu ---------- */

.mode-btn.dots { --c: #2bb3a3; --cd: #1d8a7d; }
.mode-btn { width: clamp(130px, 18vmin, 210px); }
@media (max-aspect-ratio: 1/1) {
  .mode-grid { display: flex; flex-wrap: wrap; justify-content: center; max-width: 100%; }
  .mode-btn { width: clamp(100px, 29vw, 180px); }
  .mode-label { font-size: clamp(16px, 4.6vw, 28px); }
}
@media (max-height: 520px) and (orientation: landscape) {
  .mode-btn { width: clamp(92px, 15vw, 140px); }
}
.mode-label { white-space: nowrap; font-size: clamp(16px, 2.9vmin, 30px); }
@media (max-aspect-ratio: 1/1) {
  /* 3 + 2: three buttons always fit a row; the corner buttons keep the top strip. */
  .menu { padding-top: 64px; justify-content: center; }
  .mode-grid { gap: 12px; }
  .mode-btn { width: min(180px, calc((100vw - 32px - 24px - 12px) / 3)); padding: 10px 8px 12px; }
  .mode-label { font-size: clamp(14px, 4.4vw, 26px); -webkit-text-stroke-width: 4px; }
}

/* ---------- Tic-tac-toe: marks ---------- */

.ttt-mark, .ttt-badge { display: block; width: 100%; height: 100%; }
.ttt-mark path, .ttt-badge path { stroke-dasharray: 1; stroke-dashoffset: 0; }
.ttt-mark.draw .s1 { animation: ttt-draw 0.2s ease-out both; }
.ttt-mark.draw .s2 { animation: ttt-draw 0.18s 0.16s ease-out both; }
.ttt-mark.o.draw .s1 { animation-duration: 0.34s; }
@keyframes ttt-draw { from { stroke-dashoffset: 1; } }

/* ---------- Tic-tac-toe: setup ---------- */

.choice-row[hidden] { display: none; }
/* Centred when it fits, scrollable from the top when it doesn't. */
.ttt-setup { justify-content: flex-start; gap: var(--gap); }
.ttt-setup > :first-child { margin-top: auto; }
.ttt-setup > :last-child { margin-bottom: auto; }
.ttt-top { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: var(--gap) calc(var(--gap) * 2); }
@media (max-height: 520px), (max-width: 520px) {
  .ttt-setup .choice { min-width: 76px; min-height: 76px; padding: 6px 10px; }
  .ttt-setup .choice img, .ttt-setup .choice .dice { width: 52px; height: 52px; }
  .ttt-setup .choice .stars svg { width: 26px; height: 26px; }
  .ttt-setup .choice .ttt-mode-art img { width: 38px; height: 38px; }
  .ttt-setup .ttt-slot { width: 100px; }
  .ttt-setup .play-btn { height: 80px; width: 120px; }
}
@media (max-height: 520px) and (orientation: landscape) {
  .ttt-setup { padding-right: 120px; padding-bottom: 0; }
  .ttt-setup .play-btn { position: fixed; right: 16px; bottom: 16px; z-index: 3; width: 104px; }
}
.ttt-mode-art { display: flex; gap: 2px; }
.choice .ttt-mode-art img { width: clamp(44px, 7vmin, 76px); height: clamp(44px, 7vmin, 76px); }
.ttt-slots { display: flex; align-items: center; gap: calc(var(--gap) * 1.2); }
.ttt-vs { font-size: clamp(22px, 3.6vmin, 34px); color: var(--ink-soft); }
.ttt-slot, .ttt-card { --mc: #ff5d5d; }
.ttt-slot.o, .ttt-card.o { --mc: #3fa7f5; }
.ttt-slot {
  position: relative;
  width: clamp(112px, 17vmin, 180px); aspect-ratio: 1;
  background: #fff; border: 4px solid var(--ink); border-radius: var(--radius);
  box-shadow: 0 0 0 5px var(--mc), 0 9px 0 5px var(--ink);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 10px;
}
.ttt-slot:active:not(:disabled) { transform: translateY(5px); }
.ttt-slot:disabled { cursor: default; }
.ttt-slot img { width: 74%; flex: 1; min-height: 0; object-fit: contain; }
.ttt-slot-badge { position: absolute; width: 34%; aspect-ratio: 1; right: -10%; top: -10%; }

.ttt-picker { width: min(620px, 100%); max-height: calc(100% - 16px); overflow-y: auto; }
.ttt-picker-head { display: flex; align-items: center; justify-content: space-between; }
.ttt-picker-mark { width: 64px; height: 64px; }
.ttt-picker .icon-btn { width: 56px; height: 56px; }
.ttt-pick { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; }
.ttt-pick img { min-height: 0; flex: 1; }
.ttt-pick .who-name { font-size: 14px; }
.ttt-guest-head { display: flex; align-items: center; gap: 8px; color: var(--ink-soft); font-size: 18px; }
.ttt-guest-head span { width: 28px; height: 28px; }
.ttt-guest-head svg { width: 100%; height: 100%; }

/* ---------- Tic-tac-toe: play ---------- */

.ttt-wrap { background: #fff; }
.ttt-bg, .ttt-fx { position: absolute; inset: 0; width: 100%; height: 100%; }
.ttt-fx { pointer-events: none; z-index: 4; }
.ttt-layout {
  position: absolute; inset: 0; z-index: 2;
  display: flex; align-items: center; justify-content: center; gap: 24px;
}
.ttt-layout.port {
  align-items: stretch;
  display: grid; grid-template-columns: auto auto; grid-template-areas: "x o" "b b";
  justify-content: center; align-content: center; gap: 22px 28px;
}
.ttt-layout.port .ttt-card.x { grid-area: x; }
.ttt-layout.port .ttt-card.o { grid-area: o; }
.ttt-layout.port .ttt-grid { grid-area: b; justify-self: center; }

.ttt-grid {
  position: relative; flex: none;
  width: var(--ttt-board, 300px); height: var(--ttt-board, 300px);
  display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr);
  touch-action: manipulation;
}
.ttt-square { background: transparent; border: 0; padding: 14%; border-radius: 20px; cursor: pointer; }
.ttt-square:disabled { cursor: default; }
.ttt-square:focus-visible { outline: 4px solid var(--sun); outline-offset: -8px; }
.ttt-grid.waiting .ttt-square { pointer-events: none; }
.ttt-grid.draw { animation: ttt-wiggle .7s ease-in-out; }
@keyframes ttt-wiggle { 20% { transform: rotate(-3deg); } 45% { transform: rotate(3deg); } 70% { transform: rotate(-1.5deg); } }
.ttt-line { position: absolute; inset: 0; pointer-events: none; }
.ttt-line svg { width: 100%; height: 100%; overflow: visible; }
.ttt-line path { fill: none; stroke-dasharray: 1; }
.ttt-line.on path { animation: ttt-draw .4s ease-out both; }

.ttt-card {
  position: relative; flex: none;
  width: var(--ttt-card, 150px);
  background: #fff; border: 4px solid var(--ink); border-radius: var(--radius);
  padding: 12px 10px 10px;
  display: grid; grid-template-areas: "a" "l" "s"; justify-items: center; align-content: center; gap: 4px;
  box-shadow: 0 8px 0 rgba(59, 45, 79, .35);
  transition: transform .25s, filter .25s, box-shadow .25s;
}
.ttt-card-avatar { grid-area: a; width: 76%; aspect-ratio: 1; }
.ttt-card-avatar img, .ttt-result-avatar img, .ttt-slot img { display: block; }
.ttt-card-avatar img { width: 100%; height: 100%; object-fit: contain; }
.ttt-card-label { grid-area: l; display: flex; align-items: center; justify-content: center; gap: 6px; max-width: 100%; min-width: 0; }
.ttt-card-badge { flex: none; width: clamp(24px, 3.4vmin, 32px); height: clamp(24px, 3.4vmin, 32px); }
.ttt-card .who-name { font-size: clamp(15px, 2.3vmin, 21px); min-width: 0; }
.ttt-score { grid-area: s; font-size: clamp(34px, 7vmin, 60px); line-height: 1; font-variant-numeric: tabular-nums; -webkit-text-stroke: .05em var(--ink); color: var(--mc); text-shadow: 0 .06em 0 var(--ink); }
/* Held upright: avatar and score side by side, mark + name across the bottom. */
.ttt-layout.port .ttt-card {
  grid-template-areas: "a s" "l l"; grid-template-columns: auto auto;
  justify-content: center; align-items: center; column-gap: 12px; row-gap: 4px; padding: 8px 10px;
}
.ttt-layout.port .ttt-card-avatar { width: clamp(44px, 13vw, 84px); }
.ttt-layout.port .ttt-card-badge { width: clamp(20px, 5.6vw, 30px); height: clamp(20px, 5.6vw, 30px); }
.ttt-layout.port .ttt-card-label { gap: 4px; }
.ttt-layout.port .ttt-score { font-size: clamp(30px, 9vw, 48px); }
.ttt-card.turn { transform: translateY(-6px); box-shadow: 0 0 0 6px var(--mc), 0 0 22px 10px var(--mc), 0 12px 0 6px rgba(59, 45, 79, .3); }
.ttt-card.turn .ttt-card-avatar { animation: ttt-bob 1.1s ease-in-out infinite; }
@keyframes ttt-bob { 50% { transform: translateY(-6%) rotate(-3deg); } }
.ttt-card.waiting { filter: grayscale(.7) brightness(.94); }
.ttt-card.winner { animation: ttt-jump .7s cubic-bezier(.2, 1.6, .4, 1) 2; }
@keyframes ttt-jump { 40% { transform: translateY(-26px) scale(1.12) rotate(-4deg); } }
.ttt-thinking { display: none; gap: 5px; position: absolute; bottom: -18px; background: #fff; border: 3px solid var(--ink); border-radius: 999px; padding: 5px 10px; }
.ttt-card.thinking .ttt-thinking { display: flex; }
.ttt-thinking i { width: 9px; height: 9px; border-radius: 50%; background: var(--mc); animation: ttt-dot 1s ease-in-out infinite; }
.ttt-thinking i:nth-child(2) { animation-delay: .15s; }
.ttt-thinking i:nth-child(3) { animation-delay: .3s; }
@keyframes ttt-dot { 50% { transform: translateY(-6px); } }

.ttt-result-art { display: flex; gap: 18px; }
.ttt-result .ttt-star { width: clamp(64px, 12vmin, 110px); height: clamp(64px, 12vmin, 110px); margin-bottom: -8px; }
.ttt-result-avatar { position: relative; width: clamp(96px, 20vmin, 170px); aspect-ratio: 1; }
.ttt-result-avatar img { width: 100%; height: 100%; }
.ttt-result.won .ttt-result-avatar { animation: ttt-jump .8s cubic-bezier(.2, 1.6, .4, 1) infinite; }

/* ---------- Six modes on the menu ---------- */

.mode-btn.tictactoe { --c: var(--sun); --cd: #e0a800; }
@media (min-aspect-ratio: 1/1) {
  .mode-btn { width: clamp(110px, min(18vmin, 14vw), 210px); }
}
@media (max-height: 520px) and (orientation: landscape) {
  .mode-btn { width: clamp(80px, 13.5vw, 130px); }
}

/* ---------- Menu groups: Labyrinth and Other games ---------- */

.mode-groups { display: flex; flex-wrap: wrap; justify-content: center; align-items: flex-start; gap: 12px clamp(20px, 3.5vw, 48px); max-width: 100%; }
.mode-group { display: flex; flex-direction: column; align-items: center; gap: 8px; min-width: 0; }
.mode-group-title {
  margin: 0; font-size: clamp(20px, 3.6vmin, 34px); color: #fff; white-space: nowrap;
  -webkit-text-stroke: .1em var(--ink); paint-order: stroke fill; text-shadow: 0 .08em 0 var(--ink);
}
.mode-group .mode-grid { display: flex; flex-wrap: nowrap; justify-content: center; }
@media (min-aspect-ratio: 1/1) and (min-height: 521px) {
  .mode-group .mode-btn { width: clamp(110px, min(20vmin, 13vw), 210px); }
}
@media (max-aspect-ratio: 1/1) {
  .mode-groups { flex-direction: column; align-items: center; gap: 22px; }
}
@media (max-height: 520px) and (orientation: landscape) {
  .mode-group { gap: 2px; }
  .mode-group-title { font-size: clamp(16px, 5vh, 22px); }
}

/* ---------- Before the game starts: the page's own text ---------- */

/* Crawlers and visitors without JavaScript read this; the game replaces it
   at once. Only the logo shows straight away, as a splash; the rest fades in
   only if the game has not started after 1.5 s. */
.boot {
  margin: auto; max-width: 640px; max-height: 100%; overflow-y: auto;
  text-align: center; font-weight: 700; font-size: 18px; line-height: 1.45;
  user-select: text; -webkit-user-select: text;
}
.boot-logo {
  margin: 0 0 12px; font-size: clamp(44px, 11vmin, 110px); line-height: 1;
  color: var(--sun); -webkit-text-stroke: .06em var(--ink); paint-order: stroke fill; text-shadow: 0 .07em 0 var(--ink);
}
.boot > :not(.boot-logo) { animation: boot-late .4s 1.5s both; }
@keyframes boot-late { from { opacity: 0; visibility: hidden; } }
.boot h2 { margin: 16px 0 4px; font-size: 24px; }
.boot ul { margin: 0; padding: 0; list-style: none; }
.boot li { margin: 4px 0; }
.boot a { color: var(--ink); }

/* ---------- Language switch (menu corner) ---------- */

.icon-btn.lang-btn { --c: #fff; --cd: #d6cbe8; color: var(--ink); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0; }
.icon-btn.lang-btn svg { width: 40%; height: 40%; }
.lang-btn .lang-code { font-size: 14px; line-height: 1; font-weight: 800; margin-top: 2px; }
.mode-btn .mode-label.long { font-size: .8em; letter-spacing: -.02em; }
/* Narrow phones: five corner buttons at the 64 px minimum, with tighter gaps. */
@media (max-width: 430px) {
  .menu-corner { --btn: 64px; }
  .menu-corner .avatar-btn { width: 64px; height: 64px; padding: 4px; }
  .menu-corner .corner-right, .menu-corner .sound-toggles { gap: 6px; }
}

/* ---------- Crocodiles ---------- */

.croc-best { font-size: clamp(20px, 3.6vmin, 30px); min-height: 52px; padding: 4px 16px; }
.croc-best[hidden] { display: none; }
.croc-best.beaten { background: #fff1b8; animation: croc-beaten .7s cubic-bezier(.2, 1.6, .4, 1); }
@keyframes croc-beaten { 40% { transform: scale(1.3) rotate(-6deg); } }
.croc-score { min-width: 2.4em; justify-content: center; font-weight: 800; font-size: clamp(32px, 6.5vmin, 56px); }
.croc-escapes { gap: 6px; padding: 4px 14px; }
.croc-marker { position: relative; width: clamp(34px, 6vmin, 48px); aspect-ratio: 1; flex: none; }
.croc-marker img { position: absolute; inset: 0; width: 100%; height: 100%; }
.croc-marker .filled { opacity: 0; transform: scale(.3); transition: transform .35s cubic-bezier(.2, 1.8, .4, 1), opacity .15s; }
.croc-marker.filled .filled { opacity: 1; transform: none; }
.croc-marker.filled .empty { opacity: 0; }

.croc-wrap { touch-action: none; }
.croc-wrap.mouse, .croc-wrap.mouse .croc-hole { cursor: none; }
/* The play screen sets --cols and --rows for the level and the board's shape
   (Easy: three columns of two holes on a wide board, two of three on a tall one). */
.croc-grid {
  --cols: 3; --rows: 2;
  position: absolute; inset: 0; margin: auto; z-index: 2;
  width: calc(var(--cols) * var(--croc-cell, 120px)); height: calc(var(--rows) * var(--croc-cell, 120px));
  display: grid; grid-template-columns: repeat(var(--cols), 1fr); grid-template-rows: repeat(var(--rows), 1fr);
  touch-action: none;
}
.croc-hole {
  position: relative; display: grid; place-items: center; min-width: 64px; min-height: 64px;
  background: transparent; border: 0; padding: 0; border-radius: 24px; cursor: pointer; touch-action: none;
}
.croc-stage { position: relative; width: 92%; aspect-ratio: 1; pointer-events: none; }
/* The pit is an ellipse 94% wide and 32% high, centred 21% above the stage's
   bottom; the clip's lower edge is the front half of that ellipse, so the
   crocodile rises from inside the hole. */
.croc-pit, .croc-lip { position: absolute; left: 0; bottom: 2%; width: 100%; height: 38%; }
.croc-lip { z-index: 2; }
.croc-clip {
  position: absolute; z-index: 1; left: 3%; width: 94%; top: -10%; height: 105%;
  overflow: hidden; border-radius: 0 0 50% 50% / 0 0 15.24% 15.24%;
}
/* Down in the hole unless it is up. The slides are a little shorter than the
   round's own timers (0.25 s to leave, 0.45 s dizzy), so a crocodile is out
   of sight before its hole counts as empty; if a slow frame cuts one short,
   the quick base transition finishes it. */
.croc {
  position: absolute; left: 10%; bottom: 0; width: 80%; aspect-ratio: 100 / 128;
  transform-origin: 50% 100%; transform: translateY(104%); transition: transform .1s linear;
}
.croc img { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; }
/* data-face, not data-state: an emptied hole keeps the face that went down. */
.croc-hole[data-face="up"] .up, .croc-hole[data-face="cheeky"] .cheeky, .croc-hole[data-face="dizzy"] .dizzy { opacity: 1; }
.croc-hole[data-state="up"] .croc { transform: none; transition: transform .2s cubic-bezier(.2, 1.5, .4, 1); }
.croc-hole[data-state="leaving"] .croc { transition: transform .2s ease-in; }
.croc-hole[data-state="bonked"] .croc { transition: none; animation: croc-bonk .4s ease-in forwards; }
@keyframes croc-bonk {
  0% { transform: scale(1.14, .82); }
  18% { transform: scale(.96, 1.05); }
  32% { transform: rotate(-6deg); }
  46% { transform: translateY(2%) rotate(6deg); }
  60% { transform: translateY(5%) rotate(-3deg); }
  100% { transform: translateY(104%); }
}
/* The round is over: everybody ducks. */
.croc-grid.over .croc { animation: none; transform: translateY(104%); transition: transform .3s ease-in; }

/* The first crocodile waits, with a ring and a bobbing hammer to show what to do. */
.croc-hole.hint .croc-stage::after {
  content: ""; position: absolute; z-index: 3; left: 4%; top: 0; width: 92%; aspect-ratio: 1;
  border-radius: 50%; border: 6px solid var(--sun); box-shadow: 0 0 0 3px var(--ink), inset 0 0 0 3px var(--ink);
  animation: croc-ring 1.1s ease-out infinite;
}
@keyframes croc-ring { from { transform: scale(.7); opacity: 1; } to { transform: scale(1.1); opacity: 0; } }
.croc-hint-hammer {
  position: absolute; z-index: 4; width: 36%; right: 0; top: 2%; pointer-events: none;
  transform-origin: 50% 96%; animation: croc-hint .9s ease-in-out infinite;
}
@keyframes croc-hint { 0%, 100% { transform: rotate(8deg); } 50% { transform: rotate(-40deg); } }

/* The hammer swings around the end of its handle; its head lands on (--x, --y). */
.croc-hammers { position: absolute; inset: 0; z-index: 3; overflow: hidden; pointer-events: none; }
.croc-hammer {
  position: absolute; width: var(--s); height: var(--s);
  left: calc(var(--x) + var(--s) * .17); top: calc(var(--y) - var(--s) * .84);
  transform-origin: 50% 96%; transform: rotate(-45deg);
}
.croc-hammer.swing { animation: croc-swing .26s ease-out both; }
.croc-hammer.mouse.swing { animation-name: croc-swing-mouse; }
@keyframes croc-swing {
  0% { transform: rotate(-30deg); }
  40%, 58% { transform: rotate(-82deg); opacity: 1; }
  100% { transform: rotate(-45deg); opacity: 0; }
}
@keyframes croc-swing-mouse { 0%, 100% { transform: rotate(-45deg); } 40%, 58% { transform: rotate(-82deg); } }

.croc-plus {
  position: absolute; left: var(--x); top: var(--y); pointer-events: none;
  font-size: calc(var(--croc-cell, 120px) * .36); font-weight: 800; line-height: 1; color: var(--sun);
  -webkit-text-stroke: .14em var(--ink); paint-order: stroke fill; text-shadow: 0 .07em 0 var(--ink);
  animation: croc-plus .9s ease-out forwards;
}
@keyframes croc-plus {
  0% { transform: translate(-50%, 40%) scale(.4); opacity: 0; }
  20% { transform: translate(-50%, 0) scale(1.15); opacity: 1; }
  70% { opacity: 1; }
  100% { transform: translate(-50%, -70%); opacity: 0; }
}
.croc-puff { position: absolute; z-index: 3; left: 25%; bottom: 12%; width: 50%; pointer-events: none; animation: croc-puff .4s ease-out forwards; }
@keyframes croc-puff { from { transform: scale(.4); opacity: .9; } to { transform: translateY(-12%) scale(1.3); opacity: 0; } }

/* The round card, with the crocodiles that got away peeking over its top edge. */
/* One grid cell the size of the board, so the card's height limit holds. */
.croc-wrap .overlay { grid-template: minmax(0, 1fr) / minmax(0, 1fr); }
.croc-card-wrap {
  --peek: clamp(30px, 8vmin, 60px);
  position: relative; display: flex; flex-direction: column; align-items: center;
  max-width: calc(100% - 24px); max-height: calc(100% - 16px); padding-top: var(--peek);
}
.croc-card-wrap .celebrate-card { position: relative; z-index: 1; min-height: 0; max-width: 100%; max-height: 100%; overflow: hidden; }
/* A long highscore list scrolls inside the card, so Play again stays in reach. */
.croc-result > * { flex: none; }
.croc-result > .result-extra { flex: 0 1 auto; min-height: 0; overflow-y: auto; padding: 2px 4px; }
.croc-peekers { position: absolute; top: 0; left: 0; right: 0; height: calc(var(--peek) * 2); display: flex; justify-content: center; gap: 4%; }
.croc-peeker { height: 100%; width: auto; aspect-ratio: 100 / 128; animation: croc-peek .6s cubic-bezier(.2, 1.6, .4, 1) both, croc-giggle .45s ease-in-out .6s infinite alternate; }
.croc-peeker:nth-child(2) { animation-delay: .12s, .72s; }
.croc-peeker:nth-child(3) { animation-delay: .24s, .84s; }
@keyframes croc-peek { from { transform: translateY(60%); } }
@keyframes croc-giggle { to { transform: translateY(-6%) rotate(3deg); } }
.croc-result-score { font-size: clamp(48px, 12vmin, 96px); font-weight: 800; line-height: 1; }

/* Play stays in the middle; the score to beat sits to its left. */
.croc-start { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: var(--gap); width: 100%; flex: none; }
.croc-start .croc-best { justify-self: end; }
.croc-start .play-btn { grid-column: 2; }

/* Upright phones: the back button, the score and the score to beat share the
   first row; the escape markers join the sound buttons on the second. */
@media (max-width: 600px) and (orientation: portrait) {
  .croc-play .playbar { justify-content: space-between; column-gap: 8px; }
  .croc-play .playbar .middle { display: contents; }
  .croc-play .croc-score { font-size: 32px; min-height: 56px; padding: 4px 14px; }
  .croc-play .croc-best { font-size: 20px; min-height: 48px; padding: 4px 12px; }
  .croc-play .croc-escapes { order: 5; min-height: 56px; padding: 4px 8px; }
  .croc-play .croc-marker { width: 30px; }
  .croc-play .playbar .sound-toggles { order: 6; width: auto; gap: 8px; }
}
/* Narrow phones: both card buttons side by side. */
@media (max-width: 400px) {
  .croc-result { padding: 14px 16px 18px; }
  .croc-result .icon-btn.big { width: 84px; height: 84px; }
}
/* Landscape phones: everything in the two-column side panel. */
@media (max-height: 520px) and (orientation: landscape) {
  .croc-play .playbar { grid-template-areas: "back score" "esc esc" "best best" "snd snd"; row-gap: 6px; }
  .croc-play .playbar .middle { display: contents; }
  .croc-play .croc-score { grid-area: score; min-width: 0; min-height: 56px; padding: 2px 4px; font-size: 26px; align-self: center; }
  .croc-play .croc-escapes { grid-area: esc; min-height: 44px; padding: 2px 8px; justify-content: center; gap: 4px; }
  .croc-play .croc-marker { width: 32px; }
  .croc-play .croc-best { grid-area: best; min-height: 40px; padding: 2px 10px; font-size: 20px; justify-content: center; }
  .croc-play .croc-best[hidden] { display: flex; visibility: hidden; }
  .croc-card-wrap { --peek: 26px; }
  .croc-result { padding: 8px 18px 12px; gap: 8px; }
  .croc-result .icon-btn.big { width: 72px; height: 72px; }
  .croc-result-score { font-size: 44px; }
}

/* ---------- Seven modes on the menu: Labyrinth (3) and Other games (4) ---------- */

.mode-btn.crocodiles { --c: var(--blue); --cd: var(--blue-dark); }
/* Wide screens: all seven in one row, 3 + 4. */
@media (min-aspect-ratio: 1/1) and (min-height: 521px) {
  .mode-groups { gap: 12px clamp(16px, 2.6vw, 44px); }
  .mode-group .mode-grid { gap: clamp(10px, 1.5vw, 26px); }
  .mode-group .mode-btn { width: clamp(96px, min(20vmin, 11vw), 210px); }
  .mode-label { font-size: clamp(14px, min(2.9vmin, 1.75vw), 30px); }
}
@media (max-height: 520px) and (orientation: landscape) {
  .mode-groups { gap: 8px clamp(12px, 2.4vw, 28px); }
  .mode-group .mode-grid { gap: clamp(6px, 1.2vw, 14px); }
  .mode-btn { width: clamp(64px, 11.2vw, 130px); padding: 6px 5px 8px; border-radius: 20px; }
  .mode-btn .mode-art { border-radius: 14px; padding: 3px; margin-bottom: 4px; }
  .mode-btn .mode-label { font-size: clamp(10px, 1.85vw, 20px); -webkit-text-stroke-width: 3px; }
  .mode-btn .mode-label.long { font-size: clamp(8px, 1.5vw, 16px); }
}
/* Upright tablets: four in a row still fit. */
@media (max-aspect-ratio: 1/1) {
  .mode-group.n4 .mode-btn { width: min(180px, calc((100vw - 32px - 16px - 36px) / 4)); }
}
/* Upright phones: "Other games" as two rows of two. */
@media (max-aspect-ratio: 1/1) and (max-width: 599px) {
  .mode-groups { gap: 12px; }
  .mode-group.n4 .mode-grid { display: grid; grid-template-columns: repeat(2, auto); }
  .mode-group .mode-btn, .mode-group.n4 .mode-btn { width: min(180px, calc((100vw - 32px - 24px - 12px) / 3)); aspect-ratio: 10 / 11; }
  .mode-group .mode-grid { margin-top: 2px; }
  .mode-btn .mode-label.long { font-size: min(.8em, 3.6vw); }
}

/* ---------- Sound check (#sound) ---------- */

.sound-check {
  flex: 1; min-height: 0; margin: 0; padding: 14px 16px; overflow: auto;
  background: #fff; border: 4px solid var(--ink); border-radius: 20px;
  font: 600 15px/1.5 ui-monospace, Menlo, Consolas, monospace; white-space: pre-wrap; overflow-wrap: anywhere;
  user-select: text; -webkit-user-select: text;
}
.sound-check-btn { width: 104px; height: 72px; margin-left: auto; }
.sound-check-btn svg { width: 40px; height: 40px; }

/* ---------- Setup screens on small phones ---------- */

/* What tic-tac-toe's setup already did, for every setup screen: centred when
   it fits and scrollable from the top when it doesn't (a centred column that
   overflows cuts off its top, out of reach), with smaller choices on a phone. */
.setup-body { justify-content: flex-start; }
.setup-body > :first-child { margin-top: auto; }
.setup-body > :last-child { margin-bottom: auto; }
@media (max-height: 520px), (max-width: 520px) {
  .setup-body { gap: var(--gap); }
  .setup-body .choice { min-width: 76px; min-height: 76px; padding: 6px 8px; }
  .setup-body .choice img, .setup-body .choice .dice { width: 52px; height: 52px; }
  /* Three star choices side by side, down to a 320 px wide phone. */
  .setup-body .choice .stars svg { width: min(26px, 6vw); height: min(26px, 6vw); }
  .setup-body .play-btn { width: 120px; height: 80px; }
}
/* A phone held sideways: Play stays in the corner, the choices get the height. */
@media (max-height: 520px) and (orientation: landscape) {
  .setup-body { padding-right: 128px; padding-bottom: 0; }
  .setup-body > .play-btn, .setup-body > .croc-start { position: fixed; right: 16px; bottom: 16px; z-index: 3; }
  .setup-body .play-btn { width: 104px; }
  .setup-body > :nth-last-child(2) { margin-bottom: auto; } /* the last one still in the column */
  .croc-start { display: flex; flex-direction: column; align-items: center; gap: 8px; width: auto; }
}

/* ---------- Baby ---------- */

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

/* Play bar: hearts, the level with its bar, the score to beat, good night. */
.baby-hearts { font-weight: 800; font-size: clamp(28px, 5.5vmin, 48px); min-width: 2.6em; justify-content: center; }
.baby-hearts.bump, .baby-level.bump { animation: croc-beaten .6s cubic-bezier(.2, 1.6, .4, 1); }
.baby-level { gap: 8px; font-weight: 800; font-size: clamp(22px, 4vmin, 34px); min-height: 52px; padding: 4px 14px; }
.baby-level-star { width: 1em; height: 1em; display: grid; place-items: center; border-radius: 50%; background: var(--purple); color: #fff; }
.baby-level-star svg { width: 70%; height: 70%; }
.baby-bar { width: clamp(44px, 9vmin, 96px); height: 14px; border-radius: 999px; background: #efe9f7; border: 2.5px solid var(--ink); overflow: hidden; }
.baby-bar i { display: block; height: 100%; width: var(--fill, 0%); background: #ff5d5d; transition: width .35s ease-out; }
.icon-btn.baby-moon { --c: #5b4a9e; --cd: #3f3275; }
.icon-btn.baby-moon svg { width: 62%; height: 62%; }
.icon-btn.baby-moon:disabled { opacity: .5; }

/* The board: the baby's stage and the tray. The tray is below on an upright
   board and at the side on a wide one, so the baby keeps the room. */
.baby-wrap { display: flex; touch-action: none; }
.baby-wrap.port { flex-direction: column; }
.baby-stage { position: relative; z-index: 2; flex: 1; min-width: 0; min-height: 0; display: grid; place-items: end center; padding: 6px; }
.baby-figure {
  position: relative; width: var(--baby, 200px); aspect-ratio: 200 / 232; flex: none;
  background: transparent; border: 0; padding: 0; border-radius: 30%; cursor: pointer; touch-action: none;
}
.baby-figure .baby-svg {
  display: block; width: 100%; height: 100%; overflow: visible; pointer-events: none;
  transform-origin: 50% 100%; transform: scale(var(--age, 1)); transition: transform .7s cubic-bezier(.2, 1.5, .4, 1);
}
.baby-figure.over .baby-svg { filter: drop-shadow(0 0 10px #fff) drop-shadow(0 0 4px var(--sun)); }
.baby-figure.grow { animation: baby-grow .9s cubic-bezier(.2, 1.6, .4, 1); }
@keyframes baby-grow { 30% { transform: scale(1.12) rotate(-3deg); } 60% { transform: scale(.97) rotate(2deg); } }
/* "No, not that": the head turns from side to side. */
.baby-figure.shake .baby-head { animation: baby-no .55s ease-in-out; transform-box: fill-box; transform-origin: 50% 90%; }
@keyframes baby-no { 20% { transform: rotate(-9deg); } 50% { transform: rotate(9deg); } 80% { transform: rotate(-5deg); } }
.baby-figure[data-mood="content"] .baby-head, .baby-figure[data-mood="playing"] .baby-head { animation: baby-bob 2.6s ease-in-out infinite; transform-box: fill-box; transform-origin: 50% 90%; }
@keyframes baby-bob { 50% { transform: rotate(2.5deg) translateY(-1%); } }
.baby-tear { animation: baby-tear 1s ease-in infinite; transform-box: fill-box; }
.baby-tear.late { animation-delay: .45s; }
@keyframes baby-tear { 0% { transform: translateY(-20%); opacity: 0; } 25% { opacity: 1; } 100% { transform: translateY(170%); opacity: 0; } }
.baby-z { animation: baby-z 2.4s ease-in-out infinite; }
.baby-z.z1 { animation-delay: .5s; }
.baby-z.z2 { animation-delay: 1s; }
@keyframes baby-z { 0%, 100% { opacity: .15; } 50% { opacity: 1; } }
.baby-stink { animation: baby-stink 1.4s ease-in-out infinite; transform-box: fill-box; }
@keyframes baby-stink { 50% { transform: translateY(-14%); opacity: .5; } }

/* The thing the baby is using, at its place on the baby. */
.baby-used {
  position: absolute; left: var(--sx, 50%); top: var(--sy, 50%); width: 34%; aspect-ratio: 1; pointer-events: none;
  transform: translate(-50%, -50%); animation: baby-use .5s ease-in-out infinite alternate;
}
.baby-used[data-thing="blanket"] { width: 62%; animation: none; }
.baby-used[data-thing="heart"] { animation: baby-heart .5s ease-in-out infinite alternate; }
.baby-used[data-thing="nappy"], .baby-used[data-thing="wipes"], .baby-used[data-thing="sponge"] { width: 40%; }
@keyframes baby-use { from { transform: translate(-50%, -50%) rotate(-7deg); } to { transform: translate(-50%, -48%) rotate(7deg); } }
@keyframes baby-heart { from { transform: translate(-50%, -50%) scale(.85); } to { transform: translate(-50%, -50%) scale(1.15); } }

/* Thought bubbles beside the baby's head: a picture of the thing that helps. */
.baby-bubble {
  --b: clamp(64px, calc(var(--baby, 200px) * .3), 132px);
  position: absolute; left: var(--bx, 70%); top: var(--by, 20%); width: var(--b); height: var(--b);
  display: grid; place-items: center; transform: translate(-50%, -50%); pointer-events: none;
  background: #fff; border: 4px solid var(--ink); border-radius: 50%; box-shadow: 0 5px 0 rgba(59, 45, 79, .25);
  animation: baby-bubble .4s cubic-bezier(.2, 1.7, .4, 1);
}
.baby-bubble[hidden] { display: none; }
.baby-bubble img { width: 72%; height: 72%; }
.baby-bubble::before, .baby-bubble::after {
  content: ""; position: absolute; background: #fff; border: 3px solid var(--ink); border-radius: 50%;
}
.baby-bubble::before { width: 22%; height: 22%; left: 2%; bottom: -8%; }
.baby-bubble::after { width: 12%; height: 12%; left: -10%; bottom: -20%; }
.baby-bubble.left::before { left: auto; right: 2%; }
.baby-bubble.left::after { left: auto; right: -10%; }
.baby-bubble[data-state="fussy"], .baby-bubble[data-state="crying"] { animation: baby-wobble .5s ease-in-out infinite; }
@keyframes baby-bubble { from { transform: translate(-50%, -50%) scale(.2); opacity: 0; } }
@keyframes baby-wobble { 0%, 100% { transform: translate(-50%, -50%) rotate(-5deg); } 50% { transform: translate(-50%, -50%) rotate(5deg); } }

/* A heart for every need met. */
.baby-plus {
  position: absolute; z-index: 3; left: 50%; top: 34%; width: clamp(40px, calc(var(--baby, 200px) * .22), 96px); pointer-events: none;
  animation: baby-plus 1s ease-out forwards;
}
@keyframes baby-plus {
  0% { transform: translate(-50%, 30%) scale(.3); opacity: 0; }
  25% { transform: translate(-50%, -20%) scale(1.2); opacity: 1; }
  70% { opacity: 1; }
  100% { transform: translate(-50%, -190%) scale(.9); opacity: 0; }
}

/* The tray of things, and a thing being dragged. */
.baby-tray {
  --thing: clamp(64px, 11vmin, 92px);
  position: relative; z-index: 2; flex: none; display: flex; flex-wrap: wrap; justify-content: center; align-content: center; gap: 6px; padding: 6px;
  background: rgba(255, 255, 255, .78); border-top: 4px solid var(--ink);
}
.baby-wrap.land .baby-tray { flex-direction: column; max-height: 100%; border-top: 0; border-left: 4px solid var(--ink); }
.baby-thing {
  width: var(--thing); height: var(--thing); flex: none; padding: 6px; cursor: grab; touch-action: none;
  background: #fff; border: 3px solid var(--ink); border-radius: 22%; box-shadow: 0 4px 0 rgba(59, 45, 79, .28);
  transition: transform .12s, background-color .12s;
}
.baby-thing img { width: 100%; height: 100%; pointer-events: none; }
.baby-thing.picked { transform: translateY(-8px) scale(1.08); background: #fff1b8; box-shadow: 0 10px 0 rgba(59, 45, 79, .22); }
.baby-thing.dragging img { opacity: .3; }
.baby-thing.new { animation: baby-new 1s cubic-bezier(.2, 1.6, .4, 1); }
@keyframes baby-new { 0% { transform: translateY(-140%) scale(.4) rotate(-20deg); opacity: 0; } 55% { transform: translateY(0) scale(1.2) rotate(6deg); opacity: 1; box-shadow: 0 0 0 8px var(--sun); } }
.baby-flying { position: absolute; inset: 0; z-index: 6; overflow: hidden; pointer-events: none; }
.baby-ghost {
  --thing: clamp(64px, 11vmin, 92px);
  position: absolute; width: var(--thing); height: var(--thing); left: calc(var(--x) - var(--thing) / 2); top: calc(var(--y) - var(--thing) / 2);
  transform: scale(1.2) rotate(-6deg); filter: drop-shadow(0 8px 6px rgba(59, 45, 79, .3));
}
.baby-ghost.back { transition: left .25s ease-in, top .25s ease-in, opacity .25s; opacity: 0; }

/* The good-night card. */
.baby-result > * { flex: none; }
.baby-result > .result-extra { flex: 0 1 auto; min-height: 0; overflow-y: auto; padding: 2px 4px; }
.baby-wrap .overlay { grid-template: minmax(0, 1fr) / minmax(0, 1fr); }
.baby-wrap .celebrate-card { max-height: calc(100% - 16px); overflow: hidden; }
.baby-result-moon { width: clamp(64px, 14vmin, 110px); aspect-ratio: 1; animation: spin-in 1s ease-out both; }
.baby-result-moon svg { width: 100%; height: 100%; }
.baby-result-score { font-size: clamp(44px, 11vmin, 88px); font-weight: 800; line-height: 1; }
.baby-result-top { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px 18px; }
.choice.baby-look img { width: clamp(64px, 11vmin, 120px); height: clamp(72px, 12.5vmin, 138px); }

/* The setup screen: the remembered baby asleep, or the four to pick from. */
.baby-slot { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: var(--gap); width: 100%; min-height: clamp(96px, 16vmin, 170px); flex: none; }
.baby-slot .choice-row { flex: 0 1 auto; width: auto; min-width: 0; }
.baby-saved {
  display: flex; align-items: center; gap: clamp(8px, 2vmin, 18px); padding: 8px clamp(12px, 3vmin, 24px);
  background: #fff; border: 4px solid var(--ink); border-radius: var(--radius); box-shadow: 0 5px 0 rgba(59, 45, 79, .25);
}
.baby-saved > img { width: clamp(88px, 17vmin, 170px); height: clamp(102px, 19.7vmin, 197px); }
.baby-saved-pills { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }
.baby-saved-pills .pill { font-size: clamp(20px, 3.6vmin, 30px); min-height: 44px; padding: 4px 14px; }
.baby-saved-pills .pill > span:first-child { width: 1.1em; height: 1.1em; display: inline-grid; }
.baby-saved-pills .pill svg { width: 100%; height: 100%; }
.baby-new, .baby-keep {
  position: relative; flex: none; display: grid; place-items: center; cursor: pointer;
  width: clamp(72px, 12vmin, 104px); height: clamp(72px, 12vmin, 104px); padding: 6px;
  background: #fff; border: 4px solid var(--ink); border-radius: 26%; box-shadow: 0 5px 0 rgba(59, 45, 79, .28);
}
.baby-new { margin: 10px 10px 0 0; } /* room for the plus that sticks out */
.baby-keep { margin: 12px 0 0 12px; } /* and for the arrow */
.baby-new:active, .baby-keep:active { transform: translateY(3px); box-shadow: 0 2px 0 rgba(59, 45, 79, .28); }
.baby-new img, .baby-keep img { width: 100%; height: 100%; }
.baby-new-plus {
  position: absolute; right: -10px; top: -10px; width: 36px; height: 36px; display: grid; place-items: center;
  background: var(--green); color: #fff; border: 3px solid var(--ink); border-radius: 50%; font-size: 26px; font-weight: 800; line-height: 1;
}
.baby-keep > span { position: absolute; left: -12px; top: -12px; width: 38px; height: 38px; display: grid; place-items: center; background: var(--orange); color: #fff; border: 3px solid var(--ink); border-radius: 50%; }
.baby-keep > span svg { width: 70%; height: 70%; }
/* "Are you sure?": the remembered baby, an arrow, the new one. */
.baby-swap { width: min(520px, 100%); max-height: 100%; overflow: hidden; }
.baby-swap-art { display: flex; align-items: center; justify-content: center; gap: clamp(6px, 2vmin, 14px); min-width: 0; }
.baby-swap-art .import-arrow { flex: none; }
.baby-swap-art > img { width: clamp(72px, 16vmin, 120px); height: clamp(84px, 18.5vmin, 139px); }
.baby-swap-old { display: flex; align-items: center; gap: 8px; }
.baby-swap-old > img { width: clamp(72px, 16vmin, 120px); height: clamp(84px, 18.5vmin, 139px); }
.baby-swap .actions { display: flex; justify-content: center; gap: clamp(16px, 5vmin, 40px); }
.baby-wake svg { width: 74%; height: 74%; }
@media (max-width: 600px) and (orientation: portrait) {
  .baby-swap { padding: 14px; }
  .baby-swap-old { flex-direction: column; gap: 4px; }
  .baby-swap-old .baby-saved-pills { flex-direction: row; gap: 4px; }
  .baby-swap-art .import-arrow { width: 32px; height: 32px; }
  .baby-swap .icon-btn.big { width: 84px; height: 84px; }
  .baby-swap .baby-saved-pills .pill { font-size: 18px; min-height: 36px; padding: 2px 10px; }
}
@media (max-height: 520px) and (orientation: landscape) {
  .baby-slot { min-height: 0; }
  .baby-saved > img { width: 70px; height: 81px; }
  .baby-swap { padding: 10px 16px; gap: 8px; }
  .baby-swap .icon-btn.big { width: 72px; height: 72px; }
  .baby-swap-art > img, .baby-swap-old > img { width: 64px; height: 74px; }
}

/* Upright phones: back, hearts and the level share the first row; good
   night and the sound buttons the second. */
@media (max-width: 600px) and (orientation: portrait) {
  .baby-play .playbar { justify-content: space-between; column-gap: 8px; }
  .baby-play .playbar .middle { display: contents; }
  .baby-play .baby-hearts { font-size: 30px; min-height: 56px; padding: 4px 12px; min-width: 0; }
  .baby-play .baby-level { font-size: 22px; min-height: 48px; padding: 4px 10px; gap: 6px; }
  .baby-play .baby-bar { width: 40px; }
  .baby-play .baby-moon { order: 6; }
  .baby-play .playbar .sound-toggles { order: 7; width: auto; gap: 8px; }
  .baby-result { padding: 14px 16px 18px; }
}
/* Narrow phones: the bar stays two rows (back, hearts, level; then good
   night and the sound buttons), and the card stays short. */
@media (max-width: 400px) and (orientation: portrait) {
  .baby-play .playbar { column-gap: 4px; row-gap: 8px; }
  .baby-play .playbar .icon-btn { width: 64px; height: 64px; }
  .baby-play .baby-hearts { font-size: 26px; padding: 4px 9px; gap: 6px; }
  .baby-play .baby-level { font-size: 20px; padding: 4px 8px; gap: 5px; }
  .baby-play .baby-bar { width: 30px; }
  .baby-play .playbar .sound-toggles { gap: 4px; }
  .baby-tray { gap: 4px; padding: 4px; }
  .baby-result { gap: 8px; }
  .baby-result .icon-btn.big { width: 84px; height: 84px; }
  .baby-result .big-star, .baby-result-moon { width: 60px; height: 60px; }
}
/* Landscape phones: everything in the two-column side panel. */
@media (max-height: 520px) and (orientation: landscape) {
  .baby-play .playbar { grid-template-areas: "back moon" "hearts hearts" "level level" "snd snd"; row-gap: 5px; }
  .baby-play .playbar .middle { display: contents; }
  .baby-play .baby-moon { grid-area: moon; }
  .baby-play .baby-hearts { grid-area: hearts; min-height: 42px; padding: 2px 8px; font-size: 26px; justify-content: center; }
  .baby-play .baby-level { grid-area: level; min-height: 40px; padding: 2px 8px; font-size: 20px; justify-content: center; }
  .baby-play .baby-bar { width: 44px; height: 12px; }
  .baby-result { padding: 8px 18px 12px; gap: 6px; }
  .baby-result .icon-btn.big { width: 72px; height: 72px; }
  .baby-result-score { font-size: 40px; }
  .baby-result-moon { width: 48px; }
  .baby-result .big-star { width: 60px; height: 60px; }
}

/* ---------- Eight modes on the menu: Labyrinth (3) and Other games (5) ---------- */

.mode-btn.baby { --c: var(--red); --cd: var(--red-dark); }
/* Wide screens: all eight in one row, 3 + 5. */
@media (min-aspect-ratio: 1/1) and (min-height: 521px) {
  .mode-groups { gap: 12px clamp(14px, 2.2vw, 40px); }
  .mode-group .mode-grid { gap: clamp(8px, 1.2vw, 22px); }
  .mode-group .mode-btn { width: clamp(88px, min(19vmin, 9.9vw), 200px); }
  .mode-label { font-size: clamp(13px, min(2.8vmin, 1.6vw), 28px); }
}
/* Phones held sideways: eight buttons don't fit one row, so the groups stack. */
@media (max-height: 520px) and (orientation: landscape) {
  .menu .logo { font-size: 7vmin; }
  .mode-groups { flex-direction: column; align-items: center; gap: 10px; }
  .mode-group { flex-direction: row; align-items: center; gap: 10px; }
  .mode-group-title { font-size: clamp(13px, 4.4vh, 18px); min-width: 5.5em; text-align: right; }
  .mode-group .mode-grid { margin-top: 0; gap: 8px; }
  .mode-btn { width: clamp(64px, min(12vw, 24vh), 110px); aspect-ratio: 1; padding: 5px 5px 7px; }
  .mode-btn .mode-label { font-size: clamp(10px, min(1.9vw, 3.6vh), 16px); }
  .mode-btn .mode-label.long { font-size: clamp(8px, min(1.5vw, 3vh), 13px); }
}
/* Upright tablets: five in a row still fit, with smaller labels. */
@media (max-aspect-ratio: 1/1) and (min-width: 600px) {
  .mode-group.n5 .mode-btn { width: min(180px, calc((100vw - 32px - 16px - 48px) / 5)); }
  .mode-group.n5 .mode-label { font-size: clamp(14px, 2.5vw, 24px); }
}
/* Upright phones: "Other games" in rows of three. */
@media (max-aspect-ratio: 1/1) and (max-width: 599px) {
  .mode-group.n5 .mode-grid { flex-wrap: wrap; width: calc(100vw - 32px); }
  .mode-group.n5 .mode-btn { width: min(180px, calc((100vw - 32px - 24px - 12px) / 3)); aspect-ratio: 10 / 11; }
}
