:root {
  color-scheme: dark;
  --bg: #080a12;
  --bg-deep: #090b14;
  --panel: rgba(20, 23, 37, 0.72);
  --panel-strong: rgba(24, 28, 45, 0.92);
  --line: rgba(255, 255, 255, 0.1);
  --text: #f5f6fb;
  --muted: #979caf;
  --accent: #67e8e3;
  --accent-strong: #70e5df;
  --purple: #9a7cff;
  --pink: #f17ebc;
  --warn: #ffd166;
  --danger: #ff6b7a;
  --red: #ff5f7e;
  --blue: #5db9ff;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.34);
  --radius-lg: 28px;
  --radius-md: 18px;
  --radius-sm: 12px;
  font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans SC", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  color: var(--text);
  background:
    radial-gradient(circle at 50% -15%, rgba(122, 94, 239, 0.14), transparent 36rem),
    radial-gradient(circle at 78% 8%, rgba(103, 232, 227, 0.08), transparent 28rem),
    linear-gradient(180deg, var(--bg-deep) 0%, var(--bg) 100%);
}

.ambient {
  position: fixed;
  z-index: -1;
  width: 28rem;
  height: 28rem;
  border-radius: 50%;
  filter: blur(100px);
  opacity: 0.11;
  pointer-events: none;
}

.ambient-one {
  top: 18%;
  left: -16rem;
  background: #755cff;
}

.ambient-two {
  right: -18rem;
  bottom: 12%;
  background: #38d8d0;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

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

button:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(114, 247, 211, 0.75);
  outline-offset: 3px;
}

[hidden] {
  display: none !important;
}

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

.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: linear-gradient(150deg, rgba(18, 31, 54, 0.82), rgba(9, 18, 34, 0.58));
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.hero {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  padding: clamp(22px, 4vw, 42px);
  margin-bottom: 24px;
}

.hero h1,
.section-heading h2,
.game-topline h2,
.modal-card h2 {
  margin: 0;
  letter-spacing: -0.04em;
}

.hero h1 {
  font-size: clamp(2.2rem, 6vw, 4.8rem);
}

.hero h1 span {
  color: transparent;
  background: linear-gradient(90deg, #ae8bff 0%, #f28ac0 54%, #70e5df 100%);
  -webkit-background-clip: text;
  background-clip: text;
}

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

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.hero-status {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: max-content;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: rgba(4, 9, 20, 0.38);
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--muted);
  box-shadow: 0 0 18px currentColor;
}

.status-pending {
  color: var(--warn);
  background: var(--warn);
}

.status-online {
  color: var(--accent);
  background: var(--accent);
}

.status-offline {
  color: var(--danger);
  background: var(--danger);
}

.main-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 24px;
}

.mode-panel,
.game-panel,
.leaderboard-panel {
  padding: clamp(18px, 3vw, 28px);
}

.section-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.section-heading h2,
.game-topline h2 {
  font-size: clamp(1.45rem, 3vw, 2.1rem);
}

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

.mode-card {
  min-height: 174px;
  position: relative;
  overflow: hidden;
  isolation: isolate;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 22px;
  color: var(--text);
  text-align: left;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.055), rgba(255, 255, 255, 0.018)),
    rgba(17, 20, 32, 0.86);
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.mode-card::before {
  content: "";
  position: absolute;
  inset: -30% -25% auto auto;
  z-index: -1;
  width: 190px;
  height: 190px;
  border-radius: 50%;
  opacity: 0.13;
  background: radial-gradient(circle, var(--accent), transparent 68%);
  transition: opacity 180ms ease;
}

.mode-card:hover,
.mode-card:focus-visible {
  transform: translateY(-6px);
  border-color: rgba(255, 255, 255, 0.22);
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.075), rgba(255, 255, 255, 0.022)),
    rgba(17, 20, 32, 0.92);
}

.mode-card:hover::before,
.mode-card:focus-visible::before {
  opacity: 0.25;
}

.mode-card strong {
  display: block;
  margin-bottom: 8px;
  font-size: 1.25rem;
}

