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

:root {
  --bg: #0a0a0f;
  --bg-light: #101018;
  --surface: #16161f;
  --surface-hover: #1e1e2a;
  --border: #252535;
  --text: #e2e2ea;
  --text-dim: #6e6e82;
  --accent: #6c63ff;
  --accent-glow: rgba(108, 99, 255, 0.25);
  --accent-glow-strong: rgba(108, 99, 255, 0.5);
  --green: #4ade80;
  --green-dim: rgba(74, 222, 128, 0.12);
  --green-glow: rgba(74, 222, 128, 0.35);
  --red: #ef4444;
  --red-dim: rgba(239, 68, 68, 0.10);
  --red-glow: rgba(239, 68, 68, 0.3);
  --gold: #fbbf24;
  --gold-dim: rgba(251, 191, 36, 0.12);
  --gold-glow: rgba(251, 191, 36, 0.3);
  --mono: 'JetBrains Mono', monospace;
  --sans: 'Inter', system-ui, sans-serif;
}

/* ===== ATMOSPHERIC BACKGROUND ===== */

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  overflow: hidden;
}

body {
  background:
    url("data:image/svg+xml,%3Csvg viewBox='0 0 512 512' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.75' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.03'/%3E%3C/svg%3E"),
    radial-gradient(ellipse 900px 600px at 50% 15%, rgba(108, 99, 255, 0.07), transparent 70%),
    radial-gradient(ellipse 600px 400px at 30% 80%, rgba(108, 99, 255, 0.025), transparent 70%),
    radial-gradient(ellipse 500px 300px at 80% 60%, rgba(74, 222, 128, 0.015), transparent 70%),
    var(--bg);
  position: relative;
}

body::after {
  content: '';
  position: fixed;
  inset: 0;
  box-shadow: inset 0 0 150px 60px rgba(0, 0, 0, 0.5);
  pointer-events: none;
  z-index: 999;
}

/* ===== SCREEN TRANSITIONS ===== */

.screen {
  display: none;
  position: absolute;
  inset: 0;
  justify-content: center;
  align-items: center;
  overflow-y: auto;
}

.screen.active {
  display: flex;
  animation: screenIn 0.35s ease-out;
}

@keyframes screenIn {
  0% {
    opacity: 0;
    transform: translateY(12px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ===== ERROR FLASH ===== */

.error-flash {
  position: fixed;
  inset: 0;
  background: radial-gradient(ellipse at center, rgba(239, 68, 68, 0.12), rgba(239, 68, 68, 0.04));
  pointer-events: none;
  opacity: 0;
  z-index: 1000;
  transition: opacity 0.05s ease-in;
}

.error-flash.show {
  opacity: 1;
}

/* ===== BUTTONS ===== */

.btn {
  font-family: var(--mono);
  font-weight: 700;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s ease;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  padding: 14px 40px;
  font-size: 1rem;
  box-shadow: 0 0 20px var(--accent-glow), 0 0 60px rgba(108, 99, 255, 0.1);
  position: relative;
}

.btn-primary:hover {
  box-shadow: 0 0 30px var(--accent-glow-strong), 0 0 80px rgba(108, 99, 255, 0.15);
  transform: translateY(-2px);
}

.btn-join {
  background: var(--text);
  color: var(--bg);
  padding: 14px 0;
  font-size: 1.1rem;
  width: 100%;
  letter-spacing: 0.15em;
  box-shadow: 0 4px 24px rgba(226, 226, 234, 0.08);
  position: relative;
}

.btn-join:hover {
  background: #fff;
  box-shadow: 0 4px 32px rgba(226, 226, 234, 0.15), 0 0 60px rgba(108, 99, 255, 0.1);
  transform: translateY(-2px);
}

.btn-small {
  background: var(--surface);
  color: var(--text-dim);
  padding: 8px 16px;
  font-size: 0.75rem;
  border: 1px solid var(--border);
}

.btn-small:hover {
  background: var(--surface-hover);
  color: var(--text);
  border-color: rgba(108, 99, 255, 0.3);
}

/* ===== WELCOME SCREEN ===== */

#screen-welcome {
  flex-direction: column;
}

.welcome-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  padding: 60px 20px 30px;
  width: 100%;
  max-width: 520px;
}

.logo {
  font-family: var(--mono);
  font-weight: 800;
  letter-spacing: -3px;
  color: var(--text);
  line-height: 1;
}

.logo-large {
  font-size: 4.5rem;
  margin-bottom: 6px;
  text-shadow:
    0 0 20px rgba(108, 99, 255, 0.15),
    0 0 60px rgba(108, 99, 255, 0.08);
}

.logo-dot {
  color: var(--accent);
  text-shadow:
    0 0 10px var(--accent-glow-strong),
    0 0 30px var(--accent-glow),
    0 0 60px rgba(108, 99, 255, 0.15);
  display: inline-block;
  animation: dotPulse 3s ease-in-out infinite;
}

@keyframes dotPulse {
  0%, 100% {
    text-shadow:
      0 0 10px var(--accent-glow-strong),
      0 0 30px var(--accent-glow),
      0 0 60px rgba(108, 99, 255, 0.15);
  }
  50% {
    text-shadow:
      0 0 15px var(--accent-glow-strong),
      0 0 40px var(--accent-glow-strong),
      0 0 80px rgba(108, 99, 255, 0.25);
  }
}

.welcome-tagline {
  font-family: var(--mono);
  color: var(--text-dim);
  font-size: 0.85rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-bottom: 48px;
}

.welcome-tagline::after {
  content: '_';
  animation: cursorBlink 1s step-end infinite;
  color: var(--accent);
  font-weight: 400;
}

@keyframes cursorBlink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

.welcome-card {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 2px;
  padding: 32px 28px 28px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  position: relative;
  box-shadow:
    0 8px 40px rgba(0, 0, 0, 0.3),
    0 0 1px rgba(108, 99, 255, 0.15);
}

.welcome-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(108, 99, 255, 0.3), transparent);
}

.welcome-heading {
  font-family: var(--mono);
  font-weight: 800;
  font-size: 1.15rem;
  letter-spacing: 0.08em;
  color: var(--text);
}

.welcome-desc {
  font-size: 0.85rem;
  line-height: 1.6;
  color: var(--text-dim);
}

.welcome-prompt {
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin-top: 4px;
}

.welcome-input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 2px;
  padding: 12px 14px;
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.95rem;
  letter-spacing: 0.04em;
  outline: none;
  transition: all 0.25s ease;
}

.welcome-input::placeholder {
  color: var(--text-dim);
  opacity: 0.5;
}

.welcome-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(108, 99, 255, 0.2), 0 0 20px rgba(108, 99, 255, 0.06);
}

.welcome-login-hint {
  margin-top: 20px;
  font-size: 0.8rem;
  color: var(--text-dim);
}

.welcome-login-hint a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
  transition: text-shadow 0.2s ease;
}

.welcome-login-hint a:hover {
  text-decoration: underline;
  text-shadow: 0 0 12px var(--accent-glow);
}

.welcome-footer {
  margin-top: 40px;
  font-family: var(--mono);
  font-size: 0.65rem;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  opacity: 0.5;
}

/* ===== HOME SCREEN ===== */

#screen-home {
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
}

.home-header {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 28px;
  border-bottom: 1px solid var(--border);
  position: relative;
  flex-shrink: 0;
}

.home-header::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(108, 99, 255, 0.2), transparent);
}

.home-header-left {
  font-family: var(--mono);
  font-weight: 800;
  font-size: 0.8rem;
  letter-spacing: 0.15em;
  color: var(--text-dim);
}

.home-header-back {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  color: inherit;
}

.home-header-back:hover {
  color: var(--accent);
}

.home-user-area {
  display: flex;
  align-items: center;
  gap: 10px;
}

.home-username {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 0.85rem;
  letter-spacing: 0.04em;
  color: var(--text);
}

.home-badge {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 0.6rem;
  letter-spacing: 0.1em;
  padding: 3px 8px;
  border-radius: 2px;
  background: var(--red-dim);
  color: var(--red);
}

.home-user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 4px;
  transition: background 0.2s ease;
}

.home-user-info:hover {
  background: var(--surface-hover);
}

.home-badge.ranked {
  box-shadow: 0 0 12px rgba(251, 191, 36, 0.1);
}

.home-wrapper {
  width: 100%;
  max-width: 700px;
  margin: 0 auto;
  padding: 0 24px 30px;
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
  justify-content: center;
}

.home-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 32px;
}

.home-logo {
  font-size: 2.8rem;
  letter-spacing: -2px;
  margin-bottom: 14px;
  text-shadow:
    0 0 16px rgba(108, 99, 255, 0.12),
    0 0 48px rgba(108, 99, 255, 0.06);
}

.home-select-label {
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--text-dim);
  position: relative;
  padding-bottom: 10px;
}

.home-select-label::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 40px;
  height: 2px;
  background: var(--accent);
  border-radius: 1px;
  box-shadow: 0 0 8px var(--accent-glow);
}

.home-footer {
  margin-top: 32px;
  font-family: var(--mono);
  font-size: 0.65rem;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  opacity: 0.5;
}

/* ===== MODE SELECTION GRID (Keycap Tiles) ===== */

.mode-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  width: 100%;
}

