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

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background: #000;
  color: #e0e0e0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}

.stage {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  /* Extra bottom padding reserves room for the fixed chat block so the
     centered game (incl. the Switch button) is never hidden behind it. */
  padding: 1.5rem 1.5rem 22rem;
}

.panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2rem;
  width: min(100%, 42rem);
}

.indicator-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  grid-template-rows: auto auto;
  column-gap: clamp(1rem, 4vw, 2.5rem);
  row-gap: 0.6rem;
  width: 100%;
  align-items: center;
}

.stats--red {
  grid-column: 1;
  grid-row: 2;
  align-self: center;
  justify-self: end;
  text-align: right;
}

.stats--blue {
  grid-column: 3;
  grid-row: 2;
  align-self: center;
  justify-self: start;
  text-align: left;
}

.current-streak {
  grid-column: 2;
  grid-row: 1;
  justify-self: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  text-align: center;
}

.current-streak__label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #888;
}

.current-streak__value {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.1rem;
  font-variant-numeric: tabular-nums;
  font-size: 0.9rem;
  line-height: 1.35;
  max-width: 11rem;
}

.indicator-col--red .current-streak__value {
  color: #ef5350;
}

.indicator-col--blue .current-streak__value {
  color: #42a5f5;
}

.stats {
  width: 100%;
  min-width: 0;
}

.stats__heading {
  margin: 0 0 0.75rem;
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.stats--red .stats__heading {
  color: #ef5350;
}

.stats--blue .stats__heading {
  color: #42a5f5;
}

.stats dl {
  margin: 0;
}

.stat {
  margin-bottom: 0.65rem;
}

.stat:last-child {
  margin-bottom: 0;
}

.stat dt {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #888;
  margin-bottom: 0.15rem;
}

.stat dd {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  margin: 0;
  font-variant-numeric: tabular-nums;
  font-size: 0.9rem;
  line-height: 1.35;
}

.stats--red .stat dd {
  align-items: flex-end;
}

.stats--blue .stat dd {
  align-items: flex-start;
}

.duration__ms,
.duration__ms-only {
  font-size: 0.75rem;
  color: #888;
}

.indicator-col--red .duration__human {
  color: #ef5350;
}

.indicator-col--blue .duration__human {
  color: #42a5f5;
}

#indicator.indicator {
  grid-column: 2;
  grid-row: 2;
  justify-self: center;
  width: 120px;
  height: 120px;
  border: 2px solid #333;
  border-radius: 4px;
  transition: background-color 0.15s ease;
}

.indicator--red {
  background-color: #c62828;
}

.indicator--blue {
  background-color: #1565c0;
}

.controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
}

#switch {
  padding: 0.75rem 2.5rem;
  font-size: 1rem;
  cursor: pointer;
  background: transparent;
  color: #fff;
  border: 1px solid #666;
  border-radius: 4px;
}

#switch:hover:not(:disabled) {
  border-color: #aaa;
  background: #111;
}

#switch:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.status {
  margin: 0;
  font-size: 0.8rem;
  color: #666;
  text-align: center;
}

/* Auth bar — fixed top-left, out of the way of the centered game. */
.auth-bar {
  position: fixed;
  top: 1.25rem;
  left: 1.25rem;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.5rem;
  width: 11rem;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  width: 100%;
}

.auth-form__actions {
  display: flex;
  gap: 0.4rem;
}

.auth-form input {
  width: 100%;
  padding: 0.4rem 0.6rem;
  font-size: 0.85rem;
  background: #111;
  color: #e0e0e0;
  border: 1px solid #333;
  border-radius: 4px;
}

.auth-form input:focus {
  outline: none;
  border-color: #666;
}

.auth-form button,
.auth-account button {
  flex: 1;
  padding: 0.4rem 0.5rem;
  font-size: 0.8rem;
  cursor: pointer;
  background: transparent;
  color: #ccc;
  border: 1px solid #444;
  border-radius: 4px;
}

.auth-form button:hover,
.auth-account button:hover {
  border-color: #888;
  color: #fff;
}

.auth-account {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.8rem;
  color: #888;
}

.auth-account span {
  flex: 1;
  min-width: 0;
}

.auth-account button {
  flex: 0 0 auto;
  white-space: nowrap;
}

.auth-error {
  margin: 0;
  font-size: 0.75rem;
  color: #ef5350;
}

.auth-error:empty {
  display: none;
}

/* Side panels — fixed to the top corners, understated. */
.side-panel {
  position: fixed;
  top: 1.25rem;
  z-index: 10;
  width: 11rem;
}

/* Your stats sits in the top-left, just below the auth bar. */
.side-panel--left {
  left: 1.25rem;
  top: 5.5rem;
}

/* Leaderboard in the top-right corner. */
.side-panel--right {
  right: 1.25rem;
}

.side-panel__heading {
  margin: 0 0 0.75rem;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #888;
}

.player-stats__grid {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin: 0;
}

.player-stats .stat {
  margin: 0;
}

.player-stats .stat dd {
  align-items: flex-start;
  color: #e0e0e0;
}

