:root {
  color-scheme: light;
  --ink: #222827;
  --paper: #f3efe4;
  --card: #fffaf0;
  --line: #c9c3b6;
  --coral: #e67e67;
  --teal: #609593;
  --gold: #d9b84f;
  --muted: #686d68;
  --success: #b8cfad;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --page-inline: clamp(.75rem, 3vw, 1.125rem);
  font-family: ui-monospace, "SFMono-Regular", "SF Mono", Menlo, monospace;
  font-size: 16px;
  background: var(--paper);
  color: var(--ink);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-width: 0;
  min-height: 100%;
  background: var(--paper);
}

html {
  scroll-padding-block: 5rem;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  background-image:
    linear-gradient(rgba(34, 40, 39, .035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(34, 40, 39, .035) 1px, transparent 1px);
  background-size: 22px 22px;
}

body[data-mode="game"] {
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
a:focus-visible,
dialog:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: 3px;
}

.shell {
  width: min(100%, 760px);
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding-top: calc(1.125rem + var(--safe-top));
  padding-right: calc(var(--page-inline) + var(--safe-right));
  padding-bottom: calc(1.5rem + var(--safe-bottom));
  padding-left: calc(var(--page-inline) + var(--safe-left));
}

.surface-metrics-probe {
  position: fixed;
  z-index: -100;
  top: 0;
  left: 50%;
  width: min(100%, 760px);
  height: 100vh;
  height: 100dvh;
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: .35rem;
  visibility: hidden;
  pointer-events: none;
  transform: translateX(-50%);
  padding-top: calc(.45rem + var(--safe-top));
  padding-right: calc(var(--page-inline) + var(--safe-right));
  padding-bottom: calc(.45rem + var(--safe-bottom));
  padding-left: calc(var(--page-inline) + var(--safe-left));
}

.surface-metrics-probe > .topbar {
  min-height: 2.75rem;
  margin: 0;
}

.surface-metrics-probe > .game-shell {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: .35rem;
}

.surface-metrics-probe .game-surface {
  height: 100%;
  box-shadow: none;
}

.topbar,
.game-meta {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
}

.topbar {
  min-height: 2.75rem;
  margin-bottom: clamp(2rem, 7vh, 4.625rem);
}

.brand {
  display: inline-flex;
  min-width: 0;
  min-height: 2.75rem;
  align-items: center;
  gap: .6875rem;
  color: var(--ink);
  text-decoration: none;
  font-weight: 900;
  letter-spacing: .08em;
}

.brand > span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand-mark {
  display: grid;
  flex: 0 0 2.125rem;
  width: 2.125rem;
  height: 2.125rem;
  place-items: center;
  border: 2px solid var(--ink);
  background: var(--coral);
  box-shadow: 3px 3px 0 var(--ink);
}

.topbar-actions {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: flex-end;
  gap: .4rem;
}

.header-button,
.status {
  min-height: 2.75rem;
  border: 1px solid var(--ink);
  padding: .5rem .625rem;
  background: var(--card);
  color: var(--ink);
  font-size: .6875rem;
  font-weight: 800;
  letter-spacing: .08em;
}

.header-button {
  display: inline-flex;
  align-items: center;
}

.status {
  display: inline-grid;
  place-items: center;
  white-space: nowrap;
}

.status.connected {
  background: var(--success);
}

.status.connecting,
.status.reconnecting {
  background: #f0d98c;
}

.status.offline {
  background: #efaaa0;
}

.connection-panel {
  position: fixed;
  z-index: 80;
  right: calc(.75rem + var(--safe-right));
  bottom: calc(.75rem + var(--safe-bottom));
  left: calc(.75rem + var(--safe-left));
  width: min(42rem, calc(100% - 1.5rem - var(--safe-left) - var(--safe-right)));
  margin-inline: auto;
  padding: .875rem;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: .75rem;
  align-items: center;
  border: 2px solid var(--ink);
  background: #fff3d0;
  box-shadow: 6px 6px 0 var(--ink);
}

.connection-panel > div:first-child {
  min-width: 0;
}

.connection-panel strong,
.connection-panel span {
  display: block;
}

.connection-panel strong {
  font-size: .75rem;
  letter-spacing: .08em;
}

.connection-panel span {
  margin-top: .3rem;
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: .8125rem;
  line-height: 1.4;
}

.connection-actions {
  display: flex;
  flex-wrap: wrap;
  gap: .375rem;
}

.connection-actions button {
  min-height: 2.75rem;
  border: 1px solid var(--ink);
  padding: .5rem .625rem;
  background: var(--ink);
  color: var(--paper);
  font-size: .6875rem;
  font-weight: 900;
}

.connection-actions button:last-child {
  background: transparent;
  color: var(--ink);
}

.join-card,
.lobby-card {
  width: 100%;
  max-width: 35rem;
  margin: 0 auto;
  padding: clamp(1.5rem, 6vw, 2.875rem);
  border: 2px solid var(--ink);
  background: var(--card);
  box-shadow: 8px 8px 0 var(--ink);
  overflow-wrap: anywhere;
}

.eyebrow {
  margin: 0 0 .875rem;
  color: var(--teal);
  font-size: .75rem;
  font-weight: 900;
  letter-spacing: .14em;
}

h1,
h2 {
  margin: 0;
  font-family: "Arial Black", Impact, ui-sans-serif, system-ui, sans-serif;
  line-height: .95;
  letter-spacing: -.045em;
  text-transform: uppercase;
}

h1 {
  max-width: 14ch;
  font-size: clamp(2.125rem, 9vw, 3.875rem);
}

h2 {
  font-size: clamp(1.75rem, 6vw, 3rem);
}

.lede {
  margin: 1.375rem 0 1.75rem;
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 1.0625rem;
  line-height: 1.55;
  color: #4d5350;
}

form {
  display: grid;
  gap: 1.125rem;
}

label {
  display: grid;
  gap: .5rem;
}

label > span {
  font-size: .6875rem;
  font-weight: 900;
  letter-spacing: .11em;
}

label small {
  color: var(--muted);
}

input {
  width: 100%;
  min-height: 3.625rem;
  border: 2px solid var(--ink);
  border-radius: 0;
  padding: .75rem .9375rem;
  appearance: none;
  background: #fffdf7;
  color: var(--ink);
  font-size: 1.25rem;
}

#room-code {
  font-size: 1.875rem;
  font-weight: 900;
  letter-spacing: .28em;
  text-transform: uppercase;
}

