:root {
  color-scheme: dark;
  --bg: #080b12;
  --panel: rgba(16, 22, 35, 0.74);
  --panel-strong: rgba(22, 31, 49, 0.92);
  --line: rgba(255, 255, 255, 0.12);
  --text: #f7fbff;
  --muted: #9facbf;
  --green: #2ee6a6;
  --blue: #4f8cff;
  --gold: #ffcc66;
  --red: #ff5c7a;
  --violet: #a987ff;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.38);
  font-family: Inter, system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 15% 0%, rgba(46, 230, 166, 0.2), transparent 28rem),
    radial-gradient(circle at 88% 12%, rgba(79, 140, 255, 0.22), transparent 26rem),
    linear-gradient(135deg, #080b12 0%, #101522 54%, #0a111d 100%);
  color: var(--text);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

#ambientCanvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  opacity: 0.42;
}

.app-shell {
  position: relative;
  z-index: 1;
  width: min(1240px, calc(100% - 32px));
  margin: 0 auto;
  padding: 18px 0 40px;
}

.topbar,
.hero-band,
.panel,
.typing-stage,
.control-strip {
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(22px);
}

.topbar {
  position: sticky;
  top: 12px;
  z-index: 10;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 16px;
  align-items: center;
  padding: 12px;
  border-radius: 18px;
}

.brand {
  display: inline-flex;
  gap: 10px;
  align-items: center;
  color: var(--text);
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border-radius: 13px;
  background: linear-gradient(135deg, var(--green), var(--blue));
  color: #061016;
  font-weight: 900;
}

.brand strong,
.brand small {
  display: block;
}

.brand small,
.muted,
label {
  color: var(--muted);
}

.tabs {
  display: flex;
  justify-content: center;
  gap: 8px;
}

.tab,
.name-pill,
.icon-btn,
.primary-btn,
.ghost-btn,
.danger-btn {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
  transition: transform 180ms ease, background 180ms ease, border-color 180ms ease;
}

.tab {
  padding: 0 16px;
}

.tab.active,
.icon-btn.active {
  border-color: rgba(46, 230, 166, 0.48);
  background: rgba(46, 230, 166, 0.14);
}

.tab:hover,
.name-pill:hover,
.icon-btn:hover,
.primary-btn:hover,
.ghost-btn:hover,
.danger-btn:hover {
  transform: translateY(-1px);
}

.user-box,
.button-group,
.admin-actions,
.room-tools {
  display: flex;
  gap: 10px;
  align-items: center;
}

.icon-btn {
  display: grid;
  width: 42px;
  place-items: center;
}

.name-pill {
  padding: 0 14px;
}

.hero-band {
  display: grid;
  grid-template-columns: 1fr minmax(240px, 330px);
  gap: 24px;
  align-items: end;
  margin: 18px 0;
  padding: clamp(22px, 4vw, 42px);
  border-radius: 26px;
  min-height: 235px;
  background:
    linear-gradient(110deg, rgba(12, 18, 30, 0.92), rgba(22, 31, 49, 0.58)),
    url("assets/icon.svg") right 7% center / 190px no-repeat;
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--green);
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  max-width: 800px;
  margin-bottom: 0;
  font-size: clamp(2.2rem, 5vw, 5.4rem);
  line-height: 0.95;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  font-size: 1rem;
}

.hero-score {
  padding: 18px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.08);
}

.hero-score span,
.hero-score strong {
  display: block;
}

.hero-score strong {
  margin: 8px 0 14px;
  font-size: 2.1rem;
}

.xp-track,
.race-progress {
  height: 11px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
}

.xp-track span,
.race-progress span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--green), var(--blue), var(--gold));
  box-shadow: 0 0 24px rgba(46, 230, 166, 0.38);
  transition: width 180ms ease;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.control-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: end;
  justify-content: space-between;
  padding: 14px;
  border-radius: 18px;
}

label {
  display: grid;
  gap: 6px;
  font-size: 0.82rem;
  font-weight: 700;
}

select,
input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  outline: none;
  background: rgba(4, 8, 14, 0.72);
  color: var(--text);
}

select,
input {
  height: 44px;
  padding: 0 12px;
}

textarea {
  min-height: 190px;
  padding: 12px;
  resize: vertical;
}

.primary-btn,
.ghost-btn,
.danger-btn {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  justify-content: center;
  padding: 0 16px;
  font-weight: 800;
}

.primary-btn {
  border-color: rgba(46, 230, 166, 0.6);
  background: linear-gradient(135deg, var(--green), var(--blue));
  color: #061016;
}

.danger-btn {
  border-color: rgba(255, 92, 122, 0.6);
  background: rgba(255, 92, 122, 0.14);
}

.full {
  width: 100%;
}

.game-grid,
.multi-layout,
.admin-layout,
.stats-layout {
  display: grid;
  gap: 18px;
  margin-top: 18px;
}

.game-grid {
  grid-template-columns: minmax(0, 1fr) 340px;
}

.multi-layout,
.admin-layout {
  grid-template-columns: 0.82fr 1.18fr;
}

