/* filepath: games/jigsaw/css/style.css
   拼图 Jigsaw —— 暖米白 / 软木色治愈主题（PRD §6）。
   桌面 ≥900px：棋盘居中做主体，右侧 330px 面板（关卡 / 得分 / 控制坞）。
   移动：单列，关卡 → 得分 → 棋盘 → 底部五格控制条。
   只用系统 sans-serif，不加载 webfont；动效全部带 prefers-reduced-motion 降级。 */

:root {
  --bg: #f4f1ec;
  --bg-top: #f8f6f2;
  --bg-bottom: #ece6dc;
  --surface: #fffdf9;
  --surface-2: #f7f3ec;
  --board: #e8e2d8;
  --line: #d8d0c2;
  --ink: #2a2118;
  --ink-soft: rgba(42, 33, 24, 0.62);
  --ink-faint: rgba(42, 33, 24, 0.38);
  --accent: #2a9d8f;
  --accent-deep: #1f7a6f;
  --accent-soft: rgba(42, 157, 143, 0.12);
  --accent-line: rgba(42, 157, 143, 0.22);
  --gold: #d4a84b;
  --gold-soft: rgba(212, 168, 75, 0.16);
  --warn: #c0392b;
  --radius: 16px;
  --gap: 16px;
  --board-pad: clamp(10px, 1.2vw, 18px);
  --panel-w: 344px;
  --shadow: 0 12px 28px rgba(60, 40, 20, 0.13), 0 3px 8px rgba(60, 40, 20, 0.08);
  --shadow-soft: 0 6px 16px rgba(60, 40, 20, 0.1);
  --shadow-card: 0 10px 24px -12px rgba(60, 40, 20, 0.24), 0 2px 6px rgba(60, 40, 20, 0.06);
  --raise: inset 0 1px 0 rgba(255, 255, 255, 0.85);
  --shadow-board: 0 30px 64px -22px rgba(60, 40, 20, 0.3), 0 12px 26px -14px rgba(60, 40, 20, 0.2),
    inset 0 1px 0 rgba(255, 255, 255, 0.92);
  --ring: 0 0 0 3px rgba(42, 157, 143, 0.22);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

body {
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='120' height='120' filter='url(%23n)' opacity='0.055'/%3E%3C/svg%3E")
      repeat,
    linear-gradient(180deg, var(--bg-top) 0%, var(--bg) 46%, var(--bg-bottom) 100%);
  background-size: 120px 120px, auto;
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Noto Sans CJK SC", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

/* 抽象壁纸感：柔和几何色块缓慢漂移，只做氛围不抢棋盘 */
body::before {
  content: "";
  position: fixed;
  inset: -6%;
  pointer-events: none;
  background:
    radial-gradient(40vw 40vw at 6% 2%, rgba(42, 157, 143, 0.22), transparent 66%),
    radial-gradient(36vw 36vw at 96% 94%, rgba(212, 168, 75, 0.24), transparent 68%),
    radial-gradient(28vw 28vw at 86% 0%, rgba(158, 206, 86, 0.18), transparent 70%),
    radial-gradient(30vw 30vw at 30% 100%, rgba(42, 157, 143, 0.1), transparent 72%);
  animation: aura-drift 38s ease-in-out infinite alternate;
  z-index: 0;
}

/* 柔和暗角：把视线收拢到棋盘 */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(126% 106% at 50% 44%, transparent 50%, rgba(60, 40, 20, 0.13) 100%);
  z-index: 0;
}

@keyframes aura-drift {
  from { transform: translate3d(0, 0, 0) scale(1); }
  to { transform: translate3d(-2.6%, 2.2%, 0) scale(1.07); }
}

#app {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ---------- 顶栏 ---------- */

#topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: var(--gap);
  padding: 12px clamp(14px, 3vw, 34px);
  background: linear-gradient(180deg, rgba(250, 248, 244, 0.94), rgba(250, 248, 244, 0.76));
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(60, 40, 20, 0.06);
}

