* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --accent: #d97706;
  --accent-dark: #92400e;
  --ink: #4a3018;
  --red: #c02c2c;
  --black: #26303c;
  --wood: #f3d9a4;
}

html {
  height: 100%;
}

html, body {
  font-family: "PingFang SC", "Microsoft YaHei", -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
  background: linear-gradient(160deg, #fdf6ec 0%, #f7e7ce 45%, #eeD9b8 100%);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

body {
  display: flex;
  flex-direction: column;
  align-items: center;
  /* min-height fills the screen so content centers when it fits, but the body
     can grow taller and scroll when it doesn't (fixes top/bottom clipping on
     small mobile viewports). dvh accounts for mobile browser chrome. */
  min-height: 100vh;
  min-height: 100dvh;
  padding: 16px;
  padding-top: max(16px, env(safe-area-inset-top));
  padding-bottom: max(16px, env(safe-area-inset-bottom));
}

.screen {
  margin: auto 0;
}

/* Language toggle — top-right corner, matches the playful button style. */
#langToggle {
  position: fixed;
  top: max(10px, env(safe-area-inset-top));
  right: max(10px, env(safe-area-inset-right));
  z-index: 60;
  display: flex;
  gap: 2px;
  padding: 3px;
  border: 3px solid var(--accent);
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 4px 0 rgba(146, 64, 14, 0.25);
}

#langToggle button {
  font-family: inherit;
  font-size: clamp(11px, 2.6vw, 13px);
  font-weight: 800;
  padding: 5px 8px;
  border: none;
  border-radius: 11px;
  background: transparent;
  color: var(--accent-dark);
  cursor: pointer;
  white-space: nowrap;
}

#langToggle button.active { background: var(--accent); color: #fff; }
#langToggle button:active { transform: translateY(1px); }

/* Confetti overlay */
#fx {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 50;
}

.screen {
  width: 100%;
  max-width: 520px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.hidden { display: none !important; }

/* ---- Menu ---- */
h1 {
  font-size: clamp(30px, 7.6vw, 50px);
  text-shadow: 2px 2px 0 #fff, 4px 4px 0 rgba(146, 64, 14, 0.25);
}

.subtitle {
  font-size: clamp(16px, 4vw, 22px);
  color: var(--accent-dark);
  font-weight: 600;
}

.card {
  width: 100%;
  background: rgba(255, 255, 255, 0.7);
  border-radius: 20px;
  padding: 16px;
  box-shadow: 0 6px 0 rgba(146, 64, 14, 0.15);
  text-align: center;
}

.card h2 {
  font-size: clamp(16px, 4.5vw, 20px);
  margin-bottom: 12px;
}

.segmented {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.segmented button {
  font-size: clamp(14px, 3.8vw, 17px);
  font-weight: 700;
  font-family: inherit;
  color: var(--ink);
  padding: 10px 14px;
  border: 3px solid transparent;
  border-radius: 14px;
  background: #fff;
  cursor: pointer;
}

.segmented button.selected {
  border-color: var(--accent);
  color: var(--accent-dark);
  background: #fef3e2;
}

.big-btn {
  font-size: clamp(18px, 5vw, 24px);
  font-weight: 800;
  font-family: inherit;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: 18px;
  padding: 14px 42px;
  cursor: pointer;
  box-shadow: 0 6px 0 var(--accent-dark);
}

.big-btn:active { transform: translateY(3px); box-shadow: 0 3px 0 var(--accent-dark); }

.big-btn.secondary {
  background: #fff;
  color: var(--accent-dark);
  border: 3px solid var(--accent);
  box-shadow: 0 6px 0 rgba(146, 64, 14, 0.25);
}

.credit {
  font-size: clamp(11px, 2.8vw, 13px);
  color: rgba(74, 48, 24, 0.6);
  text-align: center;
}

/* ---- Game HUD ---- */
.hud {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  min-height: 40px;
}

.hud-item {
  font-size: clamp(14px, 3.8vw, 18px);
  font-weight: 800;
  background: rgba(255, 255, 255, 0.85);
  border-radius: 12px;
  padding: 6px 16px;
  box-shadow: 0 3px 0 rgba(146, 64, 14, 0.12);
  text-align: center;
}

.hud-item.check {
  color: #fff;
  background: var(--red);
  box-shadow: 0 3px 0 #7f1d1d;
  animation: checkPulse 0.6s ease infinite alternate;
}

@keyframes checkPulse {
  from { transform: scale(1); }
  to { transform: scale(1.08); }
}

/* ---- Board ---- */
#boardWrap {
  position: relative;
  width: min(100%, 430px);
  aspect-ratio: 9 / 10;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 6px 0 rgba(146, 64, 14, 0.25), 0 10px 24px rgba(146, 64, 14, 0.25);
  background: var(--wood);
  touch-action: manipulation;
}

#boardBg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

#pieces {
  position: absolute;
  inset: 0;
}

