:root {
  color-scheme: dark;
  --bg: #060914;
  --bg-soft: #0d1325;
  --panel: rgba(13, 19, 37, 0.82);
  --panel-strong: rgba(16, 25, 48, 0.94);
  --line: rgba(157, 183, 255, 0.18);
  --line-strong: rgba(157, 183, 255, 0.34);
  --text: #edf4ff;
  --text-muted: #98a9c9;
  --cyan: #51e6ff;
  --blue: #7a8dff;
  --violet: #b06cff;
  --green: #72f0b5;
  --yellow: #ffdb71;
  --red: #ff6b8a;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.42);
  --radius-lg: 28px;
  --radius-md: 20px;
  --radius-sm: 14px;
  --board-size: min(78vw, 520px);
  font-family:
    Inter, "Microsoft YaHei", "PingFang SC", "Noto Sans CJK SC", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  scroll-behavior: smooth;
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at 18% 8%, rgba(81, 230, 255, 0.18), transparent 34rem),
    radial-gradient(circle at 82% 12%, rgba(176, 108, 255, 0.18), transparent 30rem),
    radial-gradient(circle at 50% 90%, rgba(114, 240, 181, 0.1), transparent 34rem),
    linear-gradient(135deg, #050711 0%, #081023 46%, #040612 100%);
}

body::before {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  content: "";
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px);
  background-size: 54px 54px;
  mask-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.88), transparent 80%);
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

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

a {
  color: inherit;
  text-decoration: none;
}

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

.topbar,
.hero-grid,
.main-layout,
.section-heading,
.stats-grid,
.control-bar,
.score-submit-row,
.modal-actions {
  display: flex;
}

.topbar {
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 0 28px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  width: 38px;
  height: 38px;
  border: 1px solid rgba(81, 230, 255, 0.34);
  border-radius: 14px;
  background:
    linear-gradient(135deg, rgba(81, 230, 255, 0.95), rgba(176, 108, 255, 0.7)),
    #15213d;
  box-shadow: 0 0 30px rgba(81, 230, 255, 0.36);
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-size: 1rem;
  letter-spacing: 0.08em;
}

.brand small {
  margin-top: 2px;
  color: var(--text-muted);
  font-size: 0.74rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
}

.topbar-actions {
  display: flex;
  gap: 10px;
}

.hero {
  padding-bottom: 30px;
}

.hero-grid {
  align-items: stretch;
  justify-content: space-between;
  gap: 28px;
}

.hero-copy {
  flex: 1 1 620px;
  padding: 42px 0 18px;
}

.eyebrow {
  margin: 0 0 12px;
  color: var(--cyan);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.24em;
  text-transform: uppercase;
}

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

h1 {
  max-width: 760px;
  margin-bottom: 18px;
  font-size: clamp(2.55rem, 7vw, 5.8rem);
  line-height: 0.95;
  letter-spacing: -0.08em;
}

h2 {
  margin-bottom: 10px;
  font-size: clamp(1.35rem, 2.8vw, 2rem);
  letter-spacing: -0.04em;
}

.hero-text {
  max-width: 620px;
  color: var(--text-muted);
  font-size: 1.05rem;
  line-height: 1.8;
}

.glass-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.08), transparent 30%),
    var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(20px);
}

.mode-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  width: min(680px, 100%);
  margin-top: 30px;
}

.mode-tab,
.leaderboard-tab,
.ghost-button,
.secondary-button,
.primary-button,
.text-button {
  border: 0;
  color: var(--text);
}

.mode-tab {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(12, 18, 34, 0.74);
  text-align: left;
  transition:
    transform 160ms ease,
    border-color 160ms ease,
    background 160ms ease;
}

.mode-tab:hover,
.mode-tab:focus-visible,
.leaderboard-tab:hover,
.leaderboard-tab:focus-visible,
.ghost-button:hover,
.ghost-button:focus-visible,
.secondary-button:hover,
.secondary-button:focus-visible,
.text-button:hover,
.text-button:focus-visible {
  border-color: var(--line-strong);
  outline: none;
  transform: translateY(-1px);
}

.mode-tab.is-active {
  border-color: rgba(81, 230, 255, 0.6);
  background: linear-gradient(145deg, rgba(81, 230, 255, 0.2), rgba(122, 141, 255, 0.12));
  box-shadow: 0 0 34px rgba(81, 230, 255, 0.14);
}

.mode-tab span,
.mode-tab small {
  display: block;
}

.mode-tab span {
  font-size: 1.05rem;
  font-weight: 800;
}

.mode-tab small {
  margin-top: 6px;
  color: var(--text-muted);
}

.mode-card {
  flex: 0 1 410px;
  padding: 28px;
}

.mode-card p:not(.eyebrow) {
  color: var(--text-muted);
  line-height: 1.7;
}

