:root {
  --bg: #f5f3ee;
  --surface: #ffffff;
  --ink: #111111;
  --text: #111111;
  --muted: #55534e;
  --faint: #8d8a83;
  --line: #e2dfd7;
  --yellow: #ffd60a;
  --yellow-soft: #fff3b0;
  --green: #22c55e;
  --red: #ff3b30;
  --blue: #2b59ff;
  --shadow: 6px 6px 0 var(--ink);
  --shadow-sm: 3px 3px 0 var(--ink);
  --topbar: 64px;
  --radius: 18px;
  --pop: cubic-bezier(0.34, 1.56, 0.64, 1);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121212;
    --surface: #1c1c1c;
    --ink: #f2f0ea;
    --text: #f2f0ea;
    --muted: #b3b0a8;
    --faint: #7c7972;
    --line: #2e2e2c;
    --yellow-soft: #3a3210;
    color-scheme: dark;
  }
}

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

kbd {
  display: inline-grid;
  place-items: center;
  min-width: 24px;
  height: 24px;
  padding: 0 6px;
  font: 700 12px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--text);
  background: var(--surface);
  border: 2px solid var(--ink);
  border-radius: 6px;
  box-shadow: 2px 2px 0 var(--ink);
}

@keyframes bump {
  0% {
    transform: scale(1);
  }
  40% {
    transform: scale(1.35);
  }
  100% {
    transform: scale(1);
  }
}

.bump {
  display: inline-block;
  animation: bump 0.35s var(--pop);
}

/* ---------- top bar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  height: var(--topbar);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 24px;
  background: var(--bg);
  border-bottom: 2px solid var(--ink);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: inherit;
  text-decoration: none;
  min-width: 0;
}

.logo {
  display: block;
  border-radius: 7px;
  box-shadow: 0 0 0 2px var(--ink);
}

.wordmark {
  font-weight: 800;
  font-size: 19px;
  letter-spacing: -0.04em;
}

.tag {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
}

.live {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  padding: 6px 12px;
  background: var(--surface);
  border: 2px solid var(--ink);
  border-radius: 999px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.live b {
  color: var(--text);
  font-weight: 800;
}

.live-label {
  font-weight: 800;
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 11px;
}

.live .sep {
  color: var(--faint);
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--green);
  animation: blink 1.6s steps(2, jump-none) infinite;
}

.live[data-state='connecting'] .dot {
  background: var(--faint);
  animation: none;
}

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

/* ---------- layout ---------- */

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  max-width: 1440px;
  margin: 0 auto;
}

.stage {
  padding: 44px 48px 32px;
  min-width: 0;
}

/* ---------- intro ---------- */

.intro {
  text-align: center;
  max-width: 760px;
  margin: 0 auto 40px;
}

h1 {
  margin: 0;
  font-size: clamp(40px, 6vw, 76px);
  line-height: 1.08;
  font-weight: 800;
  letter-spacing: -0.05em;
}

h1 .nowrap {
  white-space: nowrap;
}

h1 mark {
  display: inline-block;
  line-height: 1;
  color: #111;
  background: var(--yellow);
  padding: 0.02em 0.12em 0.1em;
  border-radius: 0.12em;
  transform: rotate(-2deg);
}

.sub {
  margin: 18px auto 0;
  font-size: 17px;
  font-weight: 500;
  color: var(--muted);
  max-width: 520px;
}

/* ---------- arena ---------- */

.arena {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: stretch;
  gap: 18px;
  max-width: 980px;
  margin: 0 auto;
}

.vs {
  align-self: center;
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--ink);
  color: var(--bg);
  font-weight: 900;
  font-size: 15px;
  letter-spacing: 0.02em;
  transform: rotate(-8deg);
}

.card {
  --card-bg: var(--surface);
  --card-ink: var(--text);
  --card-muted: var(--muted);
  appearance: none;
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 300px;
  padding: 26px;
  font: inherit;
  text-align: left;
  cursor: pointer;
  color: var(--card-ink);
  background: var(--card-bg);
  border: 2.5px solid var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition:
    transform 0.14s ease,
    box-shadow 0.14s ease,
    background-color 0.12s ease,
    opacity 0.25s ease;
  -webkit-tap-highlight-color: transparent;
}

.card:hover:not(:disabled) {
  transform: translate(-2px, -2px);
  box-shadow: 8px 8px 0 var(--ink);
}

.card:active:not(:disabled) {
  transform: translate(4px, 4px);
  box-shadow: 2px 2px 0 var(--ink);
}

.card:focus-visible {
  outline: 3px solid var(--blue);
  outline-offset: 4px;
}

.card:disabled {
  cursor: default;
}

.card.picked {
  --card-bg: var(--yellow);
  --card-ink: #111;
  --card-muted: #3a3a36;
  transform: translate(3px, 3px);
  box-shadow: 3px 3px 0 var(--ink);
}

