* { 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;
  border: none;
  border-radius: 6px;
  background: #232345;
  color: #fff;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  vertical-align: middle;
}

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

.board-wrap {
  display: flex;
  justify-content: center;
}

.board2048 {
  position: relative;
  background: #16213e;
  border: 2px solid #4361ee;
  border-radius: 8px;
  width: min(400px, 88vw);
  height: min(400px, 88vw);
  touch-action: none;
}

.cell2048 {
  position: absolute;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 6px;
  z-index: 0;
}

.tile2048 {
  position: absolute;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  font-weight: 700;
  font-size: 1.3rem;
  color: #fff;
  background: #3d4a8a;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.14), 0 2px 6px rgba(0, 0, 0, 0.35);
  transition: left 0.12s ease, top 0.12s ease;
}

@keyframes tileSpawn {
  from { transform: scale(0.4); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

@keyframes tilePop {
  0% { transform: scale(1); }
  45% { transform: scale(1.14); }
  100% { transform: scale(1); }
}

.tile-spawn { animation: tileSpawn 0.16s ease-out; }
.tile-pop { animation: tilePop 0.16s ease-out; }

/* Ekstra brett-nivå-puls for store sammenslåinger (>=128), oppå
   per-brikke tile-pop over. Holdes subtilt - kort glød, ikke blaff. */
@keyframes bigMergeGlow {
  0% { box-shadow: inset 0 0 0 0 rgba(255, 209, 102, 0), 0 0 0 0 rgba(255, 209, 102, 0); border-color: #4361ee; }
  40% { box-shadow: inset 0 0 14px 2px rgba(255, 209, 102, 0.45), 0 0 16px 3px rgba(255, 209, 102, 0.3); border-color: #ffd166; }
  100% { box-shadow: inset 0 0 0 0 rgba(255, 209, 102, 0), 0 0 0 0 rgba(255, 209, 102, 0); border-color: #4361ee; }
}

.board2048.big-merge { animation: bigMergeGlow 0.25s ease-out; }

.board-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: rgba(0, 0, 0, 0.6);
  border-radius: 6px;
}

.board-overlay[hidden] { display: none; }

.board-overlay .title {
  font-size: 1.4rem;
  font-weight: 700;
}

.board-overlay .subtitle {
  font-size: 0.9rem;
  color: #cfd2e3;
}

.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;
}

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