/* ===== Fonts ===== */
@font-face {
  font-family: "Bitcount Grid Single";
  src: url("/fonts/BitcountGridSingle_Roman-Regular.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

/* ===== Loading Screen ===== */
#loading-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #2c3e50;
  transition: opacity 0.4s ease;
}
#loading-screen .loading-placeholder {
  width: 380px;
  height: 44px;
  border-radius: 6px;
  background: #76ff03;
  filter: blur(12px);
  opacity: 0.6;
}
#loading-screen .loading-text {
  display: none;
}
#loading-screen.fonts-ready .loading-placeholder {
  display: none;
}
#loading-screen.fonts-ready .loading-text {
  display: block;
}
#loading-screen.fade-out {
  opacity: 0;
  pointer-events: none;
}

/* ===== Reset & Base ===== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
body {
  background: #2c3e50;
  color: #ecf0f1;
  font-family: "Bitcount Grid Single", system-ui, sans-serif;
}

h1 {
  color: #76ff03;
}
h2 {
  color: #ecf0f1;
}
a {
  color: #76ff03;
}
.error {
  color: #e74c3c;
  margin: 8px 0;
}

/* ===== Canvas ===== */
/* Make canvas ignore pointer events when menu is visible */
#menu[style*="display: block"] ~ #gameCanvas {
  pointer-events: none;
}

canvas {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  width: 100%;
  height: 100%;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  -khtml-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

@media screen and (max-width: 768px) {
  body.game-active {
    overflow: hidden;
    position: fixed;
    width: 100%;
    height: 100%;
  }
}

/* ===== Shared Form Styles (login, join, menu) ===== */
.page-form {
  max-width: 400px;
  margin: 80px auto;
  padding: 0 20px;
  text-align: center;
}

.page-form input {
  display: block;
  width: 100%;
  padding: 10px;
  margin: 8px 0;
  border: 1px solid #4db39950;
  border-radius: 4px;
  background: #1a2634;
  color: #ecf0f1;
  box-sizing: border-box;
  font-family: "Bitcount Grid Single", system-ui, sans-serif;
}

.page-form button {
  display: block;
  width: 100%;
  padding: 12px;
  margin: 12px 0;
  border: none;
  border-radius: 4px;
  background: #76ff03;
  color: #2c3e50;
  font-weight: bold;
  cursor: pointer;
  font-size: 16px;
  font-family: "Bitcount Grid Single", system-ui, sans-serif;
  min-height: 44px;
  box-sizing: border-box;
}

.page-form label {
  display: block;
  text-align: left;
  color: #ecf0f1;
  opacity: 0.7;
  font-size: 14px;
  margin-top: 12px;
  margin-bottom: 2px;
}

.page-form button:hover {
  background: #3a8c75;
}

.page-form .guest-btn {
  margin-top: 32px;
}

.page-form .forgot-password-link {
  display: block;
  text-align: right;
  color: #4db399;
  font-size: 13px;
  margin-top: 4px;
  text-decoration: none;
}

.page-form .forgot-password-link:hover {
  text-decoration: underline;
}

.page-form .success-message {
  color: #76ff03;
  margin: 16px 0;
}

.page-form .form-subtitle {
  color: #ecf0f1;
  opacity: 0.7;
  font-size: 14px;
  margin-bottom: 16px;
}

/* ===== Index (menu) page ===== */
#choose-mode-msg {
  color: #ecf0f1;
  opacity: 0.7;
  margin-bottom: 24px;
}

/* Difficulty selector */
.difficulty-label {
  display: block;
  text-align: center;
  color: #ecf0f1;
  opacity: 0.7;
  font-size: 14px;
  margin-top: 12px;
  margin-bottom: 6px;
}
.difficulty-select {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
.difficulty-btn {
  flex: 1;
  padding: 10px 0;
  border: 2px solid #4db39950;
  border-radius: 4px;
  background: #1a2634;
  color: #ecf0f1;
  cursor: pointer;
  font-size: 14px;
  font-family: "Bitcount Grid Single", system-ui, sans-serif;
  min-height: 44px;
}
.difficulty-btn:hover {
  border-color: #76ff03;
}
.difficulty-btn.selected {
  border-color: #76ff03;
  background: #76ff0322;
  color: #76ff03;
}
#bottom-bar {
  position: fixed;
  bottom: 16px;
  left: 16px;
  display: flex;
  gap: 8px;
  z-index: 2;
}
#logout-btn,
#profile-btn,
#admin-btn {
  background: none;
  border: none;
  color: #ecf0f1;
  cursor: pointer;
  padding: 8px;
  opacity: 0.5;
  width: auto;
  min-height: auto;
  margin: 0;
}
#logout-btn:hover,
#profile-btn:hover,
#admin-btn:hover {
  opacity: 1;
  background: none;
}