.mode-key {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 28px 20px 22px;
  cursor: pointer;
  font-family: var(--sans);
  color: var(--text);
  width: 100%;
  min-height: 150px;
  position: relative;
  overflow: visible;
  transform: translateY(0);
  transition: transform 0.12s cubic-bezier(0.4, 0, 0.2, 1),
              box-shadow 0.12s cubic-bezier(0.4, 0, 0.2, 1),
              border-color 0.2s ease;
  box-shadow:
    0 4px 0 0 rgba(0, 0, 0, 0.5),
    0 6px 16px rgba(0, 0, 0, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.mode-key::after {
  content: '';
  position: absolute;
  bottom: -12px;
  left: 15%;
  right: 15%;
  height: 20px;
  border-radius: 50%;
  opacity: 0;
  transition: opacity 0.25s ease;
  pointer-events: none;
  filter: blur(8px);
}

.mode-key:hover:not(.disabled) {
  transform: translateY(3px);
  box-shadow:
    0 1px 0 0 rgba(0, 0, 0, 0.5),
    0 2px 8px rgba(0, 0, 0, 0.2),
    inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.mode-key:hover:not(.disabled)::after {
  opacity: 1;
}

.mode-key:active:not(.disabled) {
  transform: translateY(4px);
  box-shadow:
    0 0 0 0 rgba(0, 0, 0, 0.5),
    0 1px 4px rgba(0, 0, 0, 0.15),
    inset 0 1px 0 rgba(255, 255, 255, 0.02);
}

/* --- Accent underglow variants --- */

.mode-key[data-accent="accent"]::after {
  background: rgba(108, 99, 255, 0.5);
}

.mode-key[data-accent="accent"]:hover:not(.disabled) {
  border-color: rgba(108, 99, 255, 0.35);
}

.mode-key[data-accent="gold"]::after {
  background: rgba(251, 191, 36, 0.45);
}

.mode-key[data-accent="gold"]:hover:not(.disabled) {
  border-color: rgba(251, 191, 36, 0.3);
}

.mode-key[data-accent="red"]::after {
  background: rgba(240, 68, 68, 0.45);
}

.mode-key[data-accent="red"]:hover:not(.disabled) {
  border-color: rgba(240, 68, 68, 0.25);
}

.mode-key[data-accent="green"]::after {
  background: rgba(74, 222, 128, 0.45);
}

.mode-key[data-accent="green"]:hover:not(.disabled) {
  border-color: rgba(74, 222, 128, 0.25);
}

.mode-key[data-accent="dim"]::after {
  background: rgba(110, 110, 130, 0.2);
}

/* --- Disabled state --- */

.mode-key.disabled {
  opacity: 0.32;
  cursor: default;
  box-shadow:
    0 3px 0 0 rgba(0, 0, 0, 0.35),
    0 4px 10px rgba(0, 0, 0, 0.2),
    inset 0 1px 0 rgba(255, 255, 255, 0.02);
}

.mode-key.disabled[data-accent="red"] {
  opacity: 0.45;
}

/* --- Inner elements --- */

.mode-key-icon {
  font-size: 1.5rem;
  line-height: 1;
  margin-bottom: 2px;
  position: relative;
  z-index: 1;
  transition: transform 0.15s ease, text-shadow 0.2s ease;
}

.mode-key:hover:not(.disabled) .mode-key-icon {
  transform: scale(1.15);
}

.mode-key[data-accent="accent"] .mode-key-icon {
  text-shadow: 0 0 12px rgba(108, 99, 255, 0.4);
}

.mode-key[data-accent="gold"] .mode-key-icon {
  text-shadow: 0 0 12px rgba(251, 191, 36, 0.35);
}

.mode-key[data-accent="red"] .mode-key-icon {
  text-shadow: 0 0 12px rgba(240, 68, 68, 0.35);
}

.mode-key[data-accent="green"] .mode-key-icon {
  text-shadow: 0 0 12px rgba(74, 222, 128, 0.35);
}

.mode-key-title {
  font-family: var(--mono);
  font-weight: 800;
  font-size: 1.05rem;
  letter-spacing: 0.08em;
  line-height: 1.2;
  position: relative;
  z-index: 1;
}

.mode-key[data-accent="accent"] .mode-key-title {
  color: var(--accent);
}

.mode-key[data-accent="gold"] .mode-key-title {
  color: var(--gold);
}

.mode-key[data-accent="red"] .mode-key-title {
  color: #f04444;
}

.mode-key[data-accent="green"] .mode-key-title {
  color: var(--green);
}

.mode-key[data-accent="dim"] .mode-key-title {
  color: var(--text-dim);
}

.mode-key-title::after {
  content: '_';
  animation: cursorBlink 1s step-end infinite;
  color: var(--accent);
  font-weight: 400;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.mode-key:hover:not(.disabled) .mode-key-title::after {
  opacity: 1;
}

.mode-key-sub {
  font-size: 0.75rem;
  color: var(--text-dim);
  letter-spacing: 0.02em;
  line-height: 1.4;
  position: relative;
  z-index: 1;
}

.mode-key-hint {
  font-family: var(--mono);
  font-size: 0.6rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  margin-top: 4px;
  position: relative;
  z-index: 1;
}

.mode-key:hover:not(.disabled) .mode-key-hint {
  opacity: 0.6;
  transform: translateY(0);
}

.mode-key-lock {
  font-size: 0.85rem;
  position: relative;
  z-index: 1;
}

.mode-key-soon {
  font-family: var(--mono);
  font-size: 0.6rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 3px 10px;
  margin-top: 4px;
  position: relative;
  z-index: 1;
}

.mode-key.disabled[data-accent="red"] .mode-key-soon {
  color: rgba(240, 68, 68, 0.6);
  border-color: rgba(240, 68, 68, 0.25);
}

/* --- Full-width last child if odd number of items --- */

.mode-grid > .mode-key:last-child:nth-child(odd) {
  grid-column: 1 / -1;
  max-width: calc(50% - 8px);
  justify-self: center;
}

/* ===== MODAL ===== */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 100;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.modal-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 2px;
  padding: 32px 28px;
  width: 360px;
  box-shadow: 0 16px 64px rgba(0, 0, 0, 0.5), 0 0 1px rgba(108, 99, 255, 0.15);
  position: relative;
  animation: modalIn 0.25s ease-out;
}

@keyframes modalIn {
  0% { opacity: 0; transform: translateY(20px) scale(0.97); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-content::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(108, 99, 255, 0.3), transparent);
}

.modal-content h2 {
  font-family: var(--mono);
  font-weight: 800;
  font-size: 1.1rem;
  letter-spacing: 0.1em;
  margin-bottom: 24px;
  text-align: center;
}

.modal-content input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 2px;
  padding: 12px 14px;
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.9rem;
  letter-spacing: 0.04em;
  margin-bottom: 12px;
  outline: none;
  transition: all 0.25s ease;
}

.modal-content input::placeholder {
  color: var(--text-dim);
  opacity: 0.5;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 0.8rem;
}

.modal-content input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(108, 99, 255, 0.2), 0 0 20px rgba(108, 99, 255, 0.06);
}

.form-error {
  color: var(--red);
  font-size: 0.8rem;
  font-family: var(--mono);
  min-height: 20px;
  margin-bottom: 8px;
}

.modal-buttons {
  display: flex;
  gap: 10px;
}

.modal-buttons .btn-join {
  flex: 1;
}

/* ===== ACCOUNT INFO MODAL ===== */

.account-modal-content {
  width: 380px;
  text-align: center;
}

.account-rank-display {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-bottom: 24px;
}

.account-rank-badge {
  font-family: var(--mono);
  font-weight: 800;
  font-size: 1.1rem;
  letter-spacing: 0.15em;
  padding: 6px 20px;
  border: 2px solid var(--gold);
  border-radius: 4px;
  color: var(--gold);
  text-shadow: 0 0 10px rgba(251, 191, 36, 0.4);
}

.account-sr-value {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 2rem;
  color: var(--text);
  letter-spacing: 0.04em;
}

.account-sr-value span {
  color: inherit;
}

.account-stats {
  display: flex;
  flex-direction: column;
  gap: 0;
  border-top: 1px solid var(--border);
}

.account-stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 4px;
  border-bottom: 1px solid var(--border);
}

.account-stat-label {
  font-family: var(--mono);
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-dim);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.account-stat-value {
  font-family: var(--mono);
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
}

/* ===== PROFILE SCREEN ===== */

#screen-profile {
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
}

.profile-wrapper {
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  padding: 28px 32px 40px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.profile-hero {
  display: flex;
  gap: 28px;
  align-items: stretch;
}

.profile-hero-left {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 220px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 28px 32px;
  position: relative;
}

.profile-hero-left::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(108, 99, 255, 0.3), transparent);
}

.profile-hero-right {
  flex: 1;
  min-width: 0;
}

.profile-username {
  font-family: var(--mono);
  font-weight: 800;
  font-size: 1.6rem;
  letter-spacing: 0.08em;
  text-align: center;
  margin-bottom: 16px;
  color: var(--text);
}

.profile-rank-display {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.profile-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}

.profile-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 20px 24px;
  position: relative;
}

.profile-section::before {
  content: '';
  position: absolute;
  top: 0;
  left: 20%;
  right: 20%;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(108, 99, 255, 0.2), transparent);
}

.profile-section-title {
  font-family: var(--mono);
  font-weight: 800;
  font-size: 0.75rem;
  letter-spacing: 0.15em;
  color: var(--text-dim);
  margin-bottom: 16px;
}