input:focus {
  box-shadow: 4px 4px 0 var(--teal);
}

.primary,
.edge-button {
  width: 100%;
  min-height: 3.875rem;
  border: 2px solid var(--ink);
  border-radius: 0;
  padding: .875rem 1.0625rem;
  background: var(--ink);
  color: var(--paper);
  font-weight: 900;
  letter-spacing: .06em;
  box-shadow: 4px 4px 0 var(--coral);
}

.primary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.primary:disabled,
.edge-button:disabled {
  cursor: default;
  opacity: .62;
  box-shadow: none;
}

.primary:not(:disabled):active,
.edge-button:not(:disabled):active {
  transform: translate(3px, 3px);
  box-shadow: 1px 1px 0 var(--coral);
}

.error {
  margin: 1.25rem 0 0;
  padding: .75rem;
  border: 2px solid var(--ink);
  background: #efaaa0;
  font-family: ui-sans-serif, system-ui, sans-serif;
  line-height: 1.45;
}

.safety-note {
  display: flex;
  gap: .8125rem;
  margin-top: 1.75rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--line);
}

.safety-note > span {
  display: grid;
  flex: 0 0 2.125rem;
  width: 2.125rem;
  height: 2.125rem;
  place-items: center;
  border: 1px solid var(--ink);
  background: var(--gold);
  font-size: 1.25rem;
}

