:root {
  --player-avatar: url("operators/weirong.png");
  --bg-a: #5b21b6;
  --bg-b: #1e3a8a;
  --card: #ffffff;
  --ink: #1e1b4b;
  --muted: #6b7280;
  --line: #e9d5ff;
  --fog: #4b5563;
  --fog-dot: #9ca3af;
  --path: #ffffff;
  --wall: #1e3a5f;
  --wall-edge: #172554;
  --player: #f97316;
  --exit-a: #111;
  --exit-b: #f8fafc;
  --pink: #ec4899;
  --purple: #a855f7;
  --blue: #3b82f6;
  --green: #22c55e;
  --shadow: 0 16px 40px rgba(30, 27, 75, 0.35);
  --font: "PingFang SC", "Microsoft YaHei", "Noto Sans SC", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(ellipse at 15% 0%, #7c3aed 0%, transparent 55%),
    radial-gradient(ellipse at 90% 100%, #2563eb 0%, transparent 50%),
    linear-gradient(160deg, var(--bg-a), var(--bg-b));
}

body {
  min-height: 100vh;
  padding: 12px;
}

.hidden { display: none !important; }

/* —— 选难度 —— */
.screen {
  min-height: calc(100vh - 24px);
  display: flex;
  align-items: center;
  justify-content: center;
}

.select-card {
  width: min(440px, 100%);
  background: var(--card);
  border-radius: 22px;
  padding: 28px 22px 18px;
  box-shadow: var(--shadow);
  text-align: center;
}

.brand-logo {
  width: 72px;
  height: 72px;
  border-radius: 16px;
  object-fit: cover;
  border: 2px solid #f5d0fe;
}

.select-card h1 {
  margin: 12px 0 6px;
  font-size: 22px;
  color: #2563eb;
}

.sub {
  margin: 0 0 18px;
  color: var(--muted);
  font-size: 13px;
}

.diff-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.diff-btn {
  appearance: none;
  border: 2px solid #e9d5ff;
  background: linear-gradient(180deg, #faf5ff, #fff);
  border-radius: 14px;
  padding: 14px 16px;
  text-align: left;
  cursor: pointer;
  transition: transform 0.1s, border-color 0.15s, box-shadow 0.15s;
  font-family: inherit;
  color: inherit;
}

.diff-btn:hover {
  border-color: #c084fc;
  box-shadow: 0 8px 20px rgba(168, 85, 247, 0.18);
}

.diff-btn:active { transform: scale(0.98); }

.diff-name {
  display: block;
  font-weight: 800;
  font-size: 17px;
  color: #7e22ce;
}

.diff-size {
  display: inline-block;
  margin-top: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #ede9fe;
  color: #5b21b6;
  font-size: 12px;
  font-weight: 700;
}

.diff-desc {
  display: block;
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted);
}

.foot-brand {
  margin: 16px 0 0;
  font-size: 12px;
  color: #a78bfa;
  font-weight: 700;
}

/* —— 对局壳 —— */
.app {
  width: min(1100px, 100%);
  margin: 0 auto;
  background: rgba(255, 255, 255, 0.97);
  border-radius: 20px;
  box-shadow: var(--shadow);
  border: 2px solid #c4b5fd;
  overflow: hidden;
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  background: linear-gradient(180deg, #f5f3ff, #fff);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-left img {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  object-fit: cover;
}

.header h1 {
  margin: 0;
  font-size: clamp(15px, 2.8vw, 20px);
  color: #2563eb;
  font-weight: 800;
}

.pills {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 4px;
}

.pill {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.pill-diff { background: #bbf7d0; color: #166534; }
.pill-size { background: #ddd6fe; color: #5b21b6; }
.pill-mode { background: #fce7f3; color: #9d174d; }
.pill-mode.post { background: #ffedd5; color: #9a3412; }

.steps-box {
  background: linear-gradient(135deg, #ec4899, #a855f7);
  color: #fff;
  border-radius: 14px;
  padding: 8px 16px;
  text-align: center;
  min-width: 96px;
}

.steps-label { display: block; font-size: 11px; opacity: 0.9; }
.steps-num { display: block; font-size: 28px; font-weight: 800; line-height: 1.1; }
.steps-box.zero { filter: grayscale(0.35); opacity: 0.85; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 12px;
  background: #4c1d95;
}

.btn {
  appearance: none;
  border: none;
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 13px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  color: #fff;
  transition: filter 0.15s, transform 0.1s;
}

.btn:hover { filter: brightness(1.06); }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; filter: none; }

.btn-blue { background: linear-gradient(135deg, #3b82f6, #2563eb); }
.btn-green { background: linear-gradient(135deg, #22c55e, #16a34a); }
.btn-pink { background: linear-gradient(135deg, #ec4899, #a855f7); }
.btn-orange { background: linear-gradient(135deg, #f97316, #ef4444); }
.btn-gold { background: linear-gradient(135deg, #eab308, #f59e0b); color: #1e1b4b; }
.btn-grey { background: linear-gradient(135deg, #6b7280, #4b5563); }
.btn-retreat { background: linear-gradient(135deg, #f43f5e, #e11d48); flex: 1; min-width: 90px; }

.main {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(260px, 0.8fr);
  gap: 14px;
  padding: 14px;
}

@media (max-width: 840px) {
  .main { grid-template-columns: 1fr; }
}

.board-wrap {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}

.board {
  display: grid;
  gap: 2px;
  background: #e2e8f0;
  padding: 4px;
  border-radius: 10px;
  border: 3px solid #fff;
  box-shadow: 0 8px 24px rgba(76, 29, 149, 0.25);
  width: 100%;
  max-width: min(92vw, 560px);
  aspect-ratio: 1 / 1;
}

.cell {
  position: relative;
  border-radius: 3px;
  min-width: 0;
  min-height: 0;
  background: var(--fog);
}

.cell.fog::after {
  content: "";
  position: absolute;
  inset: 22%;
  border-radius: 2px;
  background: var(--fog-dot);
  opacity: 0.55;
}

.cell.path {
  background: var(--path);
  box-shadow: inset 0 0 0 1px #e5e7eb;
}

.cell.wall {
  background: linear-gradient(160deg, #1e3a5f, #172554);
}

.cell.entrance.path {
  background: #bbf7d0;
}

.cell.exit-visible {
  background:
    linear-gradient(45deg, #111 25%, transparent 25%),
    linear-gradient(-45deg, #111 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #111 75%),
    linear-gradient(-45deg, transparent 75%, #111 75%);
  background-size: 10px 10px;
  background-position: 0 0, 0 5px, 5px -5px, -5px 0;
  background-color: #f8fafc;
}

.cell .sprite {
  position: absolute;
  inset: 12%;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.cell .player-ico {
  width: 86%;
  height: 86%;
  border-radius: 50%;
  background: #1f2937 var(--player-avatar) center / cover no-repeat;
  box-shadow:
    0 0 0 2px #f97316,
    0 0 0 3px rgba(255, 237, 213, 0.85),
    0 2px 8px rgba(15, 23, 42, 0.55);
  position: relative;
  image-rendering: auto;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  font-size: 12px;
  color: var(--muted);
}

.legend .lg {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 3px;
  margin-right: 4px;
  vertical-align: -1px;
}

.lg.fog { background: var(--fog); }
.lg.path { background: #fff; border: 1px solid #d1d5db; }
.lg.wall { background: var(--wall); }
.lg.player {
  background: #1f2937 var(--player-avatar) center / cover no-repeat;
  border-radius: 50%;
  box-shadow: 0 0 0 1px #f97316;
}
.lg.exit {
  background:
    linear-gradient(45deg, #111 25%, #fff 25%, #fff 50%, #111 50%, #111 75%, #fff 75%);
  background-size: 6px 6px;
}

.side {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  box-shadow: 0 4px 12px rgba(91, 33, 182, 0.06);
}

.card h2 {
  margin: 0 0 8px;
  font-size: 15px;
  color: #7e22ce;
}

.rules ol {
  margin: 0;
  padding-left: 18px;
  font-size: 13px;
  line-height: 1.55;
  color: #374151;
}

.pos-line { font-size: 14px; }
.pos-line strong { color: #2563eb; font-size: 16px; }
.dead-line {
  margin-top: 8px;
  padding: 6px 8px;
  border-radius: 8px;
  background: #fef3c7;
  color: #92400e;
  font-size: 12px;
  font-weight: 700;
}
.msg {
  margin-top: 6px;
  font-size: 13px;
  color: #9d174d;
  min-height: 1.2em;
}

.dpad {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.pad-mid {
  display: flex;
  gap: 6px;
  align-items: center;
}

.pad {
  width: 56px;
  height: 56px;
  border-radius: 12px;
  border: none;
  background: #c4b5fd;
  color: #1e1b4b;
  font-size: 18px;
  font-weight: 800;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.12s, transform 0.1s;
}

.pad.legal {
  background: linear-gradient(135deg, #34d399, #10b981);
  color: #fff;
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.35);
}

.pad:disabled, .pad.pad-center {
  background: #e5e7eb;
  color: #9ca3af;
  cursor: not-allowed;
  box-shadow: none;
}

.pad:not(:disabled):active { transform: scale(0.96); }

.pad-hint {
  margin: 8px 0 0;
  font-size: 11px;
  color: var(--muted);
  text-align: center;
}

.retreat-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.footer {
  text-align: center;
  padding: 10px;
  font-size: 12px;
  color: #7c3aed;
  font-weight: 700;
  border-top: 1px solid var(--line);
  background: #faf5ff;
}

/* —— 弹窗 —— */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}

.modal-card {
  width: min(400px, 100%);
  background: #fff;
  border-radius: 16px;
  padding: 20px;
  box-shadow: var(--shadow);
}

.modal-card h2 {
  margin: 0 0 8px;
  color: #6d28d9;
}

.modal-card p {
  margin: 0 0 12px;
  color: #4b5563;
  font-size: 14px;
  line-height: 1.5;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
  font-size: 13px;
  font-weight: 700;
  color: #5b21b6;
}

.field input {
  font: inherit;
  font-size: 18px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 2px solid #ddd6fe;
  outline: none;
}

.field input:focus { border-color: #a855f7; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.win-card {
  text-align: center;
  background: linear-gradient(180deg, #fdf4ff, #fff);
}

.win-card h2 {
  font-size: 28px;
  color: #db2777;
}

/* —— 房间码云同步 —— */
.room-card .room-status-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 10px;
  margin-bottom: 10px;
}
.room-card .rk {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}
.room-card .rcd {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0.18em;
  color: #db2777;
  font-variant-numeric: tabular-nums;
}
.room-card .rst {
  font-size: 11px;
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid #e9d5ff;
  color: #7c3aed;
  background: #faf5ff;
}
.room-card .rst.ok {
  border-color: #86efac;
  color: #15803d;
  background: #f0fdf4;
}
.room-card .rst.sync {
  border-color: #c4b5fd;
  color: #6d28d9;
  background: #f5f3ff;
}
.room-card .rst.off {
  border-color: #fca5a5;
  color: #b91c1c;
  background: #fef2f2;
}
.room-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 8px;
  text-align: left;
}
.room-field span {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}
.room-field input {
  appearance: none;
  border: 1.5px solid #e9d5ff;
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  font-family: inherit;
  color: var(--ink);
}
.room-field input:focus {
  outline: none;
  border-color: #a855f7;
  box-shadow: 0 0 0 3px rgba(168, 85, 247, 0.2);
}
.room-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}
.room-btns .btn {
  flex: 1;
  min-width: 100px;
}
.room-select-hint {
  margin-top: -8px;
  font-size: 12px !important;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  z-index: 1000;
  background: rgba(30, 27, 75, 0.92);
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  max-width: min(90vw, 420px);
  text-align: center;
}