.profile-stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.profile-stat-grid-4 {
  grid-template-columns: repeat(2, 1fr);
}

.profile-stat-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 16px 12px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.profile-stat-card-value {
  font-family: var(--mono);
  font-weight: 800;
  font-size: 1.4rem;
  color: var(--text);
  letter-spacing: 0.02em;
}

.profile-stat-card-label {
  font-family: var(--mono);
  font-weight: 600;
  font-size: 0.65rem;
  color: var(--text-dim);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.profile-section-history {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 20px 24px;
  position: relative;
}

.profile-section-history::before {
  content: '';
  position: absolute;
  top: 0;
  left: 20%;
  right: 20%;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(108, 99, 255, 0.2), transparent);
}

.profile-history-table-wrap {
  overflow-x: auto;
}

.profile-history-header,
.profile-history-row {
  display: grid;
  grid-template-columns: 60px 1fr 70px 60px 60px 70px;
  align-items: center;
  gap: 8px;
  padding: 8px 4px;
  font-family: var(--mono);
  font-size: 0.75rem;
}

.profile-history-header {
  color: var(--text-dim);
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border-bottom: 1px solid var(--border);
  padding-bottom: 10px;
  font-size: 0.65rem;
}

.profile-history-row {
  border-bottom: 1px solid rgba(37, 37, 53, 0.5);
  font-weight: 600;
  color: var(--text);
}

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

.ph-col-result { font-weight: 800; letter-spacing: 0.06em; }
.ph-win { color: var(--green); text-shadow: 0 0 6px rgba(74, 222, 128, 0.2); }
.ph-loss { color: var(--red); text-shadow: 0 0 6px rgba(239, 68, 68, 0.2); }
.ph-col-opponent { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ph-col-mode { color: var(--text-dim); }
.ph-col-wpm { text-align: right; }
.ph-col-sr { text-align: right; }
.ph-sr-pos { color: var(--green); }
.ph-sr-neg { color: var(--red); }
.ph-col-date { color: var(--text-dim); text-align: right; }

.profile-history-empty {
  padding: 24px 0;
  text-align: center;
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: 0.8rem;
}

.profile-section-email {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 20px 24px;
}

.profile-email-row {
  display: flex;
  gap: 24px;
  align-items: flex-start;
}

.profile-email-info {
  flex: 1;
  min-width: 0;
}

.profile-email-current {
  font-family: var(--mono);
  font-size: 0.9rem;
  color: var(--text);
  margin-bottom: 4px;
  word-break: break-all;
}

.profile-email-hint {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--text-dim);
}

.profile-email-form {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0;
  min-width: 0;
}

.profile-email-form .welcome-input {
  margin-bottom: 8px;
}

@media (max-width: 768px) {
  .profile-wrapper {
    padding: 16px;
    gap: 16px;
  }

  .profile-hero {
    flex-direction: column;
    gap: 16px;
  }

  .profile-hero-left {
    min-width: auto;
  }

  .profile-grid {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .profile-stat-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .profile-email-row {
    flex-direction: column;
    gap: 12px;
  }

  .profile-history-header,
  .profile-history-row {
    grid-template-columns: 50px 1fr 55px 50px 50px 60px;
    font-size: 0.68rem;
    gap: 4px;
  }
}

.form-success {
  color: var(--green);
  font-size: 0.8rem;
  font-family: var(--mono);
  min-height: 20px;
  margin-bottom: 8px;
}

/* ===== MATCHMAKING ===== */

.matchmaking-container {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
  position: relative;
}

.matchmaking-glow {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 200px;
  height: 200px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(108, 99, 255, 0.08), transparent 70%);
  pointer-events: none;
}

.matchmaking-container h2 {
  font-family: var(--mono);
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  animation: breathe 3s ease-in-out infinite;
}

@keyframes breathe {
  0%, 100% { opacity: 0.7; }
  50% { opacity: 1; }
}

.dots::after {
  content: '';
  animation: dots 1.5s steps(4, end) infinite;
}

@keyframes dots {
  0%   { content: ''; }
  25%  { content: '.'; }
  50%  { content: '..'; }
  75%  { content: '...'; }
}

.matchmaking-rings {
  position: relative;
  width: 100px;
  height: 100px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.pulse-ring {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  animation: pulse 1.8s ease-in-out infinite;
  position: absolute;
}

.pulse-ring-2 {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  border: 1px solid var(--accent);
  animation: pulse 1.8s ease-in-out infinite 0.6s;
  position: absolute;
  opacity: 0.5;
}

@keyframes pulse {
  0% { transform: scale(0.8); opacity: 1; }
  100% { transform: scale(1.8); opacity: 0; }
}

.mode-label {
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.15em;
}

/* ===== GAME SCREEN ===== */

#screen-game {
  flex-direction: column;
  padding: 16px 24px;
  justify-content: flex-start;
}

.game-header {
  width: 100%;
  max-width: 1200px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 0 auto 12px;
}

.match-score {
  font-family: var(--mono);
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-dim);
  letter-spacing: 0.02em;
}

.round-indicator {
  font-family: var(--mono);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-dim);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/* ===== DUEL METER ===== */

.duel-meter-area {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto 16px;
}

.duel-labels {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.duel-label {
  font-family: var(--mono);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--text-dim);
}

.duel-label.you {
  color: var(--green);
  text-shadow: 0 0 8px rgba(74, 222, 128, 0.15);
}

.duel-label.opp {
  color: var(--red);
  text-shadow: 0 0 8px rgba(239, 68, 68, 0.15);
}

.duel-meter {
  width: 100%;
  height: 10px;
  background: var(--surface);
  border-radius: 2px;
  display: flex;
  align-items: stretch;
  overflow: hidden;
  position: relative;
  box-shadow: inset 0 1px 4px rgba(0, 0, 0, 0.3);
}

.duel-fill-you {
  width: 50%;
  background: linear-gradient(90deg, var(--green), rgba(74, 222, 128, 0.8));
  transition: width 0.3s ease;
  position: relative;
  box-shadow: 0 0 10px rgba(74, 222, 128, 0.2);
}

.duel-fill-you.leading {
  box-shadow: 0 0 16px var(--green-glow), 0 0 4px rgba(74, 222, 128, 0.4);
}

.duel-divider {
  width: 2px;
  background: var(--text);
  flex-shrink: 0;
  box-shadow: 0 0 6px rgba(226, 226, 234, 0.4);
  z-index: 2;
}

.duel-fill-opp {
  flex: 1;
  background: linear-gradient(90deg, rgba(239, 68, 68, 0.8), var(--red));
  transition: all 0.3s ease;
  position: relative;
  box-shadow: 0 0 10px rgba(239, 68, 68, 0.2);
}

.duel-fill-opp.leading {
  box-shadow: 0 0 16px var(--red-glow), 0 0 4px rgba(239, 68, 68, 0.4);
}

/* ===== SPLIT-SCREEN LAYOUT ===== */

.game-split {
  display: flex;
  gap: 0;
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  flex: 1;
  min-height: 0;
}

.game-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.game-panel-you {
  flex: 1.1;
}

.game-panel-opp {
  flex: 0.9;
}

.game-divider {
  width: 1px;
  background: var(--border);
  margin: 0 16px;
  position: relative;
}

.game-divider::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 1px;
  background: linear-gradient(180deg, transparent, rgba(108, 99, 255, 0.2), transparent);
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  padding: 0 4px;
}

.panel-name {
  font-family: var(--mono);
  font-weight: 800;
  font-size: 0.75rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.panel-name-you {
  color: var(--green);
  text-shadow: 0 0 8px rgba(74, 222, 128, 0.15);
}

.panel-name-opp {
  color: var(--red);
  text-shadow: 0 0 8px rgba(239, 68, 68, 0.15);
}

.panel-wpm {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 0.7rem;
  color: var(--text-dim);
  letter-spacing: 0.04em;
}

.game-panel-opp .typing-area {
  flex: 1;
}

.opp-frame {
  border-color: rgba(239, 68, 68, 0.15);
  background: rgba(16, 16, 24, 0.6);
}

.opp-frame::before {
  background: linear-gradient(90deg, transparent, rgba(239, 68, 68, 0.12), transparent);
}

.game-panel-opp .sentence-display {
  font-size: 1rem;
  line-height: 1.9;
}

/* ===== VS INTRO ===== */

.vs-intro-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 55;
  background: rgba(10, 10, 15, 0.95);
  overflow: hidden;
}

.vs-intro-bg {
  position: absolute;
  inset: -50%;
  background:
    repeating-linear-gradient(
      -45deg,
      transparent,
      transparent 40px,
      rgba(108, 99, 255, 0.015) 40px,
      rgba(108, 99, 255, 0.015) 80px
    );
  animation: vsScanline 0.8s linear infinite;
}

.vs-intro-bg::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse 600px 400px at 50% 50%, rgba(108, 99, 255, 0.08), transparent 70%);
}

@keyframes vsScanline {
  0% { transform: translateX(0) translateY(0); }
  100% { transform: translateX(80px) translateY(80px); }
}

.vs-intro-content {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  width: 100%;
  max-width: 900px;
  position: relative;
  z-index: 2;
}

.vs-intro-player {
  font-family: var(--mono);
  font-weight: 800;
  font-size: 2.8rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
  opacity: 0;
  position: relative;
  padding: 0 40px;
}