.safety-note p {
  margin: 0;
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: .8125rem;
  line-height: 1.5;
}

.back-button {
  min-height: 2.75rem;
  margin: 0 0 1.25rem;
  border: 0;
  padding: .5rem 0;
  background: transparent;
  color: var(--ink);
  font-size: .6875rem;
  font-weight: 900;
  letter-spacing: .1em;
}

.identity {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: .9375rem;
  margin: 0 0 2rem;
  padding: .875rem;
  border: 1px solid var(--ink);
  background: var(--paper);
}

.identity-symbol {
  display: grid;
  flex: 0 0 2.9375rem;
  width: 2.9375rem;
  height: 2.9375rem;
  place-items: center;
  font-size: 2.125rem;
}

.identity div {
  display: grid;
  min-width: 0;
  gap: .25rem;
}

.identity strong {
  overflow: hidden;
  font-size: 1rem;
  letter-spacing: .08em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.identity small,
.waiting {
  color: var(--muted);
  font-size: .6875rem;
  letter-spacing: .08em;
}

.player-count {
  display: flex;
  min-width: 0;
  align-items: baseline;
  gap: .75rem;
  margin: 1.625rem 0 1.25rem;
  padding: 1.0625rem 0;
  border-block: 1px solid var(--line);
}

.player-count strong {
  font-family: "Arial Black", Impact, sans-serif;
  font-size: 2.375rem;
}

.player-count span {
  font-size: .6875rem;
  font-weight: 900;
  letter-spacing: .1em;
}

.waiting {
  display: block;
  margin: 1.125rem 0 0;
  font-family: ui-sans-serif, system-ui, sans-serif;
  line-height: 1.55;
  text-align: center;
}

#calibration-actions {
  display: grid;
  gap: .75rem;
  margin: 0 0 1.125rem;
}

.host-controls {
  margin: 0 0 1.125rem;
  padding: 1rem;
  border: 2px solid var(--ink);
  background: #e7e1d3;
  box-shadow: 4px 4px 0 var(--gold);
}

.host-controls .eyebrow {
  margin-bottom: .75rem;
}

.host-game-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .5rem;
}

.host-game-choice {
  min-width: 0;
  min-height: 2.75rem;
  border: 1px solid var(--ink);
  padding: .625rem .5rem;
  background: var(--card);
  color: var(--ink);
  font-size: .6875rem;
  font-weight: 900;
  letter-spacing: .06em;
  overflow-wrap: anywhere;
}

.host-game-choice[aria-pressed="true"] {
  background: var(--teal);
  color: #fff;
  box-shadow: inset 0 0 0 2px var(--gold);
}

.host-controls .primary {
  margin-top: .75rem;
}

.host-guidance {
  margin: .75rem 0 0;
  color: var(--muted);
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: .75rem;
  line-height: 1.45;
}

.edge-button {
  --hold-progress: 0%;
  position: relative;
  min-height: 6.25rem;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-areas:
    "direction copy"
    "progress progress"
    "hint hint";
  gap: .45rem .75rem;
  align-items: center;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  background: var(--teal);
  color: #fff;
  box-shadow: 4px 4px 0 var(--ink);
  text-align: left;
}

.edge-button::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  width: .5rem;
  background: var(--gold);
  box-shadow: 0 0 0 .25rem rgba(217, 184, 79, .22);
}

.edge-button.edge-left::before {
  left: 0;
}

.edge-button.edge-right::before {
  right: 0;
}

.edge-direction {
  grid-area: direction;
  padding: .3rem .45rem;
  border: 1px solid rgba(255, 255, 255, .72);
  font-size: .625rem;
  letter-spacing: .08em;
}

.edge-copy {
  grid-area: copy;
  min-width: 0;
  overflow-wrap: anywhere;
  font-size: .75rem;
  line-height: 1.3;
}

.edge-progress {
  grid-area: progress;
  height: .625rem;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, .78);
  background: rgba(34, 40, 39, .25);
}

