/* ============================================================
   扫雷大作战 · 基础布局与界面组件
   ============================================================ */

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  background: var(--bg);
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: var(--font-body);
  color: var(--fg);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom);
  transition: background-color 240ms ease, color 240ms ease;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background-image: radial-gradient(var(--grid-line) 1.2px, transparent 1.2px);
  background-size: 24px 24px;
  opacity: 0.85;
}

:root[data-theme="doodle"] body::before {
  background-image: repeating-linear-gradient(
    to bottom,
    transparent 0 31px,
    var(--grid-line) 31px 32px
  );
  background-size: 100% 32px;
  opacity: 0.6;
}

:root[data-theme="tech"] body::before {
  background-image:
    linear-gradient(to right, var(--grid-line) 1px, transparent 1px),
    linear-gradient(to bottom, var(--grid-line) 1px, transparent 1px);
  background-size: 36px 36px;
  opacity: 0.55;
}

h1,
h2,
h3,
p,
ul,
dl,
dd {
  margin: 0;
}

ul {
  padding: 0;
  list-style: none;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
}

a {
  color: var(--accent);
}

svg {
  display: block;
}

.icon {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}

.svg-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

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

.skip-link {
  position: fixed;
  left: 12px;
  top: -80px;
  z-index: 2000;
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 700;
  text-decoration: none;
  transition: top 160ms ease;
}

.skip-link:focus-visible {
  top: 12px;
}

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

/* ============================================================
   顶栏
   ============================================================ */

.topbar {
  max-width: 1180px;
  margin: 0 auto;
  padding: 16px clamp(14px, 3vw, 28px) 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  width: 50px;
  height: 50px;
  flex: none;
  display: block;
  filter: drop-shadow(0 3px 0 var(--shadow-soft));
}

.brand-svg {
  width: 100%;
  height: 100%;
}

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

.brand-text h1 {
  font-family: var(--font-display);
  font-size: clamp(20px, 2.6vw, 27px);
  font-weight: 800;
  letter-spacing: 0.01em;
  line-height: 1.08;
  white-space: nowrap;
}

.brand-text p {
  margin-top: 3px;
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.26em;
  color: var(--muted);
  white-space: nowrap;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border: 2px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--fg);
  box-shadow: 0 var(--lift) 0 var(--shadow-strong);
  font-size: 12.5px;
  font-weight: 700;
  line-height: 1;
  transition: transform 120ms ease, box-shadow 120ms ease, background-color 160ms ease;
}

.icon-btn:hover {
  background: var(--accent-softer);
}

.icon-btn:active {
  transform: translateY(var(--lift));
  box-shadow: none;
}

.btn-label {
  white-space: nowrap;
}

/* ============================================================
   主布局
   ============================================================ */

.layout {
  max-width: 1180px;
  margin: 0 auto;
  padding: 8px clamp(12px, 3vw, 28px) 26px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 18px;
  align-items: start;
}

.game-card {
  position: relative;
  min-width: 0;
  padding: clamp(10px, 1.8vw, 18px);
  background: var(--surface);
  border: 2px solid var(--line);
  border-radius: var(--radius-card);
  box-shadow:
    0 7px 0 var(--shadow),
    0 24px 48px -30px var(--shadow-strong);
}

.game-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.difficulty-bar {
  display: flex;
  align-items: stretch;
  gap: 3px;
  overflow-x: auto;
  scrollbar-width: none;
  max-width: 100%;
  padding: 2px;
}

.difficulty-bar::-webkit-scrollbar {
  display: none;
}

.diff-btn {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1px;
  padding: 6px 10px;
  border: 2px solid transparent;
  border-radius: 11px;
  background: transparent;
  color: var(--muted);
  text-align: left;
  transition: background-color 150ms ease, border-color 150ms ease, color 150ms ease;
}

.diff-btn:hover {
  background: var(--accent-softer);
  color: var(--fg);
}

.diff-btn.is-active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--fg);
}

.diff-name {
  font-size: 13px;
  font-weight: 800;
  line-height: 1.15;
  white-space: nowrap;
}

.diff-meta {
  font-family: var(--font-mono);
  font-size: 9.5px;
  letter-spacing: 0.02em;
  color: var(--muted);
  white-space: nowrap;
}