.vs-intro-left {
  color: var(--green);
  text-shadow:
    0 0 20px var(--green-glow),
    0 0 60px rgba(74, 222, 128, 0.2);
  animation: vsSlideLeft 0.6s cubic-bezier(0.16, 1, 0.3, 1) 0.2s forwards;
}

.vs-intro-left::after {
  content: '';
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 0;
  background: var(--green);
  box-shadow: 0 0 12px var(--green-glow);
  animation: vsLineGrow 0.4s ease-out 0.5s forwards;
}

.vs-intro-right {
  color: var(--red);
  text-shadow:
    0 0 20px var(--red-glow),
    0 0 60px rgba(239, 68, 68, 0.2);
  animation: vsSlideRight 0.6s cubic-bezier(0.16, 1, 0.3, 1) 0.4s forwards;
}

.vs-intro-right::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 0;
  background: var(--red);
  box-shadow: 0 0 12px var(--red-glow);
  animation: vsLineGrow 0.4s ease-out 0.7s forwards;
}

.vs-intro-center {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 120px;
  position: relative;
}

.vs-intro-vs {
  font-family: var(--mono);
  font-weight: 800;
  font-size: 5rem;
  letter-spacing: 0.15em;
  color: var(--accent);
  opacity: 0;
  transform: scale(0);
  animation: vsTextReveal 0.5s cubic-bezier(0.16, 1, 0.3, 1) 0.7s forwards;
  text-shadow:
    0 0 30px var(--accent-glow-strong),
    0 0 80px var(--accent-glow),
    0 0 120px rgba(108, 99, 255, 0.15);
  position: relative;
  z-index: 3;
}

.vs-intro-vs::before,
.vs-intro-vs::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  border: 1px solid rgba(108, 99, 255, 0.3);
  opacity: 0;
  animation: vsRingBurst 1s ease-out 0.8s forwards;
}

.vs-intro-vs::before {
  width: 100px;
  height: 100px;
}

.vs-intro-vs::after {
  width: 160px;
  height: 160px;
  animation-delay: 0.9s;
  border-color: rgba(108, 99, 255, 0.15);
}

.vs-intro-flash {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at center, rgba(108, 99, 255, 0.4), rgba(255, 255, 255, 0.15), transparent 70%);
  opacity: 0;
  z-index: 1;
  animation: vsFlash 0.6s ease-out 0.7s forwards;
  pointer-events: none;
}

.vs-intro-overlay.fade-out {
  animation: vsFadeOut 0.5s ease-in forwards;
}

@keyframes vsSlideLeft {
  0% {
    opacity: 0;
    transform: translateX(-120px) scale(0.8);
    filter: blur(8px);
  }
  60% {
    opacity: 1;
    filter: blur(0);
  }
  80% {
    transform: translateX(8px) scale(1.02);
  }
  100% {
    opacity: 1;
    transform: translateX(0) scale(1);
    filter: blur(0);
  }
}

@keyframes vsSlideRight {
  0% {
    opacity: 0;
    transform: translateX(120px) scale(0.8);
    filter: blur(8px);
  }
  60% {
    opacity: 1;
    filter: blur(0);
  }
  80% {
    transform: translateX(-8px) scale(1.02);
  }
  100% {
    opacity: 1;
    transform: translateX(0) scale(1);
    filter: blur(0);
  }
}

@keyframes vsTextReveal {
  0% {
    opacity: 0;
    transform: scale(3);
    filter: blur(12px);
  }
  50% {
    opacity: 1;
    filter: blur(0);
  }
  70% {
    transform: scale(0.9);
  }
  100% {
    opacity: 1;
    transform: scale(1);
    filter: blur(0);
  }
}

@keyframes vsRingBurst {
  0% {
    opacity: 0.8;
    transform: translate(-50%, -50%) scale(0.3);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(2.5);
  }
}

@keyframes vsFlash {
  0% {
    opacity: 0;
  }
  20% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

@keyframes vsLineGrow {
  0% { height: 0; }
  100% { height: 60px; }
}

@keyframes vsFadeOut {
  0% { opacity: 1; }
  100% { opacity: 0; }
}

/* ===== SENTENCE HIDDEN (during countdown) ===== */

.typing-area.sentence-hidden .typing-area-frame {
  position: relative;
}

.typing-area.sentence-hidden .sentence-display,
.typing-area.sentence-hidden .quote-source {
  filter: blur(14px);
  opacity: 0.2;
  user-select: none;
}

.typing-area .sentence-display,
.typing-area .quote-source {
  transition: filter 0.4s ease, opacity 0.4s ease;
}

/* ===== COUNTDOWN ===== */

.countdown-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 50;
  background: rgba(10, 10, 15, 0.88);
}

.countdown-rings {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
}

.countdown-rings::before,
.countdown-rings::after {
  content: '';
  position: absolute;
  border-radius: 50%;
  border: 1px solid rgba(108, 99, 255, 0.2);
  animation: countdownRing 0.8s ease-out;
}

.countdown-rings::before {
  width: 140px;
  height: 140px;
}

.countdown-rings::after {
  width: 200px;
  height: 200px;
  animation-delay: 0.1s;
  border-color: rgba(108, 99, 255, 0.1);
}

@keyframes countdownRing {
  0% { transform: scale(0.5); opacity: 0.8; }
  100% { transform: scale(1.5); opacity: 0; }
}

.countdown-overlay span {
  font-family: var(--mono);
  font-size: 7rem;
  font-weight: 800;
  color: var(--accent);
  animation: countPulse 0.8s ease-out;
  text-shadow:
    0 0 20px var(--accent-glow-strong),
    0 0 60px var(--accent-glow),
    0 0 100px rgba(108, 99, 255, 0.15);
  position: relative;
  z-index: 1;
}

@keyframes countPulse {
  0% { transform: scale(1.5); opacity: 0.3; }
  50% { transform: scale(1); opacity: 1; }
  100% { transform: scale(0.95); opacity: 0.8; }
}

/* ===== TYPING AREA ===== */

.typing-area {
  width: 100%;
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  min-height: 0;
}

.typing-area-frame {
  background: rgba(22, 22, 31, 0.6);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 32px 28px;
  box-shadow: inset 0 2px 12px rgba(0, 0, 0, 0.2), 0 0 1px rgba(108, 99, 255, 0.1);
  width: 100%;
  position: relative;
  overflow: hidden;
  box-sizing: border-box;
}

.typing-area-frame::before {
  content: '';
  position: absolute;
  top: 0;
  left: 20%;
  right: 20%;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(108, 99, 255, 0.15), transparent);
}

.sentence-display {
  font-family: var(--mono);
  font-size: 1.3rem;
  line-height: 2;
  letter-spacing: 0.01em;
  color: var(--text-dim);
  margin-bottom: 0;
  user-select: none;
  text-align: center;
  max-width: 100%;
  overflow-wrap: break-word;
  word-wrap: break-word;
}

.sentence-display .char {
  transition: color 0.05s, text-shadow 0.05s;
}

.sentence-display .char.correct {
  color: var(--green);
  text-shadow: 0 0 6px rgba(74, 222, 128, 0.2);
}

.sentence-display .char.error {
  color: var(--red);
  text-decoration: underline;
  text-shadow: 0 0 6px rgba(239, 68, 68, 0.2);
}

.sentence-display .char.current {
  border-left: 2px solid var(--accent);
  animation: cursorGlow 1s step-end infinite;
}

@keyframes cursorGlow {
  0%, 100% {
    border-color: var(--accent);
    text-shadow: 0 0 8px var(--accent-glow);
  }
  50% {
    border-color: transparent;
    text-shadow: none;
  }
}

.sentence-display .char.injected {
  color: var(--gold);
  text-shadow: 0 0 6px var(--gold-glow);
}

.sentence-display .char.correct.injected {
  color: var(--green);
}

.sentence-display .char.error.injected {
  color: var(--red);
}

.quote-source {
  font-family: var(--sans);
  font-size: 0.85rem;
  font-style: italic;
  color: var(--text-dim);
  opacity: 0.6;
  margin-top: 12px;
  text-align: right;
}

.typing-input {
  position: absolute;
  opacity: 0;
  pointer-events: auto;
  width: 1px;
  height: 1px;
}

/* ===== ATTACK NOTIFICATIONS ===== */

