:root {
  --bg: #0d0e12;
  --surface: #17181f;
  --surface-2: #21232c;
  --line: rgba(255, 255, 255, 0.08);
  --text: #f4f2ec;
  --muted: #9b9da8;
  --accent: #ffc83d;
  --on-accent: #1a1406;
  --danger: #ff5a5f;
  --ok: #3ddc84;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.45);

  --breakout: #ff7a45;
  --snake: #3ddc84;
  --four: #5b8cff;
  --memory: #c38bff;
  --hockey: #2ec4b6;
  --odd: #ff7eb6;

  --radius: 22px;
  --radius-sm: 14px;
  --tap: 48px;
  --font: "Baloo Bhaijaan 2", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f5f2ea;
    --surface: #ffffff;
    --surface-2: #efebe1;
    --line: rgba(20, 18, 10, 0.1);
    --text: #17161a;
    --muted: #6d6a73;
    --shadow: 0 18px 40px rgba(60, 45, 10, 0.14);
    color-scheme: light;
  }
}

:root[data-theme="light"] {
  --bg: #f5f2ea;
  --surface: #ffffff;
  --surface-2: #efebe1;
  --line: rgba(20, 18, 10, 0.1);
  --text: #17161a;
  --muted: #6d6a73;
  --shadow: 0 18px 40px rgba(60, 45, 10, 0.14);
  color-scheme: light;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
}

button,
input {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: 0;
  background: none;
  touch-action: manipulation;
}

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

@view-transition {
  navigation: auto;
}

.btn {
  min-height: var(--tap);
  padding: 0 22px;
  border-radius: 999px;
  background: var(--surface-2);
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.15s ease, background 0.15s ease;
}

.btn:active {
  transform: scale(0.96);
}

.btn-primary {
  background: var(--accent);
  color: var(--on-accent);
}

.btn-block {
  width: 100%;
}

.icon-btn {
  width: var(--tap);
  height: var(--tap);
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  font-size: 20px;
  flex: none;
}

.icon-btn svg {
  width: 22px;
  height: 22px;
}

[dir="rtl"] .flip-rtl {
  transform: scaleX(-1);
}

/* Game pages */

