:root {
  --bg: #0b1020;
  --bg2: #131a33;
  --panel: rgba(255, 255, 255, 0.05);
  --line: rgba(255, 255, 255, 0.10);
  --text: #e8ecff;
  --muted: #8b95bf;
  --accent: #4fd1ff;
  --accent2: #7c5cff;
  --gold: #ffd166;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: radial-gradient(1200px 800px at 50% -10%, #1a2450 0%, var(--bg) 55%, #070a16 100%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei",
               "PingFang SC", "Hiragino Sans GB", sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
}

/* ================= 布局：左侧栏 + 满幅迷宫 ================= */
.app {
  height: 100%;
  display: grid;
  grid-template-columns: minmax(228px, 280px) 1fr;
  gap: clamp(10px, 1.4vw, 18px);
  padding: clamp(10px, 1.4vw, 18px);
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 4px 2px;
  min-width: 0;
  overflow: hidden auto;
}

/* ---------- 品牌 ---------- */
.brand { display: flex; align-items: center; gap: 9px; }

.logo {
  font-size: 24px;
  line-height: 1;
  color: var(--accent);
  text-shadow: 0 0 18px rgba(79, 209, 255, 0.55);
}

.brand h1 {
  margin: 0;
  font-size: clamp(17px, 1.7vw, 21px);
  font-weight: 700;
  letter-spacing: 0.5px;
  white-space: nowrap;
}

/* ---------- 关卡徽章 ---------- */
.levelbox {
  align-self: flex-start;
  display: flex;
  align-items: baseline;
  gap: 5px;
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--line);
  font-size: 13px;
  color: var(--muted);
}

.levelnum {
  font-size: 20px;
  font-weight: 800;
  color: var(--accent);
  min-width: 1.2em;
  text-align: center;
}

/* ---------- 数据 ---------- */
.hud {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 12px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.stat .k { font-size: 11px; color: var(--muted); letter-spacing: 1px; }

.stat .v {
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

#time { color: var(--accent); }

/* ---------- 侧栏按钮 ---------- */
.side-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: auto;
}

.ghost {
  padding: 9px 14px;
  border-radius: 12px;
  font-size: 13px;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  transition: background .18s ease, transform .12s ease;
  cursor: pointer;
  font-family: inherit;
}

.ghost:hover { background: rgba(255, 255, 255, 0.09); }
.ghost:active { transform: scale(.97); }
.ghost[aria-pressed="false"] { color: var(--muted); }

.hint {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.6;
  opacity: 0.8;
}

/* ================= 迷宫舞台 ================= */
.stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 20px;
  background:
    radial-gradient(600px 400px at 50% 50%, rgba(124, 92, 255, 0.10), transparent 70%),
    var(--bg2);
  border: 1px solid var(--line);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.04);
  overflow: hidden;
  touch-action: none;
  cursor: grab;
  user-select: none;
}

.stage:active { cursor: grabbing; }

#maze { display: block; width: 100%; height: 100%; }

/* ================= 通关遮罩 ================= */
.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(7, 10, 22, 0.72);
  backdrop-filter: blur(6px);
  z-index: 50;
  animation: fade 0.25s ease;
}

.overlay.hidden, .hidden { display: none !important; }

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.card {
  text-align: center;
  padding: 26px 34px 30px;
  border-radius: 22px;
  background: linear-gradient(180deg, rgba(28, 38, 74, 0.96), rgba(16, 22, 44, 0.96));
  border: 1px solid rgba(124, 92, 255, 0.35);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.55), 0 0 60px rgba(124, 92, 255, 0.18);
  animation: pop 0.32s cubic-bezier(0.18, 1.2, 0.4, 1);
}

@keyframes pop {
  from { transform: scale(0.86) translateY(8px); opacity: 0; }
  to   { transform: scale(1) translateY(0); opacity: 1; }
}