.home-link {
  justify-self: start;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 15px;
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  box-shadow: var(--raise), var(--shadow-soft);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.home-link:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-card);
}

.home-link:active {
  transform: translateY(1px);
}

.home-arrow {
  color: var(--accent);
  font-size: 16px;
  line-height: 1;
}

.brand {
  text-align: center;
  min-width: 0;
}

.brand h1 {
  margin: 0;
  font-size: clamp(19px, 2.6vw, 26px);
  font-weight: 800;
  letter-spacing: 0.06em;
  line-height: 1.15;
}

.brand h1::after {
  content: "";
  display: block;
  width: 30px;
  height: 3px;
  margin: 6px auto 0;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--gold));
}

.brand p {
  margin: 3px 0 0;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--accent-deep);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.top-actions {
  justify-self: end;
  display: inline-flex;
  gap: 8px;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 42px;
  height: 42px;
  padding: 0 12px;
  border: none;
  border-radius: 13px;
  background: var(--surface);
  color: var(--ink);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--raise), var(--shadow-soft);
  transition: transform 0.2s ease, box-shadow 0.2s ease, color 0.2s ease;
}

.icon-btn svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

.icon-btn:hover {
  transform: translateY(-2px);
  color: var(--accent-deep);
  box-shadow: var(--shadow-card);
}

.icon-btn:active {
  transform: translateY(1px);
}

/* ---------- 舞台 ---------- */

#stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 14px clamp(12px, 3vw, 28px) clamp(16px, 4vw, 30px);
  min-height: 0;
}

/* 面板在 DOM 里先出现，移动端靠 order 把棋盘插到中间 */
#panel {
  display: contents;
}

#level-badge {
  order: 1;
}
#hud {
  order: 2;
}
#board-wrap {
  order: 3;
}
#toolbar {
  order: 4;
}

/* ---------- 关卡卡 ---------- */

#level-badge {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas:
    "chapter count"
    "name name"
    "meter meter";
  align-items: center;
  gap: 7px 10px;
  width: 100%;
  max-width: 100%;
  padding: 13px 16px;
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--raise), var(--shadow-card);
}

#level-chapter {
  grid-area: chapter;
  justify-self: start;
  max-width: 100%;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-deep);
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.04em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#level-name {
  grid-area: name;
  font-size: 19px;
  font-weight: 800;
  letter-spacing: 0.02em;
  line-height: 1.2;
}

.level-count {
  grid-area: count;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}

.meter {
  display: block;
  height: 6px;
  border-radius: 999px;
  background: rgba(42, 33, 24, 0.08);
  overflow: hidden;
}

.meter > i {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), #62c3b1);
  transition: width 0.32s ease;
}

.level-meter {
  grid-area: meter;
}

/* 今日拼图没有 "n/50" 进度，隐藏进度条 */
#level-badge[data-daily="1"] .level-meter {
  display: none;
}

/* ---------- HUD ---------- */

#hud {
  display: grid;
  gap: 10px;
  width: 100%;
}

.hud-hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas:
    "key val"
    "meter meter";
  align-items: baseline;
  gap: 6px 10px;
  padding: 13px 16px;
  border: 1px solid var(--accent-line);
  border-radius: 18px;
  background: linear-gradient(135deg, rgba(42, 157, 143, 0.15), rgba(212, 168, 75, 0.17));
  box-shadow: var(--raise), var(--shadow-card);
}

.hud-hero-key {
  grid-area: key;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.14em;
  color: var(--accent-deep);
}

.hud-hero-val {
  grid-area: val;
  font-size: clamp(21px, 2.2vw, 27px);
  font-weight: 800;
  letter-spacing: -0.01em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.hud-meter {
  grid-area: meter;
  background: rgba(255, 255, 255, 0.62);
}

.hud-meter > i {
  background: linear-gradient(90deg, var(--accent), var(--gold));
}

.hud-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 0;
  padding: 10px 6px;
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--raise), var(--shadow-soft);
}

