/* ============================================
   SkillSprint — Global Styles
   Dark arcade aesthetic, neon accents, mobile-first
   ============================================ */

:root {
  --bg:          #0a0a0f;
  --bg-card:     #14141f;
  --bg-card-hover: #1c1c2e;
  --surface:     #1a1a2e;
  --accent:      #00f0ff;
  --accent-dim:  #00a8b3;
  --accent-glow: rgba(0, 240, 255, 0.25);
  --pink:        #ff2d75;
  --text:        #e8e8f0;
  --text-muted:  #8888aa;
  --danger:      #ff4466;
  --success:     #00e676;
  --radius:      12px;
  --radius-sm:   8px;
  --font:        'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --transition:  0.2s ease;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}

body { position: relative; }

/* ===== Page routing ===== */
.page { display: none; min-height: 100vh; padding-bottom: env(safe-area-inset-bottom, 0); }
.page.active { display: flex; flex-direction: column; }

/* ============================================
   HOME PAGE
   ============================================ */
.app-header {
  text-align: center;
  padding: 48px 16px 24px;
}
.logo {
  font-size: 2.4rem;
  font-weight: 900;
  letter-spacing: -1px;
}
.accent { color: var(--accent); }
.tagline {
  color: var(--text-muted);
  margin-top: 6px;
  font-size: 0.95rem;
}

/* Games grid */
.games-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 16px;
  padding: 16px;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

.game-card {
  background: var(--bg-card);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: var(--radius);
  padding: 20px 16px;
  text-align: center;
  cursor: pointer;
  transition: background var(--transition), transform var(--transition), box-shadow var(--transition);
  user-select: none;
}
.game-card:hover, .game-card:active {
  background: var(--bg-card-hover);
  transform: translateY(-2px);
  box-shadow: 0 4px 24px var(--accent-glow);
}
.game-card .card-icon {
  font-size: 2.6rem;
  display: block;
  margin-bottom: 10px;
}
.game-card .card-name {
  font-weight: 700;
  font-size: 1.05rem;
  margin-bottom: 4px;
}
.game-card .card-desc {
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.35;
}
.game-card .card-top {
  margin-top: 10px;
  font-size: 0.75rem;
  color: var(--accent);
  font-weight: 600;
}

/* Played game cards (team mode) */
.game-card-played {
  opacity: 0.35;
  pointer-events: none;
  filter: grayscale(0.7);
  position: relative;
}
.game-card-played:hover,
.game-card-played:active {
  transform: none;
  box-shadow: none;
  background: var(--bg-card);
}
.card-played-badge {
  margin-top: 8px;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--success);
  letter-spacing: 1px;
  text-transform: uppercase;
}

/* ============================================
   GAME PAGE — HUD
   ============================================ */
.game-hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top, 12px));
  background: rgba(10,10,15,0.92);
  backdrop-filter: blur(8px);
  position: relative;
  z-index: 20;
  gap: 8px;
}
.hud-btn {
  background: rgba(255,255,255,0.06);
  border: 1.5px solid rgba(255,255,255,0.2);
  color: var(--text);
  font-size: 1.4rem;
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition);
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
}
.hud-btn:hover { background: rgba(255,255,255,0.12); }
.hud-score {
  font-size: 1.5rem;
  font-weight: 900;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.hud-timer {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text);
  min-width: 40px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.hud-timer.warning { color: var(--danger); animation: pulse-text 0.5s infinite alternate; }

@keyframes pulse-text { to { opacity: 0.5; } }

/* ===== Canvas ===== */
.canvas-wrap {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: var(--bg);
  touch-action: none;
}
#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* ===== Start overlay ===== */
.overlay {
  position: absolute;
  inset: 0;
  background: rgba(10,10,15,0.88);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 15;
}
.overlay.hidden { display: none; }
.overlay-content { text-align: center; padding: 24px; }
.game-title-overlay {
  font-size: 1.8rem;
  font-weight: 900;
  margin-bottom: 8px;
}
.game-desc-overlay {
  color: var(--text-muted);
  margin-bottom: 24px;
  font-size: 0.95rem;
}

/* ===== Buttons ===== */
.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-weight: 700;
  font-size: 1rem;
  padding: 14px 32px;
  cursor: pointer;
  transition: background var(--transition), transform var(--transition);
  width: 100%;
  max-width: 320px;
}
.btn-primary:hover { background: var(--accent-dim); }
.btn-primary:active { transform: scale(0.97); }
.btn-primary:disabled {
  opacity: 0.5;
  pointer-events: none;
}