.diff-daily .diff-name::before {
  content: "★";
  display: inline-block;
  margin-right: 3px;
  color: var(--gold);
  font-size: 10px;
  transform: translateY(-1px);
}

.game-status {
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.04em;
  color: var(--muted);
  white-space: nowrap;
}

/* ============================================================
   计分板
   ============================================================ */

.hud {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  margin: 10px 0 9px;
}

.hud-counter {
  justify-self: start;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 96px;
  padding: 5px 12px 6px;
  background: var(--surface-2);
  border: 2px solid var(--line);
  border-radius: 13px;
  box-shadow: inset 0 2px 0 var(--surface), 0 2px 0 var(--shadow-soft);
}

.hud-timer {
  justify-self: end;
}

.hud-label {
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.16em;
  color: var(--muted);
  line-height: 1;
}

.hud-digits {
  font-family: var(--font-mono);
  font-size: clamp(22px, 4vw, 29px);
  font-weight: 700;
  letter-spacing: 0.1em;
  line-height: 1;
  color: var(--danger);
  font-variant-numeric: tabular-nums;
}

.hud-timer .hud-digits {
  color: var(--accent);
}

.face-btn {
  width: clamp(50px, 7vw, 58px);
  height: clamp(50px, 7vw, 58px);
  flex: none;
  display: grid;
  place-items: center;
  padding: 0;
  border: 2.5px solid var(--line);
  border-radius: 50%;
  background: var(--cover);
  box-shadow: 0 4px 0 var(--shadow-strong);
  color: var(--gold);
  transition: transform 120ms ease, box-shadow 120ms ease;
}

.face-btn:hover {
  filter: brightness(1.04);
}

.face-btn:active {
  transform: translateY(4px);
  box-shadow: none;
}

.face-icon {
  width: 72%;
  height: 72%;
}

/* ============================================================
   棋盘视口与舞台（具体格子在 board.css）
   ============================================================ */

.board-viewport {
  position: relative;
  height: clamp(300px, 50vh, 518px);
  border: 2px solid var(--line);
  border-radius: var(--radius-board);
  background-color: var(--surface-2);
  background-image: radial-gradient(var(--grid-line-strong) 1px, transparent 1px);
  background-size: 17px 17px;
  overflow: hidden;
  touch-action: none;
  overscroll-behavior: contain;
  -webkit-user-select: none;
  user-select: none;
}

.board-stage {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: 0 0;
  padding: 10px;
  will-change: transform;
}

.board-hint {
  position: absolute;
  left: 50%;
  bottom: 8px;
  transform: translateX(-50%);
  z-index: 3;
  padding: 4px 11px;
  border: 1px solid var(--grid-line-strong);
  border-radius: 999px;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  font-size: 10px;
  color: var(--muted);
  white-space: nowrap;
  pointer-events: none;
  transition: opacity 300ms ease;
}

.board-hint.is-hidden {
  opacity: 0;
}

/* ============================================================
   工具栏
   ============================================================ */

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  min-width: 0;
}

.tool-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 7px 10px;
  border: 2px solid var(--line);
  border-radius: 11px;
  background: var(--surface);
  box-shadow: 0 2px 0 var(--shadow);
  color: var(--fg);
  font-size: 11.5px;
  font-weight: 700;
  line-height: 1.1;
  white-space: nowrap;
  transition: transform 120ms ease, box-shadow 120ms ease, background-color 150ms ease;
}

.tool-btn:hover:not(:disabled) {
  background: var(--accent-softer);
}

.tool-btn:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: none;
}

.tool-btn[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--line);
  color: var(--on-accent);
  box-shadow: 0 2px 0 var(--shadow-strong);
}

.tool-btn:disabled {
  opacity: 0.42;
  box-shadow: none;
}

.tool-btn .icon {
  width: 15px;
  height: 15px;
}

.zoom-group {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  border: 2px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
}

.zoom-btn {
  width: 31px;
  height: 31px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--fg);
  font-size: 17px;
  font-weight: 800;
  line-height: 1;
  transition: background-color 140ms ease;
}

.zoom-btn:hover {
  background: var(--accent-soft);
}

.zoom-btn:active {
  background: var(--accent);
  color: var(--on-accent);
}