.card.dropped {
  transform: scale(0.97);
  box-shadow: 3px 3px 0 var(--ink);
}

.card.dropped .card-top,
.card.dropped .card-name,
.card.dropped .card-desc,
.card.dropped .hint {
  opacity: 0.35;
  transition: opacity 0.2s ease;
}

.card.leaving {
  opacity: 0;
  transform: translateY(8px) scale(0.97);
}

.card.enter {
  animation: enter 0.4s var(--pop) both;
}

#card-1.enter {
  animation-delay: 0.05s;
}

@keyframes enter {
  from {
    opacity: 0;
    transform: translateY(14px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.pill {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--card-ink);
  padding: 4px 10px;
  border: 2px solid var(--card-ink);
  border-radius: 999px;
  white-space: nowrap;
}

.card-name {
  margin: 6px 0 0;
  font-size: clamp(26px, 2.6vw, 34px);
  line-height: 1.05;
  font-weight: 800;
  letter-spacing: -0.04em;
  overflow-wrap: anywhere;
}

.card-desc {
  margin: 0;
  flex: 1;
  font-size: 15.5px;
  line-height: 1.55;
  color: var(--card-muted);
}

.card-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 46px;
  padding-top: 14px;
  border-top: 2px solid var(--card-ink);
  font-size: 14px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.hint {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.delta {
  font-weight: 900;
  font-size: 18px;
  letter-spacing: -0.02em;
  color: #111;
  padding: 3px 12px;
  border: 2px solid #111;
  border-radius: 999px;
  opacity: 0;
  transform: scale(0.4) rotate(-10deg);
  transition:
    opacity 0.15s ease,
    transform 0.4s var(--pop);
  white-space: nowrap;
}

.delta.show {
  opacity: 1;
  transform: rotate(-4deg);
}

.delta.up {
  background: var(--green);
}

.delta.down {
  background: var(--red);
  color: #fff;
}

/* skeleton */
.card.loading::before,
.card.loading::after {
  content: '';
  display: block;
  border-radius: 10px;
  background: var(--line);
  animation: fade 1s ease-in-out infinite alternate;
}

.card.loading::before {
  width: 52px;
  height: 52px;
  border-radius: 12px;
}

.card.loading::after {
  width: 70%;
  height: 30px;
  margin-top: 10px;
}

@keyframes fade {
  to {
    opacity: 0.4;
  }
}

/* avatary: płaskie kolory */
.avatar {
  display: grid;
  place-items: center;
  flex: none;
  width: 52px;
  height: 52px;
  border-radius: 12px;
  border: 2px solid var(--ink);
  background: var(--c, var(--yellow));
  color: var(--fg, #111);
  font-weight: 800;
  font-size: 17px;
  letter-spacing: -0.02em;
}

.avatar.sm {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  font-size: 11.5px;
}

/* ---------- controls ---------- */

.controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  flex-wrap: wrap;
  max-width: 980px;
  margin: 26px auto 0;
}

.ghost {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font: inherit;
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  padding: 8px 16px;
  border-radius: 999px;
  border: 2px solid var(--ink);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition:
    transform 0.12s ease,
    box-shadow 0.12s ease;
}

.ghost:hover {
  transform: translate(-1px, -1px);
  box-shadow: 4px 4px 0 var(--ink);
}

.ghost:active {
  transform: translate(3px, 3px);
  box-shadow: 0 0 0 var(--ink);
}

.ghost:focus-visible {
  outline: 3px solid var(--blue);
  outline-offset: 3px;
}

.ghost kbd {
  box-shadow: none;
}

.me {
  margin: 0;
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.me b {
  color: var(--text);
  font-weight: 800;
}

.to-board {
  display: none;
  font-size: 15px;
  font-weight: 800;
  color: var(--text);
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
}

/* ---------- feed ---------- */

.feed {
  max-width: 980px;
  margin: 44px auto 0;
}

.feed h2,
.board-head h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.feed ol {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
}

.feed li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 0;
  font-size: 14px;
  color: var(--muted);
  border-bottom: 2px solid var(--line);
  animation: slideIn 0.3s var(--pop) both;
  min-width: 0;
}

.feed li b {
  color: var(--text);
  font-weight: 700;
}

.feed .what {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.feed .d {
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: #111;
  background: var(--green);
  padding: 1px 8px;
  border-radius: 999px;
}

.feed .fire {
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #111;
  background: var(--yellow);
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
}

.feed .feed-empty {
  color: var(--faint);
  animation: none;
}

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

.foot {
  max-width: 980px;
  margin: 40px auto 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px 24px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--faint);
}

.foot code {
  font: 12px ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--muted);
}

/* ---------- leaderboard ---------- */

.board {
  position: sticky;
  top: var(--topbar);
  height: calc(100vh - var(--topbar));
  height: calc(100dvh - var(--topbar));
  display: flex;
  flex-direction: column;
  border-left: 2px solid var(--ink);
  background: var(--surface);
}

.board-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 20px 22px 10px;
}

.board-meta {
  font-size: 12px;
  font-weight: 600;
  color: var(--faint);
}

.rows {
  list-style: none;
  margin: 0;
  padding: 0 10px 24px;
  overflow-y: auto;
  flex: 1;
  overscroll-behavior: contain;
}

.row {
  display: grid;
  grid-template-columns: 30px 32px minmax(0, 1fr) 30px 56px;
  align-items: center;
  gap: 10px;
  padding: 8px 12px 8px 8px;
  border-radius: 12px;
  transition:
    transform 0.5s var(--pop),
    background-color 0.2s ease;
}

.row.on-stage {
  background: var(--yellow-soft);
  box-shadow: inset 0 0 0 2px var(--ink);
}

.rank {
  justify-self: center;
  display: grid;
  place-items: center;
  min-width: 26px;
  height: 26px;
  font-size: 13px;
  font-weight: 800;
  color: var(--faint);
  font-variant-numeric: tabular-nums;
}

.row:nth-child(-n + 3) .rank {
  color: #111;
  border: 2px solid var(--ink);
  border-radius: 50%;
}

.row:nth-child(1) .rank {
  background: var(--yellow);
}

.row:nth-child(2) .rank {
  background: #d6d3cc;
}

.row:nth-child(3) .rank {
  background: #ffa36c;
}

.who {
  min-width: 0;
}

.who .name,
.who .cat {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.who .name {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.who .cat {
  font-size: 12px;
  color: var(--muted);
}

.move {
  font-size: 11px;
  font-weight: 800;
  text-align: right;
  font-variant-numeric: tabular-nums;
  opacity: 0;
  transition: opacity 0.4s ease;
}

.move.show {
  opacity: 1;
}

.move.up {
  color: var(--green);
}

.move.down {
  color: var(--red);
}

.score {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.rating {
  display: inline-block;
  font-size: 15px;
  font-weight: 800;
  padding: 0 4px;
  margin-right: -4px;
  border-radius: 5px;
}

.wl {
  display: block;
  font-size: 11px;
  color: var(--faint);
}

.rating.flash-up {
  animation: flashUp 1.1s ease;
}

.rating.flash-down {
  animation: flashDown 1.1s ease;
}

@keyframes flashUp {
  0%,
  35% {
    background: var(--green);
    color: #111;
  }
}

@keyframes flashDown {
  0%,
  35% {
    background: var(--red);
    color: #fff;
  }
}

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 20;
  transform: translate(-50%, 16px);
  opacity: 0;
  pointer-events: none;
  padding: 10px 16px;
  border-radius: 12px;
  border: 2px solid var(--ink);
  background: var(--yellow);
  color: #111;
  font-size: 14px;
  font-weight: 700;
  box-shadow: var(--shadow-sm);
  transition:
    opacity 0.15s ease,
    transform 0.3s var(--pop);
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------- responsive ---------- */

@media (max-width: 1100px) {
  .layout {
    grid-template-columns: minmax(0, 1fr) 330px;
  }
  .stage {
    padding: 40px 28px 28px;
  }
}

@media (max-width: 900px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
  }
  .board {
    position: static;
    height: auto;
    border-left: 0;
    border-top: 2px solid var(--ink);
    scroll-margin-top: var(--topbar);
  }
  .rows {
    overflow: visible;
  }
  .to-board {
    display: inline;
  }
}

@media (max-width: 640px) {
  .topbar {
    padding: 0 16px;
  }
  .tag,
  .hide-sm {
    display: none;
  }
  .stage {
    padding: 22px 16px 24px;
  }
  .intro {
    margin-bottom: 20px;
  }
  h1 {
    font-size: 38px;
  }
  .sub {
    display: none;
  }
  .arena {
    grid-template-columns: minmax(0, 1fr);
    gap: 0;
  }
  .vs {
    justify-self: center;
    margin: -10px 0;
    z-index: 1;
    width: 44px;
    height: 44px;
    font-size: 13px;
  }
  .card {
    min-height: 0;
    padding: 18px;
    gap: 10px;
    box-shadow: 4px 4px 0 var(--ink);
  }
  .card-name {
    font-size: 25px;
  }
  .card-desc {
    font-size: 14px;
  }
  .card-foot {
    min-height: 36px;
    padding-top: 10px;
  }
  .avatar {
    width: 42px;
    height: 42px;
    border-radius: 10px;
    font-size: 14px;
  }
  .board-head {
    padding: 20px 16px 10px;
  }
  .rows {
    padding: 0 6px 24px;
  }
}

@media (hover: none) {
  .kbd-only {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
