:root {
  --bg: var(--tg-theme-bg-color, #0f1115);
  --text: var(--tg-theme-text-color, #e9edf2);
  --hint: var(--tg-theme-hint-color, #8b97a7);
  --card: var(--tg-theme-secondary-bg-color, #1a1e26);
  --accent: var(--tg-theme-button-color, #3a8a5f);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --light: #ebecd0;
  --dark: #6f9a55;
  --sel: rgba(255, 221, 80, 0.55);
  --lastmove: rgba(255, 221, 80, 0.32);
  --dot: rgba(20, 20, 20, 0.28);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; background: var(--bg); color: var(--text);
  font-family: -apple-system, system-ui, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}
body { padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom); }

.screen { display: none; padding: 16px; max-width: 520px; margin: 0 auto; }
.screen.active { display: block; }

.logo { font-size: 34px; font-weight: 800; text-align: center; margin: 18px 0 4px; }
.tagline { text-align: center; color: var(--hint); margin: 0 0 20px; }

.card {
  background: var(--card); border-radius: 16px; padding: 16px; margin-bottom: 16px;
}
.card h2 { margin: 0 0 12px; font-size: 17px; }

.btn {
  appearance: none; border: 0; border-radius: 12px; padding: 13px 16px;
  background: #2b3140; color: var(--text); font-size: 15px; font-weight: 600;
  cursor: pointer; flex: 1;
}
.btn.primary { background: var(--accent); color: var(--accent-text); width: 100%; }
.btn.ghost { background: transparent; border: 1px solid #2b3140; }
.btn.small { flex: 0 0 auto; padding: 8px 14px; font-size: 13px; }
.btn:active { filter: brightness(1.12); }

.row { display: flex; gap: 10px; margin-top: 12px; }
.level-label { display: block; color: var(--hint); font-size: 14px; margin-bottom: 6px; }
input[type="range"] { width: 100%; accent-color: var(--accent); }

.join-row { display: flex; gap: 10px; margin-top: 12px; }
.join-row input, #joinCode {
  flex: 1; background: #0e1016; border: 1px solid #2b3140; color: var(--text);
  border-radius: 12px; padding: 12px; font-size: 15px; text-transform: uppercase;
}

/* game screen */
.topbar { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.status { color: var(--hint); font-size: 14px; flex: 1; text-align: right; }
.playerbar {
  font-size: 14px; font-weight: 600; padding: 8px 4px; color: var(--text);
  display: flex; align-items: center; gap: 8px;
}
.playerbar.turn::before { content: "●"; color: var(--accent); }

.board {
  width: 100%; aspect-ratio: 1 / 1; display: grid;
  grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr);
  border-radius: 10px; overflow: hidden; touch-action: manipulation;
  user-select: none;
}
.sq {
  position: relative; display: flex; align-items: center; justify-content: center;
  font-size: 0; cursor: pointer;
}
.sq.light { background: var(--light); }
.sq.dark { background: var(--dark); }
.sq .piece {
  font-size: min(9.5vw, 48px); line-height: 1;
  filter: drop-shadow(0 1px 1px rgba(0,0,0,0.35));
}
.sq.white-piece .piece { color: #fff; }
.sq.black-piece .piece { color: #111; }
.sq.sel { box-shadow: inset 0 0 0 4px var(--sel); }
.sq.lastmove { background-image: linear-gradient(var(--lastmove), var(--lastmove)); }
.sq.target::after {
  content: ""; position: absolute; width: 30%; height: 30%; border-radius: 50%;
  background: var(--dot);
}
.sq.target.capture::after {
  width: 86%; height: 86%; border-radius: 50%; background: transparent;
  border: 5px solid var(--dot);
}
.sq.check { background-image: radial-gradient(circle, rgba(220,40,40,0.85), transparent 72%); }

.coord { position: absolute; font-size: 9px; font-weight: 700; opacity: 0.5; }
.coord.file { bottom: 1px; right: 2px; }
.coord.rank { top: 1px; left: 2px; }

.controls { display: flex; gap: 10px; margin-top: 14px; justify-content: center; }

.invite {
  background: var(--card); border-radius: 14px; padding: 16px; margin-top: 14px;
  text-align: center;
}
.invite .code {
  font-size: 30px; font-weight: 800; letter-spacing: 4px; margin: 10px 0;
  color: var(--accent);
}
.invite .hint, .hint { color: var(--hint); font-size: 13px; margin-top: 8px; }
.invite .btn { margin-top: 6px; }

.hidden { display: none !important; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: #000c; color: #fff; padding: 10px 18px; border-radius: 20px;
  font-size: 14px; z-index: 50; max-width: 90%;
}

.promo-overlay {
  position: fixed; inset: 0; background: #000a; display: flex;
  align-items: center; justify-content: center; z-index: 60;
}
.promo-box { background: var(--card); border-radius: 16px; padding: 18px; text-align: center; }
.promo-title { color: var(--hint); margin-bottom: 12px; }
.promo-pieces { display: flex; gap: 8px; }
.promo-pieces button {
  font-size: 40px; width: 64px; height: 64px; border-radius: 12px; border: 0;
  background: #2b3140; color: #fff; cursor: pointer;
}
