:root {
  --bg-primary: #000000;
  --bg-secondary: #0a0d16;
  --bg-card: #121a29;
  --bg-raised: #1b2738;
  --text-primary: #ffffff;
  --text-secondary: #bdc9d6;
  --accent-primary: #42dcff;
  --accent-secondary: #62f2ae;
  --accent-warm: #ffc55a;
  --danger: #ff6577;
  --success: #62f2ae;
  --focus-glow: rgba(66, 220, 255, 0.48);
  --board-light: #294252;
  --board-dark: #13222f;
  --radius: 16px;
}

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

html, body {
  width: 600px;
  height: 600px;
  overflow: hidden;
  background: var(--bg-primary);
}

body {
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input {
  color: inherit;
  font: inherit;
  border: 0;
}

.app-root {
  width: 600px;
  height: 600px;
  padding: 8px;
  position: relative;
}

.screen {
  position: absolute;
  inset: 8px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.hidden { display: none !important; }

.header {
  min-height: 66px;
  padding: 11px 16px;
  border-radius: var(--radius);
  background: var(--bg-secondary);
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.header h1 { font-size: 22px; line-height: 1.1; flex: 1; }
.eyebrow { color: var(--accent-primary); font-size: 12px; font-weight: 700; letter-spacing: 0.15em; margin-bottom: 4px; }
.header-meta { color: var(--text-secondary); font-size: 14px; }

.content {
  min-height: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 8px 0;
}

.home-content { justify-content: center; }
.card { background: var(--bg-card); border-radius: var(--radius); }
.hero { height: 108px; padding: 14px 20px; display: flex; align-items: center; gap: 22px; }
.hero h2 { font-size: 22px; margin-bottom: 5px; }
.hero p, .helper { color: var(--text-secondary); font-size: 14px; line-height: 1.4; }
.hero-piece {
  width: 68px;
  height: 68px;
  border-radius: 18px;
  background: linear-gradient(145deg, #31d2ff, #137ba6);
  color: #06111d;
  font: 700 52px "Segoe UI Symbol", "Noto Sans Symbols 2", Georgia, serif;
  display: grid;
  place-items: center;
}

.focusable {
  border: 2px solid transparent;
  transition: transform 300ms cubic-bezier(0.6, 0, 0.4, 1), border-color 180ms ease, background 180ms ease;
}

.focusable:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 20px var(--focus-glow);
  transform: scale(0.96);
}

.action-card {
  min-height: 82px;
  width: 100%;
  padding: 14px 20px;
  background: var(--bg-card);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  justify-content: center;
  text-align: left;
}

.primary-action { background: #123447; }
.action-title { font-size: 19px; font-weight: 650; }
.action-detail { font-size: 14px; color: var(--text-secondary); margin-top: 4px; }
.badge {
  border-radius: 16px;
  background: rgba(66, 220, 255, 0.16);
  color: var(--accent-primary);
  font-size: 14px;
  font-weight: 600;
  padding: 8px 12px;
}

.back-btn, .small-action {
  min-height: 46px;
  border-radius: 12px;
  background: var(--bg-raised);
  padding: 9px 13px;
  font-size: 16px;
}

.back-btn { font-size: 22px; min-width: 52px; }
.setup-content { padding: 20px 30px; gap: 10px; }
.field-label { font-size: 15px; font-weight: 600; color: var(--text-secondary); margin-top: 9px; }
.text-input {
  background: var(--bg-card);
  border-radius: 14px;
  height: 66px;
  padding: 0 18px;
  font-size: 19px;
}

.difficulty-grid {
  display: flex;
  gap: 8px;
}

.difficulty-btn {
  flex: 1;
  height: 68px;
  border-radius: 13px;
  background: var(--bg-card);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 3px;
}

.difficulty-btn strong { font-size: 16px; }
.difficulty-btn span { color: var(--text-secondary); font-size: 13px; }
.difficulty-btn.selected {
  background: #123447;
  border-color: var(--accent-primary);
  color: var(--accent-primary);
}

.nav-item {
  min-height: 70px;
  border-radius: var(--radius);
  background: var(--bg-raised);
  text-align: center;
  font-size: 18px;
  font-weight: 650;
}

.nav-item.primary { color: #04131b; background: var(--accent-primary); }
.start-button { margin-top: 10px; }

.game-header { min-height: 62px; padding: 8px 12px; }
.game-title { flex: 1; min-width: 0; }
.game-title h1 { font-size: 19px; margin-bottom: 2px; }
.game-content { flex: 1; display: flex; flex-direction: column; align-items: center; padding-top: 9px; }
.players-row {
  height: 39px;
  width: 488px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 14px;
}

.player-chip, .move-chip {
  background: var(--bg-card);
  color: var(--text-secondary);
  border-radius: 18px;
  padding: 7px 13px;
  max-width: 176px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.player-chip.active { color: var(--accent-secondary); border: 1px solid var(--accent-secondary); }
.board {
  display: grid;
  grid-template-columns: repeat(8, 52px);
  grid-template-rows: repeat(8, 52px);
  border: 4px solid var(--bg-raised);
  border-radius: 10px;
  overflow: hidden;
  background: var(--bg-raised);
}

.square {
  height: 52px;
  min-height: 0;
  display: grid;
  place-items: center;
  position: relative;
  background: var(--board-dark);
  color: var(--text-primary);
  font: 34px "Segoe UI Symbol", "Noto Sans Symbols 2", Georgia, serif;
  border-radius: 0;
  border-width: 3px;
}

.square.light { background: var(--board-light); }
.square.selected { background: #246b76; }
.square.target::after {
  content: "";
  width: 16px;
  height: 16px;
  background: var(--accent-secondary);
  border-radius: 50%;
  opacity: 0.72;
  position: absolute;
}
.square.target.occupied::after {
  width: 43px;
  height: 43px;
  background: transparent;
  border: 4px solid var(--accent-secondary);
}
.square.in-check { background: #763340; }
.square:focus { transform: none; z-index: 2; }
.piece-white { color: #ffffff; text-shadow: 0 2px 3px #0a0d16; }
.piece-black { color: #63a4bc; text-shadow: 0 2px 2px #05080d; }
.board.ai-turn { opacity: 0.82; }
.game-prompt {
  margin-top: 8px;
  min-height: 29px;
  max-width: 500px;
  color: var(--text-secondary);
  font-size: 15px;
  text-align: center;
}

.promotion-panel {
  position: absolute;
  left: 50%;
  top: 196px;
  width: 374px;
  transform: translateX(-50%);
  padding: 14px;
  background: var(--bg-secondary);
  border: 2px solid var(--accent-primary);
  box-shadow: 0 0 24px var(--focus-glow);
  border-radius: 18px;
  z-index: 10;
}

.promotion-title {
  font-size: 17px;
  font-weight: 650;
  text-align: center;
  margin-bottom: 10px;
}

.promotion-options { display: flex; gap: 8px; }

.promotion-btn {
  flex: 1;
  height: 74px;
  border-radius: 13px;
  background: var(--bg-raised);
  color: #ffffff;
  font: 42px "Segoe UI Symbol", "Noto Sans Symbols 2", Georgia, serif;
}

.leaderboard-content { padding: 14px 10px 0; }
.tab-bar { display: flex; gap: 8px; }
.tab-item {
  flex: 1;
  min-height: 58px;
  border-radius: 14px;
  background: var(--bg-card);
  color: var(--text-secondary);
  font-weight: 600;
}
.tab-item.active { color: var(--accent-primary); background: #123447; }
.ranking-note { font-size: 14px; color: var(--text-secondary); min-height: 20px; }
.rankings-list {
  position: relative;
  max-height: 390px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-bottom: 35px;
}
.rank-row {
  min-height: 62px;
  background: var(--bg-card);
  border-radius: 13px;
  padding: 10px 15px;
  display: grid;
  grid-template-columns: 38px 1fr auto;
  align-items: center;
  gap: 10px;
}
.rank-number { color: var(--accent-warm); font-size: 20px; font-weight: 700; }
.rank-name { font-size: 17px; font-weight: 600; }
.rank-meta { color: var(--text-secondary); font-size: 14px; }
.rank-wins { color: var(--accent-secondary); font-size: 17px; font-weight: 700; }
.empty-state { background: var(--bg-card); border-radius: 14px; color: var(--text-secondary); padding: 28px; text-align: center; line-height: 1.5; }
.scroll-container::after {
  content: "";
  position: sticky;
  bottom: 0;
  display: block;
  min-height: 35px;
  background: linear-gradient(to top, var(--bg-secondary), transparent);
  pointer-events: none;
}

.loading-container { display: flex; align-items: center; justify-content: center; gap: 14px; padding: 20px; }
.loading-spinner {
  width: 30px;
  height: 30px;
  border: 3px solid var(--bg-raised);
  border-top-color: var(--accent-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { color: var(--text-secondary); }

.finish-content { justify-content: center; padding: 18px 18px 0; }
.result-card { text-align: center; padding: 26px 16px; margin-bottom: 4px; }
.result-label { color: var(--accent-warm); font-weight: 700; letter-spacing: 0.14em; font-size: 13px; }
.result-card h2 { font-size: 30px; margin: 10px 0; }
.result-card p { color: var(--text-secondary); font-size: 14px; }

.toast {
  position: fixed;
  top: 30px;
  left: 50%;
  z-index: 30;
  max-width: 536px;
  border-radius: 22px;
  padding: 13px 22px;
  color: var(--text-primary);
  background: var(--bg-raised);
  border: 1px solid var(--accent-primary);
  transform: translate(-50%, -120px);
  transition: transform 220ms ease;
  font-size: 15px;
}
.toast.visible { transform: translate(-50%, 0); }
.toast.error { border-color: var(--danger); }
.toast.success { border-color: var(--success); }