.zoom-btn .icon {
  width: 15px;
  height: 15px;
}

.zoom-label {
  min-width: 38px;
  text-align: center;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.game-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 9px;
  min-height: 18px;
}

.foot-tips {
  font-size: 10.5px;
  color: var(--muted);
  line-height: 1.5;
}

.kbd {
  display: inline-block;
  padding: 1px 5px;
  border: 1px solid var(--grid-line-strong);
  border-radius: 5px;
  background: var(--surface-2);
  font-family: var(--font-mono);
  font-size: 9.5px;
  color: var(--fg);
}

.dot {
  margin: 0 3px;
  opacity: 0.5;
}

.assist-badge {
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--gold-soft);
  border: 1px solid color-mix(in srgb, var(--gold) 42%, var(--line));
  font-size: 10px;
  font-weight: 700;
  color: var(--fg);
  white-space: nowrap;
}

.assist-badge[hidden] {
  display: none;
}

/* ============================================================
   侧栏
   ============================================================ */

.side {
  display: flex;
  flex-direction: column;
  gap: 13px;
  min-width: 0;
}

.panel {
  padding: 15px 16px;
  background: var(--surface);
  border: 2px solid var(--line);
  border-radius: var(--radius-panel);
  box-shadow: 0 5px 0 var(--shadow);
}

.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 9px;
}

.panel-head h2 {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.01em;
}

.panel-head span {
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.08em;
  color: var(--muted);
  white-space: nowrap;
}

.best-time {
  display: flex;
  align-items: baseline;
  gap: 4px;
  font-family: var(--font-display);
  font-size: clamp(38px, 5vw, 52px);
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.03em;
  color: var(--accent);
}

.best-time small {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
  letter-spacing: 0;
}

.best-meta {
  margin-top: 5px;
  font-size: 11px;
  color: var(--muted);
  line-height: 1.5;
}

.text-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 0;
  border: 0;
  background: transparent;
  color: var(--accent);
  font-size: 11.5px;
  font-weight: 700;
  text-align: left;
}

.text-btn:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.best-panel .text-btn {
  margin-top: 8px;
}

.daily-copy {
  font-size: 11.5px;
  line-height: 1.65;
  color: var(--muted);
}

.daily-best {
  margin: 8px 0 10px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg);
  padding: 6px 9px;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px dashed var(--grid-line-strong);
}

.daily-panel .primary-btn {
  width: 100%;
  padding: 9px 12px;
  font-size: 12.5px;
}

.tip-list {
  display: grid;
  gap: 7px;
}

.tip-list li {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 11.5px;
  line-height: 1.55;
  color: var(--muted);
}

.tip-list b {
  flex: none;
  width: 18px;
  height: 18px;
  display: grid;
  place-items: center;
  margin-top: 1px;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 10px;
}

.tip-panel .text-btn {
  margin-top: 9px;
}

.note-panel {
  border-style: dashed;
  box-shadow: none;
  background: transparent;
  padding: 12px 14px;
}

.note-panel p {
  font-size: 10.5px;
  line-height: 1.65;
  color: var(--muted);
}

/* ============================================================
   按钮
   ============================================================ */

.primary-btn,
.secondary-btn,
.danger-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 17px;
  border: 2px solid var(--line);
  border-radius: 12px;
  font-size: 13px;
  font-weight: 800;
  line-height: 1.15;
  text-align: center;
  transition: transform 120ms ease, box-shadow 120ms ease, filter 150ms ease;
}

.primary-btn {
  background: var(--accent);
  color: var(--on-accent);
  box-shadow: 0 3px 0 var(--shadow-strong);
}

.primary-btn:hover {
  filter: brightness(1.05);
}

.primary-btn:active {
  transform: translateY(3px);
  box-shadow: none;
}

.secondary-btn {
  background: var(--surface);
  color: var(--fg);
  box-shadow: 0 3px 0 var(--shadow);
}

.secondary-btn:hover {
  background: var(--accent-softer);
}

.secondary-btn:active {
  transform: translateY(3px);
  box-shadow: none;
}

.danger-btn {
  background: var(--danger);
  color: var(--pal-paper);
  box-shadow: 0 3px 0 var(--shadow-strong);
}

