/* Chess Arena — professional dark theme, mobile-first. */
:root {
  --bg: #161512;
  --panel: #262421;
  --panel2: #2e2a26;
  --text: #e8e3da;
  --muted: #a39e93;
  --accent: #81b64c;
  --accent2: #629636;
  --light-sq: #f0d9b5;
  --dark-sq: #b58863;
  --sel: rgba(130, 182, 76, 0.55);
  --last: rgba(205, 210, 60, 0.45);
  --check: rgba(220, 60, 50, 0.65);
  --danger: #d9534f;
  --radius: 12px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, "Vazirmatn", Tahoma, sans-serif;
  min-height: 100vh;
}
a { color: var(--accent); }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-bottom: 1px solid #33302c;
  position: sticky; top: 0; background: var(--bg); z-index: 10;
}
.brand { font-weight: 800; font-size: 20px; letter-spacing: 0.3px; }
.brand .knight { color: var(--accent); }
.live-badge {
  font-size: 12px; font-weight: 700; color: #fff;
  background: #c0392b; border-radius: 999px; padding: 4px 10px;
  display: inline-flex; align-items: center; gap: 6px;
}
.live-badge .dot { width: 8px; height: 8px; border-radius: 50%; background: #fff; animation: pulse 1.4s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.35; } }
.live-badge.off { background: #555; }
.live-badge.off .dot { animation: none; }

.wrap { max-width: 1060px; margin: 0 auto; padding: 16px; }
.card {
  background: var(--panel); border: 1px solid #35322d;
  border-radius: var(--radius); padding: 16px; margin-bottom: 14px;
}
.card h2 { margin: 0 0 6px; font-size: 17px; }
.card p.sub { margin: 0 0 12px; color: var(--muted); font-size: 13.5px; line-height: 1.6; }

.btn {
  border: 0; border-radius: 9px; padding: 11px 18px;
  background: var(--accent); color: #fff; font-weight: 700; font-size: 15px;
}
.btn:hover { background: var(--accent2); }
.btn.ghost { background: transparent; border: 1px solid #4a463f; color: var(--text); }
.btn.ghost:hover { background: #33302c; }
.btn.danger { background: var(--danger); }
.btn.small { padding: 7px 12px; font-size: 13px; }
.btn:disabled { opacity: 0.5; cursor: default; }

.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row .grow { flex: 1; min-width: 140px; }
input[type="text"], select {
  width: 100%; background: #1a1815; color: var(--text);
  border: 1px solid #4a463f; border-radius: 9px; padding: 11px 12px; font-size: 15px;
}
input[type="text"]:focus, select:focus { outline: 2px solid var(--accent); border-color: transparent; }
.key-input { text-transform: uppercase; letter-spacing: 3px; font-weight: 700; text-align: center; }

.seg { display: flex; gap: 6px; }
.seg button {
  flex: 1; padding: 9px 6px; border-radius: 8px; border: 1px solid #4a463f;
  background: #1a1815; color: var(--muted); font-weight: 700; font-size: 14px;
}
.seg button.on { background: var(--accent); border-color: var(--accent); color: #fff; }

.key-big {
  font-size: 34px; font-weight: 800; letter-spacing: 6px; text-align: center;
  background: #1a1815; border: 1px dashed #4a463f; border-radius: 10px;
  padding: 12px 8px; margin: 10px 0;
}
.prompt-box {
  width: 100%; min-height: 190px; background: #1a1815; color: #d8d2c6;
  border: 1px solid #4a463f; border-radius: 10px; padding: 12px;
  font-size: 12.5px; line-height: 1.65; resize: vertical; direction: ltr; text-align: left;
}
.hint { color: var(--muted); font-size: 12.5px; line-height: 1.6; }
.err { color: #ff8a80; font-size: 13.5px; min-height: 18px; }

/* Lobby list */
.game-row {
  display: flex; align-items: center; gap: 12px; padding: 12px 4px;
  border-bottom: 1px solid #33302c;
}
.game-row:last-child { border-bottom: 0; }
.game-row .names { flex: 1; min-width: 0; }
.game-row .names .vs { font-weight: 700; font-size: 14.5px; }
.game-row .names .meta { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.pill {
  font-size: 11.5px; font-weight: 700; border-radius: 999px; padding: 3px 9px; white-space: nowrap;
}
.pill.playing { background: #1e5c2e; color: #b9f6c3; }
.pill.waiting { background: #5c4a1e; color: #ffe9a8; }
.pill.finished { background: #444; color: #ccc; }
.empty { color: var(--muted); font-size: 14px; padding: 8px 0; }

/* Room layout */
.room-grid { display: grid; grid-template-columns: minmax(0, 620px) minmax(260px, 1fr); gap: 16px; align-items: start; }
@media (max-width: 860px) { .room-grid { grid-template-columns: 1fr; } }

.player-card {
  display: flex; align-items: center; gap: 10px;
  background: var(--panel); border: 1px solid #35322d; border-radius: 10px;
  padding: 10px 12px; margin-bottom: 10px;
}
.player-card.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.player-card .avatar {
  width: 38px; height: 38px; border-radius: 8px; display: grid; place-items: center;
  font-size: 22px; background: #1a1815; border: 1px solid #4a463f; flex: none;
}
.player-card .who { flex: 1; min-width: 0; }
.player-card .who .name { font-weight: 700; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player-card .who .sub { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.timer { font-weight: 800; font-size: 18px; font-variant-numeric: tabular-nums; }
.timer.low { color: #ff8a80; }

.board-wrap { position: relative; width: 100%; max-width: 620px; margin: 0 auto; }
.board {
  display: grid; grid-template-columns: repeat(8, 1fr);
  width: 100%; aspect-ratio: 1 / 1; border-radius: 8px; overflow: hidden;
  box-shadow: 0 8px 30px rgba(0,0,0,0.45); user-select: none;
  touch-action: manipulation;
}
.sq {
  position: relative; display: grid; place-items: center;
  font-size: clamp(26px, 7.5vw, 52px); line-height: 1; cursor: default;
}
.sq.light { background: var(--light-sq); }
.sq.dark { background: var(--dark-sq); }
.sq .pc { pointer-events: none; text-shadow: 0 1px 2px rgba(0,0,0,0.35); }
.sq .pc.w { color: #f8f8f8; }
.sq .pc.b { color: #1c1c1c; }
.sq.playable { cursor: pointer; }
.sq.sel { background: var(--sel) !important; }
.sq.last { background: var(--last) !important; }
.sq.check { background: var(--check) !important; }
.sq .dot {
  position: absolute; width: 26%; height: 26%; border-radius: 50%;
  background: rgba(20, 40, 10, 0.35); pointer-events: none;
}
.sq .ring {
  position: absolute; inset: 4%; border-radius: 50%;
  border: 4px solid rgba(20, 40, 10, 0.4); pointer-events: none;
}
.sq .coord {
  position: absolute; font-size: 10px; font-weight: 700; opacity: 0.75; pointer-events: none;
}
.sq .coord.file { right: 3px; bottom: 2px; }
.sq .coord.rank { left: 3px; top: 2px; }
.sq.light .coord { color: var(--dark-sq); }
.sq.dark .coord { color: var(--light-sq); }

.status-banner {
  margin: 12px 0; padding: 11px 14px; border-radius: 10px;
  background: var(--panel2); border: 1px solid #3a362f; font-weight: 700; font-size: 15px;
}
.status-banner.over { background: #3a2a1e; border-color: #6b4a2a; }

.moves {
  max-height: 260px; overflow-y: auto; background: #1a1815;
  border: 1px solid #35322d; border-radius: 10px; padding: 6px 0;
}
.moves table { width: 100%; border-collapse: collapse; font-size: 14px; }
.moves td { padding: 5px 10px; }
.moves td.n { color: var(--muted); width: 34px; text-align: right; }
.moves td.mv { font-weight: 600; width: 50%; }
.moves tr.latest td.mv { color: var(--accent); }

.promo-overlay {
  position: absolute; inset: 0; background: rgba(0,0,0,0.6);
  display: grid; place-items: center; z-index: 5; border-radius: 8px;
}
.promo-box { background: var(--panel); border-radius: 12px; padding: 16px; text-align: center; }
.promo-box .pieces { display: flex; gap: 10px; margin-top: 10px; }
.promo-box .pieces button {
  font-size: 40px; line-height: 1; width: 62px; height: 62px; border-radius: 10px;
  background: #1a1815; border: 1px solid #4a463f; color: var(--text);
}
.kv { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.kv .key-chip {
  font-weight: 800; letter-spacing: 3px; background: #1a1815;
  border: 1px solid #4a463f; border-radius: 8px; padding: 7px 12px;
}
.footer { color: var(--muted); font-size: 12px; text-align: center; padding: 18px 0 8px; }
