:root {
  color-scheme: dark;
  --bg: #101310;
  --panel: #181d1a;
  --panel-strong: #202821;
  --line: #334039;
  --text: #eef6ef;
  --muted: #9ead9f;
  --accent: #79d989;
  --accent-strong: #4fc76a;
  --danger: #ff746f;
  --gold: #ffd36e;
  --shadow: 0 22px 60px rgba(0, 0, 0, 0.34);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", Arial, sans-serif;
  background:
    linear-gradient(120deg, rgba(121, 217, 137, 0.12), transparent 34%),
    radial-gradient(circle at 82% 14%, rgba(255, 211, 110, 0.1), transparent 28%),
    var(--bg);
  color: var(--text);
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  min-height: 100vh;
  padding: 28px 0;
  display: grid;
  align-items: center;
}

.hidden {
  display: none !important;
}

.setup-view,
.auth-view {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 22px;
  align-items: stretch;
}

.game-view,
.admin-view {
  display: grid;
  gap: 18px;
}

.brand-panel,
.panel {
  background: rgba(24, 29, 26, 0.94);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.brand-panel {
  min-height: 520px;
  padding: clamp(28px, 6vw, 72px);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
  position: relative;
}

.brand-panel::after {
  content: "";
  position: absolute;
  inset: auto 0 0;
  height: 170px;
  background:
    linear-gradient(90deg, transparent 0 11%, rgba(121, 217, 137, 0.16) 11% 14%, transparent 14% 24%, rgba(121, 217, 137, 0.2) 24% 27%, transparent 27%),
    repeating-linear-gradient(90deg, rgba(238, 246, 239, 0.06) 0 1px, transparent 1px 32px);
  opacity: 0.8;
}

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

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h2 {
  font-size: 1.35rem;
}

.brand-panel h1 {
  font-size: clamp(2.4rem, 6vw, 5.2rem);
  line-height: 1;
}

.lead,
.muted {
  color: var(--muted);
  line-height: 1.7;
}

.score-preview {
  width: min(240px, 80%);
  border: 1px solid rgba(121, 217, 137, 0.32);
  border-radius: 8px;
  padding: 18px;
  background: rgba(17, 19, 17, 0.68);
  z-index: 1;
}

.score-preview span {
  display: block;
  color: var(--muted);
  font-weight: 700;
}

.score-preview strong {
  display: block;
  color: var(--gold);
  font-size: 4.2rem;
  line-height: 0.95;
}

.form-panel,
.auth-card {
  padding: 24px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 18px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.wide {
  grid-column: 1 / -1;
}

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #101411;
}

.tab,
.ghost-button,
.primary-button,
.icon-button,
.dpad button,
.mini-button {
  border-radius: 8px;
  color: var(--text);
}

.tab {
  border: 0;
  padding: 11px 12px;
  background: transparent;
  color: var(--muted);
}

.tab.active {
  background: var(--panel-strong);
  color: var(--text);
}

label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 0.92rem;
}

input {
  min-width: 0;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 13px 14px;
  background: #101411;
  color: var(--text);
  outline: none;
}

input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(121, 217, 137, 0.12);
}

.form-message {
  min-height: 22px;
  margin: 0;
  color: var(--danger);
}

.form-message.success {
  color: var(--accent);
}

.primary-button {
  border: 0;
  padding: 13px 18px;
  background: linear-gradient(180deg, var(--accent), var(--accent-strong));
  color: #09200f;
  font-weight: 800;
}

.primary-button:disabled {
  cursor: wait;
  opacity: 0.7;
}

.ghost-button,
.mini-button {
  padding: 10px 14px;
  background: transparent;
  border: 1px solid var(--line);
}

.mini-button {
  margin: 2px;
  padding: 7px 9px;
  font-size: 0.82rem;
}

.mini-button.danger {
  border-color: rgba(255, 116, 111, 0.6);
  color: var(--danger);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.topbar h1 {
  font-size: clamp(1.8rem, 4vw, 3.3rem);
}

.user-box {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  flex-wrap: wrap;
  justify-content: flex-end;
}

.game-grid {
  display: grid;
  grid-template-columns: minmax(320px, 1fr) 340px;
  gap: 18px;
  align-items: start;
}

.play-panel,
.leaderboard,
.admin-summary,
.admin-list {
  padding: 18px;
}

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

.stats div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #101411;
}

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

.stats strong {
  display: block;
  margin-top: 5px;
  font-size: clamp(1.25rem, 3vw, 2rem);
  line-height: 1;
}

.board-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #0c110d;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 14px;
  text-align: center;
  background: rgba(12, 17, 13, 0.72);
}

.overlay strong {
  font-size: clamp(1.3rem, 4vw, 2.4rem);
}

.actions {
  display: flex;
  gap: 10px;
  margin-top: 14px;
}

.icon-button {
  width: 46px;
  height: 42px;
  background: var(--panel-strong);
  border: 1px solid var(--line);
  font-weight: 800;
}

.dpad {
  display: none;
  grid-template-columns: repeat(3, 54px);
  grid-template-rows: repeat(2, 48px);
  gap: 8px;
  justify-content: center;
  margin-top: 14px;
}

.dpad button {
  background: var(--panel-strong);
  border: 1px solid var(--line);
  font-size: 1.2rem;
}

.dpad [data-dir="up"] {
  grid-column: 2;
}

.dpad [data-dir="left"] {
  grid-column: 1;
  grid-row: 2;
}

.dpad [data-dir="down"] {
  grid-column: 2;
  grid-row: 2;
}

.dpad [data-dir="right"] {
  grid-column: 3;
  grid-row: 2;
}

.board-title {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

ol {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

li {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  min-height: 46px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #101411;
}

.rank {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--panel-strong);
  color: var(--gold);
  font-weight: 800;
}

.player {
  overflow: hidden;
}

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

.player span {
  color: var(--muted);
  font-size: 0.78rem;
}

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

.empty {
  grid-template-columns: 1fr;
  color: var(--muted);
  text-align: center;
}

.admin-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 18px;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 680px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 12px 10px;
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 700;
}

td {
  color: var(--text);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(4, 7, 5, 0.72);
}

.modal-card {
  width: min(420px, 100%);
  padding: 20px;
  gap: 14px;
}

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

.modal-head h2 {
  margin: 0;
  font-size: 1.25rem;
}

@media (max-width: 900px) {
  .shell {
    width: min(100% - 24px, 720px);
    align-items: start;
  }

  .setup-view,
  .auth-view,
  .game-grid {
    grid-template-columns: 1fr;
  }

  .brand-panel {
    min-height: 320px;
  }

  .dpad {
    display: grid;
  }
}

@media (max-width: 540px) {
  .shell {
    padding: 14px 0;
  }

  .topbar,
  .board-title {
    align-items: flex-start;
    flex-direction: column;
  }

  .user-box {
    justify-content: flex-start;
  }

  .stats,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .wide {
    grid-column: auto;
  }

  .form-panel,
  .auth-card,
  .play-panel,
  .leaderboard,
  .admin-summary,
  .admin-list {
    padding: 14px;
  }
}