.mode-facts,
.run-list,
.result-grid {
  display: grid;
  gap: 10px;
  margin: 20px 0;
}

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

.mode-facts div,
.run-list div,
.result-grid div,
.stat-card {
  border: 1px solid rgba(157, 183, 255, 0.14);
  border-radius: var(--radius-sm);
  background: rgba(5, 9, 20, 0.5);
}

.mode-facts div {
  padding: 12px;
}

dt,
.stat-card span {
  color: var(--text-muted);
  font-size: 0.78rem;
}

dd {
  margin: 4px 0 0;
  font-weight: 800;
}

.primary-button,
.secondary-button,
.ghost-button {
  min-height: 44px;
  border-radius: 999px;
  font-weight: 800;
}

.primary-button {
  width: 100%;
  padding: 0 22px;
  background: linear-gradient(135deg, var(--cyan), var(--blue));
  color: #06101f;
  box-shadow: 0 16px 44px rgba(81, 230, 255, 0.26);
}

.primary-button:hover,
.primary-button:focus-visible {
  outline: none;
  filter: brightness(1.05);
  transform: translateY(-1px);
}

.ghost-button,
.secondary-button {
  padding: 0 18px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.05);
}

.secondary-button {
  flex: 1 1 0;
}

.main-layout {
  align-items: flex-start;
  gap: 22px;
}

.game-panel {
  flex: 1 1 720px;
  padding: 24px;
}

.side-stack {
  display: grid;
  flex: 0 0 340px;
  gap: 18px;
}

.compact-panel {
  padding: 20px;
}

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

.section-heading.compact {
  align-items: center;
}

.section-heading h2 {
  margin-bottom: 0;
}

.game-status {
  max-width: 220px;
  padding: 8px 12px;
  border: 1px solid rgba(114, 240, 181, 0.24);
  border-radius: 999px;
  color: var(--green);
  background: rgba(114, 240, 181, 0.08);
  font-size: 0.84rem;
  font-weight: 800;
  text-align: center;
}

.stats-grid {
  gap: 10px;
  margin-bottom: 16px;
}

.stat-card {
  flex: 1 1 0;
  padding: 14px;
}

.stat-card strong {
  display: block;
  margin-top: 4px;
  font-size: clamp(1.35rem, 3vw, 2rem);
  line-height: 1;
}

.progress-wrap {
  height: 8px;
  margin-bottom: 22px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
}

.progress-wrap span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--cyan), var(--green), var(--yellow));
  transition: width 180ms ease;
}

.board-wrap {
  display: grid;
  place-items: center;
  min-height: var(--board-size);
  padding: 18px;
  border: 1px solid rgba(157, 183, 255, 0.1);
  border-radius: 24px;
  background:
    radial-gradient(circle at 50% 50%, rgba(81, 230, 255, 0.08), transparent 60%),
    rgba(2, 6, 15, 0.54);
}

.lights-board {
  display: grid;
  width: var(--board-size);
  max-width: 100%;
  aspect-ratio: 1;
  gap: clamp(7px, 1.6vw, 12px);
  grid-template-columns: repeat(var(--grid-size, 5), minmax(0, 1fr));
}

.light-cell {
  position: relative;
  min-width: 0;
  border: 1px solid rgba(157, 183, 255, 0.18);
  border-radius: clamp(12px, 2.2vw, 18px);
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.08), transparent 42%),
    #0b1222;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    0 16px 30px rgba(0, 0, 0, 0.25);
  transition:
    background 180ms ease,
    box-shadow 180ms ease,
    border-color 180ms ease,
    transform 120ms ease;
}

.light-cell::after {
  position: absolute;
  inset: 19%;
  border-radius: inherit;
  content: "";
  background: rgba(255, 255, 255, 0.05);
  filter: blur(10px);
}

.light-cell.is-on {
  border-color: rgba(255, 219, 113, 0.86);
  background:
    radial-gradient(circle at 32% 28%, rgba(255, 255, 255, 0.95), transparent 18%),
    radial-gradient(circle at 50% 54%, rgba(255, 219, 113, 0.98), rgba(255, 148, 91, 0.72) 62%, rgba(92, 40, 18, 0.82)),
    #ffdb71;
  box-shadow:
    0 0 30px rgba(255, 219, 113, 0.45),
    0 0 70px rgba(255, 148, 91, 0.24),
    inset 0 1px 0 rgba(255, 255, 255, 0.42);
}

.light-cell.is-hint {
  border-color: rgba(81, 230, 255, 0.96);
  box-shadow:
    0 0 0 4px rgba(81, 230, 255, 0.18),
    0 0 34px rgba(81, 230, 255, 0.36);
}

.light-cell:focus-visible {
  outline: 3px solid rgba(81, 230, 255, 0.82);
  outline-offset: 3px;
}

