.city-challenges {
  position: fixed;
  z-index: 38;
  inset: 0;
  display: grid;
  justify-items: center;
  align-items: safe center;
  overflow: auto;
  overscroll-behavior: contain;
  padding: max(14px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  background: #151e2be6;
  animation: city-challenge-scrim 180ms ease-out both;
}

.city-challenges[hidden], .city-challenges [hidden] { display: none; }

.city-challenge {
  --case: #527b6b;
  --trim: #f8d78c;
  --bottom: color-mix(in srgb, var(--case), #192436 65%);
  --upper: color-mix(in srgb, var(--case), #d9dacb 20%);
  --panel: #f4ead8;
  --ink: #29323d;
  inline-size: min(100%, 63rem);
  box-sizing: border-box;
  padding: clamp(10px, 2vw, 21px);
  color: var(--ink);
  background-color: var(--case);
  background-image: linear-gradient(158deg, var(--upper) 0%, transparent 57%);
  border: 3px solid #18222d;
  border-radius: 22px 22px 32px 32px;
  box-shadow: inset 0 2px #fffcf546, inset 0 -9px var(--bottom), 0 6px #0e1420, 6px 12px 24px #0d131fd4;
  outline: none;
  animation: city-challenge-focus 270ms cubic-bezier(.16,.75,.25,1) both;
}

.city-challenge[data-case="sport"] { border-radius: 13px 28px 28px 39px; }
.city-challenge[data-case="atlas"] { border-radius: 24px 24px 28px 28px; }
.city-challenge[data-case="studio"] {
  border-radius: 17px 17px 35px 35px;
  background-image: repeating-linear-gradient(0deg, transparent 0 5px, #18222d24 5px 6px), linear-gradient(158deg, var(--upper) 0%, transparent 57%);
}
.city-challenge[data-case="instrument"] {
  border-radius: 8px 8px 23px 23px;
  background-image: repeating-linear-gradient(90deg, #ffffff0a 0 3px, transparent 3px 10px), linear-gradient(158deg, var(--upper) 0%, transparent 57%);
}

.city-challenge-head, .city-challenge-brand {
  display: flex;
  align-items: center;
  gap: clamp(8px, 1.5vw, 14px);
}

.city-challenge-head {
  justify-content: space-between;
  padding: 0 2px 10px;
  color: #fff9e5;
  text-shadow: 0 2px var(--bottom);
}

.city-challenge-brand { min-width: 0; }

.city-challenge-badge {
  flex: none;
  display: block;
  inline-size: clamp(32px, 5vw, 48px);
  block-size: clamp(32px, 5vw, 48px);
  box-sizing: content-box;
  background: #262c3a;
  border: 2px solid var(--trim);
  border-radius: 5px;
  box-shadow: 2px 2px #1a2330;
  image-rendering: pixelated;
}

.city-challenge-place {
  margin: 0 0 3px;
  color: #fff0c9;
  font-size: clamp(.72rem, 1.5vw, .85rem);
  font-weight: 760;
  line-height: 1.15;
}

.city-challenge-head h2 {
  margin: 0;
  font: 700 clamp(1.25rem, 3.2vw, 2.32rem)/1 var(--display, system-ui, sans-serif);
  overflow-wrap: anywhere;
}

.city-challenge-exit {
  flex: none;
  min-block-size: 44px;
  max-inline-size: 6.4rem;
  padding: 4px 10px;
  background: #272e40;
  color: #fff5cf;
  border: 2px solid var(--bottom);
  border-radius: 7px;
  box-shadow: inset 0 2px #fff7d12e, 0 3px #192230;
  font-size: .77rem;
  font-weight: 800;
  line-height: 1.1;
  touch-action: manipulation;
}

.city-challenge-exit:hover { background: #3a3d4a; }
.city-challenge-exit:focus-visible { outline: 3px solid #fff1bc; outline-offset: 3px; }

.city-challenge-body {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(16rem, 1fr);
  align-items: stretch;
  gap: clamp(7px, 1.5vw, 13px);
  padding: clamp(6px, 1.3vw, 12px);
  background: #252c3a;
  border: 2px solid #182030;
  border-radius: 11px 11px 17px 17px;
  box-shadow: inset 0 2px 3px #111925, 0 1px #ffffff5c;
}

.city-challenge-picture {
  min-width: 0;
  align-self: start;
  background: #1d2934;
  color: #fff5d6;
  border: 1px solid #101b23;
  border-radius: 5px;
}

.city-challenge-glass { position: relative; overflow: hidden; border-radius: 4px; }

.city-challenge-glass canvas {
  display: block;
  width: 100%;
  height: auto;
  background: #485b62;
  image-rendering: pixelated;
}

.city-challenge-glass canvas.is-touchable {
  touch-action: none;
  cursor: crosshair;
}

.city-challenge-touch {
  margin: 0;
  padding: 7px 9px;
  border-block-start: 2px solid var(--trim);
  font-size: .79rem;
  line-height: 1.3;
}

.city-challenge-grille {
  display: flex;
  justify-content: end;
  gap: 5px;
  padding: 9px 6px 1px;
}

.city-challenge-grille i {
  inline-size: 15px;
  block-size: 4px;
  border-radius: 1px;
  background: var(--bottom);
  box-shadow: 0 1px #ffffff50;
}
.city-challenge[data-case="sport"] .city-challenge-grille i { transform: skewX(-25deg); }
.city-challenge[data-case="studio"] .city-challenge-grille { justify-content: center; }
.city-challenge[data-case="instrument"] .city-challenge-grille i { inline-size: 6px; }

.city-challenge-motion {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 6.8rem), 1fr));
  gap: 5px;
}

.city-challenge-motion label {
  min-inline-size: 0;
  display: grid;
  padding: .25rem .45rem;
  background: #f8f1df;
  border: 1px solid #a09487;
  border-radius: 5px;
  font-weight: 750;
  font-size: .79rem;
}

.city-challenge-motion input { width: 100%; min-height: 26px; accent-color: #48496e; }

.city-challenge-meter {
  pointer-events: none;
  position: absolute;
  inset-inline: 15%;
  bottom: max(8px, 5%);
  height: 13px;
  border: 2px solid #fff0c1;
  background: #263745;
  box-shadow: 0 0 0 2px #1d2837;
}

.city-challenge-band {
  position: absolute;
  inset-block: 0;
  left: var(--start, 40%);
  right: calc(100% - var(--end, 60%));
  border-inline: 2px solid #f7d78e;
  background: repeating-linear-gradient(135deg, #cc9859 0 2px, #ebc47c 2px 5px);
}

.city-challenge-marker {
  position: absolute;
  left: var(--marker, 0%);
  inset-block: -4px;
  transform: translateX(-50%);
  width: 5px;
  background: #fffdf1;
  border: 1px solid #2f3531;
}

.city-challenge-play {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: clamp(8px, 1.3vw, 14px);
  background: var(--panel);
  border-radius: 5px;
  box-shadow: inset 0 0 0 1px #b6a994;
  font-size: .88rem;
  line-height: 1.3;
}

.city-challenge-play p { margin: 0; }
.city-challenge-stat {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 4px 8px;
  padding: 5px 7px;
  border-radius: 4px;
  background: #262f3d;
  color: #fff7db;
  font-size: .78rem;
  font-weight: 800;
}
.city-challenge-stat span:last-child { margin-left: auto; color: var(--trim); }
.city-challenge-prompt { font-size: clamp(.97rem, 1.5vw, 1.18rem); font-weight: 790; line-height: 1.14; }
.city-challenge-position { font-size: .78rem; font-variant-numeric: tabular-nums; color: #49434d; }
.city-challenge-feedback, .city-challenge-evidence {
  border-inline-start: 3px solid var(--case);
  padding: 5px 7px;
  color: #413b43;
  background: #e7dcc8;
  font-size: .82rem;
}

.city-challenge-choices {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 7.6rem), 1fr));
  gap: 6px;
}

.city-challenge-choices:empty { display: none; }
.city-challenge[data-game="mosaic"][data-phase="play"] .city-challenge-choices { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.city-challenge[data-game="mosaic"] .city-challenge-choices [data-choice="check"] { grid-column: span 2; }

.city-challenge-choices button {
  display: flex;
  justify-content: start;
  align-items: center;
  gap: 6px;
  min-block-size: 44px;
  min-inline-size: 0;
  padding: 5px 7px;
  background: #343c4d;
  color: #fff6d9;
  border: 2px solid #242b3d;
  border-radius: 7px;
  box-shadow: inset 0 2px #ffffff22, 0 2px #746a68;
  font-weight: 770;
  font-size: .86rem;
  line-height: 1.1;
  text-align: left;
  overflow-wrap: anywhere;
  touch-action: manipulation;
}

.city-challenge-choices button:hover { background: #495063; }
.city-challenge-choices button:active { box-shadow: inset 0 2px #13192338; translate: 0 2px; }
.city-challenge-choices button:focus-visible { outline: 3px solid #322769; outline-offset: 2px; }
.city-challenge-choices button[aria-pressed="true"] {
  box-shadow: inset 0 0 0 2px #fff3ca, 0 2px #746a68;
  background: #5b465e;
}

.city-challenge-choices button:is([data-choice="begin"], [data-choice="again"], [data-choice="check"], [data-choice="motion-action"], [data-choice="motion-ready"]) {
  background: var(--trim);
  color: #22263a;
  box-shadow: inset 0 2px #ffffff55, 0 2px #746a68;
}
.city-challenge-choices button:is([data-choice="begin"], [data-choice="again"], [data-choice="check"], [data-choice="motion-action"], [data-choice="motion-ready"]):hover {
  background: color-mix(in srgb, var(--trim), #fffdd5 40%);
}
.city-challenge-choices [data-palette] {
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px;
  text-align: center;
  font-size: .75rem;
}
.city-challenge-choices [data-palette]::before {
  content: '';
  inline-size: 12px;
  block-size: 12px;
  background: var(--tile);
  border: 1px solid #fff6dbb4;
  box-shadow: 1px 1px #162030;
}
.city-challenge-choices [data-choice="work-key"] {
  touch-action: none;
  user-select: none;
}

.city-challenge-choices kbd {
  flex: none;
  display: grid;
  place-items: center;
  min-width: 18px;
  height: 18px;
  border: 1px solid #b9ad9675;
  border-radius: 2px;
  background: #1e2738;
  color: #fff2cf;
  font: 650 .76rem/1 ui-monospace, monospace;
}

.city-challenge-players { display: flex; flex-wrap: wrap; gap: 4px 6px; margin: auto 0 0; padding: 1px 0 0; list-style: none; }
.city-challenge-players li { background: #e7dbc6; padding: 3px 7px; font-size: .78rem; overflow-wrap: anywhere; }
.city-challenge-players strong { color: #252b3c; font-variant-numeric: tabular-nums; }

@media (max-width: 700px) and (orientation: portrait) {
  .city-challenge-body { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 410px) {
  .city-challenges { padding-inline: max(7px, env(safe-area-inset-left)) max(7px, env(safe-area-inset-right)); }
  .city-challenge { padding: 9px; }
  .city-challenge-play { font-size: .84rem; }
  .city-challenge-choices button { padding-inline: 5px; }
}
@media (max-height: 540px) {
  .city-challenges { padding-block: max(6px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-bottom)); }
  .city-challenge { padding: 8px 11px 11px; }
  .city-challenge-head { padding-bottom: 6px; }
  .city-challenge-head h2 { font-size: clamp(1.15rem, 3.1vw, 1.7rem); }
  .city-challenge-body { gap: 7px; padding: 6px; }
  .city-challenge-play { gap: 5px; padding: 7px; }
  .city-challenge-motion label { padding-block: 0; }
  .city-challenge-grille { padding-top: 6px; }
}
@media (pointer: coarse) {
  .city-challenge-choices kbd { display: none; }
  .city-challenge-motion input { min-height: 38px; }
}

@keyframes city-challenge-scrim { from { background: #151e2b00; } }
@keyframes city-challenge-focus {
  from { transform: translateY(7px) scale(.975); opacity: .32; }
  to { transform: none; opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .city-challenges, .city-challenge { animation: none; }
}

/* The shared arcade caps follow the handheld's own moulded colours. */
#city-challenge .city-challenge .city-challenge-choices button:enabled:not([data-choice^="inspect:"]) {
  --arcade-face: color-mix(in srgb, var(--case), #e0e3e4 62%);
  --arcade-light: color-mix(in srgb, var(--case), #f8f6ec 80%);
  --arcade-shadow: color-mix(in srgb, var(--case), #414857 38%);
  --arcade-ink: #1d2733;
}

#city-challenge .city-challenge .city-challenge-choices button:enabled:is([data-choice="begin"], [data-choice="again"], [data-choice="check"], [data-choice="motion-action"], [data-choice="motion-ready"], [aria-pressed="true"]) {
  --arcade-face: var(--trim);
  --arcade-light: color-mix(in srgb, var(--trim), #fff7db 48%);
  --arcade-shadow: color-mix(in srgb, var(--trim), #57516b 45%);
  --arcade-ink: #22263a;
}

@media (max-height: 440px) and (orientation: landscape) {
  .city-challenge-body { grid-template-columns: minmax(0, 1.24fr) minmax(0, 1fr); }
  .city-challenge-play { font-size: .83rem; }
  .city-challenge-position { font-size: .74rem; }
}

.city-challenge-choices button.tile-direction {
  justify-content: center;
  font-size: .98rem;
}

.tile-direction span { font-family: system-ui, sans-serif; }