.btn-large { font-size: 1.15rem; padding: 16px 40px; }

.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  color: var(--text);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-weight: 600;
  font-size: 0.9rem;
  padding: 12px 20px;
  cursor: pointer;
  flex: 1;
  transition: background var(--transition);
}
.btn-secondary:hover { background: var(--bg-card-hover); }

.btn-link {
  background: none;
  border: none;
  color: var(--accent);
  font-family: var(--font);
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  margin-top: 12px;
  padding: 8px;
}

.pulse { animation: pulse-btn 2s infinite; }
@keyframes pulse-btn {
  0%, 100% { box-shadow: 0 0 0 0 var(--accent-glow); }
  50% { box-shadow: 0 0 0 12px transparent; }
}

/* ===== End Modal ===== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(10,10,15,0.92);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}
.modal.hidden { display: none; }

.modal-card {
  background: var(--bg-card);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius);
  padding: 32px 24px;
  width: 100%;
  max-width: 380px;
  text-align: center;
  position: relative;
}
.end-home-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
}
.modal-title {
  font-size: 1.4rem;
  font-weight: 900;
  margin-bottom: 16px;
}

.final-score-wrap {
  margin-bottom: 20px;
}
.final-score-label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 4px;
}
.final-score {
  font-size: 3rem;
  font-weight: 900;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.input-name {
  display: block;
  width: 100%;
  background: var(--surface);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
  font-size: 1rem;
  padding: 14px 16px;
  margin-bottom: 12px;
  text-align: center;
  outline: none;
  transition: border-color var(--transition);
}
.input-name:focus { border-color: var(--accent); }

.submit-status {
  font-size: 0.85rem;
  min-height: 1.2em;
  margin-bottom: 16px;
}
.submit-status.error { color: var(--danger); }
.submit-status.success { color: var(--success); }

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 8px;
}

/* ============================================
   LEADERBOARD PAGE
   ============================================ */
.lb-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: rgba(10,10,15,0.92);
  backdrop-filter: blur(8px);
}
.lb-page-title {
  font-size: 1.15rem;
  font-weight: 700;
}

.lb-tabs {
  display: flex;
  gap: 0;
  padding: 8px 16px;
  background: var(--surface);
}
.lb-tab {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-muted);
  font-family: var(--font);
  font-weight: 600;
  font-size: 0.9rem;
  padding: 10px 0;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color var(--transition), border-color var(--transition);
}
.lb-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.lb-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 16px 24px;
  max-width: 600px;
  margin: 0 auto;
  width: 100%;
}