.danger-btn:active {
  transform: translateY(3px);
  box-shadow: none;
}

.danger-text {
  color: var(--danger);
}

.primary-btn .icon,
.secondary-btn .icon,
.danger-btn .icon {
  width: 15px;
  height: 15px;
}

.wide-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 9px;
  padding: 10px 12px;
  border: 2px solid var(--line);
  border-radius: 11px;
  background: var(--surface-2);
  color: var(--fg);
  font-size: 12.5px;
  font-weight: 700;
  text-align: left;
  transition: background-color 140ms ease;
}

.wide-btn:hover {
  background: var(--accent-softer);
}

.wide-btn + .wide-btn {
  margin-top: 7px;
}

/* ============================================================
   页脚 / 提示条
   ============================================================ */

.footer {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 clamp(14px, 3vw, 28px) calc(20px + env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 10.5px;
  color: var(--muted);
}

.footer-links {
  display: flex;
  align-items: center;
  gap: 4px;
}

.footer-links .text-btn {
  font-size: 10.5px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 1300;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: calc(100vw - 24px);
  padding: 10px 15px;
  border-radius: 999px;
  background: var(--fg);
  color: var(--bg);
  box-shadow: 0 12px 30px -12px var(--shadow-strong);
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1.35;
  animation: toastIn 220ms var(--ease-out);
}

.toast[hidden] {
  display: none;
}

.toast button {
  flex: none;
  padding: 4px 10px;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 11.5px;
  font-weight: 800;
}

.toast button[hidden] {
  display: none;
}

.confetti {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1500;
  pointer-events: none;
}

/* ============================================================
   对话框
   ============================================================ */

dialog.modal {
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--fg);
  overflow: hidden;
}

dialog.modal:not([open]) {
  display: none;
}

dialog.modal[open] {
  display: grid;
  place-items: center;
  padding: clamp(10px, 3vw, 24px);
}

dialog.modal::backdrop {
  background: var(--scrim);
}

.modal-card {
  width: min(540px, calc(100vw - 20px));
  max-height: min(88dvh, 900px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--surface);
  border: 2px solid var(--line);
  border-radius: var(--radius-card);
  box-shadow: 0 26px 70px -24px var(--shadow-strong);
  animation: modalPop 240ms var(--ease-out);
}

.modal-lg {
  width: min(700px, calc(100vw - 20px));
}

.modal-sm {
  width: min(400px, calc(100vw - 20px));
}

.modal-head {
  flex: none;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 17px 20px 12px;
  border-bottom: 1px solid var(--grid-line);
}

.modal-head h2 {
  font-family: var(--font-display);
  font-size: clamp(19px, 2.4vw, 23px);
  font-weight: 800;
  line-height: 1.15;
}

.eyebrow {
  margin-bottom: 3px;
  font-family: var(--font-mono);
  font-size: 8.5px;
  letter-spacing: 0.24em;
  color: var(--muted);
}

.close-btn {
  width: 34px;
  height: 34px;
  flex: none;
  display: grid;
  place-items: center;
  border: 2px solid var(--line);
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--fg);
  transition: background-color 140ms ease, transform 120ms ease;
}

.close-btn:hover {
  background: var(--accent-soft);
}

.close-btn:active {
  transform: scale(0.94);
}

.modal-body {
  padding: 16px 20px 20px;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.modal-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 18px;
}

.modal-actions .primary-btn {
  flex: 1 1 auto;
  min-width: 120px;
}

.modal-actions .secondary-btn {
  flex: 1 1 auto;
  min-width: 110px;
}

/* ——— 设置 ——— */

.setting-group {
  padding: 13px 0;
  border-bottom: 1px dashed var(--grid-line-strong);
}

.setting-group:first-child {
  padding-top: 0;
}

.setting-group:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.setting-group h3 {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 800;
  margin-bottom: 8px;
}

.setting-note {
  margin-top: 7px;
  font-size: 11px;
  line-height: 1.6;
  color: var(--muted);
}

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

.theme-card {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 7px;
  border: 2px solid var(--grid-line-strong);
  border-radius: 14px;
  background: var(--surface-2);
  color: var(--fg);
  text-align: left;
  transition: border-color 150ms ease, background-color 150ms ease, transform 150ms ease;
}

