:root {
  color-scheme: dark;
  --bg: #171912;
  --panel: #25281d;
  --panel-2: #303323;
  --line: #535640;
  --text: #f3ecd5;
  --muted: #c9bd95;
  --accent: #d9b85f;
  --danger: #d9654f;
  --green: #6f8b4e;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at 50% 0, #303322 0, var(--bg) 46rem);
  color: var(--text);
  font-family: "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
}

button,
input {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #3b3d2b;
  color: var(--text);
  padding: 10px 14px;
  cursor: pointer;
}

button:hover {
  border-color: var(--accent);
}

button.primary {
  background: var(--accent);
  color: #1d1a10;
  border-color: #f0cf79;
  font-weight: 700;
}

button.ghost {
  background: transparent;
}

input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #161811;
  color: var(--text);
  padding: 10px 12px;
}

.hidden {
  display: none !important;
}

.app-shell {
  width: min(1180px, calc(100vw - 24px));
  margin: 0 auto;
  padding: 18px 0 28px;
}

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

.topbar h1 {
  margin: 0;
  font-size: clamp(28px, 4vw, 46px);
  letter-spacing: 0;
}

.topbar p {
  margin: 6px 0 0;
  color: var(--muted);
}

.view {
  min-height: 720px;
}

.lobby-view {
  display: grid;
  place-items: start center;
  padding-top: 48px;
}

.lobby-panel {
  width: min(760px, 100%);
  background: color-mix(in srgb, var(--panel) 92%, black);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px;
}

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

.field input {
  color: var(--text);
}

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

.mode-button {
  min-height: 132px;
  display: grid;
  align-content: center;
  text-align: left;
  background: var(--panel-2);
}

.mode-button strong {
  display: block;
  font-size: 25px;
  margin-bottom: 10px;
}

.mode-button span {
  color: var(--muted);
}

.join-row,
.room-toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.join-row input {
  flex: 1 1 220px;
}

.error-line {
  min-height: 22px;
  color: #ff9c82;
}

.room-toolbar {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 12px;
}

.room-toolbar > div {
  display: grid;
  gap: 2px;
  min-width: 110px;
}

.room-toolbar strong {
  font-size: 22px;
  color: var(--accent);
}

.room-id-line {
  display: flex;
  align-items: center;
  gap: 6px;
}

button.icon-button {
  padding: 3px 7px;
  line-height: 1.2;
}

.room-toolbar input {
  width: 140px;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
}

.toggle input {
  width: 18px;
  height: 18px;
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 720px) minmax(260px, 1fr);
  gap: 14px;
  align-items: start;
}

.stage-wrap {
  position: relative;
  width: min(720px, 100%);
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #20231b;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: crisp-edges;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  text-align: center;
  padding: 28px;
  background: rgba(18, 20, 14, 0.78);
}

.overlay h2 {
  margin: 0 0 10px;
  font-size: 32px;
}

.overlay p {
  max-width: 460px;
  margin: 0 auto;
  color: var(--muted);
  line-height: 1.7;
}

.side-panel {
  display: grid;
  gap: 14px;
  align-content: start;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  min-height: 320px;
}

.side-panel h2 {
  margin: 0;
  font-size: 20px;
}

.side-panel p {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
}

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

.player-row {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 5px 8px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #1d2017;
}

.player-row span:last-child {
  grid-column: 2;
  color: var(--muted);
  font-size: 14px;
}

.color-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.55);
}

.score-card {
  padding: 14px;
  border-radius: 6px;
  background: #1d2017;
  border: 1px solid var(--line);
  color: var(--accent);
  font-size: 22px;
  font-weight: 700;
}

.stats-list {
  display: grid;
  gap: 8px;
  color: var(--muted);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(0, 0, 0, 0.66);
}

.modal-card {
  width: min(560px, 100%);
  max-height: min(720px, calc(100vh - 36px));
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 20px;
  box-shadow: 0 16px 44px rgba(0, 0, 0, 0.45);
}

.modal-card h2 {
  margin: 0 0 12px;
}

.modal-card p {
  color: var(--muted);
  line-height: 1.65;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
}

.book-grid {
  display: grid;
  gap: 10px;
}

.book-grid div {
  display: grid;
  grid-template-columns: auto auto 1fr;
  align-items: center;
  gap: 4px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #1d2017;
}

.book-grid span {
  color: var(--muted);
}

.book-grid .book-icon {
  min-width: 36px;
  color: var(--text);
  font-size: 24px;
  text-align: center;
  margin-right: 4px;
}

.book-grid b {
  margin-right: 8px;
}

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

  .stage-wrap {
    margin: 0 auto;
  }

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