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

:root {
  --bg: #0a0a0f;
  --surface: #14141f;
  --border: #2a2a3a;
  --text: #e8e8f0;
  --text-dim: #8888aa;
  --accent: #ff4444;
  --accent-glow: #ff444488;
  --combo-mid: #ffd700;
  --combo-max: #ff4444;
  --green: #44ff88;
}

html, body {
  height: 100%;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
}

.hidden {
  display: none !important;
}

/* Screens */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow-y: auto;
}

/* Identity Gate */
#screen-identity {
  gap: 1rem;
  padding: 1.5rem 1.5rem 2rem;
  text-align: center;
  justify-content: flex-start;
  overflow-y: auto;
}

/* Logo */
.logo {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-shrink: 0;
}

.logo-icon {
  display: flex;
  gap: 6px;
  align-items: flex-end;
  height: 64px;
}

.slash {
  width: 6px;
  border-radius: 3px;
  background: linear-gradient(180deg, #FF2D2D, #FF8C00);
  transform: rotate(-12deg);
}

.slash:nth-child(1) { height: 64px; opacity: 1; }
.slash:nth-child(2) { height: 45px; opacity: 0.6; }
.slash:nth-child(3) { height: 27px; opacity: 0.3; }

.wordmark {
  display: flex;
  flex-direction: column;
  line-height: 0.9;
}

.word-freaky {
  font-family: 'Bebas Neue', Impact, sans-serif;
  font-size: 52px;
  color: #f0f0f0;
  letter-spacing: 5px;
}

.word-speed {
  font-family: 'Bebas Neue', Impact, sans-serif;
  font-size: 52px;
  background: linear-gradient(90deg, #FF2D2D, #FF8C00);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: 15px;
  position: relative;
}

.word-speed::after {
  content: '';
  position: absolute;
  bottom: -3px;
  left: 0;
  width: 100%;
  height: 2px;
  background: linear-gradient(90deg, #FF2D2D, #FF8C00);
}

.identity-hero {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  max-width: 500px;
  width: 100%;
}

.freaky-gif {
  width: 110px;
  height: 110px;
  object-fit: cover;
  border-radius: 50%;
  border: 3px solid var(--border);
  flex-shrink: 0;
}

.identity-hero .subtitle {
  text-align: left;
  font-size: 1rem;
}

.identity-top-buttons {
  display: flex;
  gap: 0.5rem;
}

.identity-options {
  display: flex;
  gap: 1rem;
  width: 100%;
  max-width: 580px;
}

.identity-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
  text-align: left;
  flex: 1;
}

.identity-card h3 {
  font-size: 0.95rem;
  color: var(--text-dim);
  margin-bottom: 0.75rem;
}

.identity-form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.identity-form input {
  padding: 0.6rem 0.8rem;
  font-size: 0.95rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  outline: none;
}

.identity-form input:focus {
  border-color: var(--accent);
}

.auth-email-buttons {
  display: flex;
  gap: 0.5rem;
}

.auth-email-buttons .btn {
  flex: 1;
}

.identity-divider {
  color: var(--text-dim);
  font-size: 0.85rem;
  text-align: center;
  display: none;
}

.auth-error {
  color: var(--accent);
  font-size: 0.85rem;
  text-align: center;
  margin-top: 0.5rem;
}

/* About section */
.about-section {
  width: 100%;
  max-width: 580px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-top: 0.5rem;
}

.about-section summary {
  padding: 1rem 1.25rem;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  color: var(--text);
  list-style: none;
}

.about-section summary::-webkit-details-marker {
  display: none;
}

.about-section summary::after {
  content: '▸';
  float: right;
  transition: transform 0.2s;
}

.about-section[open] summary::after {
  transform: rotate(90deg);
}

.about-content {
  padding: 0 1.25rem 1.25rem;
  color: var(--text-dim);
  font-size: 0.9rem;
  line-height: 1.7;
}

.about-content p {
  margin-bottom: 0.75rem;
}

.about-content h4 {
  color: #f0f0f0;
  font-size: 1.1rem;
  font-weight: 700;
  margin: 1.5rem 0 0.75rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--border);
}

.about-content ol,
.about-content ul {
  padding-left: 1.25rem;
  margin-bottom: 0.75rem;
}

.about-content li {
  margin-bottom: 0.5rem;
}

.about-content strong {
  color: var(--text);
}

.about-highlight {
  color: var(--accent);
  font-weight: 700;
  font-size: 1.05rem;
  text-align: center;
}

/* Landing */
#screen-landing {
  gap: 1rem;
  padding: 2rem;
  text-align: center;
}