.theme-card:hover {
  transform: translateY(-2px);
  border-color: var(--accent-line);
}

.theme-card.is-active {
  border-color: var(--accent);
  background: var(--accent-softer);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.theme-preview {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 3px;
  width: 100%;
  aspect-ratio: 1 / 1;
  padding: 6px;
  border-radius: 9px;
  background: var(--p-bg);
  border: 1px solid var(--p-line);
}

.theme-preview i {
  display: grid;
  place-items: center;
  border-radius: 3px;
  background: var(--p-cover);
  box-shadow: inset 0 -2px 0 color-mix(in srgb, var(--p-line) 25%, transparent);
  color: var(--p-fg);
  font-style: normal;
  font-size: 8px;
  font-weight: 800;
  line-height: 1;
}

.theme-preview i.open {
  background: var(--p-open);
  color: var(--p-accent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--p-line) 18%, transparent);
}

.theme-preview i.flag {
  color: var(--p-flag);
}

.theme-name {
  font-size: 11.5px;
  font-weight: 800;
  line-height: 1.2;
}

.theme-en {
  font-family: var(--font-mono);
  font-size: 7.5px;
  letter-spacing: 0.09em;
  color: var(--muted);
  white-space: nowrap;
}

.segmented {
  display: inline-flex;
  width: 100%;
  padding: 3px;
  gap: 3px;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: var(--surface-2);
}

.segmented button {
  flex: 1;
  padding: 7px 8px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  transition: background-color 140ms ease, color 140ms ease;
}

.segmented button:hover {
  color: var(--fg);
}

.segmented button[aria-pressed="true"] {
  background: var(--accent);
  color: var(--on-accent);
  box-shadow: 0 2px 0 var(--shadow);
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  cursor: pointer;
}

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

.switch-copy b {
  font-size: 12.5px;
  font-weight: 700;
}

.switch-copy small {
  font-size: 10.5px;
  line-height: 1.45;
  color: var(--muted);
}

.switch-row input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.switch {
  position: relative;
  flex: none;
  width: 44px;
  height: 25px;
  border: 2px solid var(--line);
  border-radius: 999px;
  background: var(--surface-3);
  transition: background-color 160ms ease;
}

.switch::after {
  content: "";
  position: absolute;
  left: 2px;
  top: 2px;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background: var(--surface);
  border: 1.5px solid var(--line);
  transition: transform 160ms var(--ease-out);
}

.switch-row input:checked + .switch {
  background: var(--accent);
}

.switch-row input:checked + .switch::after {
  transform: translateX(19px);
}

.switch-row input:focus-visible + .switch {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
}

/* ——— 战绩 ——— */

.stats-hero {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
  margin-bottom: 14px;
}

.stats-hero > div {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 11px 6px;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: var(--surface-2);
  text-align: center;
}

.stats-hero span {
  font-family: var(--font-mono);
  font-size: clamp(19px, 3vw, 24px);
  font-weight: 700;
  line-height: 1;
  color: var(--accent);
}

.stats-hero small {
  font-size: 9.5px;
  color: var(--muted);
}

.stats-list,
.daily-list {
  display: grid;
  gap: 6px;
}

.stats-list:empty::after,
.daily-list:empty::after {
  content: "还没有记录，先去开一局。";
  display: block;
  padding: 12px;
  border: 1px dashed var(--grid-line-strong);
  border-radius: 10px;
  font-size: 11px;
  color: var(--muted);
  text-align: center;
}

.stat-row,
.daily-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--grid-line);
  border-radius: 10px;
  background: var(--surface-2);
}

.stat-row.is-current {
  border-color: var(--accent);
  background: var(--accent-softer);
}

.stat-name,
.daily-name {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.stat-name b,
.daily-name b {
  font-size: 12px;
  font-weight: 800;
}

.stat-name small,
.daily-name small {
  font-family: var(--font-mono);
  font-size: 9px;
  color: var(--muted);
}

.stat-best,
.daily-best-time {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  white-space: nowrap;
}

.stat-rate,
.daily-rate {
  font-family: var(--font-mono);
  font-size: 9.5px;
  color: var(--muted);
  white-space: nowrap;
}

.subhead {
  margin: 18px 0 8px;
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 800;
}

/* ——— 自定义 ——— */

.custom-presets {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 13px;
}

.custom-presets button {
  padding: 7px 10px;
  border: 1.5px solid var(--grid-line-strong);
  border-radius: 999px;
  background: var(--surface-2);
  font-size: 10.5px;
  font-weight: 700;
}

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

.field-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 9px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
}

