:root {
  color-scheme: dark;
  --bg: #060914;
  --bg-soft: #0c1222;
  --panel: rgba(18, 27, 48, 0.82);
  --panel-strong: rgba(24, 35, 61, 0.95);
  --line: rgba(148, 163, 184, 0.2);
  --text: #e5edf8;
  --muted: #95a3ba;
  --soft: #64748b;
  --accent: #7dd3fc;
  --accent-strong: #38bdf8;
  --gold: #f8d66d;
  --danger: #fb7185;
  --ok: #6ee7b7;
  --shadow: 0 26px 80px rgba(0, 0, 0, 0.42);
  --radius-lg: 28px;
  --radius-md: 18px;
  --radius-sm: 12px;
  font-family:
    "Inter", "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", system-ui,
    sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background:
    radial-gradient(circle at top left, rgba(56, 189, 248, 0.2), transparent 32rem),
    radial-gradient(circle at bottom right, rgba(124, 58, 237, 0.18), transparent 34rem),
    var(--bg);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.04) 0 1px, transparent 1px) 0 0 /
      36px 36px,
    transparent;
}

button,
select,
input {
  font: inherit;
}

button {
  color: inherit;
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 36px 0 56px;
}

.hero,
.control-panel,
.game-panel,
.leaderboard-section,
.result-card {
  border: 1px solid var(--line);
  background: linear-gradient(145deg, rgba(18, 27, 48, 0.92), rgba(9, 14, 27, 0.86));
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.hero {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 24px;
  align-items: center;
  padding: 34px;
  border-radius: var(--radius-lg);
}

.eyebrow,
.section-kicker,
.result-badge {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 10px;
  font-size: clamp(2.2rem, 6vw, 5.2rem);
  line-height: 0.95;
  letter-spacing: -0.08em;
}

h2 {
  margin-bottom: 0;
  font-size: clamp(1.35rem, 3vw, 2.1rem);
  letter-spacing: -0.04em;
}

h3 {
  margin-bottom: 14px;
  font-size: 1rem;
}

.hero-copy {
  max-width: 620px;
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.8;
}

.hero-card {
  width: min(280px, 100%);
  padding: 20px;
  border: 1px solid rgba(125, 211, 252, 0.24);
  border-radius: var(--radius-md);
  background: rgba(8, 13, 26, 0.66);
}

.hero-card span,
.hero-card small,
.stat-card span,
.field span {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
}

.hero-card strong {
  display: block;
  margin: 8px 0;
  color: var(--gold);
}

main {
  display: grid;
  gap: 22px;
  margin-top: 22px;
}

.control-panel,
.game-panel,
.leaderboard-section {
  padding: 24px;
  border-radius: var(--radius-lg);
}

.mode-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin: 22px 0;
}

.mode-card,
.stat-card,
.leaderboard-list li {
  border: 1px solid var(--line);
  background: rgba(8, 13, 26, 0.58);
}

.mode-card {
  min-height: 136px;
  padding: 18px;
  border-radius: var(--radius-md);
  text-align: left;
  cursor: pointer;
  transition:
    transform 160ms ease,
    border-color 160ms ease,
    background 160ms ease;
}

.mode-card:hover,
.mode-card:focus-visible,
.tab-button:hover,
.tab-button:focus-visible,
.primary-button:focus-visible,
.ghost-button:focus-visible,
.tower:focus-visible,
.disk:focus-visible,
.icon-button:focus-visible {
  outline: 3px solid rgba(125, 211, 252, 0.34);
  outline-offset: 3px;
}

.mode-card:hover {
  transform: translateY(-2px);
}

.mode-card.is-active {
  border-color: rgba(125, 211, 252, 0.72);
  background: linear-gradient(145deg, rgba(14, 116, 144, 0.35), rgba(8, 13, 26, 0.72));
}

.mode-card span {
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.mode-card strong {
  display: block;
  margin: 10px 0 8px;
  font-size: 1.18rem;
}

.mode-card small {
  color: var(--muted);
  line-height: 1.6;
}

.setup-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: end;
}

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

select,
input {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text);
  background: rgba(8, 13, 26, 0.9);
  padding: 0 14px;
}