.mode-card span {
  display: inline-flex;
  margin-bottom: 14px;
  padding: 4px 10px;
  border-radius: 999px;
  color: #06101f;
  font-size: 0.8rem;
  font-weight: 800;
  background: linear-gradient(90deg, var(--purple), var(--accent));
}

.mode-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.7;
}

.game-topline {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 20px;
}

.turn-hint {
  margin: 10px 0 0;
  color: var(--muted);
  line-height: 1.7;
}

.stat-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(76px, 1fr));
  gap: 10px;
}

.stat-strip div,
.result-stats div {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 16px;
  text-align: center;
  background: rgba(255, 255, 255, 0.045);
}

.stat-strip strong,
.result-stats strong {
  display: block;
  font-size: 1.35rem;
}

.stat-strip span,
.result-stats span {
  color: var(--muted);
  font-size: 0.82rem;
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(320px, 1fr) minmax(280px, 360px);
  gap: 22px;
}

.board-column {
  min-width: 0;
}

.board {
  display: grid;
  grid-template-columns: repeat(11, minmax(22px, 1fr));
  grid-template-rows: repeat(11, minmax(22px, 1fr));
  gap: clamp(3px, 0.6vw, 6px);
  width: min(100%, 680px);
  margin: 0 auto;
  aspect-ratio: 1;
  padding: clamp(8px, 1.5vw, 14px);
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 26px;
  background:
    radial-gradient(circle at center, rgba(114, 247, 211, 0.08), transparent 26%),
    rgba(0, 0, 0, 0.18);
}

.board-cell {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: clamp(8px, 1.2vw, 14px);
  background: rgba(255, 255, 255, 0.055);
}

.track-cell {
  background: rgba(255, 255, 255, 0.075);
}

.start-red {
  border-color: rgba(255, 95, 126, 0.8);
  box-shadow: inset 0 0 0 1px rgba(255, 95, 126, 0.36);
}

.start-blue {
  border-color: rgba(93, 185, 255, 0.8);
  box-shadow: inset 0 0 0 1px rgba(93, 185, 255, 0.36);
}

.jump-cell {
  border-color: rgba(255, 209, 102, 0.68);
}

.accelerate-cell {
  border-color: rgba(80, 220, 120, 0.68);
  background: rgba(80, 220, 120, 0.1);
}

.decelerate-cell {
  border-color: rgba(255, 140, 90, 0.68);
  background: rgba(255, 140, 90, 0.1);
}

.home-red {
  background: rgba(255, 95, 126, 0.13);
}

.home-blue {
  background: rgba(93, 185, 255, 0.13);
}

.base-zone {
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  border-style: dashed;
  background: rgba(255, 255, 255, 0.04);
}

.finish-zone {
  background: linear-gradient(145deg, rgba(114, 247, 211, 0.28), rgba(93, 185, 255, 0.18));
  border-color: rgba(114, 247, 211, 0.7);
}

.cell-label {
  position: absolute;
  left: 6px;
  top: 5px;
  color: rgba(238, 245, 255, 0.58);
  font-size: clamp(0.48rem, 1.15vw, 0.7rem);
  font-weight: 700;
  pointer-events: none;
}

.cell-mark {
  position: absolute;
  right: 6px;
  top: 4px;
  color: var(--warn);
  font-size: clamp(0.58rem, 1.4vw, 0.84rem);
  pointer-events: none;
}

.tokens {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: 100%;
  padding: 4px;
}

.token {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: clamp(18px, 3.8vw, 30px);
  height: clamp(18px, 3.8vw, 30px);
  border: 0;
  border-radius: 999px;
  color: #06101f;
  font-size: clamp(0.65rem, 1.7vw, 0.92rem);
  font-weight: 900;
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.28);
}

