:root {
  --ink: #17315b;
  --panel-bg: rgba(244, 248, 252, 0.94);
  --line: rgba(23, 49, 91, 0.2);
  --bg-top: #d7ecf8;
  --bg-bottom: #ede4c9;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: "Trebuchet MS", "Arial Rounded MT Bold", "Segoe UI", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", system-ui, sans-serif;
  color: var(--ink);
}

body {
  background: linear-gradient(165deg, var(--bg-top) 0%, #e8f3fa 46%, var(--bg-bottom) 100%);
  display: flex;
  justify-content: center;
  align-items: flex-start;
  min-height: 100dvh;
  padding: 12px;
  overflow-x: hidden;
  overflow-y: auto;
}

.app-shell {
  width: min(1120px, 100%);
}

.panel {
  border: 3px solid var(--line);
  border-radius: 24px;
  background: var(--panel-bg);
  box-shadow: 0 8px 20px rgba(13, 38, 80, 0.1);
}

.hidden {
  display: none !important;
}

.menu-panel {
  text-align: center;
  padding: clamp(18px, 4vw, 32px);
}

.game-title {
  margin: 0;
  font-size: clamp(2rem, 7vw, 3.2rem);
  line-height: 1;
  color: #ff4f2e;
}

.rule {
  margin: 8px 0;
  font-size: clamp(1.04rem, 3vw, 1.28rem);
  font-weight: 700;
}

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

.main-btn,
.ghost-btn {
  border-radius: 999px;
  border: 0;
  font-size: 1rem;
  font-family: inherit;
  font-weight: 800;
  padding: 12px 20px;
  cursor: pointer;
  transition: transform 120ms ease, filter 180ms ease;
}

.main-btn {
  color: #fff;
  background: linear-gradient(130deg, #ff8f3c, #ff5037);
  box-shadow: 0 6px 14px rgba(255, 86, 56, 0.25);
}

.ghost-btn {
  color: #124096;
  background: linear-gradient(130deg, #d3ebff, #c0e2ff);
  box-shadow: 0 6px 14px rgba(56, 140, 230, 0.16);
}

.main-btn:hover,
.ghost-btn:hover {
  filter: brightness(1.05);
  transform: translateY(-1px);
}

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

.best-line {
  margin: 16px 0 0;
  font-size: 1.03rem;
}

.best-divider {
  margin: 0 8px;
  color: rgba(20, 32, 56, 0.34);
}

.game-panel {
  padding: clamp(12px, 2.8vw, 18px);
}

.canvas-wrap {
  position: relative;
  border-radius: 18px;
  overflow: hidden;
  border: 2px solid rgba(20, 32, 56, 0.15);
  background: #f4f8fc;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: min(78vh, 760px);
  height: min(78dvh, 760px);
  touch-action: manipulation;
}

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

.game-actions .ghost-btn {
  min-height: 56px;
  min-width: 180px;
}

.board-compat {
  display: none;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 14px;
  background: rgba(14, 22, 40, 0.46);
}

.overlay-card {
  width: min(480px, 100%);
  border-radius: 20px;
  border: 3px solid rgba(255, 255, 255, 0.76);
  background: linear-gradient(170deg, #fff9ed, #ffffff);
  box-shadow: 0 20px 40px rgba(15, 22, 35, 0.3);
  text-align: center;
  padding: 20px 18px;
}

.overlay-card h2 {
  margin: 0;
  font-size: clamp(1.45rem, 5vw, 2rem);
  color: #ff582a;
}

.overlay-card p {
  margin: 10px 0 16px;
  font-size: 1.1rem;
  font-weight: 700;
  white-space: pre-line;
}

@media (max-width: 760px) {
  body {
    padding: 10px;
  }

  #gameCanvas {
    height: min(72vh, 620px);
    height: min(72dvh, 620px);
  }

  .game-actions .ghost-btn {
    min-width: 150px;
    min-height: 52px;
  }
}
