/* ── Reset & base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0f0f1a;
  --bg2:       #1a1a2e;
  --bg3:       #242440;
  --border:    #2e2e52;
  --accent:    #7c5cfc;
  --accent2:   #5caafc;
  --gold:      #f0c040;
  --danger:    #fc5c5c;
  --text:      #e8e8f0;
  --muted:     #888;
  --cell-light: #f0d9b5;
  --cell-dark:  #b58863;
  --cell-size:  min(7.5vw, 7.5vh, 68px);
  --radius:    10px;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, sans-serif;
  overflow: hidden;
}

#app { width: 100%; height: 100%; }

/* ── Screens ──────────────────────────────────────────────────────────────── */
.screen {
  display: none;
  width: 100%;
  height: 100%;
  overflow-y: auto;
}
.screen.active { display: flex; flex-direction: column; align-items: center; justify-content: center; }

#screen-game.active { justify-content: flex-start; }

.hidden { display: none !important; }

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .5em;
  padding: .65em 1.4em;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: filter .15s, transform .1s;
  white-space: nowrap;
}
.btn:hover  { filter: brightness(1.15); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .4; cursor: not-allowed; }

.btn-primary  { background: var(--accent);  color: #fff; }
.btn-secondary{ background: var(--accent2); color: #fff; }
.btn-accent   { background: var(--gold);    color: #111; }
.btn-ghost    { background: var(--bg3);     color: var(--text); border: 1px solid var(--border); }
.btn-sm       { padding: .4em .9em; font-size: .85rem; }

/* ── Menu screen ──────────────────────────────────────────────────────────── */
.menu-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2rem;
  padding: 2rem;
  max-width: 600px;
  width: 100%;
}

.logo { text-align: center; }
.logo-knight { font-size: 3.5rem; display: block; animation: float 3s ease-in-out infinite; }
@keyframes float { 0%,100%{transform:translateY(0)} 50%{transform:translateY(-8px)} }
.logo h1 { font-size: 2.5rem; font-weight: 800; letter-spacing: -.02em; }
.tagline  { color: var(--muted); margin-top: .3rem; }

.menu-buttons {
  display: flex;
  flex-direction: column;
  gap: .75rem;
  width: 100%;
  max-width: 320px;
}
.menu-buttons .btn {
  width: 100%;
  justify-content: center;
  font-size: 1.05rem;
  padding: .8em 1.4em;
}

.fairy-legend {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.2rem 1.5rem;
  width: 100%;
}
.fairy-legend h3 { margin-bottom: .8rem; font-size: .9rem; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); }
.legend-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px,1fr)); gap: .6rem; }
.legend-item { display: flex; align-items: center; gap: .6rem; font-size: .85rem; }

/* ── Online screen ────────────────────────────────────────────────────────── */
.online-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
  padding: 2rem;
  max-width: 700px;
  width: 100%;
}
.online-content h2 { font-size: 1.8rem; }
.online-sub  { color: var(--muted); }

.online-panels {
  display: flex;
  gap: 1.5rem;
  width: 100%;
  align-items: flex-start;
}
@media (max-width: 520px) {
  .online-panels { flex-direction: column; }
  .divider { transform: none !important; }
}

.panel {
  flex: 1;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.2rem;
  display: flex;
  flex-direction: column;
  gap: .8rem;
}
.panel h3 { font-size: 1.05rem; }
.panel p   { font-size: .85rem; color: var(--muted); }

.divider {
  display: flex;
  align-items: center;
  color: var(--muted);
  font-weight: 700;
  padding: 0 .5rem;
  transform: translateY(2rem);
}

.code-box {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: .15em;
  color: var(--gold);
  padding: .4em .6em;
  background: var(--bg3);
  border-radius: 8px;
  text-align: center;
}
.room-code-display { display: flex; flex-direction: column; gap: .5rem; }
.room-code-display label { font-size: .8rem; color: var(--muted); }

.code-input {
  width: 100%;
  padding: .65em .8em;
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: .15em;
  text-transform: uppercase;
  text-align: center;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  outline: none;
}
.code-input:focus { border-color: var(--accent); }

.muted { color: var(--muted); font-size: .85rem; }
.error { color: var(--danger); font-size: .85rem; }