/* ===== PWA Install Banner ===== */
#install-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: #1a2634;
  border-top: 1px solid #76ff0344;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  z-index: 50;
  flex-wrap: wrap;
}
#install-banner-text {
  font-size: 14px;
  color: #ecf0f1;
  flex: 1;
}
#install-banner-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}
#install-btn {
  background: #76ff03;
  color: #1a2634;
  border: none;
  border-radius: 4px;
  padding: 8px 20px;
  font-family: inherit;
  font-size: 14px;
  font-weight: bold;
  cursor: pointer;
  width: auto;
  min-height: auto;
  margin: 0;
}
#install-btn:hover {
  background: #64dd17;
}
.install-dismiss {
  background: none;
  border: none;
  color: #ecf0f1;
  font-size: 22px;
  cursor: pointer;
  padding: 4px 8px;
  opacity: 0.6;
  width: auto;
  min-height: auto;
  margin: 0;
}
.install-dismiss:hover {
  opacity: 1;
  background: none;
}

/* Email verification banner */
#verify-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: #1a2634;
  border-bottom: 1px solid #4db39950;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  z-index: 50;
  font-size: 14px;
}
#verify-banner p {
  margin: 0;
  color: #ecf0f1;
}
.verify-resend-link {
  color: #4db399;
  text-decoration: none;
}
.verify-resend-link:hover {
  text-decoration: underline;
}
.verify-dismiss {
  background: none;
  border: none;
  color: #ecf0f1;
  font-size: 22px;
  cursor: pointer;
  padding: 4px 8px;
  opacity: 0.6;
  width: auto;
  min-height: auto;
  margin: 0;
}
.verify-dismiss:hover {
  opacity: 1;
  background: none;
}

#ios-install-steps {
  width: 100%;
  font-size: 13px;
  color: #aab;
  line-height: 1.5;
}
#ios-install-steps strong {
  color: #76ff03;
}
.ios-share-icon {
  font-family: -apple-system, system-ui;
  font-size: 16px;
  vertical-align: middle;
}

#invite-link {
  display: none;
  margin: 16px 0;
  padding: 12px;
  background: #1a2634;
  border-radius: 4px;
  word-break: break-all;
}
#invite-link a {
  color: #76ff03;
}

.back-btn {
  background: none;
  border: none;
  color: #ecf0f1;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  padding: 12px;
  align-self: flex-start;
  width: auto;
}
.back-btn:hover {
  opacity: 1;
}

#status {
  color: #ecf0f1;
  opacity: 0.7;
  margin: 12px 0;
}

/* ===== Game Over UI ===== */
#game-over-ui {
  position: relative;
  z-index: 1;
  text-align: center;
  padding: 24px 20px 40px;
  max-width: 500px;
  margin: 0 auto;
}
#game-over-ui button {
  display: inline-block;
  padding: 14px 40px;
  border: none;
  border-radius: 4px;
  background: #76ff03;
  color: #2c3e50;
  font-weight: bold;
  font-size: 18px;
  cursor: pointer;
  margin-top: 12px;
  font-family: "Bitcount Grid Single", system-ui, sans-serif;
}
#game-over-ui button:hover {
  background: #3a8c75;
}
.game-over-thanks {
  font-size: 22px;
  color: #ecf0f1;
  margin-bottom: 8px;
}
.game-over-email-prompt {
  font-size: 15px;
  color: #ecf0f1;
  opacity: 0.7;
  margin-bottom: 12px;
}
.game-over-sign-up-prompt {
  font-size: 15px;
  color: #ecf0f1;
  opacity: 0.7;
  margin-top: 32px;
  margin-bottom: 12px;
}
#guest-email-input {
  display: block;
  width: 100%;
  max-width: 320px;
  margin: 0 auto 12px;
  padding: 10px;
  border: 1px solid #4db39950;
  border-radius: 4px;
  background: #1a2634;
  color: #ecf0f1;
  font-size: 16px;
  box-sizing: border-box;
  font-family: "Bitcount Grid Single", system-ui, sans-serif;
}
#guest-email-status {
  color: #76ff03;
  margin-top: 8px;
}
/* Canvas wrapper with gradient vignette overlay */
#game-over-canvas-wrapper {
  position: relative;
  width: 80vw;
  max-width: 900px;
  margin: 24px auto 0;
}
#game-over-canvas-wrapper::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  box-shadow:
    inset 0 0 120px 60px #2c3e50,
    inset 0 0 60px 30px #2c3e50,
    inset 0 0 20px 10px #2c3e50;
}
/* Canvas in game-over mode: not fullscreen, proportionally shrunk, centered */
.game-over-canvas {
  position: relative !important;
  width: 100% !important;
  height: 60vh !important;
  display: block;
  margin: 0 !important;
  pointer-events: none;
}

