:root {
  --bg-1: #06111f;
  --bg-2: #0b1d36;
  --panel: rgba(10, 19, 36, 0.72);
  --panel-border: rgba(146, 198, 255, 0.16);
  --text: #e9f4ff;
  --muted: #a9bfd8;
  --accent: #63d2ff;
  --accent-2: #7dffbf;
  --danger: #ff5f7a;
  --shadow: 0 24px 64px rgba(0, 0, 0, 0.38);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top, rgba(99, 210, 255, 0.2), transparent 32%),
    radial-gradient(circle at 20% 20%, rgba(125, 255, 191, 0.12), transparent 24%),
    linear-gradient(180deg, var(--bg-2), var(--bg-1) 58%);
  overflow: hidden;
}

.game-shell {
  width: min(1200px, calc(100vw - 24px));
  height: min(100dvh - 24px, 980px);
  margin: 12px auto;
  display: grid;
  grid-template-rows: auto auto auto 1fr;
  gap: 14px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.auth-bar {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

.auth-notice {
  margin: 0;
  font-size: 0.72rem;
  color: var(--muted);
  max-width: 260px;
  text-align: right;
}

.auth-notice.error {
  color: #ff9fb0;
}

.login-section,
.user-section {
  display: flex;
  align-items: center;
  gap: 10px;
}

.auth-bar.logged-in .login-section {
  display: none !important;
  width: 0;
  height: 0;
  overflow: hidden;
  margin: 0;
  padding: 0;
  pointer-events: none;
}

.login-section.is-hidden,
.login-section[hidden],
.user-section[hidden] {
  display: none !important;
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid rgba(255, 255, 255, 0.18);
}

.user-name {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text);
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ghost-btn {
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 999px;
  font-weight: 700;
  cursor: pointer;
}

.ghost-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

.history-panel {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.history-column,
.topbar,
.hud,
.stage {
  border: 1px solid var(--panel-border);
  background: var(--panel);
  backdrop-filter: blur(14px);
  box-shadow: var(--shadow);
}

.history-column {
  padding: 14px 16px;
  border-radius: 18px;
  min-height: 132px;
}

.history-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.history-header h3 {
  margin: 0;
  font-size: 0.95rem;
}

.history-hint {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
  max-height: 88px;
  overflow: auto;
}

.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 10px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.history-main {
  font-size: 0.88rem;
}

.history-meta {
  color: var(--muted);
  font-size: 0.72rem;
  text-align: right;
}

.history-empty {
  color: var(--muted);
  font-size: 0.82rem;
  padding: 8px 2px;
}

.save-score-status {
  margin: 10px 0 0;
  color: var(--accent-2);
  font-size: 0.88rem;
  font-weight: 700;
  min-height: 1.2em;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px;
  border-radius: 20px;
}

.eyebrow {
  margin: 0 0 4px;
  text-transform: uppercase;
  letter-spacing: 0.22em;
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 700;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.6rem, 4vw, 2.4rem);
  line-height: 1.05;
}

.hud {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  padding: 14px;
  border-radius: 18px;
}

.hud-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.hud-label {
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.72rem;
  font-weight: 700;
}

.hud-value {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--text);
}

.stage {
  position: relative;
  overflow: hidden;
  border-radius: 24px;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.action-btn {
  border: none;
  color: #05111d;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  padding: 12px 18px;
  border-radius: 999px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 12px 30px rgba(99, 210, 255, 0.28);
  transition:
    transform 0.18s ease,
    filter 0.18s ease;
}

.action-btn:hover {
  transform: translateY(-1px);
  filter: brightness(1.05);
}

.action-btn:active {
  transform: translateY(1px) scale(0.99);
}

.action-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
  filter: none;
  box-shadow: none;
}

.sign-in-gate {
  margin: 0 0 10px;
  color: #ffd166;
  font-weight: 800;
}

.action-btn.wide {
  width: 100%;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: radial-gradient(circle at top, rgba(6, 17, 31, 0.24), rgba(6, 17, 31, 0.74));
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

.overlay-card {
  width: min(92%, 460px);
  padding: 24px;
  border-radius: 22px;
  background: rgba(10, 19, 36, 0.86);
  border: 1px solid rgba(255, 255, 255, 0.08);
  text-align: center;
  box-shadow: var(--shadow);
}

.overlay-card.danger {
  border-color: rgba(255, 95, 122, 0.3);
}

.overlay-kicker {
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 800;
  margin-bottom: 8px;
}

.overlay-card h2 {
  font-size: clamp(1.6rem, 4vw, 2.2rem);
  margin-bottom: 10px;
}

.overlay-card p {
  color: var(--muted);
  line-height: 1.6;
}

.controls-list {
  margin-top: 18px;
  display: grid;
  gap: 8px;
  color: var(--text);
  font-weight: 700;
}

@media (max-width: 720px) {
  body {
    overflow: auto;
  }

  .game-shell {
    width: calc(100vw - 16px);
    height: auto;
    min-height: calc(100dvh - 16px);
    margin: 8px auto;
  }

  .topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .topbar-actions {
    justify-content: stretch;
    flex-direction: column;
    align-items: stretch;
  }

  .auth-bar {
    align-items: stretch;
  }

  .auth-notice {
    max-width: none;
    text-align: left;
  }

  .history-panel {
    grid-template-columns: 1fr;
  }

  .hud {
    grid-template-columns: 1fr;
  }

  .stage {
    min-height: 68vh;
  }
}