.edge-progress i {
  display: block;
  width: var(--hold-progress);
  height: 100%;
  background: var(--gold);
  transition: width 80ms linear;
}

.edge-hint {
  grid-area: hint;
  color: rgba(255, 255, 255, .78);
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: .6875rem;
  font-weight: 600;
  letter-spacing: 0;
  line-height: 1.35;
}

.edge-button.local-holding {
  background: #447b78;
}

.edge-button.neighbor-holding:not(.local-holding) {
  box-shadow:
    4px 4px 0 var(--ink),
    inset 0 0 0 4px var(--gold);
}

.edge-button.done {
  cursor: default;
  background: var(--success);
  color: var(--ink);
  box-shadow: none;
}

.edge-button.done .edge-hint {
  color: #445148;
}

.edge-button.just-confirmed {
  animation: edge-confirmed 650ms ease-out both;
}

.game-shell {
  width: 100%;
  min-width: 0;
}

.game-meta {
  min-height: 2rem;
  font-size: .6875rem;
  font-weight: 900;
  letter-spacing: .1em;
}

.game-meta > span {
  min-width: 0;
  max-width: 50%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.game-meta > span:last-child {
  text-align: right;
}

.game-surface {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border: 2px solid var(--ink);
  background: #252c2c;
  color: var(--paper);
  box-shadow: 7px 7px 0 var(--ink);
  touch-action: none;
  user-select: none;
}

body[data-mode="game"] .shell {
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: .35rem;
  padding-top: calc(.45rem + var(--safe-top));
  padding-bottom: calc(.45rem + var(--safe-bottom));
}

body[data-mode="game"] .topbar {
  min-height: 2.75rem;
  margin: 0;
}

body[data-mode="game"] .game-shell {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: .35rem;
}

body[data-mode="game"] .game-surface {
  height: 100%;
  box-shadow: none;
}

.game-label {
  position: absolute;
  z-index: 8;
  top: .875rem;
  left: .875rem;
  display: grid;
  gap: .125rem;
  max-width: calc(100% - 1.75rem);
  padding: .5rem .625rem;
  border: 1px solid rgba(243, 239, 228, .5);
  background: rgba(34, 40, 39, .8);
  text-transform: uppercase;
}

.game-label strong {
  font-size: .75rem;
}

.game-label small {
  overflow: hidden;
  color: #c8cdc8;
  font-size: .625rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#game-content {
  position: absolute;
  inset: 0;
}

.road {
  position: absolute;
  inset: 36% 0;
  border-block: 5px solid #f0e4b8;
  background: #555f5d;
}

.road::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 0;
  width: 100%;
  border-top: 3px dashed rgba(255, 255, 255, .55);
}

.car {
  position: absolute;
  z-index: 3;
  width: 2.625rem;
  height: 1.5625rem;
  margin: -.75rem 0 0 -1.3125rem;
  border: 3px solid var(--paper);
  background: var(--coral);
  box-shadow: 3px 3px 0 rgba(0, 0, 0, .5);
}

.car::before,
.car::after {
  content: "";
  position: absolute;
  bottom: -.4375rem;
  width: .5625rem;
  height: .375rem;
  background: var(--ink);
}

.car::before {
  left: .25rem;
}

.car::after {
  right: .25rem;
}

.circuit {
  position: absolute;
  inset: 18%;
  display: grid;
  place-items: center;
  border: 3px solid var(--gold);
  background: radial-gradient(circle, rgba(217, 184, 79, .35), transparent 60%);
  text-align: center;
}

.circuit i {
  width: clamp(4.5rem, 24vw, 7rem);
  aspect-ratio: 1;
  border: .625rem double var(--gold);
  border-radius: 50%;
  box-shadow: 0 0 2.125rem var(--gold);
}

.circuit strong {
  position: absolute;
  right: .5rem;
  bottom: 14%;
  left: .5rem;
  font-size: .8125rem;
  letter-spacing: .1em;
}