.game-page {
  --game: var(--accent);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: max(12px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  gap: 12px;
}

.topbar {
  width: 100%;
  max-width: 560px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar h1 {
  flex: 1;
  margin: 0;
  font-size: 22px;
  line-height: 1.1;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

@media (max-width: 400px) {
  .topbar {
    gap: 6px;
  }
  .topbar .icon-btn {
    width: 42px;
    height: 42px;
  }
  .topbar h1 {
    font-size: 19px;
  }
}

.topbar h1 span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hud {
  width: 100%;
  max-width: 560px;
  display: flex;
  gap: 8px;
}

.stat {
  flex: 1;
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  text-align: center;
}

.stat small {
  display: block;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
}

.stat b {
  display: block;
  font-size: 20px;
  line-height: 1.3;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.board-wrap {
  position: relative;
  width: 100%;
  max-width: 560px;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.board-wrap canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: color-mix(in srgb, var(--bg) 72%, transparent);
  z-index: 5;
  animation: fade-in 0.2s ease;
}

.overlay[hidden] {
  display: none;
}

.card {
  width: 100%;
  max-width: 340px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px 20px 20px;
  text-align: center;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 10px;
  animation: pop-in 0.28s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}

.card .big-emoji {
  font-size: 54px;
  line-height: 1;
}

.card h2 {
  margin: 0;
  font-size: 26px;
  line-height: 1.15;
}

.card p {
  margin: 0;
  color: var(--muted);
}

.card .actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 6px;
}

.eyebrow {
  color: var(--game);
  font-weight: 800;
  font-size: 13px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: max(20px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 999px;
  font-weight: 700;
  z-index: 50;
  box-shadow: var(--shadow);
  animation: toast 2.4s ease forwards;
  pointer-events: none;
  max-width: calc(100vw - 32px);
  text-align: center;
}

/* Lobby sheet shared by the online games */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fade-in 0.2s ease;
}

.sheet {
  width: 100%;
  max-width: 480px;
  background: var(--surface);
  border-radius: 28px 28px 0 0;
  padding: 10px 20px max(22px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 12px;
  animation: sheet-up 0.32s cubic-bezier(0.2, 0.9, 0.3, 1);
}

@media (min-width: 640px) {
  .sheet-backdrop {
    align-items: center;
  }
  .sheet {
    border-radius: 28px;
    padding-bottom: 24px;
  }
}

.sheet .grip {
  width: 40px;
  height: 5px;
  border-radius: 3px;
  background: var(--line);
  align-self: center;
  margin-bottom: 4px;
}

.sheet h2 {
  margin: 0;
  font-size: 24px;
}

.sheet p {
  margin: 0;
  color: var(--muted);
}

.choice {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  min-height: 68px;
  padding: 10px 16px;
  background: var(--surface-2);
  border-radius: 18px;
  text-align: start;
  transition: transform 0.15s ease;
}

.choice:active {
  transform: scale(0.98);
}

.choice .ico {
  font-size: 28px;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: var(--surface);
  flex: none;
}

.choice b {
  display: block;
  font-size: 17px;
  line-height: 1.2;
}

.choice small {
  color: var(--muted);
  font-size: 13px;
}

.code-display {
  font-size: 52px;
  font-weight: 800;
  letter-spacing: 0.18em;
  text-align: center;
  direction: ltr;
  font-variant-numeric: tabular-nums;
  color: var(--game);
  line-height: 1.1;
  padding: 6px 0;
}

.code-input {
  width: 100%;
  height: 72px;
  border-radius: 18px;
  border: 2px solid var(--line);
  background: var(--surface-2);
  text-align: center;
  font-size: 40px;
  font-weight: 800;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  direction: ltr;
}

.code-input:focus {
  outline: none;
  border-color: var(--game);
}

.waiting {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--muted);
}

.dots {
  display: inline-flex;
  gap: 4px;
}

.dots i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--game);
  animation: bounce 1s infinite ease-in-out;
}

.dots i:nth-child(2) {
  animation-delay: 0.15s;
}

.dots i:nth-child(3) {
  animation-delay: 0.3s;
}

.net-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 10px;
  white-space: nowrap;
}

.net-badge::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ok);
}

.net-badge.floating {
  position: absolute;
  top: 8px;
  inset-inline-start: 8px;
  z-index: 4;
  pointer-events: none;
  opacity: 0.9;
}

.net-badge[hidden] {
  display: none;
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
}

@keyframes pop-in {
  from {
    opacity: 0;
    transform: scale(0.92) translateY(8px);
  }
}

@keyframes sheet-up {
  from {
    transform: translateY(100%);
  }
}

@keyframes bounce {
  0%,
  80%,
  100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  40% {
    transform: translateY(-6px);
    opacity: 1;
  }
}

@keyframes toast {
  0% {
    opacity: 0;
    transform: translate(-50%, 12px);
  }
  10%,
  85% {
    opacity: 1;
    transform: translate(-50%, 0);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, 0);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* Two-player score chips */

.players {
  width: 100%;
  max-width: 520px;
  display: flex;
  gap: 10px;
}

.player {
  --tone: var(--accent);
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 18px;
  background: var(--surface);
  border: 2px solid transparent;
  transition: border-color 0.2s ease, transform 0.2s ease;
}

.player.active {
  border-color: var(--tone);
  transform: translateY(-2px);
}

.player .token {
  width: 40px;
  height: 40px;
  flex: none;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--tone);
  font-size: 22px;
}

.player .name {
  display: block;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
}

.player .score {
  font-size: 22px;
  font-weight: 800;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.player.p1 {
  --tone: #ff5a5f;
}

.player.p2 {
  --tone: #ffc83d;
}
