:root {
  --bg: #f1e4cf;
  --bg-top: #fbf4ea;
  --panel: rgba(255, 249, 242, 0.9);
  --panel-strong: rgba(255, 252, 247, 0.96);
  --ink: #1b1713;
  --muted: #7c7267;
  --line: rgba(27, 23, 19, 0.08);
  --accent: #e36d33;
  --accent-2: #f2b661;
  --green: #2a8e82;
  --shadow: 0 24px 56px rgba(71, 45, 19, 0.1);
  --pattern: url("/img/pattern-light.png");
  --texture: url("/img/texture-light.webp");
}

body[data-theme="dark"] {
  --bg: #161b22;
  --bg-top: #1f2730;
  --panel: rgba(31, 37, 46, 0.86);
  --panel-strong: rgba(35, 42, 52, 0.94);
  --ink: #f6f0e7;
  --muted: #b8b0a7;
  --line: rgba(246, 240, 231, 0.1);
  --accent: #ff8d54;
  --accent-2: #ffc56f;
  --green: #34a593;
  --shadow: 0 24px 56px rgba(0, 0, 0, 0.32);
  --pattern: url("/img/pattern-dark.png.png");
  --texture: url("/img/texture-dark.webp");
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Manrope", sans-serif;
  color: var(--ink);
  background:
    var(--pattern) 0 0 / 420px 420px repeat,
    var(--texture) 0 0 / 250px 250px repeat,
    radial-gradient(circle at top left, rgba(227, 109, 51, 0.12), transparent 24%),
    radial-gradient(circle at bottom right, rgba(42, 142, 130, 0.1), transparent 28%),
    linear-gradient(180deg, var(--bg-top) 0%, var(--bg) 100%);
}

button {
  font: inherit;
}

[hidden] {
  display: none !important;
}

.theme-toggle {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 40;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  color: var(--ink);
  box-shadow: var(--shadow);
  cursor: pointer;
  backdrop-filter: blur(14px);
}

.theme-toggle #theme-toggle-text {
  display: none !important;
}

.theme-toggle #theme-toggle-icon {
  display: inline-flex;
  width: 22px;
  height: 22px;
  flex: 0 0 22px;
}

.app-shell {
  width: min(1260px, calc(100% - 24px));
  margin: 0 auto;
  padding: 74px 0 24px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 220px;
  gap: 16px;
  align-items: center;
  padding: 16px 18px;
}

.auth-view {
  display: grid;
  gap: 14px;
}

.hero__copy {
  display: grid;
  gap: 10px;
}

.hero h1 {
  margin: 0;
  font-family: "Rubik Mono One", sans-serif;
  font-size: clamp(2rem, 4.4vw, 3.6rem);
  line-height: 0.95;
  letter-spacing: -0.03em;
}

.hero-note,
.controls-card p,
.bonus-card p {
  color: var(--muted);
  line-height: 1.5;
}

.eyebrow,
.panel__kicker {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 0.72rem;
  font-weight: 800;
  color: var(--green);
}

h2,
p {
  margin: 0;
}

.hero__chips,
.hero__aside,
.arena-head,
.panel__head {
  display: flex;
  align-items: center;
  gap: 10px;
}

.hero__chips {
  flex-wrap: wrap;
}

.hero__chips span,
.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  background: rgba(23, 20, 17, 0.06);
  font-size: 0.88rem;
  font-weight: 800;
}

.hero__aside {
  justify-content: flex-end;
}

.ghost-link,
.ghost-button,
.primary-button,
.accent-button,
.icon-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 46px;
  padding: 0 16px;
  border-radius: 16px;
  font-weight: 800;
  text-decoration: none;
  cursor: pointer;
}

.ghost-link,
.ghost-button,
.icon-chip {
  border: 1px solid var(--line);
  background: rgba(27, 23, 19, 0.05);
  color: var(--ink);
}

.ghost-link__icon {
  width: 18px;
  height: 18px;
}

.ghost-link__icon svg,
#theme-toggle-icon svg {
  width: 100%;
  height: 100%;
}

