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

:root {
  --ink: #14201c;
  --muted: #4d635a;
  --paper: #f4f7f8;
  --teal: #1f6f5b;
  --mint: #7ec8a3;
  --sky: #3d8ea5;
  --coral: #e07a5f;
  --line: rgba(20, 32, 28, 0.15);
  --bg-grid: #d7e3de;
}

html,
body {
  height: 100%;
}

body {
  font-family: "IBM Plex Sans", "Microsoft YaHei", "PingFang SC", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(900px 520px at 0% 0%, rgba(31, 111, 91, 0.28), transparent 60%),
    radial-gradient(800px 420px at 100% 0%, rgba(126, 200, 163, 0.28), transparent 55%),
    var(--paper);
  min-height: 100dvh;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  overflow-y: auto;
  overflow-x: hidden;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

#box {
  width: min(840px, 100vw);
  padding: clamp(0.6rem, 2vw, 1rem);
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.back-home {
  align-self: flex-start;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--teal);
  padding: 0.35rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.6);
  text-decoration: none;
}

.h {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.8rem;
}

.h h1 {
  font-family: "Syne", sans-serif;
  font-weight: 800;
  font-size: clamp(2.2rem, 8vw, 3rem);
  color: var(--teal);
  letter-spacing: 0.06em;
}

.panels {
  display: grid;
  grid-template-columns: repeat(4, minmax(64px, 1fr));
  gap: 0.5rem;
  align-items: stretch;
}

.panel {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.4rem 0.6rem;
  text-align: center;
  min-height: 56px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.1rem;
}

.panel-label {
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.panel-val {
  font-weight: 800;
  font-size: 1.2rem;
  color: var(--teal);
}

.panel.next #next {
  width: 80px;
  height: 80px;
  display: block;
}

.stage {
  position: relative;
  margin: 0 auto;
  width: 300px;
}

.board {
  display: block;
  width: 300px;
  height: 600px;
  background: var(--bg-grid);
  border: 1px solid rgba(31, 111, 91, 0.25);
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(20, 32, 28, 0.18);
  touch-action: none;
}

.overlay {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(20, 32, 28, 0.4);
  backdrop-filter: blur(4px);
  border-radius: 12px;
  padding: 16px;
}

.overlay.show {
  display: flex;
}

.overlay-card {
  background: #fff;
  border-radius: 14px;
  padding: 1.3rem 1.4rem;
  max-width: 86%;
  text-align: center;
  box-shadow: 0 10px 30px rgba(20, 32, 28, 0.2);
}

.overlay-card h2 {
  font-family: "Syne", sans-serif;
  font-size: 1.6rem;
  color: var(--teal);
  margin-bottom: 0.5rem;
}

.overlay-card p {
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 1rem;
  line-height: 1.5;
}

.overlay-card button {
  font: inherit;
  font-weight: 700;
  padding: 0.6rem 1.6rem;
  border: none;
  border-radius: 10px;
  background: var(--teal);
  color: #fff;
  cursor: pointer;
  transition: transform 0.08s ease, background 0.15s ease, box-shadow 0.15s ease;
  box-shadow: 0 4px 14px rgba(31, 111, 91, 0.3);
}
.overlay-card button:hover { background: #165344; transform: translateY(-2px); }

.overlay-card button:active { background: #165344; }

.touch {
  display: grid;
  grid-template-columns: 72px auto 72px;
  align-items: center;
  gap: 0.8rem;
  width: 100%;
  max-width: 360px;
  margin: 0 auto;
}

.t-btn {
  width: 72px;
  height: 72px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid var(--line);
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--teal);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(20, 32, 28, 0.08);
  transition: transform 0.08s ease, background 0.15s ease, box-shadow 0.15s ease;
}
.t-btn:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(20, 32, 28, 0.14); }

.t-btn:active { background: var(--mint); color: #fff; }
.t-btn.primary { background: var(--teal); color: #fff; }
.t-btn.primary:active { background: #165344; }

.t-stack {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  justify-items: center;
}

/* ===== 竖屏手机适配：整页不滚动，棋盘自适应 ===== */
@media (max-width: 720px) {
  body {
    overflow: hidden;
    align-items: stretch;
  }

  #box {
    width: 100vw;
    height: 100dvh;
    padding: clamp(0.5rem, 2vw, 0.7rem);
    gap: 0.5rem;
  }

  .back-home {
    font-size: 0.75rem;
    padding: 0.25rem 0.5rem;
  }

  .h {
    gap: 0.45rem;
    flex-wrap: wrap;
  }
  .h h1 {
    font-size: clamp(1.4rem, 6vw, 1.8rem);
  }

  .panels {
    width: 100%;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.35rem;
  }
  .panel {
    padding: 0.3rem 0.2rem;
    min-height: 0;
    gap: 0;
  }
  .panel-label {
    font-size: 0.6rem;
    letter-spacing: 0.04em;
  }
  .panel-val {
    font-size: 1rem;
  }
  .panel.next #next {
    width: 44px;
    height: 44px;
  }

  .stage {
    flex: 1 1 auto;
    width: 100%;
    margin: 0;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .board {
    /* 高度跟随 .stage 剩余空间，宽度按 1:2 比例自动反推；
       max-width 保证窄屏不溢出，浏览器自动取宽高较小约束 */
    width: auto;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    aspect-ratio: 1 / 2;
  }

  .touch {
    width: 100%;
    max-width: 420px;
    grid-template-columns: 1fr 1.5fr 1fr;
    gap: 0.5rem;
  }
  .t-btn {
    width: 100%;
    height: auto;
    aspect-ratio: 1;
    font-size: clamp(1.1rem, 5vw, 1.4rem);
    border-radius: 14px;
  }
  .t-stack {
    gap: 0.4rem;
  }
}

/* ===== 横屏（矮高度）适配：左信息 + 中棋盘 + 右按钮 ===== */
@media (orientation: landscape) and (max-height: 560px) {
  body {
    overflow: hidden;
    align-items: center;
  }

  #box {
    width: 100vw;
    height: 100dvh;
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    padding: 0.5rem;
  }

  .back-home {
    position: absolute;
    top: 0.5rem;
    left: 0.5rem;
    z-index: 5;
  }

  .h {
    flex: 0 0 auto;
    flex-direction: column;
    align-items: stretch;
    width: min(180px, 28vw);
    gap: 0.5rem;
  }
  .h h1 {
    font-size: 1.3rem;
  }
  .panels {
    grid-template-columns: 1fr 1fr;
    gap: 0.35rem;
  }
  .panel.next #next {
    width: 56px;
    height: 56px;
  }

  .stage {
    flex: 0 0 auto;
    width: auto;
    height: 100%;
    margin: 0;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .board {
    width: auto;
    height: 100%;
    aspect-ratio: 1 / 2;
  }

  .touch {
    flex: 0 0 auto;
    width: min(200px, 26vw);
    max-width: none;
    grid-template-columns: 1fr;
    gap: 0.4rem;
  }
  .t-stack {
    grid-template-columns: 1fr;
    grid-template-rows: repeat(3, 1fr);
    gap: 0.4rem;
  }
  .t-btn {
    width: 100%;
    height: auto;
    aspect-ratio: 1;
  }
}
