:root {
  --bg: #0e1116;
  --bg-2: #171b23;
  --card: #1c212b;
  --gold: #d4af37;
  --gold-2: #f0d97a;
  --text: #eef1f6;
  --muted: #8a93a6;
  --accent: #4c8bf5;
  --danger: #e0555b;
  --green: #3fbf7f;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
.hidden { display: none !important; }

html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
}

#app { position: fixed; inset: 0; }

.screen {
  position: absolute; inset: 0;
  display: none;
  flex-direction: column;
  background: radial-gradient(120% 100% at 50% 0%, var(--bg-2) 0%, var(--bg) 65%);
}
.screen.active { display: flex; }

/* Loading */
#screen-loading { align-items: center; justify-content: center; gap: 14px; }
.crown { font-size: 64px; color: var(--gold); text-shadow: 0 0 24px rgba(212,175,55,.5); }
.loading-title { font-size: 20px; font-weight: 700; letter-spacing: .5px; }
.spinner {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid rgba(212,175,55,.25); border-top-color: var(--gold);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Home */
.home-header { text-align: center; padding: 28px 16px 8px; }
.crown-small { font-size: 34px; color: var(--gold); }
.home-header h1 { margin: 4px 0 6px; font-size: 22px; letter-spacing: .3px; }
.profile-line { color: var(--muted); font-size: 13px; }

.menu-list { display: flex; flex-direction: column; gap: 12px; padding: 20px; }
.menu-btn {
  display: flex; align-items: center; gap: 12px;
  background: var(--card); color: var(--text);
  border: 1px solid rgba(212,175,55,.15);
  border-radius: 16px; padding: 16px 18px;
  font-size: 16px; font-weight: 600;
  cursor: pointer;
}
.menu-btn.primary {
  background: linear-gradient(135deg, var(--gold-2), var(--gold));
  color: #1a1400; border: none;
}
.menu-btn.ghost { background: transparent; border: 1px solid rgba(255,255,255,.12); color: var(--muted); }
.menu-btn .mi { font-size: 20px; }
.menu-btn:active { transform: scale(0.98); }

.mygames-list { padding: 0 20px 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.mygame-item {
  background: var(--card); border-radius: 12px; padding: 12px 14px;
  display: flex; justify-content: space-between; align-items: center;
  font-size: 14px; border: 1px solid rgba(255,255,255,.06);
}
.mygame-item .badge { font-size: 11px; padding: 3px 8px; border-radius: 20px; background: rgba(255,255,255,.08); color: var(--muted); }
.mygame-item .badge.active { background: rgba(63,191,127,.18); color: var(--green); }
.mygame-item .badge.finished { background: rgba(255,255,255,.08); }

/* Panel (invite / ai-setup) */
.panel { margin: auto; width: 100%; max-width: 420px; padding: 24px; text-align: center; }
.panel h2 { margin: 10px 0 6px; font-size: 19px; }
.muted { color: var(--muted); font-size: 13px; margin-bottom: 18px; }
.invite-link {
  background: var(--card); border: 1px dashed rgba(212,175,55,.4);
  border-radius: 12px; padding: 14px; font-size: 13px; word-break: break-all;
  margin-bottom: 16px; color: var(--gold-2);
}
.choice-row { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; justify-content: center; }
.choice-btn {
  background: var(--card); color: var(--muted); border: 1px solid rgba(255,255,255,.1);
  border-radius: 10px; padding: 10px 14px; font-size: 13px; cursor: pointer;
}
.choice-btn.active { background: rgba(212,175,55,.15); border-color: var(--gold); color: var(--gold-2); }

/* Game */
#screen-game { padding: 0; }
.game-topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px; background: rgba(0,0,0,.25);
  z-index: 5;
}
.icon-btn {
  width: 36px; height: 36px; border-radius: 10px; border: none;
  background: rgba(255,255,255,.08); color: var(--text); font-size: 16px; cursor: pointer;
}
.turn-indicator { font-size: 14px; font-weight: 600; color: var(--gold-2); }

#board-canvas-wrap {
  position: relative; flex: 1; min-height: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px; padding: 6px 12px; touch-action: none;
}
.captured-row {
  width: 100%; max-width: 480px; min-height: 20px;
  font-size: 16px; letter-spacing: 2px; color: var(--muted); text-align: center;
  overflow: hidden; white-space: nowrap;
}

