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

:root {
  --red: #ef3340;
  --red-dark: #b71c2b;
  --gold: #ffd700;
  --gold-dim: #b8960c;
  --navy: #0a0e1a;
  --blue-mid: #001d3d;
  --blue-light: #1565c0;
  --white: #ffffff;
  --muted: #8892a4;
  --font: 'Space Grotesk', 'Segoe UI', system-ui, sans-serif;
}

html, body {
  height: 100%;
  background: var(--navy);
  color: var(--white);
  font-family: var(--font);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
}

/* ── LANDING ── */
#landing {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  transition: opacity 0.6s ease, transform 0.6s ease;
}

#landing.fade-out {
  opacity: 0;
  transform: translateY(-30px);
  pointer-events: none;
}

.landing-content {
  text-align: center;
  max-width: 520px;
  width: 100%;
}

.flag-badge {
  font-size: 64px;
  margin-bottom: 16px;
  animation: float 3s ease-in-out infinite;
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

.title {
  font-size: clamp(48px, 10vw, 96px);
  font-weight: 900;
  line-height: 1;
  background: linear-gradient(135deg, #ffffff 0%, #ffd700 60%, #ef3340 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 16px;
  letter-spacing: -2px;
}

.subtitle {
  font-size: clamp(16px, 3vw, 20px);
  color: rgba(255,255,255,0.75);
  line-height: 1.5;
  margin-bottom: 28px;
}

.live-stats {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 15px;
  color: rgba(255,255,255,0.65);
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 40px;
  padding: 10px 20px;
  margin-bottom: 32px;
  backdrop-filter: blur(8px);
}

.stat { display: flex; align-items: center; gap: 6px; }
.stat-icon { font-size: 18px; }
.stat-divider { color: rgba(255,255,255,0.3); }

.cta-button {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 20px 48px;
  background: linear-gradient(135deg, var(--red) 0%, #c62828 100%);
  color: white;
  border: none;
  border-radius: 100px;
  font-family: var(--font);
  font-size: clamp(22px, 4vw, 28px);
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 0 40px rgba(239,51,64,0.4), 0 8px 32px rgba(0,0,0,0.4);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  animation: pulse-cta 2s ease-in-out infinite;
}

@keyframes pulse-cta {
  0%, 100% { box-shadow: 0 0 40px rgba(239,51,64,0.4), 0 8px 32px rgba(0,0,0,0.4); }
  50% { box-shadow: 0 0 60px rgba(239,51,64,0.7), 0 8px 32px rgba(0,0,0,0.4); }
}

.cta-button:hover { transform: scale(1.05); }
.cta-button:active { transform: scale(0.97); animation: none; }
.cta-icon { font-size: 1.2em; }

.change-name-btn {
  display: block;
  margin: 10px auto 0;
  background: none;
  border: none;
  color: rgba(255,255,255,0.45);
  font-family: var(--font);
  font-size: 14px;
  cursor: pointer;
  transition: color 0.2s;
  padding: 4px 8px;
}
.change-name-btn:hover { color: rgba(255,255,255,0.8); }

.hint {
  margin-top: 16px;
  font-size: 13px;
  color: rgba(255,255,255,0.35);
}

/* ── GAME VIEW ── */
#game {
  position: fixed;
  inset: 0;
  z-index: 10;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.6s ease 0.3s;
}

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

.hidden { display: none !important; }

/* HUD TOP */
.hud-top {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  background: linear-gradient(180deg, rgba(10,14,26,0.9) 0%, transparent 100%);
  backdrop-filter: blur(4px);
}

.hud-logo {
  font-weight: 700;
  font-size: 16px;
  white-space: nowrap;
}

.hud-stats {
  display: flex;
  gap: 16px;
  flex: 1;
  justify-content: center;
}

.hud-stat {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 14px;
  color: rgba(255,255,255,0.8);
  background: rgba(255,255,255,0.08);
  border-radius: 20px;
  padding: 4px 12px;
}

.hud-icon { font-size: 16px; }

.hud-player {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  white-space: nowrap;
}

#player-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--gold);
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hud-strokes {
  font-size: 11px;
  color: rgba(255,255,255,0.5);
}

/* LEADERBOARD */
.leaderboard {
  position: absolute;
  top: 70px;
  right: 16px;
  width: 200px;
  background: rgba(10,14,26,0.85);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 12px;
  padding: 12px;
  backdrop-filter: blur(8px);
}

.lb-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--gold);
  margin-bottom: 8px;
  letter-spacing: 0.5px;
}