.token.red {
  background: linear-gradient(145deg, #ff9aae, var(--red));
}

.token.blue {
  background: linear-gradient(145deg, #9bd8ff, var(--blue));
}

.token.selectable {
  outline: 3px solid rgba(255, 255, 255, 0.88);
  outline-offset: 2px;
  transform: scale(1.05);
}

.board-legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 14px;
  margin-top: 14px;
  color: var(--muted);
  font-size: 0.9rem;
}

.board-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend-token {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

.legend-token.red {
  background: var(--red);
}

.legend-token.blue {
  background: var(--blue);
}

.legend-star {
  color: var(--warn);
  font-style: normal;
}

.control-column {
  display: grid;
  gap: 14px;
  align-content: start;
}

.dice-card,
.mini-panel {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.045);
}

.dice-card {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 18px;
}

.dice {
  display: grid;
  place-items: center;
  width: 84px;
  height: 84px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 24px;
  font-size: 2.5rem;
  font-weight: 900;
  background:
    radial-gradient(circle at 30% 25%, rgba(255, 255, 255, 0.22), transparent 22%),
    linear-gradient(145deg, rgba(114, 247, 211, 0.24), rgba(93, 185, 255, 0.1));
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.primary-button,
.ghost-button,
.piece-button,
.tab-button,
.icon-button {
  border: 1px solid transparent;
  border-radius: 999px;
  color: var(--text);
}

.primary-button {
  padding: 11px 18px;
  color: #031018;
  font-weight: 900;
  background: linear-gradient(145deg, var(--accent), #7fb4ff);
}

.ghost-button,
.piece-button,
.tab-button {
  padding: 10px 16px;
  border-color: var(--line);
  background: rgba(255, 255, 255, 0.055);
}

.ghost-button:hover,
.piece-button:hover,
.tab-button:hover,
.tab-button.active {
  border-color: rgba(114, 247, 211, 0.68);
  background: rgba(114, 247, 211, 0.12);
}

.mini-panel h3 {
  margin: 0 0 12px;
  font-size: 1rem;
}

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

.player-card {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(0, 0, 0, 0.14);
}

.player-card.active {
  border-color: rgba(114, 247, 211, 0.74);
  box-shadow: 0 0 24px rgba(114, 247, 211, 0.08);
}

.player-card strong {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.piece-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.82rem;
}

.piece-summary span {
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
}

.piece-actions {
  display: grid;
  gap: 8px;
}

.piece-button {
  width: 100%;
  text-align: left;
}

.shortcut-note,
.leaderboard-status,
.score-message {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.7;
}

.log-panel {
  max-height: 290px;
  overflow: auto;
}

.game-log {
  display: grid;
  gap: 8px;
  margin: 0;
  padding-left: 22px;
  color: var(--muted);
  line-height: 1.55;
}

.game-log li::marker {
  color: var(--accent);
}

.leaderboard-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}

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

.leaderboard-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.045);
}

.rank-badge {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  color: #06101f;
  font-weight: 900;
  background: var(--accent);
}

.leaderboard-item strong {
  display: block;
}

.leaderboard-item small {
  color: var(--muted);
}

.leaderboard-score {
  color: var(--accent);
  font-weight: 900;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(0, 0, 0, 0.62);
  backdrop-filter: blur(10px);
}

.modal-card {
  position: relative;
  width: min(520px, 100%);
  padding: clamp(22px, 4vw, 32px);
  border: 1px solid var(--line);
  border-radius: 28px;
  background: linear-gradient(150deg, rgba(19, 35, 61, 0.96), rgba(7, 15, 29, 0.96));
  box-shadow: var(--shadow);
}

.icon-button {
  position: absolute;
  top: 16px;
  right: 16px;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-color: var(--line);
  font-size: 1.45rem;
  background: rgba(255, 255, 255, 0.06);
}

.result-summary {
  margin: 10px 0 18px;
  color: var(--muted);
  line-height: 1.7;
}

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

.offline-notice {
  margin-bottom: 14px;
  padding: 12px 14px;
  border: 1px solid rgba(255, 107, 122, 0.38);
  border-radius: 14px;
  color: #ffd8dd;
  background: rgba(255, 107, 122, 0.12);
}

.nickname-field {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-weight: 700;
}

.nickname-field input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.065);
}

.modal-actions {
  margin-top: 16px;
}

.noscript {
  width: min(720px, calc(100% - 32px));
  margin: 20px auto;
  padding: 20px;
}

/* ===== Mobile-first responsive ===== */

