:root {
  --bg: #1b2238;
  --bg2: #141a2c;
  --panel: #252f4c;
  --line: rgba(255,255,255,.13);
  --text: #f1efe8;
  --muted: #a7b0cc;
  --accent: #f3b33d;
  --danger: #ef5a4c;
  --ok: #4fcf86;
  --wood: #c9935a;
  --wood2: #e2b47c;
  --groove: #5a3a22;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: system-ui, "Segoe UI", Roboto, sans-serif; overflow: hidden; }
#app { height: 100%; display: flex; flex-direction: column; }
button { font: inherit; color: inherit; cursor: pointer; }
.btn { background: var(--accent); color: #2a1d00; border: 0; border-radius: 12px; padding: 12px 18px; font-weight: 700; }
.btn.sec { background: rgba(255,255,255,.12); color: var(--text); }
.btn.big { padding: 16px 22px; font-size: 18px; }
.btn:disabled { opacity: .45; cursor: default; }
input[type=text] { font: inherit; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: rgba(0,0,0,.25); color: var(--text); width: 100%; }
h1 { margin: 0; font-size: 42px; letter-spacing: 1px; }

.screen { flex: 1; overflow: auto; padding: calc(20px + env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; align-items: center; gap: 14px; }
.card { width: 100%; max-width: 460px; background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.card h3 { margin: 0; font-size: 15px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.chip { background: rgba(255,255,255,.1); border: 1px solid transparent; border-radius: 999px; padding: 8px 14px; }
.chip.on { background: var(--accent); color: #2a1d00; font-weight: 700; }
.chip:disabled { opacity: .7; cursor: default; }
.code { font-size: 44px; font-weight: 800; letter-spacing: 8px; text-align: center; color: var(--accent); }
.plist { display: flex; flex-direction: column; gap: 6px; }
.pl { display: flex; justify-content: space-between; background: rgba(0,0,0,.2); border-radius: 10px; padding: 10px 12px; }
.muted { color: var(--muted); font-size: 14px; text-align: center; max-width: 460px; }
.card .muted { text-align: left; }
.tiny { font-size: 12px; color: var(--muted); }
.subtitle { font-size: 18px; font-weight: 700; color: var(--accent); letter-spacing: .08em; margin-top: -10px; text-transform: uppercase; }
.logo { width: 92px; height: 92px; margin-top: 4px; filter: drop-shadow(0 6px 14px rgba(0,0,0,.4)); }
.logo .lb { fill: var(--groove); }
.logo .lc { fill: var(--wood2); }
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.7); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50; }
.overlay .card { max-height: 90vh; overflow: auto; }
table { width: 100%; border-collapse: collapse; }
td, th { padding: 7px 6px; text-align: right; border-bottom: 1px solid var(--line); }
td:first-child, th:first-child { text-align: left; }
th { font-size: 12px; color: var(--muted); font-weight: 600; }
tr.win td { color: var(--accent); font-weight: 700; }
.rulestext { font-size: 14px; line-height: 1.5; max-width: 560px; }
.rulestext p { margin: 6px 0; }
#toast { position: fixed; left: 50%; top: 14%; transform: translateX(-50%); background: rgba(0,0,0,.85); padding: 10px 16px; border-radius: 12px; z-index: 100; max-width: 88vw; opacity: 0; pointer-events: none; transition: opacity .2s; text-align: center; }
#toast.show { opacity: 1; }
.backrow { width: 100%; max-width: 460px; }
.backbtn { background: none; border: 0; color: var(--muted); font-size: 16px; padding: 4px 0; }
.pcard { flex-direction: row; justify-content: space-between; align-items: center; text-align: left; }
.ppoints { text-align: right; font-size: 26px; font-weight: 800; color: var(--accent); line-height: 1.1; }
.bignum { font-size: 44px; font-weight: 800; color: var(--accent); display: flex; align-items: baseline; gap: 10px; }
.bignum span { font-size: 14px; color: var(--muted); font-weight: 600; }
.pkey { font-size: 28px; font-weight: 800; letter-spacing: 2px; text-align: center; color: var(--accent); user-select: all; }
.statsover { align-items: flex-start; overflow: auto; }
.statsbox { width: 100%; max-width: 460px; display: flex; flex-direction: column; gap: 12px; }
.statsover .card { max-height: none; overflow: visible; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--pc); margin-right: 6px; flex: 0 0 auto; box-shadow: 0 0 0 2px rgba(255,255,255,.2); }
.fireworks { position: fixed; inset: 0; width: 100vw; height: 100vh; z-index: 200; pointer-events: none; }

/* ---------- игра ---------- */
.game { flex: 1; display: flex; flex-direction: column; min-height: 0; position: relative; }
.top { display: flex; gap: 6px; padding: calc(4px + env(safe-area-inset-top)) calc(6px + env(safe-area-inset-right)) 4px calc(6px + env(safe-area-inset-left)); background: var(--bg2); align-items: center; }
.chips { flex: 1; min-width: 0; display: grid; grid-template-columns: repeat(var(--cols, 2), minmax(0, 1fr)); gap: 4px; }
.game.n4 .chips { --cols: 4; }
.pchip { min-width: 0; background: rgba(255,255,255,.07); border: 2px solid transparent; border-radius: 10px; padding: 3px 8px; font-size: 13px; display: flex; gap: 7px; align-items: center; white-space: nowrap; overflow: hidden; }
.pchip.turn { border-color: var(--pc); background: color-mix(in srgb, var(--pc) 18%, transparent); }
.pchip b { overflow: hidden; text-overflow: ellipsis; min-width: 2.5em; flex: 1 1 auto; }
.pchip .off { color: var(--danger); }
.pchip .wl { display: inline-flex; align-items: center; gap: 3px; font-weight: 700; }
.pchip .wl i { display: inline-block; width: 4px; height: 13px; border-radius: 2px; }
.pchip .ptotal { color: var(--accent); font-weight: 700; }
.pchip .pw { color: var(--muted); }
.pstats { background: rgba(255,255,255,.1); border: 0; border-radius: 7px; padding: 1px 5px; font-size: 12px; }
.meta { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--muted); white-space: nowrap; }
.qbtn { padding: 4px 11px; flex: 0 0 auto; }

.mainrow { flex: 1; min-height: 0; display: flex; gap: 12px; padding: 8px calc(8px + env(safe-area-inset-right)) 4px calc(8px + env(safe-area-inset-left)); }
.boardwrap { flex: 1; min-width: 0; min-height: 0; display: flex; align-items: center; justify-content: center; }
#bsvg { display: block; touch-action: none; user-select: none; -webkit-user-select: none; filter: drop-shadow(0 8px 22px rgba(0,0,0,.45)); }
#bsvg .bbg { fill: var(--groove); }
#bsvg .cell { fill: var(--wood); transition: fill .15s; }
#bsvg .cell:nth-child(odd) { fill: #c58e55; }
#bsvg .cell.can { fill: #f6dca5; }
#bsvg.mine .cell.can { cursor: pointer; animation: can 1.4s ease-in-out infinite; }
@keyframes can { 50% { fill: #fff0c8; } }
#bsvg.mine .cell.can:hover { fill: #fff6dc; }
#bsvg .from { fill: none; stroke-width: .7; stroke-dasharray: 1.4 1; opacity: .9; }
#bsvg .wall { stroke: rgba(0,0,0,.35); stroke-width: .35; }
#bsvg .wall.fresh { animation: fresh 1.2s ease-out; }
@keyframes fresh { 0% { opacity: 0; } 30% { opacity: 1; stroke: #fff; stroke-width: 1; } 100% { stroke-width: .35; } }
#bsvg .ghost { pointer-events: none; }
#bsvg .ghost.ok { fill: rgba(255,255,255,.85); stroke: var(--accent); stroke-width: .5; }
#bsvg .ghost.bad { fill: rgba(239,90,76,.55); stroke: rgba(239,90,76,.9); stroke-width: .4; stroke-dasharray: 1 .8; }
#bsvg .pawn { pointer-events: none; }
#bsvg .pawn .body { stroke: rgba(0,0,0,.45); stroke-width: .5; }
#bsvg .pawn .shine { fill: rgba(255,255,255,.45); }
#bsvg .pawn .halo { fill: none; stroke-width: .8; opacity: .9; animation: halo 1.2s ease-in-out infinite; }
@keyframes halo { 50% { opacity: .25; } }

.status { display: flex; justify-content: space-between; gap: 10px; padding: 4px calc(12px + env(safe-area-inset-right)) 4px calc(12px + env(safe-area-inset-left)); font-size: 14px; color: var(--muted); min-height: 26px; align-items: center; }
.status b { color: var(--text); }
.status .bad { color: var(--danger); }
#timer { font-variant-numeric: tabular-nums; flex: 0 0 auto; }
.bottom { padding: 2px calc(8px + env(safe-area-inset-right)) calc(8px + env(safe-area-inset-bottom)) calc(8px + env(safe-area-inset-left)); min-height: 56px; display: flex; align-items: center; justify-content: center; }
.hint { color: var(--muted); font-size: 14px; text-align: center; }
.ghostbar { display: flex; gap: 8px; width: 100%; max-width: 520px; }
.ghostbar .btn { flex: 1; padding: 12px 6px; }
.ghostbar .btn.main { flex: 1.6; }

/* ПК: справа панель хода */
.turnpanel { flex: 0 0 220px; display: flex; flex-direction: column; justify-content: center; gap: 6px; text-align: center; }
.tp-who { font-size: 18px; }
.tp-time { font-size: 44px; font-weight: 800; font-variant-numeric: tabular-nums; color: var(--accent); }
.tp-time.warn { color: var(--danger); }
.tp-label { font-size: 12px; color: var(--muted); margin-top: -6px; }
.tp-last { font-size: 14px; color: var(--muted); margin-top: 10px; }
.tp-help { font-size: 12px; color: var(--muted); margin-top: 18px; line-height: 1.45; }
.game.pc .status #timer { display: none; }
.game.pc .bottom { min-height: 0; padding-bottom: 6px; }

/* узкий экран: игроков вчетвером — сеткой 2×2 */
@media (max-width: 700px) {
  .game.n4 .chips { --cols: 2; }
  .pchip { font-size: 12px; gap: 5px; padding: 2px 6px; }
  .pchip .ptotal, .pchip .pw { display: none; }
  .turnpanel { display: none; }
  .game.pc .status #timer { display: inline; }
}
/* низкий горизонтальный экран телефона: панель хода не нужна, поле — по высоте */
@media (orientation: landscape) and (max-height: 500px) {
  .game { display: grid; grid-template-columns: 1fr minmax(220px, 34%); grid-template-rows: auto 1fr auto; }
  .game .top { grid-column: 1 / -1; }
  .game .mainrow { grid-row: 2 / 4; grid-column: 1; }
  .game .status { grid-column: 2; grid-row: 2; align-items: flex-end; flex-direction: column; justify-content: center; text-align: right; }
  .game .bottom { grid-column: 2; grid-row: 3; }
  .turnpanel { display: none; }
  .ghostbar { flex-wrap: wrap; }
  .game.pc .status #timer { display: inline; }
}
.pchip b i { font-style: normal; color: var(--muted); font-weight: 500; }
@media (max-width: 700px) { .pchip .you { display: none; } }
@media (min-width: 701px) and (min-height: 501px) { .game.pc .bottom .hint { display: none; } }
@media (max-width: 700px) { .meta > span, .pchip.self .pstats { display: none; } }
