:root {
  --bg: #0e1420;
  --bg-elevated: #161e2e;
  --text: #eef2f8;
  --text-dim: #8b96a8;
  --accent: #3ea6ff;
  --success: #34c759;
  --danger: #ff453a;
  --warning: #ffb020;
  --border: #263248;
  --board-light: #eddcc4;
  --board-dark: #a5896a;
  --board-light-hi: #f3e29b;
  --board-dark-hi: #cdb050;
}

* { 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, BlinkMacSystemFont, "Segoe UI", Tahoma, sans-serif;
  overscroll-behavior: none;
  user-select: none;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  padding: 16px;
  display: flex;
  flex-direction: column;
}

.screen { display: flex; flex-direction: column; align-items: center; flex: 1; }
.screen.hidden { display: none; }

h1 { font-size: 22px; margin: 8px 0; text-align: center; }
h2 { font-size: 24px; margin: 12px 0; text-align: center; }

.balance { font-size: 16px; color: var(--text-dim); margin: 4px 0 16px; }
.balance span { color: var(--warning); font-weight: 700; }

.hint { font-size: 13px; color: var(--text-dim); text-align: center; margin-bottom: 20px; line-height: 1.7; }

.stake-list { width: 100%; display: flex; flex-direction: column; gap: 10px; }

.stake-btn {
  width: 100%;
  padding: 16px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 18px;
  font-weight: 700;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.stake-btn:active { background: var(--accent); border-color: var(--accent); }
.stake-btn .sub { font-size: 12px; font-weight: 400; color: var(--text-dim); }

.error-text { color: var(--danger); font-size: 14px; margin-top: 16px; text-align: center; min-height: 20px; }

.spinner {
  width: 44px; height: 44px;
  border: 4px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
  margin: 60px 0 20px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.btn {
  padding: 12px 28px;
  border-radius: 12px;
  border: none;
  font-size: 15px;
  font-weight: 700;
  margin-top: 16px;
}
.btn-danger { background: var(--danger); color: #fff; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-practice { background: var(--bg-elevated); color: var(--text); border: 1px solid var(--border); width: 100%; margin-top: 14px; }
.btn-small { padding: 8px 20px; font-size: 13px; }

.player-row {
  width: 100%;
  max-width: 380px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 4px;
}
.player-name { font-size: 14px; color: var(--text-dim); font-weight: 600; }
.clock {
  font-variant-numeric: tabular-nums;
  font-size: 16px;
  font-weight: 700;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 10px;
  min-width: 56px;
  text-align: center;
}
.clock.low { color: var(--danger); border-color: var(--danger); }
.clock.active { color: var(--warning); border-color: var(--warning); }

.board-wrap {
  position: relative;
  width: 100%;
  max-width: 380px;
  margin: 4px 0;
}

.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 10px;
  overflow: hidden;
  border: 2px solid var(--border);
  direction: ltr;   /* board files always run a->h left-to-right regardless of page RTL */
}

.square {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 7.2vw;
  max-font-size: 34px;
}
@media (min-width: 480px) { .square { font-size: 34px; } }

.square.light { background: var(--board-light); }
.square.dark { background: var(--board-dark); }
.square.selected.light { background: var(--board-light-hi); }
.square.selected.dark { background: var(--board-dark-hi); }
.square.last-move.light { background: #e8e28f; }
.square.last-move.dark { background: #c9b95a; }
.square.check-square { box-shadow: inset 0 0 0 3px var(--danger); }

.square .dot {
  position: absolute;
  width: 28%;
  height: 28%;
  border-radius: 50%;
  background: rgba(30, 30, 30, 0.35);
  pointer-events: none;
}
.square .ring {
  position: absolute;
  inset: 6%;
  border-radius: 50%;
  border: 4px solid rgba(30, 30, 30, 0.35);
  pointer-events: none;
}

.piece {
  line-height: 1;
  pointer-events: none;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.35));
}
.piece.white { color: #fbfbfb; -webkit-text-stroke: 1px #2a2a2a; }
.piece.black { color: #1c1c1c; -webkit-text-stroke: 0.5px #000; }

.check-banner {
  position: absolute;
  top: 6px; left: 50%;
  transform: translateX(-50%);
  background: var(--danger);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 8px;
  pointer-events: none;
}
.check-banner.hidden { display: none; }

.promo-picker {
  position: absolute;
  inset: 0;
  background: rgba(10, 14, 22, 0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border-radius: 10px;
  z-index: 5;
}
.promo-picker.hidden { display: none; }
.promo-btn {
  font-size: 30px;
  width: 56px; height: 56px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
}
.promo-btn:active { background: var(--accent); }

#result-title { font-size: 26px; }
#result-title.win { color: var(--success); }
#result-title.lose { color: var(--danger); }
#result-title.draw { color: var(--text-dim); }
#result-detail { color: var(--text-dim); font-size: 15px; text-align: center; }