select:disabled {
  color: var(--soft);
  cursor: not-allowed;
}

.primary-button,
.ghost-button,
.tab-button,
.icon-button {
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  transition:
    transform 160ms ease,
    filter 160ms ease,
    background 160ms ease;
}

.primary-button,
.ghost-button {
  min-height: 44px;
  padding: 0 18px;
  font-weight: 800;
}

.primary-button {
  color: #03121d;
  background: linear-gradient(135deg, var(--accent), var(--ok));
}

.ghost-button {
  border: 1px solid var(--line);
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
}

.primary-button:hover,
.ghost-button:hover,
.tab-button:hover,
.icon-button:hover {
  transform: translateY(-1px);
  filter: brightness(1.08);
}

.primary-button:disabled,
.ghost-button:disabled {
  opacity: 0.55;
  cursor: wait;
  transform: none;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 14px;
}

.stat-card {
  padding: 18px;
  border-radius: var(--radius-md);
}

.stat-card strong {
  display: block;
  margin-top: 8px;
  font-size: clamp(1.4rem, 3vw, 2.1rem);
  letter-spacing: -0.04em;
}

.board-heading,
.leaderboard-top {
  display: flex;
  gap: 18px;
  align-items: end;
  justify-content: space-between;
}

.message {
  max-width: 480px;
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.7;
  text-align: right;
}

.message.is-error {
  color: var(--danger);
}

.message.is-ok {
  color: var(--ok);
}

.board {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
  margin-top: 24px;
}

.tower {
  position: relative;
  display: grid;
  min-height: 390px;
  padding: 22px 14px 18px;
  border: 1px solid rgba(148, 163, 184, 0.18);
  border-radius: 24px;
  background:
    radial-gradient(circle at center bottom, rgba(125, 211, 252, 0.13), transparent 45%),
    rgba(8, 13, 26, 0.54);
  cursor: pointer;
  overflow: hidden;
}

.tower::after {
  content: "";
  position: absolute;
  left: 9%;
  right: 9%;
  bottom: 48px;
  height: 12px;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(100, 116, 139, 0.8), rgba(226, 232, 240, 0.24));
}

.tower.is-selected {
  border-color: var(--gold);
  box-shadow: 0 0 0 1px rgba(248, 214, 109, 0.3), 0 0 36px rgba(248, 214, 109, 0.12);
}

.tower.is-target {
  background:
    radial-gradient(circle at center bottom, rgba(110, 231, 183, 0.13), transparent 45%),
    rgba(8, 13, 26, 0.54);
}

.tower.is-drop-ready {
  border-color: var(--ok);
}

.tower.is-invalid {
  animation: shake 220ms ease-in-out;
}

.peg {
  position: absolute;
  left: calc(50% - 6px);
  bottom: 48px;
  width: 12px;
  height: calc(100% - 92px);
  border-radius: 999px 999px 0 0;
  background: linear-gradient(180deg, rgba(226, 232, 240, 0.36), rgba(71, 85, 105, 0.64));
}

.stack {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column-reverse;
  align-items: center;
  justify-content: flex-start;
  align-self: end;
  gap: 8px;
  min-height: 290px;
  padding-bottom: 40px;
}

.disk {
  display: grid;
  place-items: center;
  min-width: 54px;
  height: clamp(28px, 6.4vw, 42px);
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 999px;
  color: #03121d;
  font-weight: 900;
  cursor: grab;
  box-shadow:
    inset 0 8px 16px rgba(255, 255, 255, 0.2),
    inset 0 -10px 18px rgba(15, 23, 42, 0.16),
    0 10px 26px rgba(0, 0, 0, 0.28);
}

.disk:active {
  cursor: grabbing;
}

.disk[aria-disabled="true"] {
  cursor: default;
}