/* ── Game screen ──────────────────────────────────────────────────────────── */
.game-header {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .6rem 1rem;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.turn-display {
  font-weight: 700;
  font-size: 1rem;
  padding: .4em .9em;
  border-radius: 20px;
  background: var(--bg3);
  transition: background .3s, color .3s;
}
.turn-display.in-check   { background: var(--danger); color: #fff; animation: pulse 1s ease-in-out infinite; }
.turn-display.game-over  { background: var(--gold); color: #111; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.7} }

.shape-badge { font-size: .75rem; color: var(--muted); text-transform: capitalize; }

.game-main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: .75rem;
  min-height: 0;
}

.side-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .5rem;
  width: 60px;
}
.player-label { font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.captured { display: flex; flex-direction: column; gap: 2px; flex-wrap: wrap; max-width: 56px; }
.cap-piece { font-size: 1rem; line-height: 1; }

.board-area {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Chess board ──────────────────────────────────────────────────────────── */
.board {
  display: grid;
  grid-template-columns: repeat(var(--board-cols, 8), var(--cell-size));
  grid-template-rows:    repeat(var(--board-rows, 8), var(--cell-size));
  border: 2px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0,0,0,.5);
  background: var(--bg);
}

.cell {
  width:  var(--cell-size);
  height: var(--cell-size);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: default;
  transition: background .12s;
  position: relative;
}
.cell.light { background: var(--cell-light); }
.cell.dark  { background: var(--cell-dark);  }
.cell.void  { background: transparent; pointer-events: none; }

.cell.light:not(.void):hover,
.cell.dark:not(.void):hover  { filter: brightness(1.08); cursor: pointer; }

.cell.selected { background: #7fc97f !important; }

.cell.legal::after {
  content: '';
  width: 34%;
  height: 34%;
  border-radius: 50%;
  background: rgba(0,0,0,.22);
  pointer-events: none;
}
.cell.legal-capture {
  outline: 3px solid rgba(0,0,0,.3);
  outline-offset: -3px;
}

.cell.flash { animation: cellFlash .35s ease; }
@keyframes cellFlash { 0%,100%{filter:brightness(1)} 50%{filter:brightness(1.6)} }

/* ── Pieces ───────────────────────────────────────────────────────────────── */
.piece {
  font-size: calc(var(--cell-size) * 0.72);
  line-height: 1;
  user-select: none;
  pointer-events: none;
  text-shadow: 0 1px 2px rgba(0,0,0,.3);
  display: flex;
  align-items: center;
  justify-content: center;
}
.piece.white { color: #fff; text-shadow: 0 1px 3px rgba(0,0,0,.7); }
.piece.black { color: #111; text-shadow: 0 1px 2px rgba(255,255,255,.2); }

.piece.fairy {
  font-size: calc(var(--cell-size) * 0.48);
  font-weight: 800;
  width:  calc(var(--cell-size) * 0.7);
  height: calc(var(--cell-size) * 0.7);
  border-radius: 6px;
}
.piece.fairy.white {
  background: linear-gradient(135deg, #fff 0%, #e8e8e8 100%);
  color: #222;
  text-shadow: none;
  box-shadow: 0 2px 4px rgba(0,0,0,.3);
}
.piece.fairy.black {
  background: linear-gradient(135deg, #2a2a3e 0%, #111120 100%);
  color: var(--gold);
  text-shadow: none;
  box-shadow: 0 2px 4px rgba(0,0,0,.5);
}

/* ── Status overlay ───────────────────────────────────────────────────────── */
.status-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.65);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  backdrop-filter: blur(4px);
}
.status-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem 2.5rem;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  animation: popIn .25s ease;
}
@keyframes popIn { from{transform:scale(.8);opacity:0} to{transform:scale(1);opacity:1} }
.status-card h2 { font-size: 1.5rem; }
.status-buttons { display: flex; gap: .75rem; justify-content: center; }

/* ── Promotion picker ─────────────────────────────────────────────────────── */
.promo-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(4px);
}
.promo-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem 2rem;
  text-align: center;
  animation: popIn .2s ease;
}
.promo-card h3 { margin-bottom: 1rem; }
.promo-options { display: flex; gap: .75rem; flex-wrap: wrap; justify-content: center; }
.promo-btn {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .6rem .8rem;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .4rem;
  transition: filter .15s, border-color .15s;
  color: var(--text);
  font-size: .8rem;
}
.promo-btn:hover { filter: brightness(1.2); border-color: var(--accent); }
.promo-btn .piece { font-size: 1.8rem; pointer-events: none; }
.promo-btn .piece.fairy { font-size: 1rem; width: 2rem; height: 2rem; }
.promo-name { font-size: .7rem; color: var(--muted); }

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  :root { --cell-size: min(10vw, 10vh, 52px); }
  .side-panel { display: none; }
  .game-header { padding: .4rem .6rem; }
  .menu-content { gap: 1.2rem; padding: 1.2rem; }
  .logo h1 { font-size: 2rem; }
}

@media (max-height: 600px) {
  :root { --cell-size: min(8vw, 9vh, 54px); }
  .fairy-legend { display: none; }
}
