:root {
  --bg: #1b110a;
  --bg2: #2a1a0f;
  --ink: #f3e6cc;
  --muted: #bfa982;
  --gold: #d6ae5c;
  --gold2: #b48a3a;
  --green: #5ccf7a;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(ellipse at top, #3a2414 0%, var(--bg) 70%) fixed;
  background-color: var(--bg);
  color: var(--ink);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
#app {
  max-width: 1180px; margin: 0 auto; min-height: 100%;
  display: flex; flex-direction: column;
  padding: max(8px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
.bar { display: flex; align-items: center; gap: 10px; padding: 4px 0 8px; flex-wrap: wrap; }
.brand { font-family: Georgia, "Times New Roman", serif; font-size: 20px; color: var(--gold); letter-spacing: .5px; }
.score { margin: 0 auto; display: flex; gap: 6px; align-items: baseline; background: rgba(0,0,0,.3); border: 1px solid rgba(214,174,92,.35); padding: 3px 12px; border-radius: 20px; }
.score b { font-size: 17px; color: #fff; }
.score .sep { color: var(--muted); }
.score i { font-style: normal; }
.tools { display: flex; gap: 6px; align-items: center; }
.sel { display: flex; gap: 6px; }
button, select {
  font: inherit; color: var(--ink); background: var(--bg2);
  border: 1px solid rgba(214,174,92,.45); border-radius: 10px; padding: 6px 10px; cursor: pointer;
}
select { padding: 6px 6px; }
button.icon { width: 36px; height: 34px; padding: 0; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; }
button:disabled { opacity: .4; cursor: default; }
button.primary { background: linear-gradient(#e2bd6d, #b48a3a); color: #2a1708; border-color: #f0d08a; font-weight: 700; }
button.secondary { background: rgba(0,0,0,.25); }
button:focus-visible, select:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

.game { flex: 1; display: flex; flex-direction: column; gap: 10px; min-height: 0; }
.boardWrap { width: 100%; display: flex; justify-content: center; }
#board {
  width: 100%; height: auto; aspect-ratio: 1 / 1; display: block;
  touch-action: none; user-select: none; -webkit-user-select: none;
  border-radius: 14px; box-shadow: 0 12px 40px rgba(0,0,0,.55);
}
.panel { display: flex; flex-direction: column; gap: 8px; align-items: center; text-align: center; }
.status { min-height: 1.4em; font-size: 16px; font-weight: 600; }
.status.alert { color: #ffcf7a; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.actions button { min-width: 120px; padding: 10px 14px; font-size: 16px; }
.hint { color: var(--muted); font-size: 13px; max-width: 520px; }

/* ---------- шахматы: раскладка ---------- */
.boardCol { width: 100%; max-width: min(100%, calc(100vh - 260px)); margin: 0 auto; display: flex; flex-direction: column; gap: 4px; }
.boardWrap { position: relative; }
#board { max-height: none; }
.taken { display: flex; align-items: center; gap: 6px; min-height: 28px; font-size: 14px; color: var(--muted); }
.taken .who { white-space: nowrap; }
.taken .caps { display: flex; flex-wrap: wrap; align-items: center; }
.taken .pic { width: 22px; height: 22px; margin-right: -6px; }
.taken .adv { color: #fff; font-weight: 700; margin-left: 8px; }
.pic { display: block; overflow: visible; }

/* фигуры: цвет контура и деталей передаётся внутрь <use> через наследование */
.pc.w { fill: url(#gPw); stroke: #2b2118; stroke-width: 2.3; color: #2b2118; stroke-linejoin: round; }
.pc.b { fill: url(#gPb); stroke: #050302; stroke-width: 2.3; color: #e3d2ad; stroke-linejoin: round; }
.dt { fill: currentColor; stroke: none; }
.ln { fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; }
.pc.flying { pointer-events: none; }
.lbl { font: 600 20px sans-serif; fill: #c9a24f; fill-opacity: .8; text-anchor: middle; }
.hiLast { fill: rgba(255, 214, 80, .38); }
.hiSel { fill: rgba(110, 200, 110, .5); }
.hiCheck { fill: url(#gCheck); }
.hiDest { fill: rgba(30, 55, 20, .42); pointer-events: none; }
.hiCap { fill: none; stroke: rgba(30, 55, 20, .5); stroke-width: 8; pointer-events: none; }

/* выбор фигуры при превращении */
.promo { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,.45); border-radius: 14px; z-index: 5; }
.promo[hidden] { display: none; }
.promoCard { background: linear-gradient(#3a2414, #24160c); border: 1px solid var(--gold2); border-radius: 14px; padding: 12px 14px; text-align: center; box-shadow: 0 12px 40px rgba(0,0,0,.6); }
.promoTitle { font-weight: 700; margin-bottom: 8px; }
.promoBtns { display: flex; gap: 8px; justify-content: center; margin-bottom: 10px; }
.promoBtns button { width: 68px; height: 68px; padding: 4px; background: #e9d3a6; border-color: #f0d08a; }
.promoBtns button .pic { width: 100%; height: 100%; }
.promoX { padding: 6px 18px; }

/* запись партии */
.moves { width: 100%; max-width: 520px; display: grid; grid-template-columns: 2.6em 1fr 1fr; gap: 2px 6px; max-height: 260px; overflow-y: auto;
  background: rgba(0,0,0,.25); border: 1px solid rgba(214,174,92,.25); border-radius: 10px; padding: 6px 10px; text-align: left; font-size: 15px; }
.moves .mn { color: var(--muted); }
.moves .mv.cur { color: #ffd36b; font-weight: 700; }
.moves .empty { grid-column: 1 / -1; color: var(--muted); }
.actions button.icon2 { min-width: 48px; width: 48px; padding: 8px 0; display: inline-flex; align-items: center; justify-content: center; }
.actions button[hidden] { display: none; }

/* компьютер: доска слева, панель справа */
@media (min-width: 900px) and (min-height: 560px) {
  .game { flex-direction: row; align-items: flex-start; gap: 22px; }
  .boardCol { flex: 1; max-width: calc(100vh - 140px); margin: 0; }
  .panel { width: 330px; flex: none; align-items: stretch; text-align: left; padding-top: 34px; }
  .moves { max-height: calc(100vh - 380px); min-height: 120px; }
  .actions { justify-content: flex-start; }
  .actions button { min-width: 0; flex: 1 1 40%; }
  .actions button.icon2 { flex: 0 0 48px; }
  .hint { text-align: left; }
}
/* телефон: доска на всю ширину, запись — одна строка с последними ходами */
@media (max-width: 520px) {
  #app { padding-left: max(6px, env(safe-area-inset-left)); padding-right: max(6px, env(safe-area-inset-right)); }
  .brand { display: none; }
  .bar { gap: 6px; padding-bottom: 6px; }
  .score { margin: 0 auto 0 0; }
  .tools { display: contents; }
  .sel { order: 3; flex-basis: 100%; }
  .sel select { flex: 1; min-width: 0; }
  .game { gap: 6px; }
  .panel { gap: 6px; }
  .boardCol { max-width: 100%; }
  #board { border-radius: 10px; }
  .taken { min-height: 24px; font-size: 13px; }
  .taken .pic { width: 19px; height: 19px; }
  .moves { display: flex; flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden; white-space: nowrap; gap: 5px; max-height: none; padding: 5px 8px; font-size: 14px; scrollbar-width: none; }
  .moves::-webkit-scrollbar { display: none; }
  .moves .mn { margin-left: 4px; }
  .actions { width: 100%; flex-wrap: nowrap; gap: 6px; }
  .actions button { min-width: 0; flex: 1; padding: 10px 6px; font-size: 15px; }
  .actions button.icon2 { flex: 0 0 46px; }
  .actions .long { display: none; }
  .hint { font-size: 12px; }
  .promoBtns button { width: 60px; height: 60px; }
}
/* телефон, ландшафт */
@media (orientation: landscape) and (max-height: 540px) {
  #app { padding-top: max(4px, env(safe-area-inset-top)); padding-bottom: 4px; }
  .bar { padding: 0 0 4px; }
  .brand { display: none; }
  .game { flex-direction: row; align-items: center; }
  .boardCol { max-width: calc(100vh - 110px); flex: none; width: calc(100vh - 110px); }
  .panel { flex: 1; min-width: 0; }
  .moves { max-height: 34vh; }
  .actions { flex-wrap: wrap; }
  .hint { display: none; }
}

/* Модальное окно */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 10; }
.modal[hidden] { display: none; }
.card { background: linear-gradient(#3a2414, #24160c); border: 1px solid var(--gold2); border-radius: 16px; padding: 18px 20px; max-width: 480px; width: 100%; max-height: 90vh; overflow: auto; box-shadow: 0 20px 60px rgba(0,0,0,.6); }
.card h2 { margin: 0 0 10px; font-family: Georgia, serif; color: var(--gold); font-size: 22px; }
.card p { margin: 6px 0; }
.rules { padding-left: 18px; margin: 0; } .rules li { margin: 6px 0; }
.modalBtns { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }

/* Онлайн: окно приглашения */
.invLink { width: 100%; font: inherit; font-size: 15px; padding: 10px; margin: 8px 0; border-radius: 10px; border: 1px solid rgba(214,174,92,.45); background: rgba(0,0,0,.35); color: var(--ink); }
.invBtns { display: flex; gap: 8px; } .invBtns button { flex: 1; padding: 10px; font-size: 16px; }
.hintSmall { color: var(--muted); font-size: 14px; min-height: 1.2em; }
#btnInvite[hidden] { display: none; }