.pulse-target {
  position: absolute;
  display: grid;
  width: clamp(3.5rem, 22vw, 5.25rem);
  aspect-ratio: 1;
  place-items: center;
  border: 5px solid var(--paper);
  border-radius: 50%;
  background: var(--coral);
  color: var(--ink);
  box-shadow: 0 0 0 .75rem rgba(230, 126, 103, .3);
  font-size: 1.5rem;
  font-weight: 900;
  transform: translate(-50%, -50%);
}

.territory {
  position: absolute;
  inset: 0;
}

.territory-cell {
  position: absolute;
  min-width: 0;
  min-height: 0;
  border: 1px solid rgba(243, 239, 228, .35);
  background-color: rgba(243, 239, 228, .06);
}

.territory-cell[class*="owner-pattern-"] {
  background-color: var(--cell-color);
}

.owner-pattern-0 {
  background-image: repeating-linear-gradient(
    45deg,
    transparent 0 5px,
    rgba(34, 40, 39, .34) 5px 7px
  );
}

.owner-pattern-1 {
  background-image: radial-gradient(rgba(34, 40, 39, .42) 1.5px, transparent 1.5px);
  background-size: 7px 7px;
}

.owner-pattern-2 {
  background-image:
    linear-gradient(rgba(34, 40, 39, .3) 1px, transparent 1px),
    linear-gradient(90deg, rgba(34, 40, 39, .3) 1px, transparent 1px);
  background-size: 8px 8px;
}

.owner-pattern-3 {
  background-image: repeating-radial-gradient(
    circle at 0 50%,
    transparent 0 5px,
    rgba(34, 40, 39, .3) 6px 7px
  );
}

.owner-pattern-4 {
  background-image: repeating-linear-gradient(
    90deg,
    transparent 0 6px,
    rgba(34, 40, 39, .3) 6px 8px
  );
}

.game-overlay {
  position: absolute;
  z-index: 20;
  inset: 0;
  min-width: 0;
  min-height: 0;
  display: grid;
  align-content: safe center;
  justify-items: center;
  gap: .75rem;
  overflow: auto;
  overscroll-behavior: contain;
  padding:
    calc(1.625rem + var(--safe-top))
    calc(1.625rem + var(--safe-right))
    calc(1.625rem + var(--safe-bottom))
    calc(1.625rem + var(--safe-left));
  background: rgba(34, 40, 39, .92);
  text-align: center;
  -webkit-overflow-scrolling: touch;
}

.game-overlay[hidden] {
  display: none;
}

.game-overlay > span {
  color: var(--coral);
  font-size: clamp(2.5rem, 12vw, 3.625rem);
}

.game-overlay > strong {
  max-width: 100%;
  overflow-wrap: anywhere;
  font-family: "Arial Black", Impact, sans-serif;
  font-size: clamp(2.25rem, 11vw, 3.25rem);
  line-height: .95;
}

.game-overlay > small {
  max-width: 30rem;
  color: #c9cfca;
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: .8125rem;
  line-height: 1.45;
}

.game-overlay button {
  min-height: 3rem;
  margin-top: .5rem;
  border: 2px solid var(--paper);
  padding: .75rem 1rem;
  background: var(--coral);
  color: var(--ink);
  font-weight: 900;
}

.overlay-actions {
  width: min(100%, 26rem);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: .5rem;
}

.overlay-actions button {
  flex: 1 1 9rem;
  margin-top: .5rem;
}

.countdown-number {
  color: var(--gold);
  font-size: clamp(4.25rem, 26vw, 9rem) !important;
  line-height: .8 !important;
}

.overlay-replay > span {
  animation: replay-turn 520ms ease-out both;
}

.result-scores {
  width: min(100%, 30rem);
  margin: .5rem 0 0;
  padding: 0;
  display: grid;
  gap: .375rem;
  list-style: none;
  text-align: left;
}

