:root {
  --bg: #12141a;
  --bg-soft: #1b1e27;
  --card: #222634;
  --line: #323848;
  --text: #e8ebf2;
  --muted: #9aa3b8;
  --accent: #6c8cff;
  --accent-2: #4f6ef7;
  --light-sq: #e9edf5;
  --dark-sq: #7c8aa5;
  --sel: #f2c94c;
  --target: rgba(108, 140, 255, 0.55);
  --last: rgba(242, 201, 76, 0.35);
  --check: #ff5d5d;
  --white-piece: #fbfcff;
  --black-piece: #1a1c22;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: radial-gradient(1200px 700px at 50% -10%, #1e2433 0%, var(--bg) 55%);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  min-height: 100vh;
}

a { color: inherit; text-decoration: none; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(18, 20, 26, 0.8);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  font-weight: 800;
  letter-spacing: 0.14em;
  font-size: 20px;
}
.brand span {
  display: block;
  font-size: 11px;
  letter-spacing: 0.22em;
  color: var(--muted);
  font-weight: 500;
  text-transform: uppercase;
  margin-top: 2px;
}

.conn {
  font-size: 12px;
  color: var(--muted);
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
}
.conn.ok { color: #79e0a0; border-color: #2f5d43; }
.conn.warn { color: #f2c94c; border-color: #5d532f; }

main {
  max-width: 1040px;
  margin: 0 auto;
  padding: 26px 18px 60px;
}

.view.hidden, .hidden { display: none !important; }

h1 { font-size: 24px; margin: 4px 0 18px; }
h2 { font-size: 16px; margin: 0; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px;
  margin-bottom: 18px;
}

.row { display: flex; align-items: center; }
.row.gap { gap: 10px; flex-wrap: wrap; margin-top: 14px; }
.row.between { justify-content: space-between; }

.field { display: block; }
.field span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field input,
.field select {
  width: 100%;
  padding: 11px 13px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg-soft);
  color: var(--text);
  font-size: 15px;
}
.field input:focus,
.field select:focus { outline: 2px solid var(--accent); border-color: transparent; }
.field.small { min-width: 160px; flex: 0 1 200px; }

.btn {
  border: 1px solid var(--line);
  background: var(--bg-soft);
  color: var(--text);
  padding: 11px 16px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform .05s ease, background .15s ease, border-color .15s ease;
}
.btn:hover { background: #262b39; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: linear-gradient(180deg, var(--accent), var(--accent-2)); border-color: transparent; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { background: #3a2230; border-color: #5d2f43; color: #ffb3c7; }
.btn.ghost { background: transparent; }
.btn.small { padding: 7px 12px; font-size: 13px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.gamelist { list-style: none; margin: 14px 0 0; padding: 0; }
.gamelist li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  margin-bottom: 8px;
  background: var(--bg-soft);
}
.gamelist li.empty { justify-content: center; color: var(--muted); border-style: dashed; }
.gamelist .who { font-size: 14px; }
.gamelist .who b { color: var(--text); }
.gamelist .who small { color: var(--muted); display: block; margin-top: 2px; }

/* ---------- juego ---------- */
.gamewrap {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 22px;
  align-items: start;
}
@media (max-width: 860px) {
  .gamewrap { grid-template-columns: 1fr; }
}

.boardarea { position: relative; }

.board {
  width: 100%;
  max-width: 640px;
  aspect-ratio: 1 / 1;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--line);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  user-select: none;
}

.sq {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: min(8.5vw, 52px);
  line-height: 1;
  cursor: default;
}
.sq.light { background: var(--light-sq); }
.sq.dark { background: var(--dark-sq); }
.sq.playable { cursor: pointer; }
.sq.selected::after {
  content: "";
  position: absolute;
  inset: 0;
  box-shadow: inset 0 0 0 4px var(--sel);
}
.sq.lastmove::before {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--last);
}
.sq.target::after {
  content: "";
  position: absolute;
  width: 26%;
  height: 26%;
  border-radius: 50%;
  background: var(--target);
}
.sq.target.capture::after {
  width: 86%;
  height: 86%;
  background: transparent;
  border: 4px solid var(--target);
  border-radius: 50%;
}
.sq.check::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle, rgba(255, 93, 93, 0.85), rgba(255, 93, 93, 0) 70%);
}
.sq .pc { position: relative; z-index: 2; }
.pc.w { color: var(--white-piece); text-shadow: 0 1px 0 #000, 0 0 2px #000, 0 2px 3px rgba(0,0,0,.5); }
.pc.b { color: var(--black-piece); text-shadow: 0 1px 0 rgba(255,255,255,.25); }
.sq .coord {
  position: absolute;
  font-size: 10px;
  font-weight: 700;
  opacity: .55;
  z-index: 3;
}
.sq .coord.file { right: 3px; bottom: 1px; }
.sq .coord.rank { left: 3px; top: 1px; }
.sq.light .coord { color: #5b6a86; }
.sq.dark .coord { color: #e9edf5; }

.promo {
  position: absolute;
  inset: 0;
  background: rgba(10, 12, 18, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  z-index: 30;
}
.promo-inner {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px 20px;
  text-align: center;
}
.promo-inner p { margin: 0 0 12px; color: var(--muted); font-size: 14px; }
.promo-buttons { display: flex; gap: 8px; }
.promo-buttons button {
  width: 56px; height: 56px;
  font-size: 34px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--light-sq);
  color: #1a1c22;
  cursor: pointer;
}
.promo-buttons button:hover { background: #fff; }

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
}
.players { display: grid; gap: 8px; margin-bottom: 12px; }
.player {
  display: flex; align-items: center; justify-content: space-between;
  padding: 9px 11px;
  border-radius: 9px;
  background: var(--bg-soft);
  border: 1px solid transparent;
  font-size: 14px;
}
.player.turn { border-color: var(--accent); }
.player .dot { width: 12px; height: 12px; border-radius: 50%; margin-right: 8px; border: 1px solid #000; }
.player .dot.w { background: #fbfcff; }
.player .dot.b { background: #1a1c22; }
.player .left { display: flex; align-items: center; }
.player .you { color: var(--accent); font-size: 11px; margin-left: 6px; }

.status-text {
  padding: 11px 12px;
  border-radius: 10px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  font-size: 14px;
  margin-bottom: 12px;
  min-height: 20px;
}
.status-text.win { border-color: #2f5d43; color: #9df0bd; }
.status-text.lose { border-color: #5d2f43; color: #ffb3c7; }
.status-text.wait { border-color: #5d532f; color: #f6dd8f; }

.movelist {
  list-style: none;
  margin: 0 0 14px;
  padding: 8px;
  max-height: 260px;
  overflow-y: auto;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 10px;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 13px;
}
.movelist .moverow { display: grid; grid-template-columns: 34px 1fr 1fr; gap: 6px; padding: 3px 4px; }
.movelist .moverow:nth-child(odd) { background: rgba(255,255,255,.03); border-radius: 6px; }
.movelist .num { color: var(--muted); }
.movelist .empty { color: var(--muted); padding: 6px; }

.actions { display: flex; gap: 8px; }
.actions .btn { flex: 1; }

.share { margin-top: 12px; font-size: 12px; color: var(--muted); word-break: break-all; }
.share a { color: var(--accent); }
.share button { margin-top: 6px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  background: #3a2230;
  border: 1px solid #5d2f43;
  color: #ffd7e1;
  padding: 11px 18px;
  border-radius: 10px;
  font-size: 14px;
  z-index: 50;
  box-shadow: 0 10px 30px rgba(0,0,0,.4);
}