.stats-layout {
  grid-template-columns: 1.2fr 0.8fr;
}

.typing-stage,
.panel {
  border-radius: 20px;
  padding: 18px;
}

.stats-row {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  margin: 16px 0;
}

.stats-row div {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.05);
}

.stats-row span {
  display: block;
  font: 800 1.7rem/1 JetBrains Mono, monospace;
}

.stats-row small {
  color: var(--muted);
}

.typing-text {
  height: 275px;
  overflow: auto;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(4, 8, 14, 0.62);
  font: 700 1.35rem/1.9 JetBrains Mono, monospace;
  scroll-behavior: smooth;
}

.word {
  display: inline-block;
  margin-right: 0.55rem;
  padding: 0 4px;
  border-radius: 7px;
  color: #d7deeb;
}

.word.current {
  position: relative;
  background: rgba(79, 140, 255, 0.18);
  box-shadow: inset 0 -2px 0 var(--blue);
}

.word.current::after {
  content: "";
  position: absolute;
  right: -4px;
  top: 18%;
  width: 2px;
  height: 64%;
  border-radius: 2px;
  background: var(--green);
  box-shadow: 0 0 12px rgba(46, 230, 166, 0.8);
  animation: blink 850ms steps(2, jump-none) infinite;
}

.word.correct {
  color: var(--green);
}

.word.wrong {
  color: var(--red);
  text-decoration: underline;
}

.letter-good {
  color: var(--green);
}

.letter-bad {
  color: var(--red);
  background: rgba(255, 92, 122, 0.16);
  border-radius: 4px;
}

.letter-rest {
  color: #d7deeb;
}

.typing-input {
  margin-top: 14px;
  height: 56px;
  font: 700 1.1rem JetBrains Mono, monospace;
}

.typing-input.error {
  border-color: var(--red);
  box-shadow: 0 0 0 4px rgba(255, 92, 122, 0.12);
}

.feedback-line {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  min-height: 32px;
  margin-top: 12px;
  color: var(--gold);
  font-weight: 800;
}

.performance-pulse {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

.performance-pulse span {
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.05);
}

.typing-stage.combo-glow {
  box-shadow: 0 0 0 1px rgba(255, 204, 102, 0.42), 0 28px 90px rgba(255, 204, 102, 0.12);
}

.typing-stage.mistake-shake {
  animation: shake 220ms ease;
}

@keyframes shake {
  25% { transform: translateX(-3px); }
  50% { transform: translateX(3px); }
  75% { transform: translateX(-2px); }
}

#liveCursor {
  color: var(--green);
  animation: blink 850ms steps(2, jump-none) infinite;
}

@keyframes blink {
  50% { opacity: 0; }
}

.side-stack {
  display: grid;
  gap: 18px;
  align-content: start;
}

.panel-title {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 14px;
}

.challenge-list,
.achievement-grid,
.admin-users {
  display: grid;
  gap: 10px;
}

.challenge,
.achievement,
.admin-user,
.leaderboard li {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.05);
}

.challenge,
.achievement,
.admin-user {
  padding: 12px;
}

.challenge.done,
.achievement.unlocked {
  border-color: rgba(46, 230, 166, 0.5);
  background: rgba(46, 230, 166, 0.1);
}

.leaderboard {
  display: grid;
  gap: 10px;
  padding-left: 0;
  list-style-position: inside;
}

.leaderboard li {
  padding: 12px;
}

.race-lobby,
.race-board,
.stats-layout .panel:first-child {
  min-height: 320px;
}

.player-progress {
  display: grid;
  gap: 12px;
  margin-bottom: 28px;
}

.player-progress > div:first-child {
  display: flex;
  justify-content: space-between;
}

.race-text-preview {
  max-height: 180px;
  overflow: auto;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(4, 8, 14, 0.48);
  color: #d7deeb;
  font: 700 0.95rem/1.75 JetBrains Mono, monospace;
}

.achievement-grid {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.heatmap {
  display: grid;
  grid-template-columns: repeat(13, minmax(22px, 1fr));
  gap: 8px;
}

.key-cell {
  display: grid;
  min-height: 34px;
  place-items: center;
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.07);
  color: var(--muted);
  font: 800 0.8rem JetBrains Mono, monospace;
}

.key-cell.hot {
  background: rgba(255, 92, 122, 0.24);
  color: #fff;
}

.admin-layout .panel {
  align-content: start;
}

.admin-user details {
  margin: 10px 0;
}

.admin-user summary {
  color: var(--green);
  cursor: pointer;
  font-weight: 800;
}

.admin-user pre {
  max-height: 220px;
  overflow: auto;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(4, 8, 14, 0.62);
  color: #d7deeb;
  font: 700 0.78rem/1.55 JetBrains Mono, monospace;
  white-space: pre-wrap;
}

.hidden {
  display: none !important;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 20;
  max-width: min(420px, calc(100% - 36px));
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel-strong);
  color: var(--text);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
}

.countdown-overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  background: rgba(4, 8, 14, 0.62);
  color: var(--green);
  font: 900 clamp(5rem, 18vw, 14rem)/1 JetBrains Mono, monospace;
  text-shadow: 0 0 48px rgba(46, 230, 166, 0.7);
  backdrop-filter: blur(10px);
}