.winIcon {
  font-size: 46px;
  color: var(--gold);
  text-shadow: 0 0 26px rgba(255, 209, 102, 0.65);
  animation: spin 1.1s ease-in-out;
}

@keyframes spin {
  0%   { transform: rotate(-30deg) scale(0.6); }
  60%  { transform: rotate(12deg) scale(1.15); }
  100% { transform: rotate(0) scale(1); }
}

.card h2 { margin: 6px 0 10px; font-size: 26px; letter-spacing: 2px; }

.winline { margin: 0 0 6px; color: var(--muted); font-size: 14px; }
.winline b { color: var(--text); font-size: 17px; font-variant-numeric: tabular-nums; }

.newbest {
  margin: 8px 0 0;
  color: var(--gold);
  font-weight: 700;
  animation: pulse 1.1s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%      { opacity: 0.7; transform: scale(1.05); }
}

/* ================= 按钮 ================= */
button { font-family: inherit; cursor: pointer; border: none; transition: transform 0.12s ease, background 0.18s ease, box-shadow 0.18s ease; }
button:active { transform: scale(0.96); }

.primary {
  margin-top: 18px;
  padding: 12px 34px;
  border-radius: 999px;
  font-size: 16px;
  font-weight: 700;
  color: #06101f;
  background: linear-gradient(135deg, var(--accent), #7ee0ff);
  box-shadow: 0 10px 28px rgba(79, 209, 255, 0.35);
}

.primary:hover { box-shadow: 0 12px 34px rgba(79, 209, 255, 0.5); }

/* ================= 选择关卡 ================= */
.level-card {
  width: min(92vw, 560px);
  max-height: 82vh;
  display: flex;
  flex-direction: column;
  padding: 24px 24px 22px;
}

.level-card h2 { margin: 0 0 16px; font-size: 22px; letter-spacing: 1px; }

.diffs {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.diff {
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 13px;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
}

.diff:hover { background: rgba(255, 255, 255, 0.09); }

.diff b { color: var(--muted); font-weight: 400; font-size: 11px; margin-left: 4px; }

.levels {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(54px, 1fr));
  gap: 8px;
  overflow-y: auto;
  padding: 4px 2px 6px;
  margin-bottom: 18px;
}

.lvl {
  padding: 10px 4px;
  border-radius: 10px;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
}

.lvl small { display: block; font-size: 10px; color: var(--muted); margin-top: 2px; }
.lvl:hover { border-color: rgba(79, 209, 255, 0.45); }

.lvl.active {
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: 0 0 0 1px rgba(79, 209, 255, 0.35) inset;
}

.lvl.locked {
  opacity: 0.35;
  cursor: not-allowed;
  border-style: dashed;
}

.close-btn { align-self: center; padding: 10px 30px; }

/* ================= 手机 / 窄屏：上下布局 ================= */
@media (max-width: 820px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
    gap: 8px;
    padding: 8px 8px 6px;
  }

  .sidebar {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    padding: 0;
    overflow: visible;
  }

  .brand h1 { font-size: 16px; }
  .logo { font-size: 18px; }

  .levelbox { padding: 4px 10px; font-size: 11px; }
  .levelnum { font-size: 16px; }

  .hud {
    flex-direction: row;
    flex: 1;
    gap: 5px;
    min-width: 0;
  }

  .stat {
    flex-direction: column;
    align-items: flex-start;
    gap: 0;
    padding: 5px 8px;
    border-radius: 10px;
    flex: 1;
    min-width: 0;
  }

  .stat .k { font-size: 10px; }
  .stat .v { font-size: 15px; }

  .side-actions {
    order: 3;
    width: 100%;
    flex-direction: row;
    gap: 6px;
    margin-top: 0;
  }

  .side-actions .ghost { flex: 1; padding: 8px 6px; font-size: 12px; }

  .hint { display: none; }

  .stage { border-radius: 14px; }
}

@media (max-width: 420px) {
  .stat .v { font-size: 14px; }
  .side-actions .ghost { font-size: 11px; }
}