.attack-notifications {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.attack-notification {
  font-family: var(--mono);
  font-weight: 800;
  font-size: 1.1rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 6px 16px;
  border-radius: 4px;
  animation: attackFloat 1.8s ease-out forwards;
  white-space: nowrap;
}

.attack-received {
  color: var(--gold);
  background: var(--gold-dim);
  border: 1px solid rgba(251, 191, 36, 0.25);
  text-shadow: 0 0 8px var(--gold-glow);
}

.attack-sent {
  color: var(--green);
  background: var(--green-dim);
  border: 1px solid rgba(74, 222, 128, 0.2);
  text-shadow: 0 0 8px var(--green-glow);
  font-size: 0.85rem;
}

@keyframes attackFloat {
  0% {
    opacity: 1;
    transform: translateY(0) scale(1.1);
  }
  30% {
    opacity: 1;
    transform: translateY(-10px) scale(1);
  }
  100% {
    opacity: 0;
    transform: translateY(-40px) scale(0.9);
  }
}

.sentence-display .char.scramble-flash {
  background: var(--red-dim);
  color: var(--red);
  text-shadow: 0 0 8px var(--red-glow);
  animation: scramblePulse 1.5s ease-out forwards;
}

.sentence-display .char.chaos-flash {
  background: var(--accent-glow);
  color: var(--accent);
  text-shadow: 0 0 8px var(--accent-glow-strong);
  animation: chaosPulse 1.5s ease-out forwards;
}

@keyframes scramblePulse {
  0% { background: rgba(239, 68, 68, 0.25); }
  100% { background: transparent; }
}

@keyframes chaosPulse {
  0% { background: rgba(108, 99, 255, 0.25); }
  100% { background: transparent; }
}

/* ===== PLAYER STATS ===== */

.player-stats {
  width: 100%;
  margin: 16px auto 0;
  display: flex;
  justify-content: center;
  gap: 20px;
}

.stat {
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 14px 28px;
  min-width: 100px;
  position: relative;
}

.stat::before {
  content: '';
  position: absolute;
  top: 0;
  left: 25%;
  right: 25%;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(108, 99, 255, 0.2), transparent);
}

.stat-value {
  display: block;
  font-family: var(--mono);
  font-size: 2rem;
  font-weight: 800;
  color: var(--text);
  transition: color 0.2s, text-shadow 0.2s;
}

.stat-label {
  font-family: var(--mono);
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.15em;
}

/* ===== RESULT SCREENS ===== */

.result-container {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.round-result-title, .match-result-title {
  font-family: var(--mono);
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  text-shadow: 0 0 20px rgba(108, 99, 255, 0.15);
}

.round-winner-text, .match-winner-text {
  font-size: 1rem;
  color: var(--text-dim);
}

.score-comparison {
  display: flex;
  align-items: stretch;
  gap: 0;
  margin: 10px 0;
}

.score-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 2px;
  padding: 24px 32px;
  min-width: 200px;
  position: relative;
}

.score-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  border-radius: 2px 2px 0 0;
}

.score-card.you {
  box-shadow: 0 -2px 20px rgba(74, 222, 128, 0.05);
}

.score-card.you::before {
  background: linear-gradient(90deg, var(--green), rgba(74, 222, 128, 0.3));
}

.score-card.opponent {
  box-shadow: 0 -2px 20px rgba(239, 68, 68, 0.05);
}

.score-card.opponent::before {
  background: linear-gradient(90deg, rgba(239, 68, 68, 0.3), var(--red));
}

.score-card h3 {
  font-family: var(--mono);
  font-weight: 800;
  margin-bottom: 16px;
  font-size: 0.9rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.score-card.you h3 {
  color: var(--green);
  text-shadow: 0 0 10px rgba(74, 222, 128, 0.2);
}

.score-card.opponent h3 {
  color: var(--red);
  text-shadow: 0 0 10px rgba(239, 68, 68, 0.2);
}

.score-detail {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  padding: 6px 0;
  font-size: 0.85rem;
}

.score-detail .label {
  color: var(--text-dim);
}

.score-detail .value {
  font-family: var(--mono);
  font-weight: 700;
}

.score-detail.total {
  border-top: 1px solid var(--border);
  margin-top: 8px;
  padding-top: 12px;
  font-size: 1rem;
}

.score-detail.total .value {
  color: var(--accent);
  text-shadow: 0 0 8px var(--accent-glow);
}

.vs-divider {
  display: flex;
  align-items: center;
  padding: 0 20px;
  font-family: var(--mono);
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--text-dim);
  letter-spacing: 0.1em;
  text-shadow: 0 0 15px rgba(108, 99, 255, 0.15);
  animation: vsPulse 2s ease-in-out infinite;
}

@keyframes vsPulse {
  0%, 100% { text-shadow: 0 0 15px rgba(108, 99, 255, 0.1); }
  50% { text-shadow: 0 0 20px rgba(108, 99, 255, 0.25); }
}

.next-round-text {
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: 0.8rem;
  letter-spacing: 0.04em;
}

/* ===== MATCH RESULT ===== */

.final-match-score {
  font-family: var(--mono);
  font-size: 3rem;
  font-weight: 800;
  letter-spacing: 8px;
  text-shadow:
    0 0 20px rgba(108, 99, 255, 0.2),
    0 0 60px rgba(108, 99, 255, 0.1);
}

.rating-change {
  font-family: var(--mono);
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-dim);
}

.match-result-buttons {
  display: flex;
  gap: 16px;
  margin-top: 10px;
}

.match-result-buttons .btn-primary {
  animation: btnBreathe 2.5s ease-in-out infinite;
}

@keyframes btnBreathe {
  0%, 100% {
    box-shadow: 0 0 20px var(--accent-glow), 0 0 60px rgba(108, 99, 255, 0.1);
  }
  50% {
    box-shadow: 0 0 30px var(--accent-glow-strong), 0 0 80px rgba(108, 99, 255, 0.2);
  }
}

.match-winner-text.win {
  color: var(--green);
  font-family: var(--mono);
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  text-shadow:
    0 0 10px var(--green-glow),
    0 0 30px rgba(74, 222, 128, 0.2),
    0 0 60px rgba(74, 222, 128, 0.1);
}

.match-winner-text.lose {
  color: var(--red);
  font-family: var(--mono);
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  text-shadow:
    0 0 10px var(--red-glow),
    0 0 30px rgba(239, 68, 68, 0.15);
}

.match-winner-text.draw {
  color: var(--gold);
  font-family: var(--mono);
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  text-shadow:
    0 0 10px var(--gold-glow),
    0 0 30px rgba(251, 191, 36, 0.15);
}

/* ===== SCROLLBAR ===== */

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 0; }

/* ===== FINISH TIMER ===== */

.finish-timer {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 8px 16px;
  background: rgba(108, 99, 255, 0.08);
  border: 1px solid rgba(108, 99, 255, 0.2);
  border-radius: 6px;
  animation: timerFadeIn 0.3s ease-out;
}

.finish-timer-label {
  font-family: var(--mono);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.finish-timer-count {
  font-family: var(--mono);
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--accent);
  min-width: 28px;
  text-align: center;
}

.finish-timer-count.urgent {
  color: var(--red);
  animation: timerPulse 0.5s ease-in-out infinite;
}

@keyframes timerFadeIn {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes timerPulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.5; }
}

/* ===== RESPONSIVE ===== */

@media (max-width: 900px) {
  .game-split {
    flex-direction: column;
    gap: 12px;
  }
  .game-divider {
    width: 100%;
    height: 1px;
    margin: 0;
  }
  .game-divider::after {
    top: 0;
    left: 0;
    right: 0;
    bottom: auto;
    width: auto;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(108, 99, 255, 0.2), transparent);
  }
  .game-panel-you, .game-panel-opp { flex: none; }
  .game-panel-opp .sentence-display { font-size: 0.85rem; }
}

.welcome-username-locked {
  font-family: var(--mono);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.04em;
  padding: 10px 0;
  text-transform: uppercase;
}

.welcome-back-link {
  text-align: center;
  margin-top: 8px;
  font-family: var(--mono);
  font-size: 0.75rem;
}

.welcome-back-link a {
  color: var(--text-dim);
  text-decoration: none;
  transition: color 0.2s;
}

.welcome-back-link a:hover {
  color: var(--accent);
}

.welcome-input + .welcome-input {
  margin-top: 8px;
}

@media (max-width: 600px) {
  .logo-large { font-size: 3rem; }
  .welcome-wrapper { padding: 32px 16px 20px; }
  .sentence-display { font-size: 1.05rem; }
  .score-comparison { flex-direction: column; }
  .vs-divider { padding: 12px 0; justify-content: center; }
  .player-stats { gap: 12px; }
  .stat { padding: 8px 14px; min-width: 70px; }
  .stat-value { font-size: 1.5rem; }
  #screen-game { padding: 12px; }
  .mode-grid { grid-template-columns: 1fr; gap: 12px; }
  .mode-key { min-height: 120px; padding: 22px 16px 18px; }
  .mode-grid > .mode-key:last-child:nth-child(odd) { max-width: 100%; }
  .home-wrapper { padding: 0 16px 20px; }
  .home-logo { font-size: 2.2rem; }
  .typing-area-frame { padding: 20px 16px; }
  .vs-intro-player { font-size: 1.4rem; padding: 0 16px; }
  .vs-intro-vs { font-size: 3rem; }
  .vs-intro-center { min-width: 70px; }
  .vs-intro-content { flex-direction: column; gap: 16px; }
  .vs-intro-left::after,
  .vs-intro-right::before { display: none; }
}

/* ===== COMPACT LEVEL PILL (HEADER) ===== */

.home-level-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.home-level-pill:hover {
  background: var(--surface-hover);
  border-color: rgba(108, 99, 255, 0.3);
}

.home-level-badge-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.home-level-badge-icon svg {
  width: 100%;
  height: 100%;
}

.home-level-text {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  color: var(--text);
  text-transform: uppercase;
}

/* ===== PROFILE XP BREAKDOWN ===== */

.profile-xp-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 20px;
  position: relative;
}

.profile-xp-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 20%;
  right: 20%;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(108, 99, 255, 0.25), transparent);
}

.profile-xp-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.profile-xp-badge-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  flex-shrink: 0;
}

.profile-xp-badge-icon svg {
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 0 6px currentColor);
}