@media (max-width: 900px) {
  .hero,
  .game-topline {
    display: grid;
  }

  .hero-status {
    width: fit-content;
  }

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

  .game-layout {
    grid-template-columns: 1fr;
  }

  .control-column {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 768px) {
  .page-shell {
    width: 100%;
    padding: 12px 0 32px;
  }

  .hero {
    padding: 16px;
    margin-bottom: 16px;
    border-radius: 16px;
  }

  .hero h1 {
    font-size: 1.8rem;
  }

  .hero-copy {
    font-size: 0.88rem;
    line-height: 1.6;
  }

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

  .mode-card {
    min-height: auto;
    padding: 16px;
  }

  .game-layout {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .board {
    width: 100%;
    grid-template-columns: repeat(11, minmax(0, 1fr));
    grid-template-rows: repeat(11, minmax(0, 1fr));
    gap: 2px;
    padding: 6px;
  }

  .board-cell {
    min-width: 0;
    min-height: 0;
    aspect-ratio: 1;
  }

  .cell-label {
    font-size: 0.42rem;
    left: 3px;
    top: 3px;
  }

  .cell-mark {
    font-size: 0.52rem;
    right: 3px;
    top: 2px;
  }

  .token {
    width: clamp(14px, 3.2vw, 22px);
    height: clamp(14px, 3.2vw, 22px);
    font-size: 0.58rem;
  }

  .tokens {
    gap: 2px;
    padding: 2px;
  }

  .dice-card {
    grid-template-columns: 1fr;
    gap: 14px;
    padding: 14px;
  }

  .dice {
    width: 80px;
    height: 80px;
    border-radius: 20px;
    font-size: 2.2rem;
  }

  .primary-button,
  .ghost-button {
    min-height: 44px;
    padding: 12px 20px;
    font-size: 1rem;
    border-radius: 12px;
  }

  .piece-button {
    min-height: 44px;
    padding: 12px 16px;
    font-size: 0.92rem;
  }

  .mini-panel {
    padding: 14px;
  }

  .mini-panel h3 {
    font-size: 0.95rem;
  }

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

  .stat-strip div,
  .result-stats div {
    padding: 8px 4px;
  }

  .stat-strip strong,
  .result-stats strong {
    font-size: 1.1rem;
  }

  .board-legend {
    gap: 10px;
    font-size: 0.78rem;
  }

  .log-panel {
    max-height: 200px;
  }

  .leaderboard-item {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .leaderboard-score {
    grid-column: 2;
  }

  .modal-card {
    padding: 18px;
  }

  .shortcut-note {
    display: none;
  }
}

@media (max-width: 375px) {
  .page-shell {
    padding: 8px 0 24px;
  }

  .hero {
    padding: 12px;
    margin-bottom: 12px;
    border-radius: 12px;
  }

  .hero h1 {
    font-size: 1.5rem;
  }

  .hero-copy {
    font-size: 0.82rem;
  }

  .board {
    gap: 1px;
    padding: 4px;
    border-radius: 16px;
  }

  .board-cell {
    border-radius: 4px;
  }

  .cell-label {
    font-size: 0.36rem;
  }

  .cell-mark {
    font-size: 0.44rem;
  }

  .token {
    width: clamp(10px, 3vw, 16px);
    height: clamp(10px, 3vw, 16px);
    font-size: 0.5rem;
  }

  .stat-strip strong,
  .result-stats strong {
    font-size: 0.95rem;
  }
}

/* ===== Rules panel & special cell legend ===== */
.rules-panel {
  padding: clamp(18px, 3vw, 28px);
}

.rules-content {
  color: var(--muted);
  line-height: 1.8;
}

.rules-content h3 {
  margin: 18px 0 8px;
  color: var(--text);
  font-size: 1.05rem;
}

.rules-content h3:first-child {
  margin-top: 0;
}

.rules-content ul {
  margin: 6px 0;
  padding-left: 20px;
}

.rules-content li {
  margin-bottom: 4px;
}

.rules-close-row {
  display: flex;
  justify-content: flex-end;
  margin-top: 18px;
}

.rules-note {
  margin-top: 8px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--muted);
  font-size: 0.88rem;
  background: rgba(255, 255, 255, 0.04);
}

.stack-safe-indicator {
  position: absolute;
  bottom: 2px;
  right: 3px;
  font-size: 0.42rem;
  color: rgba(80, 220, 120, 0.9);
  pointer-events: none;
}
