:root {
  --bg: #0b0f1e;
  --panel: #161c33;
  --text: #f1f3fb;
  --muted: #9aa3c4;
  --accent: #4facfe;
  --left: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  --right: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
  --launch: linear-gradient(135deg, #4facfe 0%, #00c6d7 100%);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}

body {
  -webkit-tap-highlight-color: transparent;
}

[hidden] {
  display: none !important;
}

.screen {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
}

.center {
  margin: auto;
  text-align: center;
}

h1 {
  font-size: 1.6rem;
}

.muted {
  color: var(--muted);
}

.status {
  background: var(--panel);
  border-radius: 12px;
  padding: 12px 14px;
}

.status:empty {
  display: none;
}

button {
  font: inherit;
  color: var(--text);
  background: var(--panel);
  border: 1px solid #2a3358;
  border-radius: 12px;
  padding: 12px 18px;
  cursor: pointer;
}

button:disabled {
  opacity: 0.45;
}

button.primary {
  background: var(--accent);
  border-color: transparent;
  color: #04122a;
  font-weight: 700;
}

#start {
  font-size: 1.4rem;
  padding: 22px;
}

.row {
  display: flex;
  gap: 10px;
}

.row > * {
  flex: 1;
}

input {
  font: inherit;
  min-width: 0;
  color: var(--text);
  background: var(--panel);
  border: 1px solid #2a3358;
  border-radius: 12px;
  padding: 12px;
}

form {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

form .row input {
  flex: 2;
}

.switch {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
}

.switch input {
  width: 20px;
  height: 20px;
}

.final {
  font-size: 2.2rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

/* Highscore tables */
.highscores {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

.highscores h2 {
  font-size: 1rem;
  color: var(--muted);
  margin-bottom: 6px;
}

.highscores ol {
  list-style: none;
  background: var(--panel);
  border-radius: 12px;
  overflow: hidden;
}

.highscores li {
  display: grid;
  grid-template-columns: 2.4em 1fr auto;
  gap: 8px;
  padding: 8px 12px;
  font-variant-numeric: tabular-nums;
}

.highscores li + li {
  border-top: 1px solid #222a4a;
}

.highscores li.me {
  background: #24407a;
  font-weight: 700;
}

.highscores li.gap {
  display: block;
  text-align: center;
  color: var(--muted);
  padding: 2px;
}

.highscores .name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.highscores .empty {
  color: var(--muted);
  padding: 8px 12px;
  display: block;
}

/* Play screen */
#screen-play {
  height: 100%;
  min-height: 0;
  padding: max(8px, env(safe-area-inset-top)) 8px max(8px, env(safe-area-inset-bottom));
  gap: 8px;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 8px;
  color: var(--muted);
}

.bar .score {
  color: var(--text);
  font-size: 1.6rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.flippers {
  flex: 1;
  display: flex;
  gap: 8px;
}

.pad {
  flex: 1;
  border: none;
  border-radius: 18px;
  color: white;
  font-size: 1.8rem;
  font-weight: 800;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  transition: filter 0.05s, transform 0.05s;
}

.pad[data-button="left"] {
  background: var(--left);
}

.pad[data-button="right"] {
  background: var(--right);
}

.pad.launch {
  flex: 0 0 22%;
  background: var(--launch);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.pad small {
  font-size: 0.8rem;
  font-weight: 500;
  opacity: 0.85;
}

.pad.down {
  filter: brightness(0.7);
  transform: scale(0.98);
}

#idle-warning {
  position: fixed;
  left: 16px;
  right: 16px;
  top: 30%;
  padding: 18px;
  border-radius: 14px;
  background: rgba(200, 40, 60, 0.95);
  text-align: center;
  font-weight: 600;
  pointer-events: none;
}

#toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 10;
  padding: 12px 14px;
  border-radius: 12px;
  background: #3a2440;
  border: 1px solid #a0457a;
}

/* Game and character pickers */
.games {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.game-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 16px 8px;
  font-weight: 700;
}

.game-card .icon {
  font-size: 2.2rem;
}

.game-card.selected,
.character.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent) inset;
  background: #1d2a52;
}

#character-picker h2 {
  font-size: 1rem;
  color: var(--muted);
  margin-bottom: 6px;
}

.characters {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  scroll-snap-type: x mandatory;
}

.character {
  flex: 0 0 auto;
  width: 84px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 0.75rem;
  scroll-snap-align: start;
}

.character img {
  width: 64px;
  height: 64px;
  object-fit: contain;
}

/* Crossy Road swipe pad */
#screen-crossy {
  height: 100%;
  min-height: 0;
  padding: max(8px, env(safe-area-inset-top)) 8px max(8px, env(safe-area-inset-bottom));
  gap: 8px;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

#swipe-pad {
  flex: 1;
  display: grid;
  place-items: center;
  text-align: center;
  color: rgba(255, 255, 255, 0.75);
  font-weight: 600;
  border-radius: 18px;
  background: linear-gradient(160deg, #3fa34d 0%, #2d6a3e 100%);
  touch-action: none;
  transition: filter 0.05s;
}

#swipe-pad.down {
  filter: brightness(0.85);
}