.profile-xp-level-label {
  font-family: var(--mono);
  font-weight: 800;
  font-size: 1rem;
  letter-spacing: 0.08em;
  color: var(--text);
}

.profile-xp-pct {
  margin-left: auto;
  font-family: var(--mono);
  font-weight: 700;
  font-size: 0.8rem;
  color: var(--accent);
  letter-spacing: 0.04em;
}

.profile-xp-bar-track {
  width: 100%;
  height: 10px;
  background: var(--surface);
  border-radius: 5px;
  border: 1px solid var(--border);
  overflow: hidden;
  position: relative;
  margin-bottom: 16px;
}

.profile-xp-bar-fill {
  height: 100%;
  border-radius: 5px;
  background: linear-gradient(90deg, var(--accent), #8b5cf6);
  transition: width 0.6s cubic-bezier(0.25, 1, 0.5, 1);
  min-width: 0;
  box-shadow: 0 0 8px var(--accent-glow);
}

.profile-xp-details {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.profile-xp-detail-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.profile-xp-detail-row:last-child {
  border-bottom: none;
}

.profile-xp-detail-label {
  font-family: var(--mono);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-dim);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.profile-xp-detail-value {
  font-family: var(--mono);
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.02em;
}

/* ===== LEVEL BADGE SHAPES ===== */

.level-shape-circle { }
.level-shape-triangle { }
.level-shape-diamond { }
.level-shape-pentagon { }
.level-shape-hexagon { }

/* ===== XP GAIN (MATCH RESULT) ===== */

.xp-gain-display {
  text-align: center;
  margin: 6px 0 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  animation: xpFadeIn 0.5s ease-out;
}

.xp-gain-amount {
  font-family: var(--mono);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.05em;
}

.xp-gain-pb {
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--gold);
  letter-spacing: 0.08em;
  text-shadow: 0 0 10px var(--gold-glow);
  animation: pbPulse 1s ease-in-out infinite alternate;
}

.xp-gain-levelup {
  font-family: var(--mono);
  font-size: 0.85rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  animation: levelUpGlow 1.2s ease-in-out infinite alternate;
}

@keyframes xpFadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes pbPulse {
  from { opacity: 0.7; }
  to { opacity: 1; }
}

@keyframes levelUpGlow {
  from { opacity: 0.8; text-shadow: 0 0 6px currentColor; }
  to { opacity: 1; text-shadow: 0 0 18px currentColor; }
}

/* ===== LEVEL UP OVERLAY ===== */

.levelup-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.85);
  animation: levelupOverlayIn 0.3s ease-out;
}

.levelup-overlay.fade-out {
  animation: levelupOverlayOut 0.5s ease-in forwards;
}

.levelup-content {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.levelup-badge {
  width: 80px;
  height: 80px;
  animation: levelupBadgePop 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.levelup-badge svg {
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 0 20px currentColor);
}

.levelup-message {
  font-family: var(--mono);
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  animation: levelupTextPulse 1s ease-in-out infinite alternate;
}

.levelup-level {
  font-family: var(--mono);
  font-size: 3.5rem;
  font-weight: 800;
  color: var(--text);
  letter-spacing: 0.06em;
  text-shadow: 0 0 20px var(--accent-glow);
  animation: levelupBadgePop 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) 0.15s both;
}

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

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

@keyframes levelupBadgePop {
  from { transform: scale(0); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

@keyframes levelupTextPulse {
  from { opacity: 0.85; transform: scale(1); }
  to { opacity: 1; transform: scale(1.04); }
}

/* ===== ASCEND MODE ===== */

#screen-ascend {
  flex-direction: column;
  padding: 0;
  justify-content: flex-start;
}

#screen-ascend::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 2px,
      rgba(108, 99, 255, 0.015) 2px,
      rgba(108, 99, 255, 0.015) 3px
    ),
    repeating-linear-gradient(
      90deg,
      transparent,
      transparent 80px,
      rgba(108, 99, 255, 0.01) 80px,
      rgba(108, 99, 255, 0.01) 81px
    );
  pointer-events: none;
  z-index: 0;
}

#screen-ascend > * {
  position: relative;
  z-index: 1;
}

#screen-ascend.screen-shake {
  animation: screenShake 0.4s ease-out;
}

@keyframes screenShake {
  0% { transform: translate(0, 0); }
  15% { transform: translate(-6px, 2px); }
  30% { transform: translate(5px, -3px); }
  45% { transform: translate(-4px, 1px); }
  60% { transform: translate(3px, -1px); }
  75% { transform: translate(-2px, 1px); }
  100% { transform: translate(0, 0); }
}

.ascend-layout {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* --- Header --- */

.ascend-header {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 24px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: linear-gradient(180deg, rgba(16, 16, 24, 0.6) 0%, transparent 100%);
}

.ascend-header-left,
.ascend-header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.ascend-header-center {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 2px;
}

.ascend-mode-label {
  font-family: var(--mono);
  font-weight: 800;
  font-size: 0.7rem;
  letter-spacing: 0.15em;
  color: #f04444;
  text-shadow: 0 0 10px rgba(240, 68, 68, 0.3);
}

.ascend-tier-label {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  color: var(--gold);
  padding: 2px 10px;
  border: 1px solid rgba(251, 191, 36, 0.3);
  border-radius: 4px;
  text-shadow: 0 0 8px var(--gold-glow);
  transition: all 0.3s ease;
}

.ascend-height-display {
  font-family: var(--mono);
  font-weight: 800;
  font-size: 1.8rem;
  letter-spacing: 0.04em;
  color: var(--text);
  text-shadow: 0 0 20px rgba(108, 99, 255, 0.25);
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.ascend-height-display.height-pop {
  animation: heightPop 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes heightPop {
  0% { transform: scale(1); }
  40% { transform: scale(1.15); text-shadow: 0 0 30px rgba(108, 99, 255, 0.5); }
  100% { transform: scale(1); }
}

.ascend-timer {
  font-family: var(--mono);
  font-weight: 600;
  font-size: 0.8rem;
  color: var(--text-dim);
  letter-spacing: 0.04em;
}

/* --- HP Bar (Game-style) --- */

.ascend-hp-bar-area {
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  padding: 6px 24px 4px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.ascend-hp-icon {
  width: 18px;
  height: 18px;
  color: var(--green);
  filter: drop-shadow(0 0 4px rgba(74, 222, 128, 0.4));
  flex-shrink: 0;
  transition: color 0.3s, filter 0.3s;
}

.ascend-hp-bar-area.hp-mid .ascend-hp-icon {
  color: #eab308;
  filter: drop-shadow(0 0 4px rgba(234, 179, 8, 0.4));
}
.ascend-hp-bar-area.hp-low .ascend-hp-icon,
.ascend-hp-bar-area.hp-critical .ascend-hp-icon {
  color: var(--red);
  filter: drop-shadow(0 0 6px rgba(239, 68, 68, 0.5));
}

.ascend-hp-track {
  flex: 1;
  height: 16px;
  background: rgba(22, 22, 31, 0.8);
  border-radius: 3px;
  overflow: hidden;
  border: 1px solid var(--border);
  position: relative;
}

.ascend-hp-segments {
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    90deg,
    transparent,
    transparent calc(10% - 1px),
    rgba(10, 10, 15, 0.5) calc(10% - 1px),
    rgba(10, 10, 15, 0.5) 10%
  );
  pointer-events: none;
  z-index: 2;
}

.ascend-hp-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.3s ease, background 0.4s ease, box-shadow 0.4s ease;
  position: relative;
  z-index: 1;
}

.ascend-hp-fill::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(255, 255, 255, 0.12) 45%,
    rgba(255, 255, 255, 0.2) 50%,
    rgba(255, 255, 255, 0.12) 55%,
    transparent 100%
  );
  background-size: 200% 100%;
  animation: hpShimmer 3s ease-in-out infinite;
  border-radius: 2px;
}

