/* Chess Duel */
:root {
  --bg: #11151c;
  --bg-raise: #1a2029;
  --bg-card: #1e2531;
  --line: #2c3545;
  --text: #e8e6e0;
  --text-dim: #9aa3b2;
  --accent: #d8a23a;
  --accent-ink: #1a1405;
  --danger: #c4554d;
  --ok: #6fb46f;
  --sq-light: #f0d9b5;
  --sq-dark: #b58863;
  --sq-last: rgba(216, 162, 58, 0.55);
  --sq-sel: rgba(90, 160, 255, 0.55);
  --radius: 10px;
  --board-size: min(86vmin, 640px, calc(100vw - 24px));
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  min-height: 100%;
}

body {
  background:
    radial-gradient(1100px 600px at 80% -10%, #1c2534 0%, transparent 60%),
    radial-gradient(900px 500px at -10% 110%, #181f14 0%, transparent 55%),
    var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

button { font: inherit; cursor: pointer; }
input { font: inherit; }
h1, h2, h3 { margin: 0; }

.view { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }

/* ------------------------------------------------------------- lobby --- */

.lobby-card {
  width: min(440px, 100%);
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 32px 28px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
}

.logo {
  font-size: 30px;
  letter-spacing: 0.02em;
  display: flex;
  align-items: center;
  gap: 10px;
}
.logo-knight { color: var(--accent); font-size: 36px; line-height: 1; }

.tagline { color: var(--text-dim); margin: 8px 0 24px; }

.field { display: block; margin-bottom: 20px; }
.field span { display: block; font-size: 13px; color: var(--text-dim); margin-bottom: 6px; }

input {
  width: 100%;
  background: var(--bg-raise);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  padding: 10px 12px;
  outline: none;
  /* >=16px keeps iOS Safari from auto-zooming on focus. */
  font-size: 16px;
}
input:focus { border-color: var(--accent); }

.lobby-section h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.12em; color: var(--text-dim); margin-bottom: 10px; }

.color-pick { display: flex; gap: 8px; margin-bottom: 12px; }
.color-opt {
  flex: 1;
  background: var(--bg-raise);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  font-size: 26px;
  padding: 8px 0 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  line-height: 1.1;
}
.color-opt small { font-size: 11px; color: var(--text-dim); }
.color-opt.selected { border-color: var(--accent); background: rgba(216, 162, 58, 0.12); }
.color-opt.selected small { color: var(--accent); }

.btn {
  background: var(--bg-raise);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 8px;
  padding: 9px 14px;
  transition: filter 0.12s ease, transform 0.05s ease;
}
.btn:hover { filter: brightness(1.15); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.danger { border-color: var(--danger); color: #e8938c; }
.btn.big { width: 100%; padding: 12px; font-size: 17px; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn[disabled] { opacity: 0.45; cursor: default; }

.divider {
  display: flex; align-items: center; gap: 12px;
  color: var(--text-dim); font-size: 13px;
  margin: 22px 0;
}
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }

.join-row { display: flex; gap: 8px; }
.join-row input { text-transform: uppercase; letter-spacing: 0.08em; }

.lobby-error { color: #e8938c; margin: 16px 0 0; font-size: 14px; }
.conn-note { color: var(--text-dim); margin: 16px 0 0; font-size: 13px; }

/* -------------------------------------------------------------- game --- */

#game { align-items: flex-start; padding-top: 28px; }

.game-grid {
  display: grid;
  grid-template-columns: auto minmax(280px, 360px);
  gap: 24px;
  width: 100%;
  max-width: 1060px;
  justify-content: center;
}

@media (max-width: 920px) {
  .game-grid { grid-template-columns: 1fr; max-width: 680px; }
}

.board-col { display: flex; flex-direction: column; gap: 10px; }

.seat { display: flex; align-items: center; gap: 10px; min-height: 26px; padding: 0 4px; }
.seat-dot { width: 9px; height: 9px; border-radius: 50%; background: #555; flex: none; }
.seat-dot.on { background: var(--ok); box-shadow: 0 0 6px rgba(111, 180, 111, 0.8); }
.seat-name { font-weight: 600; }
.seat-captures { color: var(--text-dim); font-size: 19px; letter-spacing: 1px; }
.seat-captures b { color: var(--text); font-weight: 600; font-size: 13px; margin-left: 4px; }

.board-frame {
  position: relative;
  width: var(--board-size);
  height: var(--board-size);
  border-radius: 6px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.55), 0 0 0 6px #0c0f14;
}

.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: 100%;
  height: 100%;
  border-radius: 4px;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.sq { position: relative; display: flex; align-items: center; justify-content: center; }
.sq.light { background: var(--sq-light); }
.sq.dark { background: var(--sq-dark); }
.sq.last::before { content: ""; position: absolute; inset: 0; background: var(--sq-last); }
.sq.sel::before { content: ""; position: absolute; inset: 0; background: var(--sq-sel); }
.sq.target::after {
  content: "";
  position: absolute;
  width: 30%;
  height: 30%;
  border-radius: 50%;
  background: rgba(20, 40, 20, 0.35);
}
.sq.target.has-piece::after {
  width: 92%; height: 92%;
  background: none;
  border: 4px solid rgba(20, 40, 20, 0.35);
}
.sq.check { background: radial-gradient(circle at 50% 50%, #e2514a 15%, #b8433f 60%, var(--sq-dark) 100%); }
.sq.light.check { background: radial-gradient(circle at 50% 50%, #e2514a 15%, #c96560 60%, var(--sq-light) 100%); }

.piece {
  font-size: calc(var(--board-size) / 8 * 0.8);
  line-height: 1;
  z-index: 2;
  pointer-events: none;
  font-family: "Segoe UI Symbol", "Noto Sans Symbols 2", "Apple Symbols", sans-serif;
}
.piece.w {
  color: #faf6ee;
  text-shadow: 0 0 2px #2b2b2b, 0 0 2px #2b2b2b, 0 2px 3px rgba(0,0,0,0.5);
}
.piece.b {
  color: #2a2320;
  text-shadow: 0 0 2px rgba(255,255,255,0.35), 0 2px 3px rgba(0,0,0,0.45);
}

.sq.movable { cursor: grab; }

.drag-ghost {
  position: fixed;
  z-index: 50;
  pointer-events: none;
  transform: translate(-50%, -50%);
}

.coords { position: absolute; pointer-events: none; font-size: 11px; font-weight: 600; }
.files { bottom: 2px; left: 0; width: 100%; display: flex; }
.files span { flex: 1; text-align: right; padding-right: 4px; }
.ranks { top: 0; left: 3px; height: 100%; display: flex; flex-direction: column; }
.ranks span { flex: 1; }
.coords span:nth-child(odd) { color: rgba(60, 40, 20, 0.75); }
.coords span:nth-child(even) { color: rgba(245, 230, 200, 0.85); }
.board-frame.flipped .coords span:nth-child(odd) { color: rgba(245, 230, 200, 0.85); }
.board-frame.flipped .coords span:nth-child(even) { color: rgba(60, 40, 20, 0.75); }

/* ---------------------------------------------------------- side panel --- */

.side-col { display: flex; flex-direction: column; gap: 14px; min-width: 0; }

.status-card, .moves-card, .chat-card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
}

.status-line { font-weight: 600; font-size: 17px; }
.status-line.your-turn { color: var(--accent); }
.status-line.check { color: #e8938c; }

.invite-box { margin-top: 10px; font-size: 14px; color: var(--text-dim); }
.invite-box p { margin: 6px 0; }
.invite-row { display: flex; gap: 8px; align-items: center; }
.invite-row code {
  flex: 1;
  background: var(--bg-raise);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.invite-code strong { color: var(--accent); letter-spacing: 0.1em; }

.draw-banner {
  margin-top: 10px;
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  background: rgba(216, 162, 58, 0.1);
  border: 1px solid rgba(216, 162, 58, 0.4);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 14px;
}
.draw-actions { display: flex; gap: 6px; margin-left: auto; }

h3 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.12em; color: var(--text-dim); margin-bottom: 8px; }

.move-list {
  margin: 0; padding: 0;
  list-style: none;
  max-height: 180px;
  overflow-y: auto;
  display: grid;
  grid-template-columns: auto 1fr 1fr;
  gap: 2px 10px;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}
.move-list .num { color: var(--text-dim); }
.move-list .ply { font-weight: 500; }
.move-list .ply.latest { color: var(--accent); }

.chat-card { display: flex; flex-direction: column; }
.chat-log {
  height: 120px;
  overflow-y: auto;
  font-size: 14px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin-bottom: 8px;
}
.chat-log .who { font-weight: 600; }
.chat-log .who.w { color: #e8e6e0; }
.chat-log .who.b { color: var(--accent); }
.chat-log .sys { color: var(--text-dim); font-style: italic; }
.chat-form { display: flex; gap: 8px; }
.chat-form input { flex: 1; }

.actions-row { display: flex; gap: 8px; flex-wrap: wrap; }
.actions-row .btn { flex: 1; min-width: 70px; }

/* ----------------------------------------------------------- overlays --- */

.overlay {
  position: fixed; inset: 0;
  background: rgba(8, 10, 14, 0.72);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  backdrop-filter: blur(3px);
}

.promo-card, .over-card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 24px 28px;
  text-align: center;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
}

.promo-row { display: flex; gap: 10px; margin-top: 14px; }
.promo-btn {
  width: 72px; height: 72px;
  font-size: 48px;
  background: var(--bg-raise);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  display: flex; align-items: center; justify-content: center;
}
.promo-btn:hover { border-color: var(--accent); }

.over-card h2 { font-size: 26px; }
.over-card p { color: var(--text-dim); margin: 10px 0 20px; }
.over-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.rematch-note { font-size: 13px; color: var(--accent) !important; margin-top: 14px !important; }

.toast {
  position: fixed;
  bottom: 24px; left: 50%;
  transform: translateX(-50%);
  background: #2a3242;
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 999px;
  padding: 9px 18px;
  font-size: 14px;
  z-index: 200;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}
