html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: #20242c;
}

body {
  position: fixed;
  inset: 0;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

canvas {
  display: block;
  touch-action: none;
}

/* Screens: DOM overlays above the canvas. The container lets touches through to the
   canvas; a screen with controls takes them only where it needs them. */
#ui {
  position: absolute;
  inset: 0;
  pointer-events: none;
  color: #fff;
  font: 16px/1.4 system-ui, sans-serif;
  text-align: center;
}

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: max(24px, env(safe-area-inset-top)) 24px max(24px, env(safe-area-inset-bottom));
  box-sizing: border-box;
}

#ui [hidden] {
  display: none !important;
}

.screen p,
.screen h1,
.screen h2 {
  margin: 0;
}

.title,
.name,
.gameover {
  background: rgba(20, 23, 29, 0.78);
}

.name,
.gameover {
  pointer-events: auto;
}

.title h1 {
  font-size: 44px;
  letter-spacing: 0.02em;
}

.title .hint {
  font-size: 18px;
  opacity: 0.85;
}

.title .welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.title .hello {
  font-size: 20px;
  font-weight: 600;
}

.title .top {
  list-style: none;
  counter-reset: rank;
  margin: 8px 0;
  padding: 0;
  width: min(100%, 260px);
}

.title .top li {
  counter-increment: rank;
  display: flex;
  gap: 8px;
  padding: 4px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.title .top li::before {
  content: counter(rank) '.';
  width: 1.5em;
  text-align: right;
  opacity: 0.6;
}

.title .top li span:first-child {
  flex: 1;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
}

.title .top li span:last-child {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.title .cta {
  font-size: 22px;
  font-weight: 700;
  animation: pulse 1.4s ease-in-out infinite;
}

@keyframes pulse {
  50% { opacity: 0.45; }
}

.link {
  pointer-events: auto;
  background: none;
  border: 0;
  padding: 8px;
  color: #9cc7ff;
  font: inherit;
  font-size: 14px;
  text-decoration: underline;
}

.dev {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.dev-panel {
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.4);
  font-size: 14px;
}

.dev-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.dev-toggle {
  display: flex;
}

.dev-toggle button {
  padding: 8px 12px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  background: none;
  color: #fff;
  font: inherit;
}

.dev-toggle button:first-child {
  border-radius: 8px 0 0 8px;
}

.dev-toggle button:last-child {
  border-radius: 0 8px 8px 0;
}

.dev-toggle button[aria-pressed='true'] {
  background: #9cc7ff;
  color: #20242c;
}

.name form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: min(100%, 300px);
}

.name label {
  font-size: 20px;
  font-weight: 600;
}

.name input {
  -webkit-user-select: text;
  user-select: text;
  font: inherit;
  font-size: 20px;
  padding: 12px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.35);
  color: #fff;
  text-align: center;
}

.name .message {
  min-height: 1.4em;
  color: #ff9c8a;
}

.primary,
.secondary {
  display: block;
  box-sizing: border-box;
  width: min(100%, 300px);
  padding: 14px;
  border: 0;
  border-radius: 12px;
  font: inherit;
  font-size: 18px;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}

.primary {
  background: #ffcc33;
  color: #20242c;
}

.primary:disabled {
  opacity: 0.4;
  cursor: default;
}

.secondary {
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
}

.gameover .score {
  font-size: 56px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.gameover dl {
  display: grid;
  grid-template-columns: auto auto;
  gap: 2px 16px;
  margin: 0;
}

.gameover dt {
  text-align: right;
  opacity: 0.7;
}

.gameover dd {
  margin: 0;
  text-align: left;
  font-variant-numeric: tabular-nums;
}

.gameover .status {
  font-weight: 600;
  margin: 4px 0 8px;
}

.gameover .connect {
  padding: 18px;
  font-size: 20px;
}

.pause {
  padding: 0;
}

.pause p {
  padding: 18px 24px;
  align-self: stretch;
  background: rgba(0, 0, 0, 0.6);
  font-size: 20px;
  font-weight: 600;
}