.summary-modal {
  position: fixed;
  inset: 0;
  z-index: 25;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(4, 8, 14, 0.68);
  backdrop-filter: blur(12px);
}

.identity-modal,
.confirm-modal {
  position: fixed;
  inset: 0;
  z-index: 35;
  display: grid;
  place-items: center;
  padding: 18px;
  background:
    radial-gradient(circle at 50% 20%, rgba(46, 230, 166, 0.16), transparent 24rem),
    rgba(4, 8, 14, 0.76);
  backdrop-filter: blur(14px);
}

.identity-card,
.confirm-card {
  position: relative;
  width: min(560px, 100%);
  border: 1px solid var(--line);
  border-radius: 24px;
  background:
    linear-gradient(145deg, rgba(22, 31, 49, 0.98), rgba(9, 14, 24, 0.98)),
    var(--panel-strong);
  box-shadow: var(--shadow);
}

.identity-card {
  display: grid;
  grid-template-columns: 190px minmax(0, 1fr);
  overflow: hidden;
}

.identity-hero {
  position: relative;
  display: grid;
  min-height: 100%;
  place-items: center;
  border-right: 1px solid var(--line);
  background:
    linear-gradient(160deg, rgba(46, 230, 166, 0.18), rgba(79, 140, 255, 0.1)),
    rgba(255, 255, 255, 0.04);
}

.identity-hero strong {
  display: grid;
  width: 88px;
  height: 88px;
  place-items: center;
  border-radius: 24px;
  background: linear-gradient(135deg, var(--green), var(--blue));
  color: #061016;
  font-size: 2rem;
  font-weight: 900;
  box-shadow: 0 24px 60px rgba(46, 230, 166, 0.24);
}

.identity-keylines {
  position: absolute;
  inset: 24px;
  border-radius: 18px;
  background:
    linear-gradient(rgba(255, 255, 255, 0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.08) 1px, transparent 1px);
  background-size: 24px 24px;
  -webkit-mask-image: linear-gradient(145deg, transparent 0%, #000 25%, #000 75%, transparent 100%);
  mask-image: linear-gradient(145deg, transparent 0%, #000 25%, #000 75%, transparent 100%);
}

.identity-form,
.confirm-card {
  padding: 24px;
}

.identity-form h2,
.confirm-card h2 {
  font-size: 1.55rem;
}

.identity-form label {
  margin-top: 14px;
}

.identity-form input {
  height: 52px;
  font-weight: 800;
}

.identity-form input:focus,
.confirm-card button:focus-visible,
.summary-card button:focus-visible {
  border-color: rgba(46, 230, 166, 0.74);
  box-shadow: 0 0 0 4px rgba(46, 230, 166, 0.14);
}

.error-text {
  color: var(--red);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

.summary-card {
  position: relative;
  width: min(520px, 100%);
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background:
    linear-gradient(145deg, rgba(22, 31, 49, 0.96), rgba(13, 20, 33, 0.96)),
    var(--panel-strong);
  box-shadow: var(--shadow);
}

.summary-close {
  position: absolute;
  right: 16px;
  top: 16px;
}

.summary-score {
  display: grid;
  gap: 8px;
  margin: 18px 0;
  padding: 18px;
  border-radius: 16px;
  background: rgba(46, 230, 166, 0.1);
}

.summary-score strong {
  font: 900 2.6rem/1 JetBrains Mono, monospace;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.summary-grid div {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: rgba(255, 255, 255, 0.05);
}

.summary-grid span {
  display: block;
  font: 900 1.2rem JetBrains Mono, monospace;
}

.summary-grid small {
  color: var(--muted);
}

@media (max-width: 920px) {
  .topbar,
  .hero-band,
  .game-grid,
  .multi-layout,
  .admin-layout,
  .stats-layout {
    grid-template-columns: 1fr;
  }

  .tabs {
    justify-content: start;
    overflow-x: auto;
  }

  .hero-band {
    background:
      linear-gradient(110deg, rgba(12, 18, 30, 0.92), rgba(22, 31, 49, 0.58)),
      url("assets/icon.svg") right 12px bottom 12px / 120px no-repeat;
  }
}

@media (max-width: 620px) {
  .app-shell {
    width: min(100% - 20px, 1240px);
    padding-top: 10px;
  }

  .topbar {
    position: static;
  }

  .brand {
    min-width: 0;
  }

  .tabs,
  .user-box,
  .button-group,
  .room-tools {
    flex-wrap: wrap;
  }

  .stats-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .summary-grid {
    grid-template-columns: 1fr;
  }

  .identity-card {
    grid-template-columns: 1fr;
  }

  .identity-hero {
    min-height: 150px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .modal-actions {
    flex-direction: column-reverse;
  }

  .modal-actions button {
    width: 100%;
  }

  .typing-text {
    height: 230px;
    padding: 16px;
    font-size: 1rem;
  }

  h1 {
    font-size: 2.35rem;
  }
}