.subtitle {
  font-size: 1.1rem;
  color: var(--text-dim);
  max-width: 360px;
}

.user-greeting {
  font-size: 1.1rem;
  color: var(--green);
  min-height: 1.4em;
}

#landing-pb {
  font-size: 1.1rem;
  color: var(--combo-mid);
  min-height: 1.4em;
}

.btn {
  padding: 0.8rem 2rem;
  font-size: 1.1rem;
  font-weight: 700;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.1s;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.btn:active {
  transform: scale(0.96);
}

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

.btn-primary {
  background: linear-gradient(135deg, #ff4444, #ff6644);
  color: white;
  box-shadow: 0 4px 20px var(--accent-glow);
}

.btn-primary:hover:not(:disabled) {
  box-shadow: 0 6px 30px var(--accent-glow);
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-small {
  padding: 0.5rem 1.2rem;
  font-size: 0.85rem;
}

.btn-link {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 0.8rem;
  cursor: pointer;
  text-decoration: underline;
  padding: 0.25rem;
}

.btn-link:hover {
  color: var(--text);
}

.landing-buttons {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  width: 100%;
  max-width: 280px;
}

.landing-footer {
  display: flex;
  gap: 1.5rem;
  justify-content: center;
  margin-top: 0.5rem;
}

.run-counter {
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-top: 0.5rem;
}

/* Game screen */
#screen-game {
  padding: 0;
  overflow: hidden;
}

.game-container {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

#webcam {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
  opacity: 0.5;
  z-index: 0;
}

.game-hud {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  pointer-events: none;
}

#score {
  font-size: 6rem;
  font-weight: 900;
  text-shadow: 0 0 40px rgba(255, 68, 68, 0.5);
  line-height: 1;
}

#timer {
  font-size: 2.5rem;
  font-weight: 700;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

.combo {
  font-size: 1.5rem;
  font-weight: 800;
  min-height: 2rem;
  transition: all 0.15s;
}

.combo-mid {
  color: var(--combo-mid);
  font-size: 2rem;
  animation: pulse 0.3s ease;
}

.combo-max {
  color: var(--combo-max);
  font-size: 2.5rem;
  text-shadow: 0 0 20px var(--accent-glow);
  animation: pulse 0.3s ease, shake 0.1s ease infinite;
}

#countdown {
  position: absolute;
  z-index: 10;
  font-size: 8rem;
  font-weight: 900;
  text-shadow: 0 0 60px rgba(255, 255, 255, 0.3);
  animation: popIn 0.3s ease;
}

#calibration-msg {
  position: absolute;
  z-index: 10;
  font-size: 1.3rem;
  color: var(--combo-mid);
  text-align: center;
  padding: 1rem;
  background: rgba(0, 0, 0, 0.7);
  border-radius: 12px;
}

#freaky-popup {
  position: absolute;
  z-index: 5;
  font-size: 3rem;
  font-weight: 900;
  color: var(--accent);
  text-shadow: 0 0 30px var(--accent-glow);
  pointer-events: none;
  top: 30%;
}

#freaky-popup.pop {
  animation: popIn 0.35s ease forwards;
}

/* End screen */
#screen-end {
  gap: 0.75rem;
  padding: 1.5rem;
  text-align: center;
}

