: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; max-height: calc(100vh - 200px);
  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: 10px; flex-wrap: wrap; justify-content: center; }
.actions button { min-width: 150px; padding: 10px 14px; font-size: 16px; }
.hint { color: var(--muted); font-size: 13px; max-width: 520px; }

/* Вертикальная доска: цифры поворачиваем обратно, чтобы читались */
#board.vert { aspect-ratio: 768 / 950; }
#board.vert text { transform-box: fill-box; transform-origin: center; transform: rotate(-90deg); }


/* Доска уголков */
#board { max-width: min(100%, calc(100vh - 200px)); }
.lbl { font: 600 20px sans-serif; fill: #c9a24f; fill-opacity: .75; text-anchor: middle; }
.cTone { fill: #9a6a36; fill-opacity: .13; }
.grid { stroke: #8a5f33; stroke-opacity: .45; stroke-width: 1.5; }
.edge { fill: none; stroke: #2a170c; stroke-width: 3; }
.zW { fill: #ffd36b; fill-opacity: .22; stroke: #b48a3a; stroke-width: 4; }
.zB { fill: #5a3318; fill-opacity: .22; stroke: #6b4120; stroke-width: 4; }
.pc.mov > circle:first-child { stroke: var(--gold); stroke-width: 5; }
.pc.sel > circle:first-child { stroke: #ffd36b; stroke-width: 7; }
.pc.stop > circle:first-child { animation: glow 0.9s ease-in-out infinite alternate; }
@keyframes glow { from { stroke: #ffd36b; } to { stroke: #5ccf7a; } }
.tick { fill: none; stroke: #2f7a44; stroke-width: 6; stroke-linecap: round; stroke-linejoin: round; pointer-events: none; }
.hiDest { fill: rgba(92,207,122,.6); stroke: #2f7a44; stroke-width: 3; animation: pulse 1s ease-in-out infinite alternate; }
.hiPath { fill: rgba(255,211,107,.3); }
.hiLast { fill: rgba(255,211,107,.24); }
.trail { fill: none; stroke: #ffd36b; stroke-width: 6; stroke-opacity: .7; stroke-dasharray: 2 12; stroke-linecap: round; }
.lastTrail { fill: none; stroke: #b48a3a; stroke-width: 5; stroke-opacity: .55; stroke-dasharray: 2 12; stroke-linecap: round; }
.pieces { color: var(--muted); font-size: 14px; }
@keyframes pulse { from { opacity: .55; } to { opacity: 1; } }
#btnStop[hidden] { 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; }
.big { font-size: 26px; font-weight: 800; color: #fff; }

/* Телефон, портрет: шапка в две строки — счёт и кнопки, ниже режим и уровень */
@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; }
  .actions button { min-width: 0; flex: 1; }
  .actions { width: 100%; }
  .game { gap: 6px; }
  .panel { gap: 6px; }
  #board { border-radius: 10px; max-height: none; }
}
/* Телефон, ландшафт: доска слева, панель справа */
@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; }
  .boardWrap { flex: 1; min-width: 0; }
  #board { max-height: calc(100vh - 56px); width: auto; max-width: 100%; height: calc(100vh - 56px); }
  .panel { width: 190px; flex: none; }
  .actions { flex-direction: column; width: 100%; }
  .actions button { min-width: 0; width: 100%; }
  .hint { display: none; }
}

/* Онлайн: окно приглашения */
.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; }