.stat-key {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.1em;
  color: var(--ink-faint);
}

.stat-val {
  font-size: 17px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

/* ---------- 棋盘（做成一块"拼图板"） ---------- */

#board-wrap {
  position: relative;
  width: min(100%, 68dvh, 560px);
  padding: var(--board-pad);
  border-radius: 26px;
  background: linear-gradient(160deg, #f8f4ec 0%, #ebe4d7 55%, #ded5c4 100%);
  box-shadow: var(--shadow-board), inset 0 0 0 1px rgba(60, 40, 20, 0.07);
}

#board {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  height: auto;
  border-radius: 13px;
  background: var(--board);
  box-shadow: 0 2px 8px rgba(60, 40, 20, 0.14);
  touch-action: none;
  cursor: grab;
}

#board:active {
  cursor: grabbing;
}

#board:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

/* ---------- 控制坞 ---------- */

#toolbar {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 2px;
  width: 100%;
  padding: 7px;
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--raise), var(--shadow-card);
}

.tool-btn {
  position: relative;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 9px 2px 8px;
  border: none;
  border-radius: 13px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, transform 0.2s ease;
}

.tool-btn svg {
  width: 20px;
  height: 20px;
  flex: none;
  fill: none;
  stroke: currentColor;
}

.tool-btn:hover:not(:disabled) {
  background: var(--accent-soft);
  color: var(--accent-deep);
  transform: translateY(-2px);
}

.tool-btn:active:not(:disabled) {
  transform: translateY(1px);
}

.tool-btn:disabled {
  opacity: 0.36;
  cursor: not-allowed;
}

.tool-btn[aria-pressed="true"] {
  background: var(--accent);
  color: #fff;
}

.tool-btn--ghost {
  color: var(--ink-soft);
}

.tool-count {
  position: absolute;
  top: 3px;
  right: 4px;
  min-width: 16px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-deep);
  font-size: 10px;
  font-weight: 800;
  line-height: 15px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.tool-btn[aria-pressed="true"] .tool-count {
  background: rgba(255, 255, 255, 0.3);
  color: #fff;
}

/* ---------- 提示与播报 ---------- */

#toast {
  position: absolute;
  left: 50%;
  bottom: calc(var(--board-pad) + 12px);
  transform: translate(-50%, 12px);
  max-width: 88%;
  padding: 8px 16px;
  border-radius: 999px;
  background: rgba(42, 33, 24, 0.9);
  color: #fff;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.24s ease, transform 0.24s ease;
  text-align: center;
}

#toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

#toast[data-tone="warn"] {
  background: rgba(192, 57, 43, 0.94);
}

#toast[data-tone="good"] {
  background: rgba(31, 122, 111, 0.94);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.bump {
  animation: bump 0.32s ease;
}

@keyframes bump {
  0% { transform: scale(1); }
  40% { transform: scale(1.16); }
  100% { transform: scale(1); }
}

