:root {
  --bg1: #fff7ed;
  --bg2: #eef2ff;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --line: rgba(15, 23, 42, 0.10);
  --p1: #2563eb;
  --p2: #ef4444;
  --shadow: 0 18px 60px rgba(0, 0, 0, 0.10);
  --shadow-soft: 0 12px 30px rgba(2, 6, 23, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: ui-rounded, "Comic Sans MS", "PingFang SC", "Microsoft YaHei", ui-sans-serif, system-ui, -apple-system, Arial,
    sans-serif;
  background: radial-gradient(1200px 800px at 20% 10%, var(--bg1), transparent 60%),
    radial-gradient(1200px 800px at 80% 20%, var(--bg2), transparent 55%),
    linear-gradient(180deg, #f8fafc, #eef2ff);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

.wrap {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
  gap: 14px;
}

.card {
  width: min(520px, 100%);
  background: var(--card);
  border-radius: 18px;
  padding: 20px 18px;
  box-shadow: var(--shadow);
  border: 2px solid rgba(15, 23, 42, 0.06);
}

.header h1 {
  font-size: 26px;
  margin: 0 0 8px;
  letter-spacing: 0.5px;
}

.desc {
  margin: 0 0 14px;
  color: var(--muted);
  line-height: 1.55;
  font-size: 14px;
}

.status {
  margin: 10px 0 14px;
  font-size: 16px;
  font-weight: 700;
  background: rgba(15, 23, 42, 0.04);
  border: 1px solid rgba(15, 23, 42, 0.06);
  padding: 10px 12px;
  border-radius: 999px;
}

.stats {
  margin: 10px 0 12px;
  border-radius: 16px;
  padding: 12px 12px;
  border: 1px solid rgba(15, 23, 42, 0.06);
  background: linear-gradient(180deg, rgba(34, 197, 94, 0.10), rgba(59, 130, 246, 0.06));
  box-shadow: 0 10px 24px rgba(2, 6, 23, 0.06);
}

.statsRow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.statsRateSmall {
  font-size: 12px;
  font-weight: 900;
  color: rgba(15, 23, 42, 0.72);
  letter-spacing: 0.2px;
}

.statsSide {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  min-width: 96px;
}

.diffWrap {
  display: grid;
  place-items: center start;
  gap: 4px;
}

.diffLabel {
  font-size: 12px;
  font-weight: 900;
  color: rgba(15, 23, 42, 0.70);
  letter-spacing: 0.2px;
}

.diffGrid {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 10px;
  gap: 4px;
  padding: 4px 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid rgba(15, 23, 42, 0.10);
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
}

.diffDot {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  border: 1px solid rgba(15, 23, 42, 0.22);
  background: rgba(255, 255, 255, 0.55);
}

.diffDot.isOn {
  background: rgba(15, 23, 42, 0.92);
  border-color: rgba(15, 23, 42, 0.92);
}

.diffPicker {
  margin-top: 6px;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 18px;
  gap: 6px;
  padding: 6px 8px;
  border-radius: 14px;
  border: 1px solid rgba(15, 23, 42, 0.10);
  background: rgba(255, 255, 255, 0.55);
  width: fit-content;
}

.diffPickDot {
  width: 18px;
  height: 18px;
  border-radius: 6px;
  border: 1px solid rgba(15, 23, 42, 0.22);
  background: rgba(255, 255, 255, 0.55);
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
}

.diffPickDot.isOn {
  background: rgba(15, 23, 42, 0.92);
  border-color: rgba(15, 23, 42, 0.92);
}

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

.statsSub {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.statsSub .dot {
  opacity: 0.6;
}

.uid {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}

.p1 {
  color: var(--p1);
}

.p2 {
  color: var(--p2);
}

.board {
  width: min(420px, 100%);
  aspect-ratio: 1 / 1;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  border: 3px solid var(--line);
  border-radius: 22px;
  overflow: hidden;
  background: #fff;
  box-shadow: var(--shadow-soft);
}

.cell {
  appearance: none;
  border: 0;
  background: linear-gradient(180deg, #ffffff, #f8fafc);
  border-right: 3px solid var(--line);
  border-bottom: 3px solid var(--line);
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0;
  user-select: none;
  width: 100%;
  height: 100%;
  touch-action: manipulation;
  transition: transform 90ms ease, filter 180ms ease, background 180ms ease, opacity 180ms ease;
}

.mark {
  font-size: clamp(48px, 8vw, 72px);
  font-weight: 900;
  line-height: 1;
}

.cell:hover {
  filter: brightness(1.04);
}

.cell:active {
  transform: scale(0.98);
}

.cell:nth-child(3n) {
  border-right: 0;
}
.cell:nth-last-child(-n + 3) {
  border-bottom: 0;
}

.cell.x {
  color: var(--p1);
}
.cell.o {
  color: var(--p2);
}

.cell:disabled {
  cursor: not-allowed;
  opacity: 0.98;
}

.cell.win {
  background: #fef9c3;
}

.mark.about {
  opacity: 0.45;
  filter: saturate(0.55) brightness(1.15);
}

.mark.fading {
  animation: vanish 320ms ease-out forwards;
}

@keyframes vanish {
  0% {
    opacity: 1;
    filter: saturate(1) brightness(1);
  }
  100% {
    opacity: 0;
    filter: saturate(0.25) brightness(1.6);
  }
}

.meta {
  margin-top: 14px;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.metaRow {
  font-size: 14px;
  color: var(--text);
}

.label {
  font-weight: 800;
  margin-right: 8px;
}

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

.btn {
  width: min(360px, 100%);
  background: linear-gradient(180deg, #22c55e, #16a34a);
  color: #fff;
  border: 0;
  border-radius: 999px;
  padding: 12px 14px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(22, 163, 74, 0.25);
  touch-action: manipulation;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

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

.btnSecondary {
  background: linear-gradient(180deg, rgba(37, 99, 235, 0.92), rgba(29, 78, 216, 0.92));
  box-shadow: 0 10px 24px rgba(37, 99, 235, 0.20);
}

.footer {
  color: var(--muted);
  font-size: 12px;
}

.modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
  z-index: 50;
}

.modal.isOpen {
  display: flex;
}

.modalBackdrop {
  position: absolute;
  inset: 0;
  background: rgba(2, 6, 23, 0.55);
  backdrop-filter: blur(4px);
}

.restModal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
  z-index: 999;
}

.restModal.isOpen {
  display: flex;
}

.restBackdrop {
  position: absolute;
  inset: 0;
  background: rgba(2, 6, 23, 0.70);
  backdrop-filter: blur(5px);
}

.restPanel {
  position: relative;
  width: min(420px, 100%);
  border-radius: 18px;
  background: #fff;
  border: 2px solid rgba(15, 23, 42, 0.10);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.22);
  padding: 16px 14px;
  transform: translateY(6px);
  animation: pop 160ms ease-out forwards;
}

.restTitle {
  font-weight: 1000;
  font-size: 16px;
}

.restBody {
  margin-top: 8px;
}

.restMsg {
  font-size: 18px;
  font-weight: 1000;
  line-height: 1.5;
  color: rgba(15, 23, 42, 0.92);
}

.restSub {
  margin-top: 10px;
  font-size: 13px;
  color: rgba(100, 116, 139, 0.95);
}

.restCount {
  font-weight: 1000;
}

.modalPanel {
  position: relative;
  width: min(420px, 100%);
  border-radius: 18px;
  background: #fff;
  border: 2px solid rgba(15, 23, 42, 0.10);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.22);
  padding: 16px 14px;
  transform: translateY(6px);
  animation: pop 160ms ease-out forwards;
}

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

.modalTitle {
  font-weight: 1000;
  font-size: 16px;
}

.modalBody {
  margin-top: 8px;
  font-size: 22px;
  font-weight: 1000;
  letter-spacing: 0.4px;
}

.modalActions {
  margin-top: 14px;
  display: flex;
  justify-content: center;
}

.modalBtn {
  width: min(320px, 100%);
}

.tipPanel {
  width: min(420px, 100%);
  padding: 14px 14px;
}

.tipText {
  font-size: 16px;
  font-weight: 800;
  line-height: 1.5;
  color: rgba(15, 23, 42, 0.86);
}

@media (max-width: 420px) {
  .wrap {
    /* 手机端：避免内容被底部安全区/地址栏挤压，优先让底部按钮露出来 */
    min-height: 100svh;
    place-items: start center;
    padding: 12px 12px calc(16px + env(safe-area-inset-bottom));
  }
  .card {
    padding: 14px 12px;
    border-radius: 16px;
  }
  .header h1 {
    /* 去掉第一个大标题（手机端隐藏） */
    display: none;
  }
  .desc {
    font-size: 12px;
    line-height: 1.45;
    margin: 0 0 10px;
  }
  .status {
    margin: 8px 0 10px;
    padding: 8px 10px;
    font-size: 14px;
  }
  .stats {
    margin: 8px 0 10px;
    padding: 8px 10px;
    border-radius: 14px;
  }
  .statsTitle {
    font-size: 12px;
  }
  .statsRateSmall {
    font-size: 12px;
  }
  .statsSide {
    min-width: 88px;
  }
  .diffGrid {
    grid-auto-columns: 9px;
    gap: 3px;
    padding: 3px 5px;
  }
  .diffLabel {
    font-size: 11px;
  }
  .diffDot {
    width: 9px;
    height: 9px;
    border-radius: 3px;
  }
  .diffPicker {
    grid-auto-columns: 16px;
    gap: 5px;
    padding: 5px 7px;
  }
  .diffPickDot {
    width: 16px;
    height: 16px;
    border-radius: 6px;
  }
  .statsSub {
    margin-top: 4px;
    font-size: 12px;
  }
  .meta {
    margin-top: 10px;
  }
  .actions {
    margin-top: 12px;
    /* 按钮随页面自然滚动（不固定/不吸底） */
  }
  .btn {
    font-size: 15px;
    padding: 11px 14px;
  }
  .board {
    border-radius: 18px;
    /* 兼容部分移动端 WebView 对 aspect-ratio 的兼容问题 */
    height: min(380px, 86vw);
    position: relative;
    z-index: 1;
  }
  .cell {
    pointer-events: auto;
  }
  .tipText {
    font-size: 15px;
  }
}