.end-score {
  font-size: 4.5rem;
  font-weight: 900;
  background: linear-gradient(135deg, #ff4444, #ffdd44);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1.1;
}

.end-stats {
  display: flex;
  gap: 2rem;
  justify-content: center;
  color: var(--text-dim);
  font-size: 0.9rem;
}

.end-stats span {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.end-stats strong {
  color: var(--text);
  font-size: 1.3rem;
}

#new-best {
  color: var(--combo-mid);
  font-size: 1.2rem;
  font-weight: 700;
  animation: pulse 0.5s ease infinite alternate;
}

.submit-status {
  font-size: 0.9rem;
  color: var(--text-dim);
  min-height: 1.3em;
}

.rank-display {
  font-size: 1.3rem;
  color: var(--text);
}

.rank-display strong {
  font-size: 1.8rem;
  color: var(--combo-mid);
}

.end-buttons {
  display: flex;
  gap: 0.75rem;
}

/* Leaderboard */
.leaderboard-section {
  width: 100%;
  max-width: 460px;
}

.lb-heading {
  font-size: 1rem;
  color: var(--text-dim);
  margin-bottom: 0.5rem;
}

.leaderboard-table {
  max-height: 280px;
  overflow-y: auto;
  text-align: left;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.lb-row {
  display: flex;
  align-items: center;
  padding: 0.4rem 0.6rem;
  font-size: 0.85rem;
  border-bottom: 1px solid var(--border);
  gap: 0.5rem;
}

.lb-row:last-child {
  border-bottom: none;
}

.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-row-highlight {
  background: rgba(255, 68, 68, 0.15);
  border-left: 3px solid var(--accent);
}

.lb-rank {
  width: 2.5rem;
  font-weight: 700;
  flex-shrink: 0;
}

.lb-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lb-score {
  font-weight: 700;
  color: var(--accent);
  flex-shrink: 0;
  width: 3rem;
  text-align: right;
}

.lb-date {
  color: var(--text-dim);
  font-size: 0.75rem;
  flex-shrink: 0;
  width: 5rem;
  text-align: right;
}

/* Rank card (shown when player not in top 100) */
.rank-card {
  width: 100%;
  max-width: 460px;
  background: var(--surface);
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 0.75rem;
  margin-top: 0.5rem;
}

.rank-card-label {
  font-size: 0.75rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.rank-card-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.25rem;
  font-size: 0.95rem;
}

.rank-card-rank {
  font-weight: 700;
  color: var(--combo-mid);
  width: 3.5rem;
}

.rank-card-name {
  flex: 1;
}

.rank-card-score {
  font-weight: 700;
  color: var(--accent);
}

/* Debug overlay */
#debug-overlay {
  position: fixed;
  top: 0.5rem;
  left: 0.5rem;
  background: rgba(0, 0, 0, 0.85);
  color: #0f0;
  font-family: monospace;
  font-size: 0.75rem;
  padding: 0.5rem;
  border-radius: 6px;
  z-index: 100;
  line-height: 1.5;
  pointer-events: none;
}

/* Modals */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 2rem;
  max-width: 460px;
  width: 100%;
  text-align: left;
}

.modal h2 {
  margin-bottom: 1rem;
  text-align: center;
}

.modal ol {
  padding-left: 1.5rem;
  line-height: 1.8;
  color: var(--text-dim);
}

.modal .btn {
  margin-top: 1rem;
  width: 100%;
}

.modal .leaderboard-table {
  max-height: 350px;
}

/* Mute button */
#mute-btn {
  position: fixed;
  top: 0.5rem;
  right: 0.5rem;
  z-index: 50;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Animations */
@keyframes pulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.15); }
  100% { transform: scale(1); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-2px); }
  75% { transform: translateX(2px); }
}

@keyframes popIn {
  0% { transform: scale(0.3); opacity: 0; }
  60% { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

/* Responsive */
@media (max-width: 600px) {
  .identity-hero {
    flex-direction: column;
    text-align: center;
  }
  .identity-hero .subtitle {
    text-align: center;
  }
  .identity-options {
    flex-direction: column;
    max-width: 340px;
  }
  .identity-divider {
    display: block;
  }
}

@media (max-width: 480px) {
  .word-freaky, .word-speed { font-size: 36px; letter-spacing: 3px; }
  .word-speed { letter-spacing: 10px; }
  .logo-icon { height: 46px; }
  .slash:nth-child(1) { height: 46px; }
  .slash:nth-child(2) { height: 32px; }
  .slash:nth-child(3) { height: 20px; }
  #score { font-size: 4rem; }
  #timer { font-size: 1.8rem; }
  #countdown { font-size: 5rem; }
  #freaky-popup { font-size: 2rem; }
  .end-score { font-size: 3rem; }
  .end-stats { gap: 1rem; }
  .lb-date { display: none; }
}
