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

:root {
  --bg-a:      #020814;
  --bg-b:      #071a2a;
  --panel:     rgba(5,15,28,0.88);
  --panel-border: rgba(122,220,255,0.22);
  --accent:    #63ddff;
  --sky-top:   #0d1b35;
  --sky-bot:   #1a3a6e;
  --pipe:      #3ecf5a;
  --pipe-dark: #267a38;
}

body {
  background: var(--bg-a);
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  font-family: 'Segoe UI', Tahoma, sans-serif;
  color: #d0eeff;
}

.home-link {
  position: fixed;
  top: 1rem;
  left: 1rem;
  z-index: 30;
  padding: 0.45rem 1rem;
  border-radius: 999px;
  border: 1px solid rgba(99,221,255,0.28);
  background: rgba(5,15,28,0.86);
  color: var(--accent);
  text-decoration: none;
  font-size: 0.9rem;
  letter-spacing: 0.08em;
  transition: background 0.2s, border-color 0.2s, box-shadow 0.2s;
}

.home-link:hover {
  background: rgba(12, 36, 54, 0.95);
  border-color: var(--accent);
  box-shadow: 0 0 16px rgba(99,221,255,0.22);
}

.app {
  width: 100%;
  max-width: 760px;
  padding: 1.2rem;
}

.game-wrap {
  display: grid;
  grid-template-columns: 1fr 210px;
  gap: 1.2rem;
  align-items: start;
}

.canvas-wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: 9 / 16;
  background: var(--sky-top);
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--panel-border);
}

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

/* Overlay */
#overlay {
  position: absolute;
  inset: 0;
  background: rgba(2, 8, 20, 0.78);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.9rem;
  z-index: 10;
}

#overlay-title {
  font-size: 2.4rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  color: var(--accent);
  text-shadow: 0 0 24px rgba(99,221,255,0.5);
}

#overlay-message {
  font-size: 1rem;
  opacity: 0.75;
  text-align: center;
}

#start-btn {
  margin-top: 0.4rem;
  padding: 0.55rem 2.4rem;
  background: linear-gradient(135deg, #1a5470 0%, #0e3248 100%);
  border: 1px solid var(--accent);
  border-radius: 6px;
  color: var(--accent);
  font-size: 1rem;
  letter-spacing: 0.1em;
  cursor: pointer;
  transition: box-shadow 0.2s;
}
#start-btn:hover { box-shadow: 0 0 18px rgba(99,221,255,0.45); }

/* Panel */
.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 1rem 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.stat {
  display: flex;
  flex-direction: column;
}
.label {
  font-size: 0.65rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  opacity: 0.5;
}
.value {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--accent);
  line-height: 1.1;
}

.panel-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  opacity: 0.5;
  display: block;
  margin-bottom: 0.25rem;
}

.player-input {
  width: 100%;
  background: rgba(99,221,255,0.06);
  border: 1px solid rgba(99,221,255,0.22);
  border-radius: 5px;
  color: #d0eeff;
  font-size: 0.9rem;
  padding: 0.35rem 0.5rem;
  outline: none;
}
.player-input:focus { border-color: var(--accent); }

.board-title {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  opacity: 0.5;
  margin-top: 0.3rem;
}

#leaderboard-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.28rem;
  counter-reset: lb;
  flex: 1;
  overflow-y: auto;
  max-height: 200px;
}

#leaderboard-list li {
  counter-increment: lb;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.82rem;
  padding: 0.2rem 0.35rem;
  border-radius: 4px;
  background: rgba(99,221,255,0.04);
}
#leaderboard-list li::before {
  content: counter(lb);
  font-size: 0.65rem;
  opacity: 0.4;
  min-width: 1rem;
  text-align: right;
}
#leaderboard-list li .lb-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#leaderboard-list li .lb-score { color: var(--accent); font-weight: 700; }
#leaderboard-list li.highlight { background: rgba(99,221,255,0.12); border: 1px solid rgba(99,221,255,0.3); }

#leaderboard-list .empty-msg {
  display: block;
  padding: 0.55rem 0.2rem;
  color: #7da6be;
  font-style: italic;
  background: transparent;
}

#show-all-leaderboard {
  width: 100%;
  padding: 0.35rem 0.45rem;
  border-radius: 5px;
  border: 1px solid rgba(99,221,255,0.2);
  background: rgba(99,221,255,0.06);
  color: #9cdcf6;
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  cursor: pointer;
}

#show-all-leaderboard:hover {
  border-color: rgba(99,221,255,0.4);
  background: rgba(99,221,255,0.1);
}

.controls {
  font-size: 0.72rem;
  opacity: 0.4;
  line-height: 1.6;
  margin-top: auto;
}

@media (max-width: 720px) {
  body {
    align-items: flex-start;
  }

  .app {
    padding: 4.5rem 0.9rem 1rem;
  }

  .game-wrap {
    grid-template-columns: 1fr;
  }
}
