:root {
  --bg: #17202b;
  --bg2: #111821;
  --panel: #222e3c;
  --line: rgba(255,255,255,.13);
  --text: #f1efe8;
  --muted: #a7b0cc;
  --accent: #f3b33d;
  --danger: #ef5a4c;
  --ok: #4fcf86;
}
* { 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); }
.langrow { width: 100%; max-width: 460px; display: flex; justify-content: flex-end; margin-bottom: -8px; }
.langsel { display: inline-flex; align-items: center; gap: 4px; font-size: 14px; color: var(--muted, #9aa3c0); }
.langsel select { background: transparent; color: inherit; border: 1px solid rgba(255,255,255,.18); border-radius: 8px; padding: 4px 6px; font: inherit; }
.langsel option { color: #000; }
.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)); }
.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(2, minmax(0, 1fr)); gap: 4px; }
.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 b i { font-style: normal; color: var(--muted); font-weight: 500; }
.pchip .off { color: var(--danger); }
.pchip .ring { font-weight: 700; font-variant-numeric: tabular-nums; }
.pchip .ring.hot { color: var(--danger); }
.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: 6px calc(8px + env(safe-area-inset-right)) 2px calc(8px + env(safe-area-inset-left)); }
.boardwrap { flex: 1; min-width: 0; min-height: 0; display: flex; border-radius: 18px;
  background: radial-gradient(ellipse at center, #22323f 0%, #1a2530 60%, #151e27 100%); box-shadow: inset 0 0 40px rgba(0,0,0,.35); }
#bsvg { display: block; width: 100%; height: 100%; touch-action: manipulation; user-select: none; -webkit-user-select: none; }
#bsvg .cellbg { fill: rgba(255,255,255,.025); stroke: rgba(255,255,255,.09); stroke-width: .5; }
#bsvg .from { fill: none; stroke-width: .9; stroke-dasharray: 1.6 1.2; opacity: .9; }
.tile { stroke-width: 1; }
#bsvg .tile { filter: drop-shadow(0 1.2px 1.2px rgba(0,0,0,.45)); }
.crownring { fill: none; stroke: #ffd65a; stroke-width: .9; opacity: .9; }
.glyph .gl { fill: none; stroke: #fff; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.glyph .gl-bold { stroke-width: 2.2; }
.glyph .gl-fill, .glyph .gl-dot { fill: #fff; }
.glyph .gl-crown { fill: #ffd65a; stroke: rgba(0,0,0,.35); stroke-width: .5; stroke-linejoin: round; }
#bsvg.mine .pc.movable { cursor: pointer; }
#bsvg.mine:not(.selecting) .pc.movable .tile { stroke: #fff6d0; stroke-width: 1.3; }
#bsvg .pc.sel .tile { stroke: #fff; stroke-width: 2; animation: selpulse 1s ease-in-out infinite; }
@keyframes selpulse { 50% { stroke-opacity: .35; } }
#bsvg .pc.last .tile { stroke: var(--accent); stroke-width: 1.6; }
#bsvg .pc.fresh { animation: pop .45s ease-out; }
@keyframes pop { 0% { opacity: 0; } 100% { opacity: 1; } }
#bsvg .tgt { cursor: pointer; }
#bsvg .tgt polygon { fill: rgba(240,185,65,.18); stroke: var(--accent); stroke-width: .9; stroke-dasharray: 2 1.2; animation: tgt 1.3s ease-in-out infinite; }
#bsvg .tgt circle { fill: var(--accent); opacity: .8; }
#bsvg .tgt:hover polygon { fill: rgba(240,185,65,.4); }
#bsvg .tgt .ghost { opacity: .35; pointer-events: none; }
#bsvg .tgt .ghost .tile { stroke: none; }
@keyframes tgt { 50% { fill: rgba(240,185,65,.32); } }
#bsvg .push { cursor: pointer; }
#bsvg .push .pushhit { fill: transparent; }
#bsvg .push path { fill: var(--accent); stroke: #2a1d00; stroke-width: .6; animation: pushme 1s ease-in-out infinite; }
@keyframes pushme { 50% { transform: translateX(1.6px); } }

.status { display: flex; justify-content: space-between; gap: 10px; padding: 2px calc(12px + env(safe-area-inset-right)) 2px calc(12px + env(safe-area-inset-left)); font-size: 14px; color: var(--muted); min-height: 24px; 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(6px + env(safe-area-inset-bottom)) calc(8px + env(safe-area-inset-left)); display: flex; flex-direction: column; align-items: center; gap: 4px; }
.hint { color: var(--muted); font-size: 13px; text-align: center; min-height: 1.2em; }

/* запас фишек */
.tray { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; width: 100%; max-width: 560px; }
.tk { position: relative; background: rgba(255,255,255,.07); border: 2px solid transparent; border-radius: 12px; padding: 4px 2px 3px; display: flex; flex-direction: column; align-items: center; gap: 1px; min-width: 0; }
.tk svg { width: 40px; height: 40px; }
.tk b { position: absolute; top: 2px; right: 6px; font-size: 13px; background: rgba(0,0,0,.45); border-radius: 8px; padding: 0 5px; }
.tk span { font-size: 11px; color: var(--muted); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tk.on { border-color: var(--accent); background: rgba(240,185,65,.16); }
.tk:disabled { opacity: .38; cursor: default; }
.tk.empty { opacity: .18; }
.minitray { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 700; flex-wrap: wrap; justify-content: center; }
.mini { display: inline-flex; align-items: center; gap: 1px; }
.mini svg { width: 20px; height: 20px; }

/* ПК: справа панель хода */
.turnpanel { flex: 0 0 240px; 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: 8px; }
.tp-moves { font-size: 12px; color: var(--muted); }
.tp-help { font-size: 12px; color: var(--muted); margin-top: 10px; line-height: 1.45; }
.legend { display: flex; flex-direction: column; gap: 4px; text-align: left; font-size: 12.5px; color: var(--muted); margin-top: 10px; }
.legend div { display: flex; align-items: center; gap: 8px; }
.legend svg { width: 26px; height: 26px; flex: 0 0 auto; }
.legend b { color: var(--text); }
.rulestext .legend { font-size: 14px; margin: 4px 0 6px; }
.game.pc .status #timer { display: none; }
.game.pc .hint { display: none; }
.logo { width: 110px; height: 110px; }

@media (max-width: 760px) {
  .pchip { font-size: 12px; gap: 5px; padding: 2px 6px; }
  .pchip .ptotal, .pchip .pw, .pchip .you { display: none; }
  .turnpanel { display: none; }
  .game.pc .status #timer, .game.pc .hint { display: inline; }
  .meta > span, .pchip.self .pstats { display: none; }
  .tk svg { width: 34px; height: 34px; }
}
/* низкий горизонтальный экран телефона: поле слева, запас справа */
@media (orientation: landscape) and (max-height: 500px) {
  .game { display: grid; grid-template-columns: 1fr minmax(240px, 40%); 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; }
  .tk svg { width: 28px; height: 28px; }
  .game.pc .status #timer, .game.pc .hint { display: inline; }
}
