:root {
  --bg-1: #f5f1e7;
  --bg-2: #cde7e2;
  --bg-3: #f1caa8;
  --panel: rgba(255, 255, 255, 0.86);
  --panel-border: rgba(17, 38, 35, 0.12);
  --text: #13201f;
  --muted: #50635f;
  --accent: #e76f51;
  --accent-dark: #ba4428;
  --ok: #189d72;
  --warn: #eb7b2d;
  --danger: #c13f3f;
  --shadow: 0 24px 50px rgba(16, 44, 39, 0.14);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: 'Chivo', sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 85% 12%, rgba(235, 123, 45, 0.35), transparent 30%),
    radial-gradient(circle at 15% 88%, rgba(24, 157, 114, 0.3), transparent 32%),
    linear-gradient(145deg, var(--bg-1), var(--bg-2) 50%, var(--bg-3));
}

body.room-page {
  transition: background 420ms ease, color 220ms ease;
}

body.room-page.results-finalized {
  background:
    radial-gradient(circle at 14% 20%, rgba(227, 47, 72, 0.26), transparent 35%),
    radial-gradient(circle at 82% 16%, rgba(24, 157, 114, 0.28), transparent 38%),
    linear-gradient(155deg, #fff5df, #f7e7bd 42%, #d8f2ea);
}

.shell {
  width: min(1080px, calc(100% - 2rem));
  margin: 2rem auto 3rem;
  display: grid;
  gap: 1.1rem;
}

.hero-card,
.panel,
.banner,
.room-header {
  border: 1px solid var(--panel-border);
  border-radius: 20px;
  background: var(--panel);
  backdrop-filter: blur(4px);
  box-shadow: var(--shadow);
}

.hero-card,
.panel,
.room-header {
  padding: 1.1rem 1.25rem;
}

.kicker {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0.2rem 0 0.6rem;
  line-height: 1.15;
}

h1 {
  font-size: clamp(1.8rem, 4vw, 2.8rem);
}

h2 {
  font-size: clamp(1.2rem, 2.5vw, 1.5rem);
}

p {
  margin: 0.35rem 0;
}

.muted {
  color: var(--muted);
}

.panel-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

.layout-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.room-shell {
  gap: 0.85rem;
}

.room-header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
}

.header-actions,
.hero-actions,
.row-group {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
}

label {
  display: block;
  font-weight: 700;
  font-size: 0.95rem;
  margin-bottom: 0.3rem;
}

input {
  width: 100%;
  border: 1px solid rgba(19, 32, 31, 0.2);
  border-radius: 12px;
  padding: 0.7rem 0.75rem;
  font-size: 1rem;
  font-family: inherit;
  background: #fffdf8;
  color: var(--text);
}

form {
  display: grid;
  gap: 0.6rem;
}

.button {
  border: 1px solid rgba(22, 39, 36, 0.25);
  border-radius: 12px;
  background: #fffaf0;
  color: var(--text);
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0.65rem 0.9rem;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 120ms ease, background 120ms ease, border-color 120ms ease;
}

.button:hover {
  transform: translateY(-1px);
  border-color: rgba(19, 32, 31, 0.45);
}

.button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.button.primary {
  background: linear-gradient(145deg, #ff8f63, var(--accent));
  color: #fff;
  border-color: rgba(136, 40, 15, 0.5);
}

.button.primary:hover {
  background: linear-gradient(145deg, #ff7c49, var(--accent-dark));
}

.button.subtle {
  background: rgba(248, 243, 233, 0.7);
}

.banner {
  padding: 0.65rem 0.9rem;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.9rem;
}

.banner.info {
  border-left: 4px solid var(--ok);
}

.banner.warn {
  border-left: 4px solid var(--warn);
}

.banner.error {
  border-left: 4px solid var(--danger);
}

.error {
  min-height: 1.2em;
  color: var(--danger);
  font-size: 0.95rem;
}

.players-list {
  list-style: none;
  padding: 0;
  margin: 0.8rem 0 0;
  display: grid;
  gap: 0.45rem;
}

.players-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border: 1px solid rgba(22, 39, 36, 0.14);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.72);
  padding: 0.5rem 0.65rem;
}