#lb-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

#lb-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  padding: 3px 6px;
  border-radius: 6px;
}

#lb-list li.me {
  background: rgba(255,215,0,0.15);
  color: var(--gold);
  font-weight: 600;
}

#lb-list li .lb-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 120px;
  color: rgba(255,255,255,0.8);
}

#lb-list li .lb-score {
  font-weight: 600;
  color: rgba(255,255,255,0.6);
  white-space: nowrap;
  margin-left: 8px;
}

/* STROKE BUTTON */
.stroke-area {
  position: absolute;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.stroke-wrap { position: relative; }

.stroke-btn {
  position: relative;
  width: 140px;
  height: 140px;
  border-radius: 50%;
  border: none;
  background: rgba(10,14,26,0.6);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s ease, opacity 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}

.stroke-btn:disabled { cursor: not-allowed; opacity: 0.7; }

.stroke-btn.ready {
  background: linear-gradient(135deg, var(--red) 0%, #c62828 100%);
  box-shadow: 0 0 40px rgba(239,51,64,0.5), 0 4px 20px rgba(0,0,0,0.4);
  animation: pulse-btn 1.5s ease-in-out infinite;
}

@keyframes pulse-btn {
  0%, 100% { box-shadow: 0 0 30px rgba(239,51,64,0.4), 0 4px 20px rgba(0,0,0,0.4); }
  50% { box-shadow: 0 0 60px rgba(239,51,64,0.8), 0 4px 20px rgba(0,0,0,0.4); }
}

.stroke-btn.ready:active { transform: scale(0.93); animation: none; }

.stroke-btn.rowed {
  animation: rowed-bounce 0.4s ease;
}

@keyframes rowed-bounce {
  0% { transform: scale(1); }
  30% { transform: scale(0.88); }
  60% { transform: scale(1.08); }
  100% { transform: scale(1); }
}

.progress-ring {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
  pointer-events: none;
}

.ring-bg {
  fill: none;
  stroke: rgba(255,255,255,0.1);
  stroke-width: 6;
}

.ring-fill {
  fill: none;
  stroke: var(--gold);
  stroke-width: 6;
  stroke-linecap: round;
  stroke-dasharray: 327; /* 2 * PI * 52 */
  stroke-dashoffset: 327;
}

.stroke-inner {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1;
  gap: 2px;
}

.stroke-icon { font-size: 32px; }
.stroke-label { font-family: var(--font); font-weight: 900; font-size: 22px; color: white; }
.stroke-timer { font-size: 13px; color: rgba(255,255,255,0.65); min-height: 16px; font-weight: 600; }

/* SHARE BUTTON */
.share-btn {
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 100px;
  color: white;
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  padding: 10px 22px;
  cursor: pointer;
  transition: background 0.2s ease;
  backdrop-filter: blur(4px);
}

.share-btn:hover { background: rgba(255,255,255,0.18); }
.share-btn:active { background: rgba(255,255,255,0.08); }

/* TOAST */
#toast {
  position: fixed;
  bottom: 240px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  pointer-events: none;
}

.toast-msg {
  background: rgba(10,14,26,0.95);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 12px;
  padding: 12px 20px;
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  animation: toast-in 0.3s ease, toast-out 0.3s ease 2.7s forwards;
  backdrop-filter: blur(8px);
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes toast-out {
  from { opacity: 1; }
  to { opacity: 0; }
}

/* MOBILE SCORE */
.mobile-score {
  display: none;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  font-weight: 600;
  color: var(--gold);
  background: rgba(255,215,0,0.1);
  border: 1px solid rgba(255,215,0,0.25);
  border-radius: 20px;
  padding: 6px 14px;
  white-space: nowrap;
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ms-sep { color: rgba(255,215,0,0.4); }
#ms-name { overflow: hidden; text-overflow: ellipsis; max-width: 130px; }

/* STROKE ACTIONS ROW */
.stroke-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* LEADERBOARD TOGGLE BUTTON (mobile) */
.lb-toggle-btn {
  display: none;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 50%;
  width: 44px;
  height: 44px;
  font-size: 20px;
  cursor: pointer;
  transition: background 0.2s;
  flex-shrink: 0;
}
.lb-toggle-btn:hover { background: rgba(255,255,255,0.2); }

/* MOBILE LEADERBOARD OVERLAY */
#lb-overlay { position: fixed; inset: 0; z-index: 30; }

.lbo-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
}

.lbo-panel {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  background: #0d1527;
  border-radius: 20px 20px 0 0;
  padding: 20px 20px 40px;
  max-height: 70vh;
  overflow-y: auto;
  animation: slide-up 0.3s ease;
}

@keyframes slide-up {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.lbo-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 16px;
  font-weight: 700;
  color: var(--gold);
  margin-bottom: 16px;
}

.lbo-close {
  background: rgba(255,255,255,0.1);
  border: none;
  color: white;
  width: 32px; height: 32px;
  border-radius: 50%;
  font-size: 14px;
  cursor: pointer;
}

#lbo-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

#lbo-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 15px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(255,255,255,0.05);
}

#lbo-list li.me {
  background: rgba(255,215,0,0.15);
  color: var(--gold);
  font-weight: 700;
}

