:root {
  --bg-deep: #0b0f1a;
  --bg-card: #111827;
  --bg-elevated: #1e293b;
  --primary: #6366f1;
  --primary-light: #818cf8;
  --primary-glow: rgba(99, 102, 241, 0.35);
  --accent: #a78bfa;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --pac-yellow: #fbbf24;
  --dot: #c4b5fd;
  --danger: #f43f5e;
  --success: #34d399;
  --border: rgba(99, 102, 241, 0.35);
}

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

body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse at 20% 0%, rgba(99, 102, 241, 0.18) 0%, transparent 55%),
    radial-gradient(ellipse at 80% 100%, rgba(167, 139, 250, 0.12) 0%, transparent 50%),
    var(--bg-deep);
  color: var(--text);
  font-family: "Lato", "Segoe UI", system-ui, sans-serif;
}

.wrap {
  width: min(980px, 100%);
  padding: 1.5rem;
}

header {
  text-align: center;
  margin-bottom: 1.25rem;
}

.eyebrow {
  font-size: 0.78rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--primary-light);
  margin-bottom: 0.35rem;
}

header h1 {
  font-size: 2rem;
  font-weight: 900;
  letter-spacing: 0.06em;
  background: linear-gradient(135deg, var(--primary-light), var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.subtitle {
  margin-top: 0.4rem;
  font-size: 0.92rem;
  color: var(--text-muted);
}

.layout {
  display: grid;
  grid-template-columns: 1fr 260px;
  gap: 1.25rem;
  align-items: start;
}

.game-panel,
.leaderboard-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1rem;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}

.hud {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 1rem 1.5rem;
  margin-bottom: 0.85rem;
  font-size: 0.88rem;
  color: var(--text-muted);
}

.hud strong {
  color: var(--pac-yellow);
  font-weight: 700;
}

#game {
  display: block;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  border: 2px solid var(--border);
  border-radius: 10px;
  background: #05070f;
  box-shadow: 0 0 28px var(--primary-glow);
}

.status {
  margin-top: 0.85rem;
  min-height: 1.4rem;
  text-align: center;
  font-size: 0.92rem;
  color: var(--accent);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
}

.panel-head h2 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
}

.panel-hint {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 0.85rem;
}

.leaderboard {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  min-height: 220px;
}

.leaderboard li {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.6rem;
  border-radius: 8px;
  background: var(--bg-elevated);
  font-size: 0.85rem;
}

.leaderboard li.is-new {
  outline: 1px solid var(--success);
  background: rgba(52, 211, 153, 0.08);
}

.leaderboard .rank {
  color: var(--primary-light);
  font-weight: 700;
  text-align: center;
}

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

.leaderboard .pts {
  color: var(--pac-yellow);
  font-weight: 700;
}

.leaderboard .empty {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--text-muted);
  background: transparent;
  padding: 1.5rem 0.5rem;
}

.name-form {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.name-form.hidden {
  display: none;
}

.name-form label {
  display: block;
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 0.45rem;
}

.name-row {
  display: flex;
  gap: 0.5rem;
}

.name-row input {
  flex: 1;
  min-width: 0;
  padding: 0.55rem 0.7rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-deep);
  color: var(--text);
  font: inherit;
}

.name-row input:focus {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

.btn-primary,
.btn-ghost {
  border: none;
  border-radius: 8px;
  font: inherit;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.btn-primary {
  padding: 0.55rem 0.9rem;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
}

.btn-primary:hover {
  background: var(--primary-light);
}

.btn-ghost {
  padding: 0.3rem 0.55rem;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.78rem;
}

.btn-ghost:hover {
  color: var(--danger);
}

.controls-mobile {
  display: none;
  margin-top: 1rem;
  gap: 0.4rem;
  flex-direction: column;
  align-items: center;
}

.controls-row {
  display: flex;
  gap: 0.4rem;
}

.controls-mobile button {
  width: 52px;
  height: 52px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-elevated);
  color: var(--primary-light);
  font-size: 1.2rem;
  cursor: pointer;
}

.controls-mobile button:active {
  background: var(--primary);
  color: #fff;
}

footer {
  margin-top: 1.35rem;
  text-align: center;
  font-size: 0.88rem;
}

footer a {
  color: var(--primary-light);
  text-decoration: none;
}

footer a:hover {
  text-decoration: underline;
}

footer span {
  color: var(--text-muted);
  margin: 0 0.35rem;
}

@media (max-width: 860px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .leaderboard {
    min-height: auto;
  }
}

@media (max-width: 600px), (hover: none) {
  .controls-mobile {
    display: flex;
  }
}