.primary-button {
  border: none;
  background: linear-gradient(135deg, var(--accent), #ff9a56);
  color: #fffaf2;
}

.accent-button {
  border: none;
  background: linear-gradient(135deg, var(--green), #3cb5a3);
  color: #f8fffd;
}

.icon-chip {
  width: 44px;
  min-width: 44px;
  height: 44px;
  min-height: 44px;
  padding: 0;
  border-radius: 14px;
}

.icon-chip svg {
  width: 20px;
  height: 20px;
}

.auth-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.panel--inner,
.auth-card {
  display: grid;
  gap: 14px;
  align-content: start;
}

.auth-card {
  min-height: 290px;
  padding: 18px;
}

.leaderboard-card {
  margin-top: 12px;
  padding: 18px;
}

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

.leaderboard-card__head h2 {
  margin: 0;
  font-size: clamp(1.35rem, 1.7vw, 1.75rem);
  line-height: 1;
}

.leaderboard-card__badge {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 141, 84, 0.12);
  color: var(--accent-strong);
  font-size: 0.82rem;
  font-weight: 900;
}

.leaderboard-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.leaderboard-row {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-height: 58px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.56);
}

.leaderboard-row__place {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), #ffd36f);
  color: #201813;
  font-weight: 950;
}

.leaderboard-row__meta {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.leaderboard-row__meta strong,
.leaderboard-row__meta span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leaderboard-row__meta strong {
  color: var(--ink);
  font-size: 0.98rem;
}

.leaderboard-row__meta span,
.leaderboard-empty {
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.4;
}

.leaderboard-row__score {
  min-width: 74px;
  text-align: right;
  color: var(--ink);
  font-size: 1.18rem;
  font-weight: 950;
}

.leaderboard-empty {
  margin: 0;
  padding: 12px;
  border: 1px dashed var(--line);
  border-radius: 14px;
}

.auth-card__head {
  display: grid;
  gap: 8px;
}

.auth-card__head h2 {
  margin: 0;
  font-size: clamp(1.55rem, 2vw, 2rem);
  line-height: 1;
}

.auth-card__head p:last-child,
.auth-status {
  color: var(--muted);
  line-height: 1.5;
}

.field {
  display: grid;
  gap: 8px;
}

.field span {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.62);
  color: var(--ink);
  font: inherit;
}

select {
  width: 100%;
  min-height: 48px;
  padding: 12px 38px 12px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.62);
  color: var(--ink);
  font: inherit;
  font-weight: 800;
  appearance: none;
}

.auth-card > button {
  align-self: end;
  width: 100%;
  margin-top: auto;
}

.game-view {
  display: grid;
  gap: 12px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
}

.topbar > div:first-child {
  display: grid;
  gap: 6px;
}

.topbar__line,
.topbar__actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.topbar__line h2 {
  margin: 0;
  font-size: clamp(1.55rem, 1.8vw, 2rem);
  line-height: 1;
}

.topbar__note {
  color: var(--muted);
  line-height: 1.45;
}

.code-chip {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(27, 23, 19, 0.05);
  font-weight: 900;
}

.topbar__actions .primary-button,
.topbar__actions .ghost-button {
  min-width: 112px;
}

.topbar__actions .primary-button:disabled {
  opacity: 0.5;
  cursor: default;
}

.game-layout {
  display: grid;
  grid-template-columns: 258px minmax(560px, 1fr) 258px;
  gap: 12px;
  align-items: start;
  margin-top: 12px;
}

.side-panel,
.arena-panel {
  padding: 14px;
}

.side-panel {
  display: grid;
  gap: 12px;
  align-content: start;
}

.arena-head,
.panel__head {
  justify-content: space-between;
  margin-bottom: 12px;
}

.arena-head h2,
.panel__head h2 {
  font-size: clamp(1.2rem, 1.7vw, 1.55rem);
  line-height: 1;
}

.stats-grid,
.bonus-list {
  display: grid;
  gap: 10px;
}

.stat-box,
.controls-card,
.bonus-card,
.opponent-card {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.45);
}

.stat-box,
.controls-card,
.opponent-card {
  padding: 12px;
}

.stat-box {
  display: grid;
  gap: 6px;
}

.stat-box--progress {
  gap: 8px;
}

.level-progress {
  width: 100%;
  height: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(32, 24, 19, 0.1);
}

.level-progress span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), #ffd36f);
  transition: width 0.22s ease;
}