@keyframes hpShimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.ascend-hp-fill.hp-high {
  background: linear-gradient(90deg, #22c55e, #4ade80);
  box-shadow: 0 0 10px rgba(74, 222, 128, 0.3), inset 0 1px 0 rgba(255,255,255,0.1);
}

.ascend-hp-fill.hp-mid {
  background: linear-gradient(90deg, #ca8a04, #eab308);
  box-shadow: 0 0 10px rgba(234, 179, 8, 0.3), inset 0 1px 0 rgba(255,255,255,0.1);
}

.ascend-hp-fill.hp-low {
  background: linear-gradient(90deg, #dc2626, #ef4444);
  box-shadow: 0 0 12px rgba(239, 68, 68, 0.35), inset 0 1px 0 rgba(255,255,255,0.1);
  animation: hpLowPulse 1.2s ease-in-out infinite alternate;
}

.ascend-hp-fill.hp-critical {
  background: linear-gradient(90deg, #b91c1c, #dc2626);
  box-shadow: 0 0 16px rgba(239, 68, 68, 0.5), inset 0 1px 0 rgba(255,255,255,0.1);
  animation: hpCriticalPulse 0.5s ease-in-out infinite alternate;
}

.ascend-hp-bar-area.hp-damage {
  animation: hpDamageShake 0.35s ease-out;
}

@keyframes hpDamageShake {
  0% { transform: translateX(0); }
  20% { transform: translateX(-5px); }
  40% { transform: translateX(4px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(2px); }
  100% { transform: translateX(0); }
}

@keyframes hpLowPulse {
  from { opacity: 0.8; box-shadow: 0 0 10px rgba(239, 68, 68, 0.25); }
  to { opacity: 1; box-shadow: 0 0 18px rgba(239, 68, 68, 0.45); }
}

@keyframes hpCriticalPulse {
  from { opacity: 0.7; box-shadow: 0 0 10px rgba(239, 68, 68, 0.3); }
  to { opacity: 1; box-shadow: 0 0 22px rgba(239, 68, 68, 0.6); }
}

.ascend-hp-text {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 0.8rem;
  color: var(--text);
  min-width: 28px;
  text-align: right;
  transition: color 0.3s;
}

.ascend-hp-bar-area.hp-mid .ascend-hp-text { color: #eab308; }
.ascend-hp-bar-area.hp-low .ascend-hp-text,
.ascend-hp-bar-area.hp-critical .ascend-hp-text { color: var(--red); }

/* --- Momentum Segments --- */

.ascend-momentum-segments {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 4px;
  padding: 4px 24px 6px;
  flex-shrink: 0;
}

.momentum-seg {
  width: 18px;
  height: 18px;
  clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
  background: rgba(108, 99, 255, 0.08);
  border: none;
  transition: background 0.25s ease, box-shadow 0.25s ease, transform 0.25s ease;
  position: relative;
}

.momentum-seg.active.tier-low {
  background: rgba(108, 99, 255, 0.35);
  box-shadow: 0 0 6px rgba(108, 99, 255, 0.15);
}

.momentum-seg.active.tier-mid {
  background: rgba(139, 92, 246, 0.65);
  box-shadow: 0 0 10px rgba(139, 92, 246, 0.3);
  animation: momentumPulseMid 1.5s ease-in-out infinite alternate;
}

.momentum-seg.active.tier-high {
  background: linear-gradient(135deg, #a855f7, #ec4899);
  box-shadow: 0 0 14px rgba(168, 85, 247, 0.4), 0 0 4px rgba(236, 72, 153, 0.3);
  animation: momentumPulseHigh 1s ease-in-out infinite alternate;
}

.momentum-seg.active.tier-max {
  background: linear-gradient(135deg, #fbbf24, #fff);
  box-shadow: 0 0 18px rgba(251, 191, 36, 0.5), 0 0 6px rgba(255, 255, 255, 0.3);
  animation: momentumMax 0.7s ease-in-out infinite alternate;
}

.momentum-seg.seg-pop {
  animation: segPop 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) !important;
}

@keyframes momentumPulseMid {
  from { opacity: 0.8; transform: scale(1); }
  to { opacity: 1; transform: scale(1.05); }
}

@keyframes momentumPulseHigh {
  from { opacity: 0.85; transform: scale(1); box-shadow: 0 0 10px rgba(168, 85, 247, 0.3); }
  to { opacity: 1; transform: scale(1.1); box-shadow: 0 0 20px rgba(168, 85, 247, 0.5), 0 0 6px rgba(236, 72, 153, 0.4); }
}

@keyframes momentumMax {
  from { opacity: 0.9; transform: scale(1); box-shadow: 0 0 14px rgba(251, 191, 36, 0.4); }
  to { opacity: 1; transform: scale(1.15); box-shadow: 0 0 24px rgba(251, 191, 36, 0.7), 0 0 8px rgba(255, 255, 255, 0.4); }
}

@keyframes segPop {
  0% { transform: scale(1); }
  50% { transform: scale(1.6); filter: brightness(1.5); }
  100% { transform: scale(1); }
}

/* --- Burnout Banner --- */

.ascend-burnout-banner {
  width: 100%;
  text-align: center;
  padding: 8px 16px;
  background: linear-gradient(90deg, transparent, rgba(239, 68, 68, 0.1) 30%, rgba(239, 68, 68, 0.1) 70%, transparent);
  border-bottom: 1px solid rgba(239, 68, 68, 0.2);
  animation: burnoutPulse 1.2s ease-in-out infinite;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.ascend-burnout-banner::before {
  content: '⚠';
  font-size: 0.9rem;
  filter: grayscale(1) brightness(1.5);
}

.ascend-burnout-banner span {
  font-family: var(--mono);
  font-weight: 800;
  font-size: 0.8rem;
  letter-spacing: 0.12em;
  color: var(--red);
  text-shadow: 0 0 12px var(--red-glow);
}

@keyframes burnoutPulse {
  0%, 100% { background: linear-gradient(90deg, transparent, rgba(239, 68, 68, 0.06) 30%, rgba(239, 68, 68, 0.06) 70%, transparent); }
  50% { background: linear-gradient(90deg, transparent, rgba(239, 68, 68, 0.15) 30%, rgba(239, 68, 68, 0.15) 70%, transparent); }
}

/* --- Game Body --- */

.ascend-game-body {
  flex: 1;
  display: flex;
  gap: 0;
  min-height: 0;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding: 12px 24px;
}

.ascend-typing-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  justify-content: center;
}

.ascend-typing-panel .typing-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.ascend-typing-panel .typing-area-frame {
  position: relative;
  border: 1px solid var(--border);
  border-radius: 6px;
  transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

.ascend-typing-panel .typing-area-frame::before {
  content: '';
  position: absolute;
  inset: -1px;
  border-radius: 7px;
  padding: 1px;
  background: linear-gradient(135deg, rgba(108,99,255,0.15), rgba(139,92,246,0.08), transparent, rgba(108,99,255,0.1));
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.4s ease;
}

.ascend-typing-panel.momentum-glow-low .typing-area-frame {
  border-color: rgba(108, 99, 255, 0.2);
  box-shadow: 0 0 8px rgba(108, 99, 255, 0.06);
}
.ascend-typing-panel.momentum-glow-low .typing-area-frame::before { opacity: 0.4; }

.ascend-typing-panel.momentum-glow-mid .typing-area-frame {
  border-color: rgba(139, 92, 246, 0.3);
  box-shadow: 0 0 14px rgba(139, 92, 246, 0.1);
}
.ascend-typing-panel.momentum-glow-mid .typing-area-frame::before { opacity: 0.7; }

.ascend-typing-panel.momentum-glow-high .typing-area-frame {
  border-color: rgba(168, 85, 247, 0.4);
  box-shadow: 0 0 20px rgba(168, 85, 247, 0.15), 0 0 4px rgba(236, 72, 153, 0.1);
  animation: frameGlowHigh 1.5s ease-in-out infinite alternate;
}
.ascend-typing-panel.momentum-glow-high .typing-area-frame::before { opacity: 1; }

.ascend-typing-panel.momentum-glow-max .typing-area-frame {
  border-color: rgba(251, 191, 36, 0.4);
  box-shadow: 0 0 24px rgba(251, 191, 36, 0.15), 0 0 6px rgba(255, 255, 255, 0.08);
  animation: frameGlowMax 1s ease-in-out infinite alternate;
}
.ascend-typing-panel.momentum-glow-max .typing-area-frame::before {
  opacity: 1;
  background: linear-gradient(135deg, rgba(251,191,36,0.2), rgba(255,255,255,0.1), transparent, rgba(251,191,36,0.15));
}

@keyframes frameGlowHigh {
  from { box-shadow: 0 0 14px rgba(168, 85, 247, 0.1); }
  to { box-shadow: 0 0 24px rgba(168, 85, 247, 0.2), 0 0 6px rgba(236, 72, 153, 0.15); }
}

@keyframes frameGlowMax {
  from { box-shadow: 0 0 18px rgba(251, 191, 36, 0.1); }
  to { box-shadow: 0 0 30px rgba(251, 191, 36, 0.2), 0 0 8px rgba(255, 255, 255, 0.12); }
}

/* --- Stat Cards (Glass-morphism) --- */

.ascend-typing-panel .player-stats {
  margin-top: 12px;
}

.ascend-typing-panel .player-stats .stat {
  background: rgba(22, 22, 31, 0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(37, 37, 53, 0.6);
  border-radius: 6px;
  transition: border-color 0.3s, box-shadow 0.3s;
}

.ascend-typing-panel .player-stats .stat-value {
  font-size: 1.6rem;
  font-weight: 800;
  transition: color 0.3s, text-shadow 0.3s;
}

.ascend-typing-panel .player-stats .stat-value.wpm-hot {
  color: var(--green);
  text-shadow: 0 0 10px rgba(74, 222, 128, 0.3);
}

.ascend-typing-panel .player-stats .stat-value.wpm-fire {
  color: var(--accent);
  text-shadow: 0 0 12px var(--accent-glow);
}

.ascend-typing-panel .player-stats .stat-value.errors-active {
  color: var(--red);
  text-shadow: 0 0 8px var(--red-glow);
}

/* --- Scoreboard Panel --- */

.ascend-scoreboard-panel {
  width: 300px;
  flex-shrink: 0;
  margin-left: 20px;
  border-left: 1px solid var(--border);
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.ascend-scoreboard-title {
  font-family: var(--mono);
  font-weight: 800;
  font-size: 0.7rem;
  letter-spacing: 0.15em;
  color: var(--text-dim);
  margin-bottom: 10px;
  text-transform: uppercase;
}

.ascend-scoreboard {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.ascend-sb-row {
  display: grid;
  grid-template-columns: 22px 1fr 50px 40px;
  align-items: center;
  gap: 8px;
  padding: 7px 8px 7px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--border);
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 0.72rem;
  transition: all 0.3s ease;
  animation: sbRowSlideIn 0.3s ease-out both;
}

.ascend-sb-row:nth-child(1) { animation-delay: 0s; }
.ascend-sb-row:nth-child(2) { animation-delay: 0.04s; }
.ascend-sb-row:nth-child(3) { animation-delay: 0.08s; }
.ascend-sb-row:nth-child(4) { animation-delay: 0.12s; }
.ascend-sb-row:nth-child(5) { animation-delay: 0.16s; }
.ascend-sb-row:nth-child(6) { animation-delay: 0.2s; }
.ascend-sb-row:nth-child(7) { animation-delay: 0.24s; }
.ascend-sb-row:nth-child(8) { animation-delay: 0.28s; }
.ascend-sb-row:nth-child(9) { animation-delay: 0.32s; }
.ascend-sb-row:nth-child(10) { animation-delay: 0.36s; }

@keyframes sbRowSlideIn {
  from { opacity: 0; transform: translateX(12px); }
  to { opacity: 1; transform: translateX(0); }
}

.ascend-sb-row.tier-high { border-left-color: var(--gold); }
.ascend-sb-row.tier-mid { border-left-color: var(--accent); }
.ascend-sb-row.tier-low { border-left-color: var(--text-dim); }

.ascend-sb-row.ascend-sb-self {
  background: rgba(108, 99, 255, 0.08);
  border-color: rgba(108, 99, 255, 0.25);
  box-shadow: 0 0 10px rgba(108, 99, 255, 0.06);
}
.ascend-sb-row.ascend-sb-self.tier-high { border-left-color: var(--gold); }
.ascend-sb-row.ascend-sb-self.tier-mid { border-left-color: var(--accent); }

.ascend-sb-row.ascend-sb-eliminated {
  opacity: 0.3;
}

.ascend-sb-row.ascend-sb-eliminated .ascend-sb-name {
  text-decoration: line-through;
  text-decoration-color: rgba(239, 68, 68, 0.5);
}

.ascend-sb-rank {
  font-weight: 700;
  color: var(--text-dim);
  text-align: center;
  display: flex;
  align-items: center;
  gap: 3px;
}

.ascend-sb-tier-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.ascend-sb-tier-dot.td-high { background: var(--gold); box-shadow: 0 0 4px var(--gold-glow); }
.ascend-sb-tier-dot.td-mid { background: var(--accent); box-shadow: 0 0 4px var(--accent-glow); }
.ascend-sb-tier-dot.td-low { background: var(--text-dim); }

.ascend-sb-name-cell {
  overflow: hidden;
  min-width: 0;
}

.ascend-sb-name {
  font-weight: 700;
  font-size: 0.75rem;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: block;
}

.ascend-sb-hp-mini {
  height: 3px;
  background: rgba(10, 10, 15, 0.6);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 3px;
}

.ascend-sb-hp-mini-fill {
  height: 100%;
  background: var(--green);
  border-radius: 2px;
  transition: width 0.3s ease;
}

.ascend-sb-height {
  font-weight: 600;
  color: var(--accent);
  text-align: right;
  font-size: 0.7rem;
}

.ascend-sb-wpm {
  font-weight: 600;
  color: var(--text-dim);
  text-align: right;
  font-size: 0.68rem;
}

/* --- Ascend Notifications --- */

.ascend-tier-notification {
  color: var(--gold) !important;
  background: var(--gold-dim) !important;
  border: 1px solid rgba(251, 191, 36, 0.25) !important;
  text-shadow: 0 0 16px var(--gold-glow) !important;
  font-size: 1.4rem !important;
  letter-spacing: 0.08em !important;
}

.ascend-ko-notification {
  color: var(--green) !important;
  background: var(--green-dim) !important;
  border: 1px solid rgba(74, 222, 128, 0.25) !important;
  text-shadow: 0 0 14px var(--green-glow) !important;
  font-size: 1.2rem !important;
}

#screen-ascend .attack-notification {
  font-size: 1.15rem;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

/* Tier-up flash overlay */
.ascend-tier-flash {
  position: fixed;
  inset: 0;
  background: radial-gradient(ellipse at center, rgba(251, 191, 36, 0.15), transparent 70%);
  pointer-events: none;
  z-index: 100;
  animation: tierFlash 0.6s ease-out forwards;
}

@keyframes tierFlash {
  0% { opacity: 1; }
  100% { opacity: 0; }
}

/* --- Ascend Result Screen --- */

#screen-ascend-result {
  flex-direction: column;
}

.ascend-result-stats {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  margin: 10px 0;
}

.ascend-result-big {
  display: flex;
  align-items: baseline;
  gap: 4px;
}

.ascend-result-height {
  font-family: var(--mono);
  font-weight: 800;
  font-size: 4rem;
  color: var(--text);
  text-shadow: 0 0 30px rgba(108, 99, 255, 0.2);
  letter-spacing: 0.02em;
}

.ascend-result-height-unit {
  font-family: var(--mono);
  font-weight: 600;
  font-size: 1.5rem;
  color: var(--text-dim);
}

.ascend-result-details {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 16px 28px;
  min-width: 220px;
}

.ascend-result-details .score-detail {
  padding: 6px 0;
}

/* --- Ascend Responsive --- */

@media (max-width: 900px) {
  .ascend-game-body {
    flex-direction: column;
    gap: 12px;
  }
  .ascend-scoreboard-panel {
    width: 100%;
    margin-left: 0;
    border-left: none;
    padding-left: 0;
    border-top: 1px solid var(--border);
    padding-top: 12px;
    max-height: 180px;
  }
  .ascend-hp-bar-area {
    padding: 6px 16px 4px;
  }
  .ascend-momentum-segments {
    padding: 4px 16px 6px;
  }
}

@media (max-width: 600px) {
  .ascend-header {
    padding: 6px 12px;
  }
  .ascend-height-display {
    font-size: 1.3rem;
  }
  .ascend-game-body {
    padding: 8px 12px;
  }
  .ascend-result-height {
    font-size: 2.5rem;
  }
  .ascend-sb-row {
    grid-template-columns: 20px 1fr 44px 36px;
    font-size: 0.68rem;
    padding: 5px 6px 5px 8px;
  }
  .momentum-seg {
    width: 14px;
    height: 14px;
  }
  .ascend-hp-track {
    height: 12px;
  }
}

/* ===== LEADERBOARD SCREEN ===== */

#screen-leaderboard {
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
}

.lb-wrapper {
  width: 100%;
  max-width: 800px;
  margin: 0 auto;
  padding: 24px 32px 40px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.lb-tabs {
  display: flex;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px;
}

.lb-tab {
  flex: 1;
  font-family: var(--mono);
  font-weight: 700;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  padding: 10px 8px;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  transition: all 0.2s ease;
}

.lb-tab:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.lb-tab.active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 0 12px var(--accent-glow);
}

.lb-table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.lb-table-header {
  display: grid;
  grid-template-columns: 48px 1fr 100px 80px;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  font-family: var(--mono);
  font-weight: 700;
  font-size: 0.65rem;
  letter-spacing: 0.1em;
  color: var(--text-dim);
  text-transform: uppercase;
  border-bottom: 1px solid var(--border);
}

.lb-table-body {
  flex: 1;
  overflow-y: auto;
  max-height: calc(100vh - 260px);
}

.lb-row {
  display: grid;
  grid-template-columns: 48px 1fr 100px 80px;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  font-family: var(--mono);
  font-size: 0.82rem;
  border-bottom: 1px solid rgba(37, 37, 53, 0.5);
  transition: background 0.15s ease;
}

.lb-row:hover {
  background: var(--surface-hover);
}

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

.lb-col-rank {
  font-weight: 800;
  color: var(--text-dim);
  text-align: center;
}

.lb-col-name {
  font-weight: 700;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lb-col-tier {
  font-weight: 700;
  font-size: 0.72rem;
  letter-spacing: 0.04em;
}

.lb-col-stat {
  font-weight: 800;
  color: var(--text);
  text-align: right;
}

.lb-rank-1 .lb-col-rank {
  color: var(--gold);
  text-shadow: 0 0 8px var(--gold-glow);
  font-size: 1rem;
}

.lb-rank-2 .lb-col-rank {
  color: #c0c0c0;
  text-shadow: 0 0 6px rgba(192, 192, 192, 0.3);
}

.lb-rank-3 .lb-col-rank {
  color: #cd7f32;
  text-shadow: 0 0 6px rgba(205, 127, 50, 0.3);
}

.lb-rank-1 .lb-col-name {
  color: var(--gold);
}

.lb-loading,
.lb-empty {
  padding: 40px 0;
  text-align: center;
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: 0.85rem;
  letter-spacing: 0.04em;
}

.lb-loading {
  animation: breathe 2s ease-in-out infinite;
}

@media (max-width: 600px) {
  .lb-wrapper {
    padding: 16px;
  }

  .lb-tabs {
    flex-wrap: wrap;
  }

  .lb-tab {
    font-size: 0.65rem;
    padding: 8px 4px;
  }

  .lb-table-header,
  .lb-row {
    grid-template-columns: 36px 1fr 70px 60px;
    gap: 8px;
    padding: 10px 12px;
    font-size: 0.75rem;
  }

  .lb-table-header {
    font-size: 0.6rem;
  }
}