.light-cell:active {
  transform: scale(0.96);
}

.control-bar {
  gap: 10px;
  margin-top: 18px;
}

.keyboard-help,
.muted-state,
.form-note {
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.6;
}

.keyboard-help {
  margin: 14px 0 0;
}

.run-list {
  margin-bottom: 0;
}

.run-list div,
.result-grid div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
}

.run-list dd,
.result-grid dd {
  margin: 0;
}

.text-button {
  padding: 0;
  color: var(--cyan);
  background: transparent;
  font-weight: 800;
}

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

.leaderboard-tab {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.05);
  font-weight: 800;
}

.leaderboard-tab.is-active {
  border-color: rgba(81, 230, 255, 0.58);
  color: #081020;
  background: linear-gradient(135deg, var(--cyan), var(--green));
}

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

.leaderboard-row {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border: 1px solid rgba(157, 183, 255, 0.14);
  border-radius: var(--radius-sm);
  background: rgba(5, 9, 20, 0.48);
}

.leaderboard-rank {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border-radius: 10px;
  color: #07101e;
  background: linear-gradient(135deg, var(--yellow), var(--cyan));
  font-weight: 900;
}

.leaderboard-name {
  overflow: hidden;
}

.leaderboard-name strong,
.leaderboard-name small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leaderboard-name small {
  margin-top: 2px;
  color: var(--text-muted);
  font-size: 0.76rem;
}

.leaderboard-score {
  font-weight: 900;
}

.modal {
  width: min(560px, calc(100% - 28px));
  padding: 0;
  border: 0;
  color: var(--text);
  background: transparent;
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(10px);
}

.modal-card {
  position: relative;
  padding: 28px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-lg);
  background:
    linear-gradient(145deg, rgba(81, 230, 255, 0.1), transparent 32%),
    var(--panel-strong);
  box-shadow: var(--shadow);
}

.modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
  font-size: 1.4rem;
}

.rules-list {
  display: grid;
  gap: 12px;
  margin: 18px 0 0;
  padding-left: 1.3rem;
  color: var(--text-muted);
  line-height: 1.7;
}

.result-message {
  color: var(--text-muted);
  line-height: 1.7;
}

.result-score {
  padding: 18px;
  margin: 18px 0;
  border: 1px solid rgba(81, 230, 255, 0.26);
  border-radius: var(--radius-md);
  background: rgba(81, 230, 255, 0.08);
}

.result-score span {
  color: var(--text-muted);
}

.result-score strong {
  display: block;
  margin-top: 6px;
  font-size: clamp(2rem, 8vw, 4rem);
  line-height: 1;
}

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

.score-form {
  margin-top: 18px;
}

.score-form label {
  display: block;
  margin-bottom: 8px;
  font-weight: 900;
}

.score-submit-row {
  gap: 10px;
}

.score-submit-row input {
  flex: 1 1 auto;
  min-width: 0;
  height: 46px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
}

.score-submit-row input:focus {
  border-color: rgba(81, 230, 255, 0.76);
  outline: none;
  box-shadow: 0 0 0 4px rgba(81, 230, 255, 0.12);
}

.score-submit-row .primary-button {
  flex: 0 0 auto;
  width: auto;
}

.modal-actions {
  gap: 10px;
  margin-top: 18px;
}

.modal-actions .secondary-button,
.modal-actions .ghost-button {
  flex: 1 1 0;
}

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

.is-success {
  color: var(--green);
}

@media (max-width: 920px) {
  .hero-grid,
  .main-layout {
    flex-direction: column;
  }

  .hero-copy {
    padding-top: 20px;
  }

  .mode-card,
  .side-stack {
    width: 100%;
    flex-basis: auto;
  }

  .main-layout {
    align-items: stretch;
  }
}

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

  .topbar {
    align-items: flex-start;
    flex-direction: column;
    padding-bottom: 16px;
  }

  .topbar-actions,
  .control-bar,
  .modal-actions,
  .score-submit-row {
    width: 100%;
  }

  .topbar-actions .ghost-button {
    flex: 1 1 0;
  }

  .mode-tabs,
  .stats-grid,
  .mode-facts,
  .result-grid {
    grid-template-columns: 1fr;
  }

  .stats-grid,
  .control-bar,
  .score-submit-row,
  .modal-actions {
    flex-direction: column;
  }

  .section-heading {
    flex-direction: column;
  }

  .game-status {
    max-width: none;
    width: 100%;
  }

  .game-panel,
  .compact-panel,
  .modal-card,
  .mode-card {
    padding: 18px;
    border-radius: 22px;
  }

  .board-wrap {
    padding: 10px;
  }

  .lights-board {
    width: min(92vw, 520px);
    gap: 7px;
  }

  .keyboard-help {
    font-size: 0.82rem;
  }
}

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