.stat-box span {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
}

.stat-box strong {
  font-size: 1.45rem;
  line-height: 1;
}

.board-wrap {
  position: relative;
  display: grid;
  place-items: center;
}

.match-board {
  --cell: min(7.2vw, 58px);
  display: grid;
  grid-template-columns: repeat(8, var(--cell));
  grid-template-rows: repeat(8, var(--cell));
  gap: 5px;
  width: fit-content;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background:
    linear-gradient(180deg, rgba(18, 23, 29, 0.94), rgba(11, 15, 20, 0.96)),
    rgba(12, 17, 22, 0.92);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
  touch-action: none;
}

.gem {
  position: relative;
  display: grid;
  place-items: center;
  width: var(--cell);
  height: var(--cell);
  border: 0;
  border-radius: 12px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.045), rgba(255, 255, 255, 0.015)),
    rgba(255, 255, 255, 0.02);
  padding: 0;
  filter: drop-shadow(0 8px 4px rgba(0, 0, 0, 0.28));
  cursor: pointer;
  transform: translateY(0) scale(1);
  transition: transform 0.18s cubic-bezier(0.2, 0.8, 0.2, 1), filter 0.16s ease, box-shadow 0.16s ease, opacity 0.16s ease, background 0.16s ease;
  will-change: transform, opacity;
  user-select: none;
}

.gem::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: var(--gem-width, 78%);
  height: var(--gem-height, 78%);
  border-radius: var(--gem-radius, 18px);
  background:
    radial-gradient(circle at 31% 22%, rgba(255, 255, 255, 0.9) 0 11%, transparent 12%),
    linear-gradient(135deg, rgba(255, 255, 255, 0.58) 0 22%, transparent 23% 100%),
    linear-gradient(215deg, rgba(255, 255, 255, 0.36) 0 22%, transparent 23% 100%),
    linear-gradient(320deg, rgba(0, 0, 0, 0.2) 0 24%, transparent 25% 100%),
    var(--gem-fill);
  clip-path: var(--gem-shape);
  transform: translate(-50%, -50%);
  box-shadow:
    inset 0 2px 2px rgba(255, 255, 255, 0.56),
    inset 0 -10px 13px rgba(0, 0, 0, 0.2),
    inset -5px -5px 9px rgba(0, 0, 0, 0.12),
    inset 7px 7px 10px rgba(255, 255, 255, 0.17);
}

.gem::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: var(--gem-width, 78%);
  height: var(--gem-height, 78%);
  border-radius: var(--gem-radius, 18px);
  background:
    linear-gradient(90deg, transparent 0 48%, rgba(255, 255, 255, 0.24) 49% 51%, transparent 52% 100%),
    linear-gradient(145deg, transparent 0 46%, rgba(255, 255, 255, 0.2) 47% 49%, transparent 50% 100%),
    radial-gradient(circle at 24% 18%, rgba(255, 255, 255, 0.48) 0 8%, transparent 9%);
  clip-path: var(--gem-shape);
  transform: translate(-50%, -50%);
  opacity: 0.82;
  pointer-events: none;
}

.gem .gem-selection {
  display: none;
}

.gem:hover {
  transform: translateY(-2px) scale(1.02);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.13), rgba(255, 255, 255, 0.045)),
    rgba(255, 255, 255, 0.055);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.14),
    0 8px 18px rgba(0, 0, 0, 0.18);
  filter: brightness(1.05);
}

.gem.is-selected {
  border-radius: 12px;
  background:
    linear-gradient(180deg, rgba(255, 248, 215, 0.32), rgba(255, 197, 80, 0.14)),
    rgba(255, 255, 255, 0.1);
  box-shadow:
    inset 0 0 0 2px rgba(255, 246, 201, 0.92),
    inset 0 0 0 5px rgba(255, 178, 65, 0.24),
    0 0 0 1px rgba(255, 199, 91, 0.36),
    0 0 20px rgba(255, 190, 72, 0.4);
  filter:
    drop-shadow(0 10px 7px rgba(0, 0, 0, 0.34))
    brightness(1.08);
}