.board {
  position: relative;
  width: min(100%, 480px);
  aspect-ratio: 1 / 1;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 12px 30px rgba(0,0,0,.45), 0 0 0 6px #2a1c10, 0 0 0 8px rgba(212,175,55,.55);
  transition: transform .35s ease;
}
.board.flipped { transform: rotate(180deg); }

.board-squares {
  position: absolute; inset: 0;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
}
.sq.light { background: #F3E8D0; }
.sq.dark { background: #8a6248; }

.board-highlights, .board-pieces { position: absolute; inset: 0; pointer-events: none; }

.hl { position: absolute; width: 12.5%; height: 12.5%; box-sizing: border-box; }
.hl.last { background: rgba(212,175,55,.25); }
.hl.check { background: rgba(224,85,91,.6); }
.hl.selected { box-shadow: inset 0 0 0 3px rgba(212,175,55,.9); }
.hl.move::after, .hl.capture::after {
  content: ''; position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%);
}
.hl.move::after { width: 30%; height: 30%; border-radius: 50%; background: rgba(20,20,20,.35); }
.hl.capture::after {
  width: 82%; height: 82%; border-radius: 50%; background: transparent;
  box-shadow: inset 0 0 0 5px rgba(20,20,20,.35);
}

.piece {
  position: absolute; width: 12.5%; height: 12.5%;
  display: flex; align-items: center; justify-content: center;
  transition: left .22s cubic-bezier(.2,.7,.3,1), top .22s cubic-bezier(.2,.7,.3,1), opacity .2s ease, transform .2s ease;
}
.piece .glyph {
  font-size: min(8.6vw, 40px);
  line-height: 1;
  filter: drop-shadow(0 2px 3px rgba(0,0,0,.55));
  transition: transform .22s ease;
}
/* Both colors previously used a gold outline, which made white pieces wash
   out against the light squares and blurred the white/black distinction at
   a glance. White gets a dark outline, black gets a light outline — same
   pairing chess.com/lichess use — so the two sides stay unmistakable on
   either square color. */
.piece.white .glyph { color: #fffdf7; -webkit-text-stroke: 1.6px #2a1c10; paint-order: stroke fill; }
.piece.black .glyph { color: #141414; -webkit-text-stroke: 1.6px #f3e8d0; paint-order: stroke fill; }
.board.flipped .piece .glyph { transform: rotate(180deg); }
.piece.captured-anim { opacity: 0; transform: scale(0.3); }

.game-bottombar { display: flex; gap: 10px; padding: 10px 12px; background: rgba(0,0,0,.25); }
.ghost-btn {
  flex: 1; padding: 12px; border-radius: 12px; border: 1px solid rgba(255,255,255,.12);
  background: rgba(255,255,255,.04); color: var(--text); font-size: 13px; cursor: pointer;
}
.ghost-btn:active { background: rgba(255,255,255,.1); }

.promo-picker {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%,-50%);
  background: var(--card); border: 1px solid var(--gold);
  border-radius: 16px; padding: 16px; display: flex; gap: 10px;
  box-shadow: 0 10px 40px rgba(0,0,0,.5);
}
.promo-picker.hidden { display: none; }
.promo-piece {
  width: 54px; height: 54px; border-radius: 12px; background: rgba(212,175,55,.12);
  border: 1px solid rgba(212,175,55,.4); font-size: 26px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; color: var(--gold-2);
}

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.modal-overlay.hidden { display: none; }
.modal {
  background: var(--card); border: 1px solid rgba(212,175,55,.3);
  border-radius: 18px; padding: 24px; width: 88%; max-width: 360px; text-align: center;
}
.modal h3 { margin: 4px 0 10px; font-size: 20px; }
.modal p { color: var(--muted); font-size: 14px; margin-bottom: 18px; }