.disk[data-disk="1"] {
  background: linear-gradient(135deg, #c4b5fd, #7dd3fc);
}

.disk[data-disk="2"] {
  background: linear-gradient(135deg, #93c5fd, #6ee7b7);
}

.disk[data-disk="3"] {
  background: linear-gradient(135deg, #fcd34d, #fb923c);
}

.disk[data-disk="4"] {
  background: linear-gradient(135deg, #f0abfc, #fb7185);
}

.disk[data-disk="5"] {
  background: linear-gradient(135deg, #a7f3d0, #22d3ee);
}

.disk[data-disk="6"] {
  background: linear-gradient(135deg, #fde68a, #f472b6);
}

.disk[data-disk="7"] {
  background: linear-gradient(135deg, #bfdbfe, #a78bfa);
}

.tower-label {
  position: absolute;
  z-index: 3;
  left: 0;
  right: 0;
  bottom: 14px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
  text-align: center;
}

.leaderboard-section {
  display: grid;
  gap: 18px;
}

.leaderboard-tabs {
  display: flex;
  gap: 8px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(8, 13, 26, 0.58);
}

.tab-button {
  padding: 9px 14px;
  color: var(--muted);
  background: transparent;
  font-size: 0.9rem;
  font-weight: 800;
}

.tab-button.is-active {
  color: #03121d;
  background: var(--accent);
}

.leaderboard-list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.leaderboard-list li {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 14px;
  border-radius: var(--radius-md);
}

.leaderboard-rank {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  color: #03121d;
  background: var(--gold);
  font-weight: 900;
}

.leaderboard-player strong,
.leaderboard-player small,
.leaderboard-score strong,
.leaderboard-score small {
  display: block;
}

.leaderboard-player strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leaderboard-player small,
.leaderboard-score small,
.leaderboard-state,
.submit-state {
  color: var(--muted);
  font-size: 0.84rem;
}

.leaderboard-score {
  text-align: right;
}

.leaderboard-score strong {
  color: var(--ok);
}

.leaderboard-state {
  margin: 0;
}

.result-modal[hidden] {
  display: none;
}

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

.modal-backdrop {
  position: absolute;
  inset: 0;
  border: 0;
  background: rgba(2, 6, 23, 0.78);
  cursor: pointer;
}

.result-card {
  position: relative;
  z-index: 1;
  width: min(620px, 100%);
  max-height: min(900px, calc(100vh - 40px));
  overflow: auto;
  padding: 28px;
  border-radius: var(--radius-lg);
}

.icon-button {
  position: absolute;
  top: 18px;
  right: 18px;
  width: 38px;
  height: 38px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.06);
  font-size: 1.5rem;
  line-height: 1;
}

.result-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin: 20px 0;
}

.result-stats div {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: rgba(8, 13, 26, 0.62);
}

.result-stats span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
}

.result-stats strong {
  display: block;
  margin-top: 6px;
  font-size: 1.35rem;
}

.nickname-field {
  margin-bottom: 14px;
}

.nickname-field input {
  width: 100%;
}

.result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}

.modal-leaderboard {
  margin-top: 18px;
}

.compact li {
  grid-template-columns: 40px minmax(0, 1fr) auto;
  padding: 11px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-6px);
  }
  75% {
    transform: translateX(6px);
  }
}

@media (max-width: 900px) {
  .hero,
  .board-heading,
  .leaderboard-top {
    grid-template-columns: 1fr;
  }

  .hero {
    display: grid;
  }

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

  .board {
    gap: 10px;
  }

  .tower {
    min-height: 340px;
    padding-inline: 8px;
  }

  .message {
    text-align: left;
  }
}

@media (max-width: 640px) {
  .app-shell {
    width: min(100% - 20px, 1180px);
    padding-top: 18px;
  }

  .hero,
  .control-panel,
  .game-panel,
  .leaderboard-section,
  .result-card {
    border-radius: 20px;
    padding: 18px;
  }

  .mode-grid,
  .status-grid {
    grid-template-columns: 1fr;
  }

  .setup-row,
  .result-actions {
    align-items: stretch;
    flex-direction: column;
  }

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

  .tower {
    min-height: 240px;
  }

  .stack {
    min-height: 154px;
  }

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

  .leaderboard-list li {
    grid-template-columns: 38px minmax(0, 1fr);
  }

  .leaderboard-score {
    grid-column: 2;
    text-align: left;
  }
}

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