.gem.is-bomb::before {
  width: 58%;
  height: 58%;
  border-radius: 999px;
  clip-path: none;
  background:
    radial-gradient(circle at 33% 24%, rgba(255, 255, 255, 0.78) 0 12%, transparent 13%),
    radial-gradient(circle at 68% 28%, rgba(255, 255, 255, 0.2) 0 12%, transparent 13%),
    radial-gradient(circle at 38% 25%, #fff9dc 0 16%, #ffe36b 17% 30%, #ff7d35 31% 56%, #8d39ff 57% 78%, #25106c 79% 100%);
  box-shadow:
    inset 7px 8px 10px rgba(255, 255, 255, 0.2),
    inset -9px -12px 14px rgba(38, 9, 83, 0.48),
    0 0 0 3px rgba(255, 231, 130, 0.88),
    0 0 18px rgba(255, 126, 49, 0.5),
    0 0 28px rgba(141, 57, 255, 0.32);
}

.gem.is-bomb::after {
  width: 34%;
  height: 34%;
  left: 59%;
  top: 22%;
  border-radius: 999px;
  clip-path: none;
  background:
    radial-gradient(circle at 92% 15%, #fff4ba 0 7%, #ffcf3a 8% 15%, transparent 16%),
    linear-gradient(135deg, transparent 0 34%, #ffe45d 35% 43%, transparent 44% 100%),
    radial-gradient(ellipse at 28% 66%, transparent 0 42%, #2b1629 43% 55%, transparent 56% 100%);
  opacity: 1;
}

.gem.is-bomb {
  background:
    radial-gradient(circle at 50% 48%, rgba(255, 226, 94, 0.24), rgba(141, 57, 255, 0.14) 58%, rgba(255, 255, 255, 0.04) 100%),
    rgba(255, 255, 255, 0.08);
  box-shadow:
    inset 0 0 0 2px rgba(255, 230, 130, 0.78),
    inset 0 0 0 5px rgba(141, 57, 255, 0.14),
    0 0 20px rgba(255, 126, 49, 0.32),
    0 0 28px rgba(141, 57, 255, 0.18);
}

.gem.is-rocket {
  background:
    radial-gradient(circle at 50% 48%, rgba(255, 209, 74, 0.22), rgba(218, 31, 56, 0.14) 58%, rgba(255, 255, 255, 0.04) 100%),
    rgba(255, 255, 255, 0.08);
  box-shadow:
    inset 0 0 0 2px rgba(255, 236, 178, 0.76),
    inset 0 0 0 5px rgba(255, 82, 48, 0.13),
    0 0 18px rgba(255, 137, 47, 0.3),
    0 0 26px rgba(218, 31, 56, 0.18);
}

.gem.is-rocket::before {
  width: 54%;
  height: 68%;
  top: 45%;
  border-radius: 999px 999px 16px 16px;
  clip-path: polygon(50% 0%, 84% 20%, 86% 68%, 100% 86%, 76% 82%, 64% 100%, 36% 100%, 24% 82%, 0% 86%, 14% 68%, 16% 20%);
  background:
    radial-gradient(circle at 34% 18%, rgba(255, 255, 255, 0.9) 0 11%, transparent 12%),
    linear-gradient(125deg, rgba(255, 255, 255, 0.68) 0 18%, transparent 19% 100%),
    linear-gradient(140deg, #fff4f5 0 22%, #ff7880 23% 50%, #df2338 51% 74%, #6a111b 75% 100%);
  box-shadow:
    inset 8px 9px 10px rgba(255, 255, 255, 0.28),
    inset -9px -12px 13px rgba(78, 8, 22, 0.42),
    0 0 0 3px rgba(255, 240, 240, 0.66),
    0 0 16px rgba(255, 122, 52, 0.36);
}

.gem.is-rocket::after {
  width: 24%;
  height: 24%;
  left: 50%;
  top: 79%;
  border-radius: 0 0 999px 999px;
  clip-path: polygon(50% 100%, 100% 0%, 67% 8%, 50% 0%, 33% 8%, 0% 0%);
  background:
    linear-gradient(180deg, #fff4a8 0%, #ff9a2f 48%, #e02c1f 100%);
  opacity: 1;
}

.gem.is-rocket-flying {
  z-index: 8;
  pointer-events: none;
  animation: rocket-flight 0.32s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
}

.gem.is-rocket-target {
  background:
    linear-gradient(90deg, rgba(84, 179, 255, 0.12), rgba(255, 231, 122, 0.24), rgba(84, 179, 255, 0.12)),
    rgba(255, 255, 255, 0.08);
  box-shadow:
    inset 0 0 0 2px rgba(255, 229, 116, 0.5),
    0 0 14px rgba(255, 205, 83, 0.26);
}

.gem.is-bomb-target {
  background:
    radial-gradient(circle at 50% 50%, rgba(255, 91, 62, 0.26), rgba(255, 189, 64, 0.1) 58%, rgba(255, 255, 255, 0.04) 100%),
    rgba(255, 255, 255, 0.08);
  box-shadow:
    inset 0 0 0 2px rgba(255, 124, 75, 0.62),
    inset 0 0 18px rgba(255, 189, 64, 0.16),
    0 0 16px rgba(255, 94, 51, 0.28);
}

.gem.is-dragging {
  z-index: 5;
  pointer-events: none;
  transform: translate(var(--drag-x, 0), var(--drag-y, 0)) scale(1.06);
  filter: drop-shadow(0 17px 13px rgba(0, 0, 0, 0.42)) brightness(1.12);
  box-shadow: none;
}

.gem.is-swapping {
  z-index: 4;
  transition-duration: 0.2s;
  transform: translate(var(--swap-x, 0), var(--swap-y, 0)) scale(1.04);
}

.gem.is-clearing {
  animation: gem-clear 0.24s ease forwards;
}

.gem.is-dropping {
  animation: gem-drop 0.2s cubic-bezier(0.16, 1, 0.3, 1) both;
  animation-delay: var(--drop-delay, 0ms);
}

.gem.is-new {
  animation: gem-new 0.2s cubic-bezier(0.16, 1, 0.3, 1) both;
  animation-delay: var(--drop-delay, 0ms);
}

.gem--0 {
  --gem-fill: conic-gradient(from 25deg at 50% 50%, #ff9b9b 0 14%, #e93041 15% 34%, #a51627 35% 50%, #ff5f63 51% 68%, #c71e32 69% 84%, #ffdbd7 85% 100%);
  --gem-shape: polygon(50% 2%, 94% 26%, 86% 82%, 62% 98%, 38% 98%, 14% 82%, 6% 26%);
}

.gem--1 {
  --gem-fill: conic-gradient(from 28deg at 50% 50%, #fff09b 0 14%, #ffc326 15% 34%, #d9900f 35% 49%, #ffe066 50% 68%, #eca20f 69% 84%, #fff8c4 85% 100%);
  --gem-shape: polygon(20% 2%, 80% 2%, 98% 20%, 98% 80%, 80% 98%, 20% 98%, 2% 80%, 2% 20%);
  --gem-radius: 13px;
}

.gem--2 {
  --gem-fill: conic-gradient(from 15deg at 50% 50%, #94ffc0 0 13%, #10bd4f 14% 34%, #047c31 35% 50%, #39df76 51% 68%, #09953c 69% 84%, #ddffee 85% 100%);
  --gem-shape: polygon(50% 2%, 94% 30%, 88% 70%, 62% 98%, 38% 98%, 12% 70%, 6% 30%);
  --gem-radius: 999px;
}

.gem--3 {
  --gem-fill: conic-gradient(from 20deg at 50% 50%, #9feaff 0 13%, #118eff 14% 34%, #083fc2 35% 50%, #27c9ff 51% 68%, #0d62dd 69% 84%, #e3fbff 85% 100%);
  --gem-shape: polygon(50% 0%, 88% 14%, 98% 42%, 74% 86%, 50% 100%, 26% 86%, 2% 42%, 12% 14%);
  --gem-radius: 7px 7px 18px 18px;
}

.gem--4 {
  --gem-fill: conic-gradient(from 35deg at 48% 48%, #ffd8ff 0 12%, #c63cff 13% 28%, #7a139f 29% 44%, #ef7bff 45% 61%, #a51ed6 62% 80%, #fff0ff 81% 100%);
  --gem-shape: polygon(50% 0%, 76% 8%, 96% 30%, 96% 70%, 76% 92%, 50% 100%, 24% 92%, 4% 70%, 4% 30%, 24% 8%);
  --gem-radius: 999px;
}

.gem--5 {
  --gem-fill: conic-gradient(from 35deg at 50% 42%, #ffe0ef 0 14%, #ff2f9f 15% 35%, #a40046 36% 50%, #ff7fbd 51% 68%, #d4146d 69% 84%, #fff5fa 85% 100%);
  --gem-shape: polygon(16% 4%, 84% 4%, 100% 30%, 50% 98%, 0% 30%);
  --gem-radius: 6px;
}

.gem--6 {
  --gem-fill: conic-gradient(from 18deg at 50% 48%, #ffe7bd 0 12%, #ff9b2f 13% 30%, #a64c00 31% 48%, #ffc45f 49% 66%, #d96c08 67% 84%, #fff7e8 85% 100%);
  --gem-shape: polygon(50% 0%, 92% 22%, 78% 76%, 50% 100%, 22% 76%, 8% 22%);
  --gem-radius: 999px;
}

@keyframes gem-clear {
  0% {
    opacity: 1;
    transform: scale(1);
  }

  45% {
    opacity: 1;
    transform: scale(1.12);
    filter: brightness(1.18);
  }

  100% {
    opacity: 0;
    transform: scale(0.2) rotate(14deg);
  }
}

@keyframes gem-drop {
  0% {
    opacity: 0.78;
    transform: translateY(calc(var(--drop-distance, 1) * -1 * (var(--cell) + 5px)));
  }

  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes gem-new {
  0% {
    opacity: 0;
    transform: translateY(calc(var(--drop-distance, 1) * -1 * (var(--cell) + 5px)));
  }

  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes rocket-flight {
  0% {
    opacity: 1;
    transform: translate(0, 0) rotate(var(--rocket-rotation, 0deg)) scale(1);
  }

  72% {
    opacity: 1;
    transform: translate(var(--rocket-flight-x, 0px), var(--rocket-flight-y, 0px)) rotate(var(--rocket-rotation, 0deg)) scale(1.08);
  }

  100% {
    opacity: 0;
    transform: translate(var(--rocket-flight-x, 0px), var(--rocket-flight-y, 0px)) rotate(var(--rocket-rotation, 0deg)) scale(0.9);
  }
}

.overlay-banner {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  text-align: center;
  border-radius: 24px;
  background: linear-gradient(180deg, rgba(16, 21, 27, 0.34), rgba(16, 21, 27, 0.72));
  color: #fff5e9;
  font-family: "Rubik Mono One", sans-serif;
  font-size: clamp(1rem, 2vw, 1.5rem);
  line-height: 1.1;
  pointer-events: none;
}

.bonus-card {
  display: grid;
  grid-template-columns: 44px 1fr;
  gap: 12px;
  align-items: center;
  padding: 12px;
}

.bonus-card strong {
  display: block;
  margin-bottom: 4px;
}

.opponent-card {
  display: grid;
  gap: 10px;
}

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

.opponent-row span {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

.bonus-gem {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: linear-gradient(135deg, #ffd45f, #e5a92c);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35), 0 10px 18px rgba(0, 0, 0, 0.12);
}

.bonus-gem--line { background: linear-gradient(135deg, #5aa4ff, #3b63d8); }
.bonus-gem--burst { background: linear-gradient(135deg, #9a78ff, #6a48db); }
.bonus-gem--cascade { background: linear-gradient(135deg, #49d0b2, #249f8c); }

.players-list {
  display: grid;
  gap: 10px;
}

.player-row {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.45);
}

.player-row--self {
  border-color: rgba(227, 109, 51, 0.42);
  background: linear-gradient(135deg, rgba(255, 243, 218, 0.82), rgba(255, 255, 255, 0.42));
}

.player-row__place {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 12px;
  background: rgba(27, 23, 19, 0.08);
  font-weight: 900;
}

.player-row__meta {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.player-row__meta strong,
.player-row__meta span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.player-row__meta span,
.player-row__score span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.player-row__score {
  display: grid;
  gap: 2px;
  text-align: right;
}

.player-row__score strong {
  font-size: 1.12rem;
  line-height: 1;
}

.modal[hidden] {
  display: none;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 18px;
}

.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(11, 15, 20, 0.58);
  backdrop-filter: blur(10px);
}

.modal__card {
  position: relative;
  z-index: 1;
  width: min(620px, 100%);
  max-height: min(760px, calc(100vh - 36px));
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--panel-strong);
  box-shadow: var(--shadow);
}

.modal__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.modal__head h3 {
  margin: 4px 0 0;
  font-size: 1.35rem;
  line-height: 1;
}

.modal__body {
  display: grid;
  gap: 12px;
  padding: 16px;
}

.modal__body p,
.help-list {
  color: var(--muted);
  line-height: 1.5;
}

.help-intro,
.help-section,
.help-rule {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.45);
}

.help-intro,
.help-rule {
  display: grid;
  gap: 6px;
  padding: 12px;
}

.help-section summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 46px;
  padding: 0 14px;
  font-weight: 900;
  cursor: pointer;
}

.help-section summary::-webkit-details-marker {
  display: none;
}

.help-section summary::after {
  content: "+";
  color: var(--green);
  font-weight: 900;
}

.help-section[open] summary::after {
  content: "-";
}

.help-section__content {
  display: grid;
  gap: 10px;
  padding: 0 12px 12px;
}

.help-list {
  margin: 0;
  padding-left: 20px;
  display: grid;
  gap: 8px;
}

body[data-theme="dark"] .stat-box,
body[data-theme="dark"] .controls-card,
body[data-theme="dark"] .bonus-card,
body[data-theme="dark"] .opponent-card,
body[data-theme="dark"] .player-row,
body[data-theme="dark"] .leaderboard-card__badge,
body[data-theme="dark"] .leaderboard-row,
body[data-theme="dark"] .leaderboard-empty,
body[data-theme="dark"] .help-intro,
body[data-theme="dark"] .help-section,
body[data-theme="dark"] .help-rule,
body[data-theme="dark"] input,
body[data-theme="dark"] select,
body[data-theme="dark"] .ghost-link,
body[data-theme="dark"] .ghost-button,
body[data-theme="dark"] .icon-chip,
body[data-theme="dark"] .code-chip,
body[data-theme="dark"] .status-pill,
body[data-theme="dark"] .hero__chips span {
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(246, 240, 231, 0.1);
  color: #f6f0e7;
}

body[data-theme="dark"] .player-row--self {
  background: linear-gradient(135deg, rgba(255, 141, 84, 0.18), rgba(255, 255, 255, 0.06));
  border-color: rgba(255, 141, 84, 0.38);
}

body[data-theme="dark"] .modal__card {
  background: var(--panel-strong);
  border-color: rgba(246, 240, 231, 0.1);
}

body[data-theme="dark"] .modal__body p,
body[data-theme="dark"] .help-list,
body[data-theme="dark"] .leaderboard-row__meta span,
body[data-theme="dark"] .leaderboard-empty,
body[data-theme="dark"] .player-row__meta span,
body[data-theme="dark"] .player-row__score span {
  color: #b8b0a7;
}

body[data-theme="dark"] .leaderboard-row__meta strong,
body[data-theme="dark"] .leaderboard-row__score {
  color: #f6f0e7;
}

body[data-theme="dark"] .level-progress {
  background: rgba(255, 255, 255, 0.1);
}

@media (max-width: 1080px) {
  .hero,
  .auth-grid,
  .game-layout {
    grid-template-columns: 1fr;
  }

  .hero__aside {
    justify-content: flex-start;
  }

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

  .leaderboard-list {
    grid-template-columns: 1fr;
  }

  .match-board {
    --cell: min(10vw, 56px);
  }
}

@media (max-width: 720px) {
  .theme-toggle {
    top: 12px;
    right: 12px;
  }

  .app-shell {
    width: min(100% - 16px, 1260px);
    padding-top: 72px;
  }

  .hero,
  .topbar,
  .side-panel,
  .arena-panel {
    padding: 16px;
  }

  .topbar {
    display: grid;
  }

  .topbar__actions > * {
    flex: 1 1 0;
  }

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

  .match-board {
    --cell: min(9.5vw, 44px);
    gap: 5px;
    padding: 8px;
  }

  .gem {
    border-radius: 12px;
  }
}
