: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 - 190px);
  aspect-ratio: 950 / 768; 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); }

/* SVG */
.ptnum { font: 600 12px sans-serif; fill: #c9a24f; fill-opacity: .7; text-anchor: middle; }
.cnt { font: 700 22px sans-serif; text-anchor: middle; pointer-events: none; }
.cnt.cw { fill: #5a4a2e; } .cnt.cb { fill: #e8d8b8; }
.ck.mov circle:first-child { stroke: var(--gold); stroke-width: 3; }
.ck.sel circle:first-child { stroke: #ffd36b; stroke-width: 5; }
.hiSel { fill: #ffd36b; opacity: .16; }
.hiSelBar { fill: rgba(255,211,107,.25); stroke: #ffd36b; stroke-width: 3; }
.hiDest { fill: var(--green); opacity: .2; }
.hiRing { fill: rgba(92,207,122,.25); stroke: var(--green); stroke-width: 3; stroke-dasharray: 6 5; animation: pulse 1s ease-in-out infinite alternate; }
.hiRing.hiSp { fill: rgba(255,211,107,.3); stroke: #ffd36b; stroke-width: 4; }
.bonus { background: linear-gradient(#ffe08a, #d6a43c); color: #2a1708; font-weight: 800; padding: 4px 14px; border-radius: 20px; box-shadow: 0 0 18px rgba(255,211,107,.55); animation: pulse .7s ease-in-out infinite alternate; }
.bonus[hidden] { display: none; }
.hiOff { fill: rgba(92,207,122,.22); stroke: var(--green); stroke-width: 3; animation: pulse 1s ease-in-out infinite alternate; }
@keyframes pulse { from { opacity: .55; } to { opacity: 1; } }
.die.used { opacity: .35; }
.die.rolling { animation: tumble .18s linear infinite; }
@keyframes tumble { 0% { transform: rotate(0deg) translateY(0); } 50% { transform: rotate(180deg) translateY(-6px); } 100% { transform: rotate(360deg) translateY(0); } }

/* Модальное окно */
.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; }