.players-list .status {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.players-list .status.ready,
.players-list .status.finished {
  color: var(--ok);
}

.players-list .status.started {
  color: var(--warn);
}

.players-list .status.forfeited {
  color: var(--danger);
}

.game-panel {
  position: relative;
  overflow: hidden;
}

body.room-page.run-focus .room-header,
body.room-page.run-focus #status-banner,
body.room-page.run-focus #join-panel,
body.room-page.run-focus .layout-grid > article:first-child,
body.room-page.run-focus #leaderboard-panel {
  display: none !important;
}

body.room-page.run-focus .shell {
  width: min(1180px, calc(100% - 1rem));
  margin: 0.5rem auto;
  gap: 0.6rem;
}

body.room-page.run-focus .layout-grid {
  grid-template-columns: 1fr;
}

body.room-page.run-focus #game-panel {
  min-height: calc(100vh - 1rem);
  display: grid;
  align-content: start;
}

body.room-page.run-focus #game-panel .reaction-button {
  min-height: calc(100vh - 245px);
}

.game-panel.miss-flash {
  animation: missFlash 280ms ease;
}

.timer {
  font-size: clamp(1.4rem, 3.8vw, 2.3rem);
  margin: 0.3rem 0;
  font-family: 'IBM Plex Mono', monospace;
}

