:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --text: #182033;
  --muted: #5a6478;
  --border: #d7ddeb;
  --button-bg: #ffffff;
  --button-hover: #f2f5ff;
}

html[data-theme="dark"] {
  --bg: #0d1220;
  --surface: #151c2e;
  --text: #edf1fb;
  --muted: #b7c0d8;
  --border: #2a3550;
  --button-bg: #1b2440;
  --button-hover: #253154;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, "Helvetica Neue", sans-serif;
}

main {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.75rem;
}

.game-shell {
  width: min(99vw, 1400px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
}

.topbar {
  width: min(100%, 1000px);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 0.1rem;
  position: relative;
  z-index: 5;
}

.topbar-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.2rem;
  height: 2.2rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--button-bg);
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
  font: inherit;
  transition: background 0.15s ease;
}

html:not([data-theme="dark"]) .topbar-btn {
  background: rgba(255, 255, 255, 0.85);
  border-color: rgba(15, 25, 45, 0.18);
  box-shadow: 0 6px 18px rgba(15, 25, 45, 0.12);
}

html[data-theme="dark"] .topbar-btn {
  background: rgba(27, 36, 64, 0.85);
  border-color: rgba(255, 255, 255, 0.22);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
}

.topbar-btn:hover {
  background: var(--button-hover);
}

.game-hud {
  position: absolute;
  left: 12px;
  right: 12px;
  top: 12px;
  z-index: 2;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  flex-wrap: wrap;
  gap: 0.4rem;
  font-size: 0.9rem;
  color: #f6f8ff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.55);
}

.game-hud span {
  background: rgba(12, 18, 32, 0.42);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  padding: 0.3rem 0.45rem;
  text-align: center;
}

.game-canvas-wrap {
  display: flex;
  justify-content: center;
  position: relative;
}

#brick-canvas {
  display: block;
  border-radius: 10px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.18);
  touch-action: none;
}

.center-overlay {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 2;
  width: min(88%, 420px);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.35rem;
  color: #f6f8ff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7);
}

.overlay-title {
  margin: 0 0 0.1rem;
  font-size: clamp(1.5rem, 4vw, 2rem);
  font-weight: 700;
}

#btn-start {
  font: inherit;
  color: var(--text);
  background: var(--button-bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.6rem 1rem;
  cursor: pointer;
}

#btn-start:hover {
  background: var(--button-hover);
}

#btn-tilt {
  font: inherit;
  color: var(--text);
  background: var(--button-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.45rem 0.85rem;
  cursor: pointer;
}

#btn-tilt:hover {
  background: var(--button-hover);
}

.theme-toggle-icon {
  width: 1rem;
  height: 1rem;
}

.theme-toggle-icon--moon {
  display: block;
}

.theme-toggle-icon--sun {
  display: none;
}

html[data-theme="dark"] .theme-toggle-icon--moon {
  display: none;
}

html[data-theme="dark"] .theme-toggle-icon--sun {
  display: block;
}

.game-status,
.tilt-hint,
.scoreboard__meta {
  color: var(--muted);
}

.game-status {
  margin: 0;
  font-size: 0.9rem;
  color: #f6f8ff;
}

.tilt-hint {
  margin: 0;
  font-size: 0.85rem;
  color: #dbe4ff;
}

.scoreboard {
  width: 100%;
  max-width: 340px;
  margin-top: 0.35rem;
  border-top: 1px solid rgba(255, 255, 255, 0.24);
  padding-top: 0.5rem;
}

.scoreboard h2 {
  margin: 0 0 0.4rem;
  font-size: 0.95rem;
  color: #f6f8ff;
}

#scoreboard-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.scoreboard__row {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 0.45rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.2);
  font-size: 0.85rem;
}

.scoreboard__row:last-child {
  border-bottom: none;
}

.scoreboard__profile {
  word-break: break-word;
}

.scoreboard__meta {
  font-size: 0.78rem;
  color: #dbe4ff;
}

.scoreboard__empty {
  padding: 0.3rem 0;
  color: #dbe4ff;
}

@media (max-width: 560px) {
  .game-hud {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