/* Leaderboard tabs */
/* Active player count */
.leaderboard__active {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0 0 0.75rem;
  font-size: 0.75rem;
  color: #999;
}

.leaderboard__active-dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: #4caf50;
  box-shadow: 0 0 0 0 rgba(76, 175, 80, 0.6);
  animation: active-pulse 2s ease-out infinite;
}

#active-players-count {
  color: #ddd;
  font-weight: 600;
}

@keyframes active-pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(76, 175, 80, 0.5);
  }
  70% {
    box-shadow: 0 0 0 0.35rem rgba(76, 175, 80, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(76, 175, 80, 0);
  }
}

.leaderboard__tabs {
  display: flex;
  gap: 0.25rem;
  margin-bottom: 0.75rem;
}

.leaderboard__tab {
  flex: 1;
  padding: 0.3rem 0.2rem;
  font-size: 0.72rem;
  cursor: pointer;
  background: transparent;
  color: #777;
  border: 1px solid transparent;
  border-bottom-color: #2a2a2a;
  border-radius: 4px 4px 0 0;
}

.leaderboard__tab:hover {
  color: #ccc;
}

.leaderboard__tab.is-active {
  color: #fff;
  border-color: #3a3a3a;
  border-bottom-color: transparent;
}

.leaderboard__tab--red.is-active {
  color: #ef5350;
}

.leaderboard__tab--blue.is-active {
  color: #42a5f5;
}

/* Leaderboard list */
.leaderboard__list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.leaderboard__list li {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}

.leaderboard__rank {
  width: 1.25rem;
  flex-shrink: 0;
  text-align: right;
  color: #666;
}

.leaderboard__name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #ccc;
}

.leaderboard__count {
  flex-shrink: 0;
  color: #888;
}

.leaderboard__list li.is-you .leaderboard__name {
  color: #fff;
  font-weight: 600;
}

.leaderboard__empty,
.leaderboard__you {
  margin: 0.6rem 0 0;
  font-size: 0.8rem;
  color: #888;
}

.leaderboard__you {
  color: #ccc;
  border-top: 1px solid #222;
  padding-top: 0.55rem;
}

/* On narrow screens, drop the fixed side panels back into normal flow. */
/* Global chat — fixed to the bottom-center, understated like the side panels. */
.chat {
  position: fixed;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  width: min(92vw, 34rem);
  padding: 1rem;
  background: rgba(17, 17, 17, 0.85);
  border: 1px solid #333;
  border-radius: 6px;
  backdrop-filter: blur(4px);
}

.chat__heading {
  margin: 0;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #888;
}

.chat__log {
  list-style: none;
  margin: 0;
  padding: 0;
  height: 13rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.85rem;
}

.chat__msg {
  line-height: 1.3;
  word-break: break-word;
}

.chat__name {
  font-weight: 600;
  color: #9ecbff;
  margin-right: 0.4rem;
}

/* The signed-in user's own name stands out in green. */
.chat__name--me {
  color: #66bb6a;
}

.chat__name::after {
  content: ":";
  color: #666;
}

.chat__text {
  color: #e0e0e0;
}

.chat__form {
  display: flex;
  gap: 0.4rem;
}

.chat__form input {
  flex: 1;
  min-width: 0;
  padding: 0.4rem 0.6rem;
  font-size: 0.85rem;
  background: #111;
  color: #e0e0e0;
  border: 1px solid #333;
  border-radius: 4px;
}

.chat__form input:focus {
  outline: none;
  border-color: #666;
}

.chat__form input:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Rate-limit state: red "Slow down" placeholder shown in-place. */
.chat__form input.chat-input--cooldown {
  opacity: 1;
  color: #ef5350;
  border-color: #ef5350;
}

.chat__form input.chat-input--cooldown::placeholder {
  color: #ef5350;
  opacity: 1;
}

.chat__form button {
  flex: 0 0 auto;
  padding: 0.4rem 0.8rem;
  font-size: 0.8rem;
  cursor: pointer;
  background: transparent;
  color: #ccc;
  border: 1px solid #444;
  border-radius: 4px;
}

.chat__form button:hover:not(:disabled) {
  border-color: #888;
  color: #fff;
}

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

@media (max-width: 768px) {
  .stage {
    min-height: auto;
    padding: 2rem 1.5rem 1.5rem;
  }

  .auth-bar,
  .side-panel {
    position: static;
    transform: none;
    width: min(100%, 20rem);
    margin: 1rem auto 0;
  }

  .chat {
    position: static;
    transform: none;
    width: min(100%, 20rem);
    margin: 1rem auto 1.5rem;
  }

  .auth-bar {
    align-items: center;
  }

  .side-panel {
    margin-bottom: 1.5rem;
  }

  .player-stats__grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(7rem, 1fr));
    gap: 0.75rem;
  }
}

@media (max-width: 480px) {
  .indicator-row {
    column-gap: 0.75rem;
  }

  #indicator.indicator {
    width: 96px;
    height: 96px;
  }

  .stat dd {
    font-size: 0.9rem;
  }
}