.reaction-button {
  width: 100%;
  min-height: 230px;
  border: 2px solid rgba(20, 37, 35, 0.28);
  border-radius: 18px;
  font-size: clamp(1.6rem, 6vw, 3rem);
  font-weight: 900;
  letter-spacing: 0.08em;
  color: #fff;
  cursor: pointer;
  background: linear-gradient(160deg, #2e8f6c, #197a5a);
  transition: transform 120ms ease, filter 100ms ease;
}

.reaction-button:hover {
  transform: scale(1.01);
}

.reaction-button:disabled {
  opacity: 1;
  cursor: default;
}

.reaction-button.red {
  background: linear-gradient(145deg, #e32f48, #b8112c);
  animation: pulse 220ms linear infinite;
}

.reaction-button.done {
  background: linear-gradient(145deg, #5f6f86, #46586d);
}

.reaction-button.miss {
  background: linear-gradient(145deg, #45b083, #2b8d66);
  animation: pulse 180ms linear 2;
}

@keyframes pulse {
  from {
    filter: brightness(1);
  }
  to {
    filter: brightness(1.13);
  }
}

@keyframes missFlash {
  from {
    box-shadow: inset 0 0 0 0 rgba(24, 157, 114, 0.55);
  }
  to {
    box-shadow: inset 0 0 0 8px rgba(24, 157, 114, 0);
  }
}

#reaction-status {
  min-height: 1.1em;
  margin-top: 0.5rem;
  text-align: center;
  font-size: 0.74rem;
  letter-spacing: 0.03em;
  font-family: 'IBM Plex Mono', monospace;
}

.leaderboard-panel {
  overflow: hidden;
  transition: transform 360ms ease, box-shadow 360ms ease, border-color 320ms ease;
}

body.room-page.results-finalized .leaderboard-panel {
  transform: translateY(-5px);
  box-shadow: 0 28px 62px rgba(36, 64, 58, 0.24);
  border-color: rgba(15, 88, 66, 0.24);
}

.leaderboard-heading {
  display: flex;
  gap: 0.7rem;
  justify-content: space-between;
  align-items: baseline;
  flex-wrap: wrap;
}

.results-stage {
  margin-top: 0.35rem;
}

.results-pending {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.9rem;
  border: 1px dashed rgba(19, 32, 31, 0.25);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.55);
}

.pulse-dot {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--warn);
  box-shadow: 0 0 0 0 rgba(235, 123, 45, 0.65);
  animation: waitingPulse 1.2s ease-out infinite;
}

@keyframes waitingPulse {
  0% {
    box-shadow: 0 0 0 0 rgba(235, 123, 45, 0.5);
  }
  70% {
    box-shadow: 0 0 0 11px rgba(235, 123, 45, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(235, 123, 45, 0);
  }
}

.results-final {
  display: grid;
  gap: 0.9rem;
}

.results-hero {
  padding: 0.9rem 1rem;
  border: 1px solid rgba(26, 65, 58, 0.17);
  border-radius: 14px;
  background: linear-gradient(130deg, rgba(255, 255, 255, 0.95), rgba(243, 253, 248, 0.92));
  animation: resultsReveal 360ms ease;
}

.results-hero h3 {
  margin: 0.16rem 0 0.42rem;
  font-size: clamp(1.18rem, 2.3vw, 1.55rem);
}

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

.leaderboard-cards {
  display: grid;
  gap: 0.85rem;
}

.result-empty {
  margin: 0;
  padding: 0.95rem;
  border-radius: 12px;
  border: 1px dashed rgba(19, 32, 31, 0.22);
  background: rgba(255, 255, 255, 0.58);
}

.leaderboard-card {
  border: 1px solid rgba(21, 46, 42, 0.2);
  border-radius: 16px;
  padding: 0.8rem;
  background: rgba(255, 255, 255, 0.78);
  display: grid;
  gap: 0.68rem;
}

.leaderboard-card.leader {
  border-color: rgba(231, 111, 81, 0.62);
  background: linear-gradient(128deg, rgba(255, 249, 240, 0.95), rgba(255, 238, 212, 0.82));
}

.leaderboard-card.forfeited {
  border-color: rgba(193, 63, 63, 0.35);
}

.leaderboard-card.unranked .rank-chip {
  border-style: dashed;
}

.leaderboard-card-head {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.65rem;
}

.rank-chip {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.86rem;
  font-weight: 700;
  border: 1px solid rgba(19, 32, 31, 0.35);
  border-radius: 999px;
  padding: 0.18rem 0.48rem;
  min-width: 2.4rem;
  text-align: center;
  background: rgba(255, 255, 255, 0.75);
}

.leaderboard-card-head h3 {
  margin: 0;
  font-size: clamp(1rem, 2vw, 1.2rem);
}

.totals {
  display: grid;
  gap: 0.16rem;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.78rem;
  text-align: right;
}

.card-chart {
  border: 1px solid rgba(19, 32, 31, 0.13);
  border-radius: 12px;
  padding: 0.55rem 0.62rem;
  background: rgba(254, 255, 255, 0.65);
}

.hbar-chart {
  display: grid;
  gap: 0.42rem;
}

.hbar-axis {
  display: flex;
  justify-content: space-between;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.72rem;
  color: var(--muted);
}

.hbar-rows {
  display: grid;
  gap: 0.32rem;
}

.hbar-row {
  display: grid;
  grid-template-columns: 2.2rem 1fr 4.8rem;
  gap: 0.45rem;
  align-items: center;
}

.hbar-label {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.75rem;
  color: var(--muted);
}

.hbar-track {
  height: 9px;
  border-radius: 999px;
  position: relative;
  background:
    linear-gradient(
      to right,
      rgba(20, 37, 35, 0.06) 0,
      rgba(20, 37, 35, 0.06) calc(50% - 1px),
      rgba(20, 37, 35, 0.18) calc(50% - 1px),
      rgba(20, 37, 35, 0.18) calc(50% + 1px),
      rgba(20, 37, 35, 0.06) calc(50% + 1px),
      rgba(20, 37, 35, 0.06) 100%
    );
  border: 1px solid rgba(19, 32, 31, 0.12);
}

.hbar-fill {
  display: block;
  height: 100%;
  border-radius: 999px;
  width: 0;
}

.hbar-fill.hit {
  background: linear-gradient(90deg, #14a174, #1fbe87);
}

.hbar-fill.miss {
  background: linear-gradient(90deg, #c13f3f, #ec8d6a);
}

.hbar-fill.pending {
  background: transparent;
}

.hbar-value {
  text-align: right;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.74rem;
}

.card-foot {
  display: flex;
  gap: 0.7rem;
  flex-wrap: wrap;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.76rem;
}

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

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  text-align: left;
  padding: 0.55rem 0.35rem;
  border-bottom: 1px solid rgba(19, 32, 31, 0.12);
  font-size: 0.92rem;
}

th {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
}

.hidden {
  display: none !important;
}

.docs-shell {
  width: min(760px, calc(100% - 2rem));
}

.docs-links {
  margin: 0.7rem 0;
  padding-left: 1.2rem;
}

@media (max-width: 860px) {
  .panel-grid,
  .layout-grid {
    grid-template-columns: 1fr;
  }

  .room-header {
    flex-direction: column;
  }

  .reaction-button {
    min-height: 180px;
  }

  .leaderboard-card-head {
    grid-template-columns: auto 1fr;
  }

  .totals {
    grid-column: 1 / -1;
    text-align: left;
  }

  .hbar-row {
    grid-template-columns: 2rem 1fr 4.2rem;
  }
}
