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

:root {
  --accent: #ff8a3d;
  --accent-dark: #ef6c00;
  --ink: #4a3526;
  /* One shared board-width formula so squares and piece glyphs stay in sync. */
  --bw: min(92vw, 440px, calc(100dvh - 250px));
}

html {
  height: 100%;
}

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

body {
  display: flex;
  flex-direction: column;
  align-items: center;
  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));
}

/* 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(239, 108, 0, 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 {
  margin: auto 0;
  width: 100%;
  max-width: 600px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.hidden { display: none !important; }

/* ---- Menu ---- */
h1 {
  font-size: clamp(32px, 8vw, 52px);
  text-shadow: 2px 2px 0 #fff, 4px 4px 0 rgba(239, 108, 0, 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(239, 108, 0, 0.15);
  text-align: center;
}

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

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

.segmented button {
  font-size: clamp(16px, 4.5vw, 20px);
  font-weight: 700;
  padding: 12px 18px;
  border: 3px solid var(--accent);
  border-radius: 14px;
  background: #fff;
  color: var(--accent-dark);
  cursor: pointer;
}

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

.big-btn {
  font-size: clamp(22px, 6vw, 30px);
  font-weight: 800;
  color: #fff;
  background: linear-gradient(180deg, #ffa94d, var(--accent-dark));
  border: none;
  border-radius: 18px;
  padding: 16px 40px;
  cursor: pointer;
  box-shadow: 0 6px 0 #c75b00;
}

.big-btn:active { transform: translateY(3px); box-shadow: 0 3px 0 #c75b00; }

/* ---- Game ---- */
.status {
  font-size: clamp(18px, 5vw, 26px);
  font-weight: 800;
  min-height: 34px;
  text-align: center;
}

/* Board: an 8×8 grid of tappable squares (lichess wood palette). */
#board {
  width: var(--bw);
  height: var(--bw);
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border-radius: 12px;
  overflow: hidden;
  border: 5px solid #8a6343;
  box-shadow: 0 8px 0 rgba(180, 120, 60, 0.35), 0 12px 24px rgba(0, 0, 0, 0.15);
  touch-action: manipulation;
}

.sq {
  position: relative;
  border: none;
  padding: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font: inherit;
}

.sq.light { background: #f0d9b5; }
.sq.dark { background: #b58863; }

/* Overlay tints stay under the piece glyph. */
.sq::before {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.sq.last::before { background: rgba(255, 213, 79, 0.45); }
.sq.sel::before { background: rgba(45, 177, 255, 0.4); }
.sq.check::before { background: radial-gradient(circle, rgba(255, 61, 48, 0.7) 20%, rgba(255, 61, 48, 0) 75%); }
.sq.hint::before { box-shadow: inset 0 0 0 3px #2db1ff; background: rgba(45, 177, 255, 0.18); }

/* Legal-move markers: a dot on empty squares, a ring on captures. */
.sq.target::after {
  content: '';
  position: absolute;
  width: 30%;
  height: 30%;
  border-radius: 50%;
  background: rgba(45, 140, 80, 0.45);
  pointer-events: none;
}

.sq.capture::after {
  content: '';
  position: absolute;
  inset: 6%;
  border-radius: 50%;
  border: calc(var(--bw) / 110) solid rgba(45, 140, 80, 0.55);
  pointer-events: none;
}

.piece {
  position: relative;
  z-index: 1;
  font-size: calc(var(--bw) / 8 * 0.74);
  line-height: 1;
  pointer-events: none;
}

.piece.white {
  color: #fdfdfd;
  text-shadow: 0 2px 3px rgba(0, 0, 0, 0.4);
  -webkit-text-stroke: calc(var(--bw) / 300) #4a4a4a;
}

.piece.black {
  color: #33302d;
  text-shadow: 0 2px 3px rgba(0, 0, 0, 0.35);
  -webkit-text-stroke: calc(var(--bw) / 300) #111;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
}

.ctrl-btn {
  font-size: clamp(15px, 4vw, 18px);
  font-weight: 700;
  padding: 12px 16px;
  border: none;
  border-radius: 14px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  box-shadow: 0 4px 0 rgba(180, 120, 60, 0.3);
}

.ctrl-btn:active { transform: translateY(2px); box-shadow: 0 2px 0 rgba(180, 120, 60, 0.3); }

/* ---- Promotion picker ---- */
#promo {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: rgba(0, 0, 0, 0.5);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}

#promo .promo-box {
  background: #fff;
  border-radius: 20px;
  padding: 20px 22px;
  text-align: center;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
}

#promo h2 {
  font-size: clamp(17px, 4.6vw, 21px);
  margin-bottom: 14px;
}

.promo-btns { display: flex; gap: 10px; justify-content: center; }

.promo-piece {
  font-size: clamp(38px, 11vw, 54px);
  line-height: 1;
  width: clamp(58px, 16vw, 76px);
  height: clamp(58px, 16vw, 76px);
  border: 3px solid var(--accent);
  border-radius: 14px;
  background: #fff8ef;
  cursor: pointer;
}

.promo-piece:active { transform: scale(0.94); }
.promo-piece.white { color: #fdfdfd; -webkit-text-stroke: 1.5px #4a4a4a; text-shadow: 0 2px 3px rgba(0, 0, 0, 0.4); }
.promo-piece.black { color: #33302d; -webkit-text-stroke: 1.5px #111; }