#lbo-list li .lb-name { flex: 1; }
#lbo-list li .lb-score { font-weight: 700; color: rgba(255,255,255,0.7); margin-left: 12px; }
#lbo-list li.me .lb-score { color: var(--gold); }

/* NAME MODAL */
#name-modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

@media (min-width: 600px) {
  #name-modal { align-items: center; }
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.75);
  backdrop-filter: blur(6px);
}

.modal-card {
  position: relative;
  background: #0d1527;
  border-radius: 24px 24px 0 0;
  padding: 32px 24px 40px;
  width: 100%;
  max-width: 440px;
  animation: slide-up 0.35s ease;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

@media (min-width: 600px) {
  .modal-card {
    border-radius: 24px;
    padding: 36px 32px;
    animation: fade-in 0.25s ease;
  }
}

@keyframes fade-in {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

.modal-head {
  font-size: 20px;
  font-weight: 700;
  text-align: center;
}

.modal-fields { display: flex; flex-direction: column; gap: 12px; }

.modal-label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: rgba(255,255,255,0.6);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.modal-label small { font-weight: 400; text-transform: none; }

.modal-label input {
  width: 100%;
  padding: 14px 16px;
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 12px;
  color: white;
  font-family: var(--font);
  font-size: 18px;
  font-weight: 600;
  outline: none;
  transition: border-color 0.2s;
  user-select: text;
  -webkit-user-select: text;
}

.modal-label input:focus {
  border-color: rgba(255,215,0,0.6);
  background: rgba(255,255,255,0.1);
}

.modal-label input::placeholder { color: rgba(255,255,255,0.3); font-weight: 400; }

.modal-cta { width: 100%; justify-content: center; font-size: 20px; padding: 18px; animation: none; }

.modal-random {
  background: none;
  border: none;
  color: rgba(255,255,255,0.45);
  font-family: var(--font);
  font-size: 14px;
  cursor: pointer;
  text-align: center;
  padding: 4px;
  transition: color 0.2s;
}
.modal-random:hover { color: rgba(255,255,255,0.75); }

/* ── RESPONSIVE ── */
@media (max-width: 600px) {
  .leaderboard { display: none; }
  .hud-player { display: none; }
  .cta-button { padding: 18px 36px; }
  .stroke-btn { width: 120px; height: 120px; }
  .stroke-icon { font-size: 26px; }
  .stroke-label { font-size: 20px; }
  .ring-fill, .ring-bg { stroke-width: 5; }
  .mobile-score { display: flex; }
  .lb-toggle-btn { display: flex; align-items: center; justify-content: center; }
}

@media (max-height: 600px) {
  .stroke-area { bottom: 16px; }
  .stroke-btn { width: 100px; height: 100px; }
  .stroke-icon { font-size: 22px; }
  .stroke-label { font-size: 17px; }
  .mobile-score { display: none; }
}