/* ===== Login page ===== */
#login-form h1 {
  margin-bottom: 8px;
}

/* ===== Join page ===== */
#join-btn {
  margin-top: 12px;
}

/* ===== Color Picker ===== */
.color-picker-label {
  display: block;
  text-align: left;
  color: #ecf0f1;
  opacity: 0.7;
  font-size: 14px;
  margin-top: 16px;
}
.color-picker-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 12px;
  margin-top: 13px;
}
.color-swatch {
  aspect-ratio: 1;
  border: 3px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  transition:
    border-color 0.15s,
    transform 0.15s;
}
.color-swatch:hover {
  transform: scale(1.1);
}
.color-swatch.selected {
  border-color: #76ff03;
  transform: scale(1.1);
}

/* ===== Profile page header ===== */
.profile-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.profile-header h1 {
  margin: 0;
}
.profile-header a {
  color: #76ff03;
  text-decoration: none;
  font-size: 14px;
}

/* ===== Admin page ===== */
.admin-container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px;
  color: #ecf0f1;
  font-family: "Bitcount Grid Single", monospace;
}
.admin-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}
.admin-header h1 {
  margin: 0;
  font-size: 1.5rem;
}
.admin-header a {
  color: #76ff03;
  text-decoration: none;
}
.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  border-bottom: 2px solid #4db39950;
}
.tab {
  padding: 8px 20px;
  cursor: pointer;
  background: #1a2634;
  color: #ecf0f1;
  opacity: 0.6;
  border: 1px solid #4db39950;
  border-bottom: none;
  border-radius: 6px 6px 0 0;
  font-family: "Bitcount Grid Single", monospace;
  font-size: 0.9rem;
}
.tab.active {
  background: #2c3e50;
  color: #ecf0f1;
  opacity: 1;
  border-color: #76ff03;
}
.tab-content {
  display: none;
}
.tab-content.active {
  display: block;
}
.admin-container table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
.admin-container th,
.admin-container td {
  text-align: left;
  padding: 8px 12px;
  border-bottom: 1px solid #4db39950;
}
.admin-container th {
  background: #1a2634;
  color: #76ff03;
  font-weight: bold;
  position: sticky;
  top: 0;
}
.admin-container tr:hover td {
  background: #1a2634;
}
.count {
  color: #ecf0f1;
  opacity: 0.5;
  font-size: 0.85rem;
  margin-left: 8px;
}
.loading {
  color: #ecf0f1;
  opacity: 0.5;
  padding: 20px;
}
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
}
.badge-active {
  background: #3a8c7533;
  color: #76ff03;
}
.badge-abandoned {
  background: #e74c3c33;
  color: #e74c3c;
}
.badge-solo {
  background: #3498db33;
  color: #3498db;
}
.badge-coop {
  background: #9b59b633;
  color: #9b59b6;
}
.badge-waiting {
  background: #f39c1233;
  color: #f39c12;
}
.badge-finished {
  background: #2c3e50;
  color: #ecf0f1;
  opacity: 0.6;
}
.badge-admin {
  background: #4db39933;
  color: #76ff03;
}
.badge-expired {
  background: #e74c3c33;
  color: #e74c3c;
}
.badge-valid {
  background: #3a8c7533;
  color: #76ff03;
}
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 16px;
  padding: 12px 0;
}
.pagination button {
  padding: 6px 16px;
  background: #1a2634;
  color: #ecf0f1;
  border: 1px solid #4db39950;
  border-radius: 4px;
  cursor: pointer;
  font-family: "Bitcount Grid Single", monospace;
  font-size: 0.85rem;
}
.pagination button:hover:not(:disabled) {
  background: #2c3e50;
  border-color: #76ff03;
}
.pagination button:disabled {
  opacity: 0.3;
  cursor: default;
}
.pagination-info {
  color: #ecf0f1;
  opacity: 0.7;
  font-size: 0.85rem;
}

