*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #0f0f1a;
  --surface: #1a1a2e;
  --border: #2d2d44;
  --text: #e8e8f0;
  --muted: #8888aa;
  --accent: #6c5ce7;
  --accent-glow: rgba(108, 92, 231, 0.4);
  --board-bg: #12121f;
}

body {
  min-height: 100vh;
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  background-image:
    radial-gradient(ellipse at 20% 0%, rgba(108, 92, 231, 0.15) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 100%, rgba(0, 206, 201, 0.1) 0%, transparent 50%);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.app {
  width: 100%;
  max-width: 860px;
}

.header {
  text-align: center;
  margin-bottom: 1.5rem;
}

.header h1 {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  background: linear-gradient(135deg, #a29bfe, #00cec9);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.subtitle {
  color: var(--muted);
  font-size: 0.875rem;
  margin-top: 0.25rem;
}

.player-info {
  font-size: 0.9rem;
  color: var(--muted);
}

.user-bar {
  margin-top: 0.75rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
}

.user-bar.hidden {
  display: none;
}

.user-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: center;
}

.btn-outline {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  padding: 0.45rem 1rem;
  font-size: 0.85rem;
  font-weight: 600;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.btn-outline:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: var(--muted);
}

.btn-outline.btn-danger {
  color: #ff8a80;
  border-color: rgba(255, 82, 82, 0.4);
}

.btn-outline.btn-danger:hover {
  background: rgba(255, 82, 82, 0.12);
  border-color: #ff5252;
}

#player-name {
  color: #a29bfe;
  font-weight: 600;
}

.game-layout {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: 1.25rem;
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-width: 130px;
}

.stat-box,
.preview-box,
.controls,
.leaderboard-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.875rem;
}

.label {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.5rem;
}

.value {
  font-size: 1.75rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.preview-box canvas {
  display: block;
  margin: 0 auto;
  border-radius: 6px;
}

.board-wrap {
  position: relative;
  flex-shrink: 0;
}

#game-canvas {
  display: block;
  border: 3px solid var(--border);
  border-radius: 8px;
  background: var(--board-bg);
  box-shadow:
    0 0 30px var(--accent-glow),
    inset 0 0 60px rgba(0, 0, 0, 0.5);
}

.overlay {
  position: absolute;
  inset: 0;
  background: rgba(15, 15, 26, 0.85);
  backdrop-filter: blur(4px);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.overlay.hidden {
  display: none;
}

.overlay-content {
  text-align: center;
  padding: 1.5rem;
}

.overlay-content h2 {
  font-size: 1.5rem;
  margin-bottom: 0.75rem;
}

.overlay-content p {
  color: var(--muted);
  margin-bottom: 1.25rem;
  font-size: 0.9rem;
}

.btn {
  background: linear-gradient(135deg, var(--accent), #5a4bd1);
  color: white;
  border: none;
  padding: 0.75rem 2rem;
  font-size: 1rem;
  font-weight: 600;
  border-radius: 8px;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
}

.btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px var(--accent-glow);
}

.btn:active {
  transform: translateY(0);
}

.btn-block {
  width: 100%;
}

.btn-text {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 0.8rem;
  cursor: pointer;
  margin-top: 0.75rem;
  text-decoration: underline;
}

.btn-text:hover {
  color: var(--text);
}

.login-screen {
  position: fixed;
  inset: 0;
  background: rgba(15, 15, 26, 0.92);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
}

.login-screen.hidden {
  display: none;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 2rem;
  width: 100%;
  max-width: 360px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
}

.login-card h2 {
  font-size: 1.5rem;
  margin-bottom: 0.5rem;
}

.login-hint {
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 1.25rem;
}

#name-input {
  width: 100%;
  padding: 0.75rem 1rem;
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  outline: none;
  margin-bottom: 0.5rem;
}

#name-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.login-error {
  color: #ff5252;
  font-size: 0.8rem;
  margin-bottom: 0.75rem;
}

.login-error.hidden {
  display: none;
}

.leaderboard-list {
  list-style: none;
  font-size: 0.8rem;
  max-height: 220px;
  overflow-y: auto;
}

.leaderboard-list li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
}

.leaderboard-list li:last-child {
  border-bottom: none;
}

.leaderboard-list li.is-me {
  color: var(--text);
  background: rgba(108, 92, 231, 0.12);
  margin: 0 -0.5rem;
  padding-left: 0.5rem;
  padding-right: 0.5rem;
  border-radius: 6px;
}

.leaderboard-list .rank {
  width: 1.25rem;
  font-weight: 700;
  color: var(--accent);
  flex-shrink: 0;
}

.leaderboard-list .rank.top1 { color: #ffd700; }
.leaderboard-list .rank.top2 { color: #c0c0c0; }
.leaderboard-list .rank.top3 { color: #cd7f32; }

.leaderboard-list .lb-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leaderboard-list .lb-score {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  flex-shrink: 0;
}

.leaderboard-empty {
  color: var(--muted);
  font-size: 0.8rem;
  text-align: center;
  padding: 0.5rem 0;
}

.controls ul {
  list-style: none;
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.8;
}

kbd {
  display: inline-block;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.1em 0.4em;
  font-size: 0.75rem;
  font-family: inherit;
  color: var(--text);
}

.mobile-controls {
  display: none;
  margin-top: 1.25rem;
  gap: 0.5rem;
  justify-content: center;
  flex-wrap: wrap;
}

.mob-btn {
  width: 56px;
  height: 56px;
  font-size: 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.1s;
}

.mob-btn:active {
  background: var(--accent);
}

@media (max-width: 640px) {
  .panel-left .controls,
  .panel-right .controls {
    display: none;
  }

  .panel-left {
    order: 2;
    flex-direction: row;
    flex-wrap: wrap;
    min-width: unset;
    width: 100%;
    justify-content: center;
  }

  .panel-left .stat-box {
    flex: 1;
    min-width: 80px;
    text-align: center;
  }

  .panel-left .preview-box {
    display: none;
  }

  .panel-right .controls {
    display: none;
  }

  .panel-right {
    order: 3;
    width: 100%;
    max-width: 300px;
  }

  .leaderboard-list {
    max-height: 140px;
  }

  .game-layout {
    flex-direction: column;
    align-items: center;
  }

  .mobile-controls {
    display: flex;
  }

  #game-canvas {
    width: 100%;
    max-width: 300px;
    height: auto;
  }
}
