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

html, body {
  overflow-x: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #1a1a2e;
  color: #fff;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.back-link {
  position: fixed;
  top: 16px;
  left: 16px;
  color: #cfd2e3;
  text-decoration: none;
  font-weight: 500;
}

.back-link:hover { color: #fff; }

.wrap {
  text-align: center;
}

h1 { margin-bottom: 2px; font-size: 1.4rem; }

.auth-box {
  margin: 6px 0;
  min-height: 30px;
}

.auth-form[hidden],
.auth-loggedin[hidden] {
  display: none;
}

.auth-form {
  display: flex;
  gap: 6px;
  justify-content: center;
  flex-wrap: wrap;
}

.auth-form input {
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid #3a3a5c;
  background: #232345;
  color: #fff;
  font-size: 0.85rem;
  width: 120px;
}

.auth-form input::placeholder { color: #6b7399; }

.auth-form button,
.auth-loggedin button {
  padding: 6px 14px;
  border-radius: 6px;
  border: none;
  background: #4361ee;
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  font-size: 0.85rem;
}

.auth-form button:hover,
.auth-loggedin button:hover { background: #3348c4; }

.auth-loggedin {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: center;
  color: #cfd2e3;
  font-size: 0.9rem;
}

.auth-error {
  color: #ff6b6b;
  margin-top: 6px;
  min-height: 1em;
  font-size: 0.8rem;
}

.game-scoreboard {
  color: #8890b5;
  margin-bottom: 8px;
  font-size: 0.85rem;
}

a.restart-btn {
  display: inline-block;
  text-decoration: none;
}

.leaderboard-btn {
  margin-left: 8px;
  background: #232345;
}

.leaderboard-btn:hover { background: #2f2f5c; }

.leaderboard-wrap {
  max-width: 420px;
  width: 100%;
  margin: 0 auto;
}

.leaderboard-list {
  background: #16213e;
  border: 2px solid #4361ee;
  border-radius: 8px;
  padding: 10px;
  margin-top: 16px;
}

.leaderboard-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 6px;
  font-family: monospace;
}

.leaderboard-row.you {
  background: rgba(67, 97, 238, 0.25);
  border: 1px solid #4361ee;
  font-weight: 700;
}

.leaderboard-row .rank {
  width: 32px;
  color: #8890b5;
  flex-shrink: 0;
}

.leaderboard-row .name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: left;
}

.leaderboard-row .points {
  flex-shrink: 0;
}

.leaderboard-divider {
  text-align: center;
  color: #6b7399;
  padding: 2px 0;
}

.score { color: #cfd2e3; margin-bottom: 16px; }

.mute-btn {
  margin-left: 6px;
  width: 30px;
  height: 30px;
  padding: 0;
  border-radius: 6px;
  border: 1px solid #3a3a5c;
  background: #232345;
  color: #fff;
  font-size: 0.95rem;
  cursor: pointer;
  vertical-align: middle;
  line-height: 1;
}

.mute-btn:hover { background: #2f2f5c; }

.canvas-wrap {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: 16px;
  flex-wrap: wrap;
}

.tetris-canvas {
  background: #16213e;
  border: 2px solid #4361ee;
  border-radius: 8px;
  touch-action: none;
  display: block;
  image-rendering: pixelated;
}

#board {
  height: min(400px, 80vh);
  width: calc(min(400px, 80vh) / 2);
}

/* Brief screen-shake on a 4-line ("tetris") clear - toggled on #board. */
@keyframes tetrisShake {
  0% { transform: translate(0, 0); }
  20% { transform: translate(-3px, 2px); }
  40% { transform: translate(3px, -2px); }
  60% { transform: translate(-2px, -3px); }
  80% { transform: translate(2px, 3px); }
  100% { transform: translate(0, 0); }
}

.shake {
  animation: tetrisShake 0.2s;
}

.side-panels {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.mini-canvas {
  width: 80px;
}

.next-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.panel-label {
  color: #8890b5;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.tetris-controls {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  margin: 20px auto 0;
  max-width: 360px;
}

.tetris-btn {
  width: 56px;
  height: 56px;
  font-size: 1.3rem;
  background: #16213e;
  color: #fff;
  border: 2px solid #4361ee;
  border-radius: 10px;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
}

.tetris-btn:active { background: #4361ee; }

.tetris-btn-drop { font-size: 1.1rem; }
.tetris-btn-hold { font-size: 0.85rem; }

.restart-btn {
  margin-top: 20px;
  background: #4361ee;
  color: #fff;
  border: none;
  padding: 12px 28px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
}

.restart-btn:hover { background: #3348c4; }

.hint {
  color: #8890b5;
  margin-top: 16px;
  font-size: 0.9rem;
}

@media (hover: hover) and (pointer: fine) {
  .tetris-controls { display: none; }
}

.credit {
  color: #6b7399;
  margin-top: 8px;
  font-size: 0.8rem;
}