/* Overview stat cards */
.stat-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}
.stat-card {
  background: #1a2634;
  border: 1px solid #4db39950;
  border-radius: 8px;
  padding: 16px;
  text-align: center;
}
.stat-value {
  font-size: 1.6rem;
  color: #76ff03;
  font-weight: bold;
}
.stat-label {
  font-size: 0.75rem;
  color: #ecf0f1;
  opacity: 0.6;
  margin-top: 4px;
}
.recent-games {
  margin-top: 8px;
}
.recent-games h3 {
  font-size: 1rem;
  margin-bottom: 8px;
  color: #ecf0f1;
}

/* Screen-reader only — visually hidden but accessible */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Animated ellipsis loading indicator */
button.btn-loading {
  pointer-events: none;
  opacity: 0.7;
}
.btn-loading::after {
  content: "...";
  animation: ellipsis 1.2s steps(3, end) infinite;
  display: inline-block;
  width: 1em;
  text-align: left;
}
@keyframes ellipsis {
  0% {
    content: "...";
  }
  33% {
    content: ".";
  }
  66% {
    content: "..";
  }
}

/* ===== Instructions link ===== */
.instructions-link {
  display: inline-block;
  margin-top: 16px;
  color: #ecf0f1;
  opacity: 0.6;
  font-size: 14px;
  text-decoration: underline;
  cursor: pointer;
}
.instructions-link:hover {
  opacity: 1;
  color: #76ff03;
}

/* ===== Lobby High Scores ===== */
.lobby-high-score {
  margin-top: 16px;
  font-size: 14px;
  color: #ecf0f1;
  opacity: 0.7;
}
.lobby-high-score:empty {
  display: none;
}
.lobby-high-score .hs-label {
  color: #76ff03;
  font-size: 13px;
  margin-bottom: 4px;
}
.lobby-high-score .hs-value {
  font-size: 18px;
  color: #ecf0f1;
}
.lobby-high-score .hs-row {
  display: flex;
  justify-content: space-between;
  padding: 2px 0;
}
.lobby-high-score .hs-difficulty {
  text-transform: capitalize;
  color: #ecf0f1;
  opacity: 0.6;
  font-size: 13px;
}

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-content {
  position: relative;
  background: #1a2634;
  border: 1px solid #4db39950;
  border-radius: 8px;
  padding: 32px 28px 28px;
  max-width: 520px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  text-align: left;
}
.modal-content h2 {
  color: #76ff03;
  margin-bottom: 8px;
  font-size: 1.3rem;
}
.modal-close {
  position: absolute;
  top: 10px;
  right: 14px;
  background: none;
  border: none;
  color: #ecf0f1;
  font-size: 1.6rem;
  cursor: pointer;
  opacity: 0.6;
  width: auto;
  min-height: auto;
  padding: 4px 8px;
  margin: 0;
}
.modal-close:hover {
  opacity: 1;
  background: none;
}
.instructions-objective {
  color: #ecf0f1;
  font-size: 15px;
  margin-bottom: 12px;
}
.instructions-body {
  color: #ecf0f1;
  opacity: 0.75;
  font-size: 14px;
  line-height: 1.5;
  margin-bottom: 16px;
}
.instructions-extra {
  color: #ecf0f1;
  opacity: 0.75;
  font-size: 14px;
  line-height: 1.5;
  margin-bottom: 16px;
}
.instructions-extra:empty {
  display: none;
}
.instructions-controls h3 {
  color: #76ff03;
  font-size: 15px;
  margin-bottom: 10px;
}
.instructions-controls-split {
  display: flex;
  gap: 24px;
}
.instructions-col {
  flex: 1;
}
.instructions-col h4 {
  color: #ecf0f1;
  font-size: 14px;
  margin-bottom: 6px;
}
.instructions-col ul {
  list-style: none;
  padding: 0;
}
.instructions-col li {
  color: #ecf0f1;
  opacity: 0.75;
  font-size: 13px;
  margin-bottom: 4px;
}
kbd {
  display: inline-block;
  padding: 1px 6px;
  background: #2c3e50;
  border: 1px solid #4db39950;
  border-radius: 3px;
  font-family: "Bitcount Grid Single", monospace;
  font-size: 12px;
  color: #76ff03;
}
@media screen and (max-width: 480px) {
  .instructions-controls-split {
    flex-direction: column;
    gap: 12px;
  }
}
