:root {
  color-scheme: dark;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  background: #080a12;
  color: #f5f3ea;
  touch-action: none;
}

* { box-sizing: border-box; }

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

button { font: inherit; }

#game-shell {
  position: fixed;
  inset: 0;
  min-height: 100dvh;
  overflow: hidden;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
}

.level-video {
  position: absolute;
  inset: 0;
  z-index: 4;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #080a12;
  pointer-events: none;
}

.level-video.hidden { display: none; }

.overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  padding: max(24px, env(safe-area-inset-top)) max(24px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(24px, env(safe-area-inset-left));
  background: rgba(8, 10, 18, 0.78);
  backdrop-filter: blur(8px);
  transition: opacity 180ms ease;
}

.overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.panel {
  width: min(480px, 100%);
  text-align: center;
}

.panel.compact { width: min(340px, 100%); }

h1 {
  margin: 0 0 32px;
  color: #f5f3ea;
  font-size: clamp(44px, 10vw, 92px);
  line-height: 0.82;
  letter-spacing: -0.08em;
  text-shadow: 5px 5px 0 #ff3b70;
}

.actions { display: grid; gap: 10px; }

.tilt-option {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 9px;
  min-height: 34px;
  color: #969cac;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.06em;
  cursor: pointer;
}

.tilt-option input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.toggle-track {
  position: relative;
  width: 34px;
  height: 19px;
  border: 1px solid #626979;
  border-radius: 20px;
  background: #252a39;
  transition: 140ms ease;
}

.toggle-track span {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: #969cac;
  transition: 140ms ease;
}

.tilt-option input:checked + .toggle-track {
  border-color: #5de4ff;
  background: rgba(93, 228, 255, 0.18);
}

.tilt-option input:checked + .toggle-track span {
  left: 18px;
  background: #5de4ff;
}

button {
  min-height: 52px;
  border: 2px solid #f5f3ea;
  border-radius: 4px;
  padding: 12px 18px;
  background: #f5f3ea;
  color: #080a12;
  font-weight: 900;
  letter-spacing: 0.06em;
  cursor: pointer;
  box-shadow: 5px 5px 0 #ff3b70;
}

button:active { transform: translate(3px, 3px); box-shadow: 2px 2px 0 #ff3b70; }

button.secondary { background: transparent; color: #f5f3ea; }

.controls {
  margin: 24px 0 0;
  color: #969cac;
  font-size: 12px;
  letter-spacing: 0.04em;
}

.leaderboard {
  width: min(330px, 100%);
  margin: 26px auto 0;
  padding-top: 16px;
  border-top: 1px solid #303545;
  text-align: left;
}

.leaderboard h2 {
  margin: 0 0 9px;
  color: #969cac;
  font-size: 11px;
  letter-spacing: 0.16em;
  text-align: center;
}

.score-list {
  display: grid;
  gap: 5px;
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: rank;
}

.score-list li {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) auto;
  gap: 8px;
  color: #f5f3ea;
  font-size: 12px;
  line-height: 1.3;
  counter-increment: rank;
}

.score-list li::before {
  content: counter(rank) ".";
  color: #626979;
}

.score-list .score-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.score-list .score-value { color: #5de4ff; font-weight: 800; font-variant-numeric: tabular-nums; }
.score-list .score-message { display: block; color: #626979; text-align: center; }
.score-list .score-message::before { content: none; }

.score-form { margin: 0 0 14px; }
.score-form > label {
  display: block;
  margin-bottom: 8px;
  color: #969cac;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.12em;
}

.score-entry { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }

.score-entry input {
  min-width: 0;
  border: 2px solid #f5f3ea;
  border-radius: 4px;
  padding: 0 12px;
  background: #080a12;
  color: #f5f3ea;
  font: inherit;
  font-size: 13px;
  text-transform: uppercase;
  outline: none;
}

.score-entry input:focus { border-color: #5de4ff; }
.score-entry button { min-height: 46px; padding-inline: 14px; }
.score-status { min-height: 14px; margin: 7px 0 0; color: #5de4ff; font-size: 10px; }
.score-form.saved .score-entry { display: none; }
.end-action { width: 100%; background: transparent; color: #f5f3ea; }

.mobile-copy { display: none; }

.icon-button {
  position: absolute;
  z-index: 4;
  right: max(12px, env(safe-area-inset-right));
  bottom: max(12px, env(safe-area-inset-bottom));
  min-height: 36px;
  border-width: 1px;
  padding: 7px 10px;
  background: rgba(8, 10, 18, 0.72);
  color: #969cac;
  font-size: 10px;
  box-shadow: none;
}

.exit-button {
  top: max(12px, env(safe-area-inset-top));
  right: auto;
  bottom: auto;
  left: 50%;
  z-index: 6;
  transform: translateX(-50%);
  color: #f5f3ea;
}

.exit-button:active { transform: translate(calc(-50% + 3px), 3px); }

.icon-button.hidden { display: none; }

.eyebrow { margin: 0; color: #969cac; font-size: 12px; letter-spacing: 0.15em; }

.final-score { margin: 5px 0 24px; font-size: clamp(64px, 18vw, 110px); font-weight: 900; line-height: 1; }

@media (pointer: coarse), (max-width: 700px) {
  .desktop-copy { display: none; }
  .mobile-copy { display: block; }
  h1 { margin-bottom: 26px; }
  .panel { width: min(360px, 92vw); }
}

@media (pointer: coarse) {
  .tilt-option { display: flex; }
}

@media (orientation: landscape) and (max-height: 520px) {
  h1 { font-size: clamp(38px, 10vh, 62px); margin-bottom: 18px; }
  .controls { margin-top: 14px; }
  .leaderboard { margin-top: 14px; padding-top: 10px; }
  .score-list { grid-template-columns: 1fr 1fr; column-gap: 20px; }
}

@media (prefers-reduced-motion: reduce) {
  .overlay { transition: none; backdrop-filter: none; }
}