.result-scores li {
  min-width: 0;
  padding: .625rem .75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  border: 1px solid rgba(243, 239, 228, .42);
  background-color: color-mix(in srgb, var(--player-color) 58%, #222827);
  color: #fff;
}

.result-scores span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.result-scores b {
  flex: 0 0 auto;
  font-size: 1.125rem;
}

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

.assistive-action:focus-visible {
  right: 1rem;
  bottom: 1rem;
  width: auto;
  height: auto;
  min-height: 2.75rem;
  clip-path: none;
  border: 2px solid var(--paper);
  padding: .75rem;
  background: var(--coral);
  color: var(--ink);
  white-space: normal;
}

.game-host-control {
  position: absolute;
  z-index: 32;
  top: .75rem;
  right: .75rem;
  max-width: 45%;
  min-height: 2.75rem;
  border: 2px solid var(--paper);
  padding: .625rem .75rem;
  background: var(--gold);
  color: var(--ink);
  font-size: .625rem;
  font-weight: 900;
  letter-spacing: .06em;
}

.connect-help {
  width: min(43rem, calc(100% - 1.5rem - var(--safe-left) - var(--safe-right)));
  max-width: 43rem;
  max-height: calc(100vh - 1.5rem - var(--safe-top) - var(--safe-bottom));
  max-height: calc(100dvh - 1.5rem - var(--safe-top) - var(--safe-bottom));
  margin: auto;
  border: 2px solid var(--ink);
  padding: 0;
  overflow: auto;
  overscroll-behavior: contain;
  background: var(--card);
  color: var(--ink);
  box-shadow: 9px 9px 0 var(--ink);
}

.connect-help::backdrop {
  background: rgba(34, 40, 39, .72);
  backdrop-filter: blur(2px);
}

.connect-help-card {
  padding: clamp(1.25rem, 5vw, 2.25rem);
}

.dialog-heading {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 1rem;
  align-items: start;
}

.dialog-heading h2 {
  max-width: 15ch;
}

.dialog-close {
  width: 2.75rem;
  height: 2.75rem;
  border: 1px solid var(--ink);
  background: var(--paper);
  color: var(--ink);
  font-size: 1.5rem;
  line-height: 1;
}

.connect-demo {
  position: relative;
  height: 13.5rem;
  margin: 1.5rem 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border: 1px solid var(--ink);
  background:
    linear-gradient(rgba(34, 40, 39, .04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(34, 40, 39, .04) 1px, transparent 1px),
    #eee9dc;
  background-size: 18px 18px;
}

.demo-phone {
  position: relative;
  width: 6.25rem;
  height: 10.625rem;
  padding: .375rem;
  border: 3px solid var(--ink);
  border-radius: 1.125rem;
  background: #34413d;
  box-shadow: 0 .75rem 1.5rem rgba(34, 40, 39, .18);
}

.demo-phone-left {
  animation: demo-left 5.2s ease-in-out infinite;
}

.demo-phone-right {
  animation: demo-right 5.2s ease-in-out infinite;
}

.demo-screen {
  display: grid;
  width: 100%;
  height: 100%;
  place-items: center;
  border-radius: .75rem;
  background: #fff7e7;
  color: var(--coral);
  font-size: 2rem;
}

.demo-phone-right .demo-screen {
  color: var(--teal);
}

.demo-rail {
  position: absolute;
  z-index: 2;
  top: 23%;
  bottom: 23%;
  width: .5rem;
  background: var(--gold);
  box-shadow: 0 0 0 .25rem rgba(217, 184, 79, .28);
}

.demo-rail-right {
  right: -.375rem;
}

.demo-rail-left {
  left: -.375rem;
}

.demo-touch {
  position: absolute;
  z-index: 4;
  top: 48%;
  width: 1.75rem;
  height: 1.75rem;
  border: 3px solid #fff;
  border-radius: 50%;
  opacity: 0;
  background: rgba(230, 126, 103, .7);
  box-shadow: 0 0 0 .5rem rgba(230, 126, 103, .18);
  animation: demo-touch 5.2s ease-in-out infinite;
}

.demo-touch-left {
  right: -.9rem;
}

.demo-touch-right {
  left: -.9rem;
}

.demo-seam {
  position: absolute;
  z-index: 3;
  top: 25%;
  bottom: 25%;
  left: 50%;
  width: .75rem;
  overflow: hidden;
  transform: translateX(-50%);
}

.demo-seam span {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--success);
  transform: scaleY(0);
  transform-origin: bottom;
  animation: demo-seam 5.2s ease-in-out infinite;
}

.demo-success {
  position: absolute;
  z-index: 5;
  bottom: .7rem;
  left: 50%;
  padding: .45rem .6rem;
  opacity: 0;
  transform: translateX(-50%);
  border: 1px solid var(--ink);
  background: var(--success);
  color: var(--ink);
  font-size: .6875rem;
  font-weight: 900;
  letter-spacing: .08em;
  animation: demo-success 5.2s ease-in-out infinite;
}

.connect-steps {
  margin: 0;
  padding: 0;
  display: grid;
  gap: .75rem;
  list-style: none;
}

.connect-steps li {
  display: grid;
  grid-template-columns: 2.25rem minmax(0, 1fr);
  gap: .75rem;
  align-items: start;
}

.connect-steps li > span {
  display: grid;
  width: 2.25rem;
  height: 2.25rem;
  place-items: center;
  border: 1px solid var(--ink);
  background: var(--gold);
  font-weight: 900;
}

.connect-steps p,
.input-truth,
.failure-help {
  margin: 0;
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: .875rem;
  line-height: 1.5;
}

.input-truth {
  margin-top: 1.25rem;
  padding: .875rem;
  border: 2px solid var(--ink);
  background: #f3dfd6;
}

.failure-help {
  margin-top: .875rem;
  color: #535b57;
}

.dialog-done {
  margin-top: 1.25rem;
}

.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

[hidden] {
  display: none !important;
}

@keyframes edge-confirmed {
  0% {
    transform: scale(.98);
  }
  45% {
    transform: scale(1.025);
    box-shadow: 0 0 0 .5rem rgba(184, 207, 173, .35);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes pulse {
  50% {
    box-shadow: 0 0 0 1.375rem rgba(230, 126, 103, .08);
    transform: translate(-50%, -50%) scale(1.06);
  }
}

@keyframes replay-turn {
  to {
    transform: rotate(360deg);
  }
}

@keyframes demo-left {
  0%,
  12% {
    transform: translateX(-1.25rem);
  }
  27%,
  88% {
    transform: translateX(0);
  }
  100% {
    transform: translateX(-1.25rem);
  }
}

@keyframes demo-right {
  0%,
  12% {
    transform: translateX(1.25rem);
  }
  27%,
  88% {
    transform: translateX(0);
  }
  100% {
    transform: translateX(1.25rem);
  }
}

@keyframes demo-touch {
  0%,
  31%,
  82%,
  100% {
    opacity: 0;
    transform: scale(.8);
  }
  38%,
  74% {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes demo-seam {
  0%,
  39% {
    transform: scaleY(0);
  }
  68%,
  84% {
    transform: scaleY(1);
  }
  100% {
    transform: scaleY(0);
  }
}

@keyframes demo-success {
  0%,
  64%,
  100% {
    opacity: 0;
    transform: translate(-50%, .5rem);
  }
  70%,
  88% {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

@media (prefers-reduced-motion: no-preference) {
  .pulse-target {
    animation: pulse 1s ease-in-out infinite;
  }
}

@media (max-width: 520px) {
  .shell,
  .surface-metrics-probe {
    --page-inline: .75rem;
  }

  .topbar {
    flex-wrap: wrap;
    margin-bottom: 2rem;
  }

  .brand {
    flex: 0 0 auto;
    gap: .45rem;
    font-size: .75rem;
  }

  .topbar-actions {
    flex: 1 1 10rem;
  }

  .header-button {
    min-width: 0;
    max-width: none;
    flex: 1 1 4.5rem;
    justify-content: center;
    line-height: 1.15;
    text-align: center;
  }

  .status {
    min-width: 0;
    flex: 0 1 auto;
  }

  .join-card,
  .lobby-card {
    padding: 1.5rem 1.25rem;
    box-shadow: 5px 5px 0 var(--ink);
  }

  .connection-panel {
    grid-template-columns: 1fr;
  }

  .connection-actions button {
    flex: 1 1 8rem;
  }

  .game-overlay {
    padding: 1rem;
  }
}

@media (max-width: 370px) {
  .brand > span:last-child {
    display: none;
  }

  .topbar-actions {
    flex: 1;
  }

  .header-button {
    margin-left: auto;
  }

  .status {
    padding-inline: .4rem;
  }
}

@media (orientation: landscape) and (max-height: 500px) {
  body[data-mode="game"] .shell,
  .surface-metrics-probe {
    --page-inline: .4rem;
    gap: .2rem;
    padding-top: calc(.25rem + var(--safe-top));
    padding-bottom: calc(.25rem + var(--safe-bottom));
  }

  body[data-mode="game"] .topbar,
  .surface-metrics-probe > .topbar {
    min-height: 2.25rem;
  }

  body[data-mode="game"] .brand > span:last-child,
  .surface-metrics-probe .brand > span:last-child {
    display: none;
  }

  body[data-mode="game"] .brand,
  body[data-mode="game"] .header-button,
  body[data-mode="game"] .status,
  .surface-metrics-probe .brand,
  .surface-metrics-probe .header-button,
  .surface-metrics-probe .status {
    min-height: 2.25rem;
  }

  body[data-mode="game"] .brand-mark,
  .surface-metrics-probe .brand-mark {
    width: 1.875rem;
    height: 1.875rem;
    flex-basis: 1.875rem;
  }

  .game-meta {
    min-height: 1.5rem;
  }

  .game-label {
    top: .4rem;
    left: .4rem;
    padding: .35rem .45rem;
  }

  .game-overlay {
    padding:
      calc(.65rem + var(--safe-top))
      calc(.65rem + var(--safe-right))
      calc(.65rem + var(--safe-bottom))
      calc(.65rem + var(--safe-left));
    gap: .35rem;
  }

  .game-overlay > span {
    font-size: 2rem;
  }

  .game-overlay > strong {
    font-size: clamp(1.6rem, 8vw, 2.5rem);
  }

  .result-scores {
    grid-template-columns: 1fr 1fr;
  }

  .result-scores li {
    padding: .35rem .5rem;
  }

  .connect-help-card {
    padding: 1rem;
  }

  .connect-demo {
    height: 9rem;
    margin-block: .75rem;
  }

  .demo-phone {
    width: 4.25rem;
    height: 7.25rem;
  }

  .connect-steps {
    gap: .45rem;
  }
}

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

  .demo-phone {
    transform: none;
  }

  .demo-touch,
  .demo-success {
    opacity: 1;
  }

  .demo-touch {
    transform: scale(1);
  }

  .demo-success {
    transform: translate(-50%, 0);
  }

  .demo-seam span {
    transform: scaleY(1);
  }
}

.force-reduced-motion *,
.force-reduced-motion *::before,
.force-reduced-motion *::after {
  scroll-behavior: auto !important;
  animation: none !important;
  transition-duration: .01ms !important;
}

.force-reduced-motion .demo-phone {
  transform: none;
}

.force-reduced-motion .demo-touch,
.force-reduced-motion .demo-success {
  opacity: 1;
}

.force-reduced-motion .demo-touch {
  transform: scale(1);
}

.force-reduced-motion .demo-success {
  transform: translate(-50%, 0);
}

.force-reduced-motion .demo-seam span {
  transform: scaleY(1);
}