/* ---------- 弹层 ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(42, 33, 24, 0.34);
  backdrop-filter: blur(3px);
}

.overlay[hidden] {
  display: none;
}

.panel {
  width: min(100%, 460px);
  max-height: min(88dvh, 760px);
  overflow: auto;
  padding: clamp(20px, 4vw, 30px);
  border-radius: 24px;
  background: var(--surface);
  box-shadow: var(--shadow);
  text-align: center;
  animation: panel-in 0.22s ease;
}

@keyframes panel-in {
  from { opacity: 0; transform: translateY(10px) scale(0.985); }
  to { opacity: 1; transform: none; }
}

.panel h2 {
  margin: 0 0 8px;
  font-size: clamp(20px, 3.6vw, 24px);
  font-weight: 800;
  letter-spacing: 0.04em;
}

.panel h2::after {
  content: "";
  display: block;
  width: 34px;
  height: 3px;
  margin: 9px auto 0;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--gold));
}

.panel-desc {
  margin: 0 0 16px;
  font-size: 13.5px;
  line-height: 1.65;
  color: var(--ink-soft);
}

.panel-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 18px;
}

.primary-btn,
.ghost-btn {
  padding: 12px 22px;
  border: none;
  border-radius: 13px;
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
}

.primary-btn {
  background: linear-gradient(135deg, var(--accent), #34b3a2);
  color: #fff;
  box-shadow: 0 10px 22px -8px rgba(42, 157, 143, 0.6);
}

.ghost-btn {
  background: rgba(42, 33, 24, 0.06);
  color: var(--ink);
}

.primary-btn.small {
  padding: 9px 15px;
  font-size: 13px;
}

.primary-btn:hover,
.ghost-btn:hover {
  transform: translateY(-2px);
}

.primary-btn:active,
.ghost-btn:active {
  transform: translateY(1px);
}

.primary-btn:hover {
  box-shadow: 0 14px 26px -8px rgba(42, 157, 143, 0.68);
}

.win-flag {
  display: inline-block;
  margin: 0 0 14px;
  padding: 4px 13px;
  border-radius: 999px;
  background: var(--gold-soft);
  color: #8a6a1f;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.04em;
}

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

.win-grid > div {
  padding: 11px 8px;
  border-radius: 14px;
  background: var(--surface-2);
}

.win-grid > div:last-child {
  background: linear-gradient(135deg, rgba(42, 157, 143, 0.14), rgba(212, 168, 75, 0.16));
  border: 1px solid var(--accent-line);
}

.win-grid dt {
  font-size: 11px;
  letter-spacing: 0.1em;
  color: var(--ink-faint);
  font-weight: 600;
}

.win-grid dd {
  margin: 4px 0 0;
  font-size: 18px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.win-grid > div:last-child dd {
  font-size: 22px;
  color: var(--accent-deep);
}

.win-best {
  margin: 14px 0 0;
  font-size: 12.5px;
  color: var(--ink-soft);
}

/* ---------- 结算仪式感：依次点亮 + 微粒子喷发 ---------- */

.win-panel h2 {
  animation: win-pop 0.34s cubic-bezier(0.2, 0.9, 0.3, 1.35) both;
}

.win-flag {
  animation: win-pop 0.36s cubic-bezier(0.2, 0.9, 0.3, 1.4) both;
  animation-delay: 0.05s;
}

.win-grid > div {
  animation: win-pop 0.4s cubic-bezier(0.2, 0.9, 0.3, 1.3) both;
}

.win-grid > div:nth-child(1) { animation-delay: 0.1s; }
.win-grid > div:nth-child(2) { animation-delay: 0.16s; }
.win-grid > div:nth-child(3) { animation-delay: 0.22s; }
.win-grid > div:nth-child(4) { animation-delay: 0.28s; }

.win-best {
  animation: win-pop 0.36s ease both;
  animation-delay: 0.34s;
}

.win-panel .panel-actions {
  animation: win-pop 0.36s ease both;
  animation-delay: 0.4s;
}

@keyframes win-pop {
  from { opacity: 0; transform: translateY(9px) scale(0.94); }
  to { opacity: 1; transform: none; }
}

/* 微粒子：从弹窗中心向四周炸开的小方片，只在结算出现时播放一次 */
.burst {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 0;
  height: 0;
  pointer-events: none;
  z-index: 2;
}

.burst i {
  position: absolute;
  left: 0;
  top: 0;
  width: 9px;
  height: 9px;
  margin: -4px 0 0 -4px;
  border-radius: 2px;
  opacity: 0;
  animation: burst 1.15s cubic-bezier(0.16, 0.72, 0.28, 1) both;
}