.field input {
  width: 100%;
  padding: 9px 10px;
  border: 2px solid var(--line);
  border-radius: 9px;
  background: var(--field-bg);
  color: var(--fg);
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 700;
  text-align: center;
}

.field input:focus-visible {
  border-color: var(--accent);
  outline: 3px solid var(--accent-soft);
  outline-offset: 1px;
}

.form-note {
  margin-top: 8px;
  font-size: 10.5px;
  color: var(--muted);
  line-height: 1.5;
}

.form-error {
  margin-top: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--danger-soft);
  border: 1px solid color-mix(in srgb, var(--danger) 36%, transparent);
  font-size: 11px;
  font-weight: 700;
  color: var(--danger);
}

.form-error[hidden] {
  display: none;
}

/* ——— 结算 ——— */

.result-card {
  width: min(470px, calc(100vw - 20px));
  align-items: center;
  text-align: center;
  padding: 22px 22px 20px;
  overflow-y: auto;
}

.result-icon {
  width: 74px;
  height: 74px;
  display: grid;
  place-items: center;
  margin-bottom: 10px;
  border-radius: 50%;
  background: var(--gold-soft);
  border: 2px solid var(--line);
  color: var(--gold);
  box-shadow: 0 5px 0 var(--shadow);
}

.result-svg {
  width: 44px;
  height: 44px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.result-card.is-loss .result-icon {
  background: var(--danger-soft);
  border-color: color-mix(in srgb, var(--danger) 45%, var(--line));
  color: var(--danger);
}

.result-card.is-loss .result-time {
  color: var(--danger);
}

.result-card .eyebrow {
  color: var(--muted);
}

.result-card h2 {
  font-family: var(--font-display);
  font-size: clamp(25px, 4vw, 33px);
  font-weight: 800;
  line-height: 1.12;
  letter-spacing: -0.01em;
}

.result-sub {
  margin-top: 5px;
  max-width: 30em;
  font-size: 12px;
  line-height: 1.55;
  color: var(--muted);
}

.result-time {
  display: flex;
  align-items: baseline;
  gap: 5px;
  margin: 11px 0 4px;
  font-family: var(--font-mono);
  font-size: clamp(32px, 6vw, 42px);
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--accent);
}

.result-time small {
  font-family: var(--font-body);
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0;
  color: var(--muted);
}

.result-badges {
  display: flex;
  justify-content: center;
  gap: 5px;
  flex-wrap: wrap;
  min-height: 4px;
  margin-bottom: 10px;
}

.result-badges span {
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--accent-soft);
  border: 1px solid var(--accent-line);
  font-size: 10px;
  font-weight: 700;
  color: var(--fg);
}

.result-badges span.gold {
  background: var(--gold-soft);
  border-color: color-mix(in srgb, var(--gold) 45%, var(--line));
}

.result-badges span.casual {
  background: var(--surface-2);
  border-color: var(--grid-line-strong);
  color: var(--muted);
}

.result-stats {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  text-align: left;
}

.result-stats > div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 9px;
  background: var(--surface-2);
  border: 1px solid var(--grid-line);
}

.result-stats dt {
  font-size: 10px;
  color: var(--muted);
  white-space: nowrap;
}

.result-stats dd {
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-weight: 700;
  text-align: right;
}

.result-actions {
  width: 100%;
  justify-content: center;
  margin-top: 15px;
}

.result-actions .primary-btn {
  flex: 1 1 100%;
}

.result-actions .secondary-btn {
  flex: 1 1 0;
  min-width: 0;
  padding: 9px 10px;
  font-size: 11.5px;
}

.result-actions .secondary-btn[hidden],
.result-actions .primary-btn[hidden] {
  display: none;
}

/* ——— 分享 ——— */

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

.share-preview {
  display: grid;
  place-items: center;
  padding: 7px;
  border: 1px solid var(--grid-line-strong);
  border-radius: 12px;
  background: var(--surface-2);
}

