:root {
  color-scheme: dark;
  --bg: #151119;
  --surface: #211a28;
  --surface-inset: #19141f;
  --border: #3d3047;
  --text: #f8f0fc;
  --muted: #c1b3ca;
  --purple: #d8b0f7;
  --gold: #f9d780;
  font-family: system-ui, "Microsoft YaHei UI", "PingFang SC", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-width: 0;
  min-height: 100vh;
  background: radial-gradient(ellipse at 30% 0%, #35243e 0%, transparent 52rem), var(--bg);
  color: var(--text);
}

button, input { font: inherit; }
button, a, label { -webkit-tap-highlight-color: transparent; }
button { touch-action: manipulation; }
button:focus-visible, a:focus-visible, .choice-row input:focus-visible + span {
  outline: 2px solid var(--purple);
  outline-offset: 3px;
}
h1, h2, p { margin: 0; }
a { color: inherit; }

.page-width {
  width: min(1140px, calc(100% - 48px));
  margin-inline: auto;
}

.top-bar {
  border-bottom: 1px solid rgba(218, 184, 241, .15);
  background: rgba(21, 17, 25, .78);
}

.top-bar-inner {
  display: flex;
  min-height: 64px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.club-link {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: .9rem;
  font-weight: 700;
  text-decoration: none;
}

.club-link img {
  border-radius: 50%;
  object-fit: cover;
}

.back-link {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  color: var(--muted);
  font-size: .85rem;
  text-decoration: none;
}

.back-link:hover { color: var(--purple); }

.intro {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  padding-block: 26px 19px;
}

.intro h1 {
  font-size: clamp(2.15rem, 5vw, 3.55rem);
  line-height: 1;
  letter-spacing: -.055em;
}

.intro h1 span { color: var(--purple); }

.intro p {
  margin-top: 10px;
  color: var(--muted);
  font-size: .92rem;
  line-height: 1.5;
}

.status-pill {
  flex: 0 0 auto;
  padding: .44rem .72rem;
  border: 1px solid #594466;
  border-radius: 999px;
  background: #2c2034;
  color: var(--purple);
  font-size: .8rem;
  font-weight: 700;
  white-space: nowrap;
}

.status-pill.is-complete {
  border-color: #8c6636;
  background: #38291c;
  color: var(--gold);
}

.workspace {
  display: grid;
  grid-template-areas: "board settings";
  grid-template-columns: minmax(0, 1fr) minmax(280px, 320px);
  align-items: start;
  gap: 18px;
  padding-bottom: 30px;
}

.surface {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: 0 12px 44px rgba(8, 4, 13, .22);
}

.board-panel { grid-area: board; padding: 16px; }

.board-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}

.surface h2 { font-size: 1.05rem; line-height: 1.3; }

.board-header p {
  margin-top: 4px;
  color: var(--muted);
  font-size: .79rem;
}

.quiet-button, .confirm-button {
  min-height: 42px;
  padding: 6px 10px;
  border: 1px solid #624d6e;
  border-radius: 10px;
  background: #2e2236;
  color: var(--text);
  cursor: pointer;
  font-size: .79rem;
  font-weight: 700;
  white-space: nowrap;
}

.quiet-button:hover:not(:disabled) { background: #422e4d; }
.quiet-button:disabled { opacity: .48; cursor: default; }

.board-frame {
  overflow: hidden;
  border: 1px solid #624a35;
  border-radius: 11px;
  background: #261a11;
}

/* 全屏时保留原棋盘位置，关闭后原页面的滚动位置不会跳动。 */
.board-fullscreen .board-slot { aspect-ratio: 1370 / 1360; }

html.board-fullscreen { overflow: hidden; }

.board-dialog {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
  border: 0;
  background: var(--bg);
  color: var(--text);
}

.board-dialog[open] {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.board-dialog-header {
  display: flex;
  min-height: 56px;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 6px clamp(6px, 2vw, 20px);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.board-dialog-header h2 {
  font-size: .9rem;
  white-space: nowrap;
}

.board-dialog-stage {
  display: grid;
  min-width: 0;
  min-height: 0;
  place-items: center;
  padding: clamp(4px, 1vw, 12px);
  container-type: size;
}

.board-dialog-stage .board-frame {
  width: min(100%, calc(100vh - 80px));
  width: min(100cqw, 100cqh);
}

.board {
  position: relative;
  width: 100%;
  aspect-ratio: 1370 / 1360;
  isolation: isolate;
}

.board-image {
  display: block;
  width: 100%;
  height: auto;
  user-select: none;
  pointer-events: none;
}

.tile {
  position: absolute;
  z-index: 1;
  margin: 0;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  cursor: pointer;
}

@media (hover: hover) {
  .tile:hover { box-shadow: inset 0 0 0 1px var(--purple); background: rgba(216, 176, 247, .12); }
}

.tile:focus-visible {
  z-index: 3;
  outline: 2px solid #fff;
  outline-offset: 0;
}

.tile.is-lit {
  border-color: #edc9ff;
  background: rgba(189, 119, 229, .20);
  box-shadow: inset 0 0 0 1px #c892ed, inset 0 0 14px #ab65c17d;
}

.tile.is-lit::after {
  position: absolute;
  top: 2px;
  right: 2px;
  width: clamp(7px, 1.35vw, 13px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: #e6c1ff;
  box-shadow: 0 0 0 1px #1a1320;
  content: "";
}

.tile.is-connected {
  border-color: #ffeaaf;
  background: rgba(255, 201, 104, .22);
  box-shadow: inset 0 0 0 1px #f8ca74, inset 0 0 14px #d0974cad;
}

.tile.is-connected::after { background: var(--gold); }

.board-line {
  position: absolute;
  z-index: 2;
  height: clamp(2px, .33vw, 4px);
  border-radius: 10px;
  background: var(--gold);
  box-shadow: 0 0 9px #ffd17db0, 0 0 0 1px #33220f;
  transform: translateY(-50%) rotate(var(--angle));
  transform-origin: left center;
  pointer-events: none;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  margin-top: 12px;
  color: var(--muted);
  font-size: .77rem;
}

.legend span {
  display: flex;
  align-items: center;
  gap: 6px;
}

.legend-icon {
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 1px solid #8a7596;
  border-radius: 3px;
}
.legend-icon.lit { border-color: #deb1ff; background: #b481d6; }
.legend-icon.connected { border-color: var(--gold); background: var(--gold); }

.settings-panel {
  grid-area: settings;
  padding: 17px;
}

.settings-panel > h2 { margin-bottom: 14px; }

fieldset {
  min-inline-size: 0;
  margin: 0 0 14px;
  padding: 0;
  border: 0;
}

legend {
  margin: 0 0 7px;
  padding: 0;
  color: var(--muted);
  font-size: .8rem;
}

.choice-row {
  display: grid;
  gap: 5px;
}

.targets { grid-template-columns: repeat(7, minmax(0, 1fr)); }
.directions { grid-template-columns: repeat(3, minmax(0, 1fr)); }

.choice-row label {
  position: relative;
  cursor: pointer;
}

.choice-row input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.choice-row label span {
  display: flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  gap: 4px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-inset);
  color: var(--muted);
  font-size: .77rem;
  font-weight: 700;
  white-space: nowrap;
}

.choice-row input:checked + span {
  border-color: #a574c6;
  background: #3c2849;
  color: #faeaff;
}

.choice-row label:hover span { border-color: var(--purple); }
.directions b { color: var(--purple); font-size: .97rem; }

.stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.metric {
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-inset);
  white-space: nowrap;
}

.metric span, .metric small {
  color: var(--muted);
  font-size: .73rem;
}
.metric span { display: block; margin-bottom: 3px; }
.metric strong { font-size: 1.27rem; font-variant-numeric: tabular-nums; }

.panel-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 13px;
}

.panel-footer p {
  color: var(--muted);
  font-size: .74rem;
  line-height: 1.35;
}

.reset-dialog {
  width: min(370px, calc(100% - 32px));
  padding: 19px;
  border: 1px solid var(--border);
  border-radius: 15px;
  background: var(--surface);
  color: var(--text);
}

.reset-dialog::backdrop { background: rgba(10, 6, 13, .78); }
.reset-dialog h2 { font-size: 1.05rem; }
.reset-dialog p { margin-top: 7px; color: var(--muted); font-size: .88rem; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.confirm-button { background: var(--purple); color: #1a1120; }

@media (max-width: 850px) {
  .page-width { width: min(700px, calc(100% - 24px)); }
  .workspace { grid-template-areas: "settings" "board"; grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .intro { align-items: flex-start; padding-block: 19px 14px; }
  .intro p { font-size: .82rem; }
  .surface { border-radius: 13px; }
  .board-panel, .settings-panel { padding: 12px; }
  .settings-panel > h2 { margin-bottom: 10px; }
  fieldset { margin-bottom: 10px; }
  .panel-footer { margin-top: 9px; }
}

@media (max-width: 360px) {
  .page-width { width: calc(100% - 16px); }
  .top-bar-inner { min-height: 54px; }
  .intro { gap: 8px; }
  .status-pill { padding: .38rem .55rem; font-size: .72rem; }
  .board-panel, .settings-panel { padding: 9px; }
  .targets { gap: 4px; }
  .targets label span { font-size: .7rem; }
}