.lb-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  animation: fadeInRow 0.25s ease both;
}
.lb-row:nth-child(1) .lb-rank { color: #ffd700; }
.lb-row:nth-child(2) .lb-rank { color: #c0c0c0; }
.lb-row:nth-child(3) .lb-rank { color: #cd7f32; }

.lb-rank {
  font-weight: 900;
  font-size: 0.95rem;
  width: 28px;
  text-align: center;
  color: var(--text-muted);
  flex-shrink: 0;
}
.lb-flag {
  font-size: 1.3rem;
  flex-shrink: 0;
}
.lb-name {
  flex: 1;
  font-weight: 600;
  font-size: 0.95rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.lb-score-val {
  font-weight: 700;
  font-size: 1rem;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}

.lb-empty {
  text-align: center;
  color: var(--text-muted);
  padding: 48px 16px;
  font-size: 0.95rem;
}

.lb-loading {
  text-align: center;
  color: var(--text-muted);
  padding: 48px 16px;
}
.lb-loading::after {
  content: '';
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid var(--accent);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  vertical-align: middle;
  margin-left: 8px;
}

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fadeInRow { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ===== Utility ===== */
.hidden { display: none !important; }

/* ============================================
   HOW TO PLAY PANEL
   ============================================ */
.btn-how-to-play {
  display: block;
  margin: 16px auto 0;
  background: none;
  border: 1px solid rgba(255,255,255,0.12);
  color: var(--text-muted);
  font-family: var(--font);
  font-weight: 600;
  font-size: 0.85rem;
  padding: 10px 24px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: color var(--transition), border-color var(--transition), background var(--transition);
  letter-spacing: 0.5px;
}
.btn-how-to-play:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: rgba(0,240,255,0.06);
}

.hud-help-btn {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--text-muted);
  width: 34px;
  height: 34px;
  font-family: var(--font);
}
.hud-help-btn:hover { color: var(--accent); }

.htp-panel {
  position: absolute;
  inset: 0;
  background: rgba(10,10,15,0.94);
  backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 16px;
  animation: htpFadeIn 0.25s ease;
}
.htp-panel.hidden { display: none; }

@keyframes htpFadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.htp-card {
  background: var(--bg-card);
  border: 1px solid rgba(0,240,255,0.12);
  border-radius: var(--radius);
  padding: 28px 24px 24px;
  width: 100%;
  max-width: 380px;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 8px 40px rgba(0,240,255,0.08);
}

.htp-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.htp-title {
  font-size: 1.2rem;
  font-weight: 900;
  color: var(--accent);
}

.htp-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.6rem;
  cursor: pointer;
  padding: 4px 8px;
  line-height: 1;
  border-radius: 50%;
  transition: color var(--transition), background var(--transition);
}
.htp-close:hover {
  color: var(--text);
  background: rgba(255,255,255,0.08);
}

.htp-game-name {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.htp-steps {
  list-style: none;
  padding: 0;
  margin: 0 0 16px;
}

.htp-steps li {
  position: relative;
  padding: 8px 0 8px 32px;
  font-size: 0.9rem;
  color: var(--text);
  line-height: 1.45;
  border-left: 2px solid rgba(0,240,255,0.15);
  margin-left: 10px;
}

.htp-steps li::before {
  content: attr(data-step);
  position: absolute;
  left: -12px;
  top: 7px;
  width: 22px;
  height: 22px;
  background: var(--accent);
  color: #000;
  font-size: 0.7rem;
  font-weight: 800;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.htp-steps li:last-child {
  border-left-color: transparent;
}

.htp-tips {
  background: rgba(0,240,255,0.06);
  border: 1px solid rgba(0,240,255,0.1);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-bottom: 18px;
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.htp-tips strong {
  color: var(--accent);
  font-weight: 700;
}

.htp-tips:empty { display: none; }

/* ============================================
   TEAM COMPETITION UI
   ============================================ */

/* ---- Compete Button in Header ---- */
.btn-compete {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-top: 16px;
  padding: 12px 28px;
  background: transparent;
  border: 2px solid var(--accent);
  color: var(--accent);
  font-family: var(--font);
  font-weight: 700;
  font-size: 0.95rem;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background var(--transition), color var(--transition), transform var(--transition);
  letter-spacing: 0.5px;
}
.btn-compete:hover {
  background: var(--accent);
  color: #000;
}
.btn-compete:active { transform: scale(0.97); }

/* ---- Team Header Bar ---- */
.team-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: rgba(0, 240, 255, 0.06);
  border-bottom: 1px solid rgba(0, 240, 255, 0.12);
  flex-wrap: wrap;
  gap: 8px;
}
.team-header-info {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.team-badge {
  background: var(--accent);
  color: #000;
  font-weight: 800;
  font-size: 0.75rem;
  padding: 4px 10px;
  border-radius: 6px;
  letter-spacing: 1.5px;
  font-family: var(--font);
}
.team-meta {
  font-size: 0.85rem;
  color: var(--text-muted);
}
.team-you {
  color: var(--text);
  font-weight: 600;
}
.team-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
.btn-team-board {
  background: var(--surface);
  border: 1px solid rgba(255,255,255,0.1);
  color: var(--text);
  font-family: var(--font);
  font-weight: 600;
  font-size: 0.8rem;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition);
}
.btn-team-board:hover { background: var(--bg-card-hover); }

.btn-team-leave {
  background: none;
  border: 1px solid rgba(255,68,102,0.3);
  color: var(--danger);
  font-size: 1.3rem;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition);
  line-height: 1;
}
.btn-team-leave:hover { background: rgba(255,68,102,0.1); }

/* ---- Create Team Modal ---- */
.modal-top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}
.modal-top-row .modal-title { margin-bottom: 0; }

.team-create-card,
.team-join-card {
  text-align: left;
  max-width: 420px;
}

.ct-subtitle {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 18px;
  line-height: 1.4;
}

.ct-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
  margin-top: 14px;
}
.ct-label:first-of-type { margin-top: 0; }

.ct-modes {
  display: flex;
  gap: 8px;
  margin-bottom: 18px;
}
.ct-mode-option {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 8px;
  background: var(--surface);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
  font-size: 0.85rem;
  font-weight: 600;
}
.ct-mode-option:has(input:checked) {
  border-color: var(--accent);
  background: rgba(0,240,255,0.06);
}
.ct-mode-option input[type="radio"] {
  accent-color: var(--accent);
  margin: 0;
}

.ct-result {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid rgba(255,255,255,0.06);
}
.ct-result-label {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 10px;
}
.ct-link-row {
  display: flex;
  gap: 8px;
}
.ct-link-input {
  flex: 1;
  background: var(--surface);
  border: 1px solid rgba(0,240,255,0.2);
  border-radius: var(--radius-sm);
  color: var(--accent);
  font-family: var(--font);
  font-size: 0.85rem;
  padding: 10px 12px;
  outline: none;
}
.ct-copy-btn {
  flex: none;
  padding: 10px 16px;
}

/* ---- Team Join Overlay ---- */
.team-join-card {
  text-align: center;
}
.team-join-card .ct-label { text-align: left; }

.tj-name-status {
  font-size: 0.8rem;
  min-height: 1.2em;
  margin-bottom: 12px;
  text-align: left;
}
.tj-name-status.available { color: var(--success); }
.tj-name-status.taken { color: var(--danger); }
.tj-name-status.checking { color: var(--text-muted); }

/* ---- Team Board ---- */
.tb-code-badge {
  background: var(--accent);
  color: #000;
  font-weight: 800;
  font-size: 0.7rem;
  padding: 3px 8px;
  border-radius: 4px;
  letter-spacing: 1px;
  margin-left: auto;
}
.tb-tab {
  font-size: 0.8rem;
  white-space: nowrap;
}

#tb-tabs {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  flex-wrap: nowrap;
  gap: 0;
}

/* Score row for team board (reuses lb-row) */
.tb-member-rank {
  font-weight: 900;
  font-size: 0.95rem;
  width: 28px;
  text-align: center;
  flex-shrink: 0;
}
.tb-member-rank.gold   { color: #ffd700; }
.tb-member-rank.silver { color: #c0c0c0; }
.tb-member-rank.bronze { color: #cd7f32; }

/* ===== Responsive ===== */
@media (min-width: 480px) {
  .games-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (min-width: 768px) {
  .games-grid { grid-template-columns: repeat(4, 1fr); }
  .logo { font-size: 3rem; }
}
@media (min-width: 1024px) {
  .games-grid { grid-template-columns: repeat(5, 1fr); }
}
@media (min-width: 1280px) {
  .games-grid { grid-template-columns: repeat(6, 1fr); }
}