.piece {
  position: absolute;
  width: 10.4%;
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "Kaiti SC", "STKaiti", KaiTi, "PingFang SC", serif;
  font-weight: 800;
  font-size: min(6vw, 26px);
  background: radial-gradient(circle at 35% 30%, #fffdf5, #f5e3bd 68%, #e4c98f);
  border: 2px solid rgba(74, 48, 24, 0.55);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.35), inset 0 0 0 2.5px #fffdf5, inset 0 0 0 4px rgba(74, 48, 24, 0.35);
  cursor: pointer;
  transition: left 0.18s ease, top 0.18s ease;
  z-index: 2;
}

.piece.red { color: var(--red); }
.piece.black { color: var(--black); }

.piece.sel {
  box-shadow: 0 0 0 3px #fbbf24, 0 3px 8px rgba(0, 0, 0, 0.4), inset 0 0 0 2.5px #fffdf5, inset 0 0 0 4px rgba(74, 48, 24, 0.35);
  z-index: 4;
}

.piece.last {
  box-shadow: 0 0 0 3px rgba(217, 119, 6, 0.65), 0 2px 4px rgba(0, 0, 0, 0.35), inset 0 0 0 2.5px #fffdf5, inset 0 0 0 4px rgba(74, 48, 24, 0.35);
}

.piece.hintFlash {
  animation: hintBlink 0.35s ease 3;
}

.piece.fade {
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.4);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

/* legal-destination markers */
.dot {
  position: absolute;
  width: 4.4%;
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: rgba(217, 119, 6, 0.75);
  box-shadow: 0 0 0 2px rgba(255, 253, 245, 0.8);
  z-index: 3;
  pointer-events: none;
}

.dot.captureDot {
  width: 9.4%;
  background: transparent;
  border: 3px dashed rgba(192, 44, 44, 0.85);
  box-shadow: none;
}

.dot.hintDot {
  background: rgba(59, 130, 246, 0.7);
  animation: hintBlink 0.35s ease 3;
}

@keyframes hintBlink {
  50% { opacity: 0.15; }
}

/* mark of the square a piece just left */
.fromMark {
  position: absolute;
  width: 5.6%;
  aspect-ratio: 1;
  transform: translate(-50%, -50%) rotate(45deg);
  background: rgba(217, 119, 6, 0.4);
  z-index: 1;
  pointer-events: none;
}

/* ---- Controls ---- */
.controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.ctrl-btn {
  font-size: clamp(13px, 3.4vw, 16px);
  font-weight: 700;
  font-family: inherit;
  color: var(--ink);
  padding: 9px 12px;
  border: none;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.92);
  cursor: pointer;
  box-shadow: 0 3px 0 rgba(146, 64, 14, 0.18);
}

.ctrl-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(146, 64, 14, 0.18); }

.ctrl-btn:disabled { opacity: 0.5; cursor: default; }

/* ---- Result overlay ---- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 55;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(74, 48, 24, 0.45);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  padding: 20px;
}

.overlay-card {
  background: #fff;
  border-radius: 22px;
  padding: 28px 24px;
  text-align: center;
  max-width: 340px;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  animation: cardPop 0.25s ease;
}

@keyframes cardPop {
  from { transform: scale(0.85); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.overlay-card h2 { font-size: clamp(22px, 6vw, 30px); }

.overlay-card p {
  font-size: clamp(15px, 4vw, 18px);
  font-weight: 600;
  color: var(--accent-dark);
  min-height: 1.2em;
}