.burst i:nth-child(1)  { background: #2a9d8f; animation-delay: 0.12s; --tx: -150px; --ty: -62px; }
.burst i:nth-child(2)  { background: #d4a84b; animation-delay: 0.18s; --tx: -92px;  --ty: -142px; }
.burst i:nth-child(3)  { background: #9ece56; animation-delay: 0.1s;  --tx: 0;      --ty: -172px; }
.burst i:nth-child(4)  { background: #4aa3d8; animation-delay: 0.2s;  --tx: 92px;   --ty: -142px; }
.burst i:nth-child(5)  { background: #d4a84b; animation-delay: 0.14s; --tx: 150px;  --ty: -62px; }
.burst i:nth-child(6)  { background: #2a9d8f; animation-delay: 0.22s; --tx: 162px;  --ty: 42px; }
.burst i:nth-child(7)  { background: #9ece56; animation-delay: 0.16s; --tx: 102px;  --ty: 134px; }
.burst i:nth-child(8)  { background: #4aa3d8; animation-delay: 0.24s; --tx: 0;      --ty: 162px; }
.burst i:nth-child(9)  { background: #d4a84b; animation-delay: 0.13s; --tx: -102px; --ty: 134px; }
.burst i:nth-child(10) { background: #2a9d8f; animation-delay: 0.19s; --tx: -162px; --ty: 42px; }

@keyframes burst {
  0% { opacity: 0; transform: translate(0, 0) rotate(0deg) scale(0.35); }
  18% { opacity: 1; }
  100% { opacity: 0; transform: translate(var(--tx), var(--ty)) rotate(300deg) scale(1); }
}

/* ---------- 选关 ---------- */

.levels-panel {
  width: min(100%, 720px);
}

.daily-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  padding: 13px 16px;
  border: 1px solid var(--accent-line);
  border-radius: 16px;
  background: linear-gradient(120deg, rgba(42, 157, 143, 0.15), rgba(212, 168, 75, 0.17));
  text-align: left;
}

.daily-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

#daily-label {
  font-size: 14px;
  font-weight: 800;
}

.daily-hint {
  font-size: 11.5px;
  color: var(--ink-soft);
}

.levels-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 10px;
  text-align: left;
}

.lv-chapter {
  grid-column: 1 / -1;
  margin: 10px 0 0;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.12em;
  color: var(--accent-deep);
}

.lv-chapter:first-child {
  margin-top: 0;
}

.level-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px;
  border: 2px solid transparent;
  border-radius: 15px;
  background: var(--surface-2);
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.level-card:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: var(--shadow-soft);
}

.level-card:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.level-card[data-state="current"] {
  border-color: var(--accent);
  box-shadow: var(--ring);
}

.level-card[data-state="cleared"] .lv-meta {
  color: var(--accent-deep);
  font-weight: 700;
}

.lv-thumb {
  width: 100%;
  aspect-ratio: 1 / 1;
  height: auto;
  border-radius: 9px;
  background: var(--board);
}

.level-card:disabled .lv-thumb {
  filter: grayscale(1);
}

.lv-no {
  font-size: 12px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.lv-name {
  font-size: 12px;
  color: var(--ink-soft);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lv-meta {
  font-size: 10.5px;
  color: var(--ink-faint);
  font-variant-numeric: tabular-nums;
}

/* ---------- 玩法说明 ---------- */

.help-panel {
  width: min(100%, 560px);
  text-align: left;
}

.help-panel h2 {
  text-align: center;
}

.help-body h3 {
  margin: 18px 0 6px;
  font-size: 13.5px;
  letter-spacing: 0.08em;
  color: var(--accent-deep);
}

.help-body p,
.help-body li {
  margin: 0;
  font-size: 13px;
  line-height: 1.7;
  color: var(--ink-soft);
}

.help-body ul {
  margin: 0;
  padding-left: 18px;
}

.help-body li + li {
  margin-top: 4px;
}

/* ---------- 无脚本兜底 ---------- */

.noscript {
  max-width: 520px;
  margin: 18vh auto;
  padding: 24px;
  border-radius: 18px;
  background: var(--surface);
  text-align: center;
  box-shadow: var(--shadow-soft);
}

/* ---------- 桌面：棋盘做主体 + 右侧 330px 面板 ---------- */

@media (min-width: 900px) {
  #stage {
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: clamp(28px, 3vw, 52px);
    width: 100%;
    max-width: 1560px;
    margin: 0 auto;
    padding: 18px clamp(24px, 3vw, 40px) 28px;
  }

  #board-wrap {
    order: 0;
    flex: 0 1 auto;
    width: min(72vw, calc(100dvh - 132px), 880px);
  }

  #panel {
    order: 1;
    display: flex;
    flex-direction: column;
    gap: 14px;
    flex: 0 0 var(--panel-w);
    width: var(--panel-w);
  }

  /* 棋盘很大，右侧面板相应加大字号，避免显得"轻" */
  #level-badge { padding: 15px 18px; }
  #level-name { font-size: 21px; }
  .hud-hero { padding: 15px 18px; }
  .hud-hero-val { font-size: clamp(24px, 2vw, 30px); }
  .stat { padding: 12px 6px; }
  .stat-val { font-size: 18px; }

  /* 桌面恢复横排：图标在左、文字在右，重排次数贴右 */
  #toolbar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 4px;
    padding: 8px;
  }

  .tool-btn {
    flex-direction: row;
    justify-content: flex-start;
    gap: 8px;
    padding: 10px 12px;
    font-size: 13px;
  }

  .tool-btn--ghost {
    grid-column: 1 / -1;
  }

  .tool-count {
    position: static;
    margin-left: auto;
    min-width: 20px;
    padding: 1px 6px;
    font-size: 11px;
    line-height: 16px;
  }
}

/* ---------- 移动端断点 ---------- */

@media (max-width: 480px) {
  #topbar { padding: 10px 12px; }
  .home-link { padding: 8px 12px; }
  .home-link span[data-i18n] { display: none; }
  .brand h1 { font-size: 18px; }
  .brand p { font-size: 11px; }
  #stage { gap: 10px; padding: 10px 12px 16px; }
  #level-badge { padding: 11px 13px; border-radius: 16px; }
  #level-name { font-size: 17px; }
  .hud-hero { padding: 11px 13px; border-radius: 16px; }
  .stat { padding: 8px 4px; border-radius: 12px; }
  .stat-val { font-size: 15px; }
  .tool-btn { padding: 8px 1px 7px; font-size: 10.5px; }
  .tool-btn svg { width: 19px; height: 19px; }
  .levels-grid { grid-template-columns: repeat(auto-fill, minmax(80px, 1fr)); gap: 8px; }
}

@media (max-width: 390px) {
  #stage { padding: 8px 10px 14px; gap: 9px; }
  #board-wrap { width: 100%; }
  .panel { padding: 16px; border-radius: 20px; }
  .win-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .win-grid dd { font-size: 16px; }
  .win-grid > div:last-child dd { font-size: 19px; }
  .levels-grid { grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); }
}

@media (max-height: 620px) {
  #topbar { padding: 6px 12px; }
  .brand p { display: none; }
  #stage { gap: 8px; }
  .stat { padding: 6px 4px; }
  .hud-hero { padding: 9px 13px; }
}

/* 窄且矮（横屏手机）：棋盘按 58dvh 收，避免顶掉控制条 */
@media (max-height: 620px) and (max-width: 899px) {
  #board-wrap { width: min(100%, 58dvh); }
}

/* 矮而宽的桌面窗口（如未最大化的笔记本窗口）：
   棋盘改按视口高度收缩，但必须仍明显大于右侧 344px 面板，不能退化成小图 */
@media (min-width: 900px) and (max-height: 720px) {
  #board-wrap { width: min(72vw, calc(100dvh - 96px), 880px); }
}

@media (orientation: landscape) and (max-height: 560px) and (max-width: 899px) {
  #stage { flex-direction: row; align-items: center; justify-content: center; flex-wrap: wrap; }
  #panel { display: flex; flex-direction: column; gap: 8px; flex: 1 1 260px; max-width: 320px; }
  #board-wrap { width: min(52vw, 92dvh); }
}

/* ---------- 减少动效 ---------- */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}