.share-preview img {
  width: auto;
  max-width: 100%;
  max-height: min(46dvh, 460px);
  border-radius: 6px;
  border: 1px solid var(--grid-line);
  box-shadow: 0 8px 22px -14px var(--shadow-strong);
}

.share-note {
  font-size: 10.5px;
  line-height: 1.6;
  color: var(--muted);
}

/* ——— 玩法说明 ——— */

.help-body {
  display: grid;
  gap: 14px;
}

.help-section h3 {
  margin-bottom: 5px;
  font-family: var(--font-display);
  font-size: 13.5px;
  font-weight: 800;
}

.help-section p {
  font-size: 11.5px;
  line-height: 1.7;
  color: var(--muted);
}

.help-section ul {
  display: grid;
  gap: 5px;
}

.help-section li {
  position: relative;
  padding-left: 13px;
  font-size: 11.5px;
  line-height: 1.65;
  color: var(--muted);
}

.help-section li::before {
  content: "";
  position: absolute;
  left: 2px;
  top: 0.65em;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--accent);
}

.help-section b {
  color: var(--fg);
  font-weight: 700;
}

.confirm-body {
  font-size: 12.5px;
  line-height: 1.7;
  color: var(--muted);
}

/* ============================================================
   动效
   ============================================================ */

@keyframes modalPop {
  from {
    opacity: 0;
    transform: translateY(14px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translate(-50%, 10px);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

/* ============================================================
   响应式
   ============================================================ */

@media (max-width: 960px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .side {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: start;
  }

  .note-panel {
    grid-column: 1 / -1;
  }

  .board-viewport {
    height: clamp(300px, 52vh, 500px);
  }
}

@media (max-width: 640px) {
  .topbar {
    padding-top: 12px;
  }

  .brand-mark {
    width: 42px;
    height: 42px;
  }

  .brand-text p {
    display: none;
  }

  .btn-label {
    display: none;
  }

  .icon-btn {
    width: 40px;
    height: 40px;
    padding: 0;
    justify-content: center;
  }

  .icon-btn .icon {
    width: 19px;
    height: 19px;
  }

  .game-status {
    display: none;
  }

  .game-head {
    display: block;
  }

  .difficulty-bar {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    margin: 0 -2px;
    gap: 2px;
    overflow: visible;
  }

  .diff-btn {
    align-items: center;
    min-width: 0;
    padding: 5px 2px;
    text-align: center;
  }

  .diff-name {
    font-size: 11px;
  }

  .diff-meta {
    font-size: 8px;
    letter-spacing: 0;
  }

  .hud-counter {
    min-width: 84px;
    padding: 4px 9px 5px;
  }

  .toolbar {
    justify-content: space-between;
  }

  .tool-btn {
    padding: 7px 8px;
  }

  .tool-btn .icon {
    width: 14px;
    height: 14px;
  }

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

  .theme-card {
    flex-direction: row;
    align-items: center;
    gap: 10px;
  }

  .theme-preview {
    width: 62px;
    flex: none;
  }

  .theme-name {
    flex: 1;
  }

  .stats-hero > div {
    padding: 9px 3px;
  }

  .modal-actions {
    gap: 6px;
  }

  .modal-actions .primary-btn,
  .modal-actions .secondary-btn {
    min-width: 0;
    padding: 9px 11px;
    font-size: 12px;
  }

  .field-row {
    gap: 6px;
  }

  .result-card {
    padding: 18px 14px 16px;
  }

  .result-stats {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 400px) {
  .brand-text h1 {
    font-size: 18px;
  }

  .tool-btn {
    font-size: 10.5px;
  }

  .zoom-label {
    min-width: 32px;
  }

  .zoom-btn {
    width: 28px;
    height: 28px;
  }

  .diff-meta {
    font-size: 8.5px;
  }

  .foot-tips {
    font-size: 9.5px;
  }
}

@media (max-height: 620px) and (orientation: landscape) {
  .topbar {
    padding-top: 8px;
    padding-bottom: 4px;
  }

  .brand-mark {
    width: 38px;
    height: 38px;
  }

  .board-viewport {
    height: max(250px, calc(100dvh - 230px));
  }

  .layout {
    padding-bottom: 14px;
  }
}

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