:root {
  --bg: #ffffff; --text: #111114; --muted: #6b7280; --line: #e5e7eb; --panel: #f4f6f9; --panel2: #eceff4;
  --ink: #16161a; --blue: #0b5ad9; --blue2: #3f9bf0; --gold: #ffc233; --good: #12a150; --bad: #d92d3a;
  --radius: 14px; font-family: ui-rounded, -apple-system, "Segoe UI", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
body { min-height: 100dvh; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
.muted { color: var(--muted); } .small { font-size: 12.5px; line-height: 1.45; }
code { background: var(--panel2); padding: 1px 5px; border-radius: 5px; }

.btn { font: inherit; color: #fff; border: 0; border-radius: 12px; padding: 10px 16px; cursor: pointer; background: var(--ink); transition: transform .08s, background .15s, opacity .15s; }
.btn:hover:not(:disabled) { background: #2b2b33; } .btn:active:not(:disabled) { transform: scale(.97); }
.btn:disabled { opacity: .35; cursor: default; }
.btn.primary { background: var(--blue); font-weight: 700; } .btn.primary:hover:not(:disabled) { background: #0a4fc0; }
.btn.danger { background: var(--bad); } .btn.danger:hover:not(:disabled) { background: #bd2431; }
.btn.ghost { background: var(--panel2); color: var(--text); } .btn.ghost:hover:not(:disabled) { background: #e0e4eb; }
.btn.big { padding: 14px 22px; font-size: 18px; width: 100%; }
.link { background: none; border: 0; color: var(--muted); cursor: pointer; font: inherit; padding: 8px; } .link:hover { color: var(--text); }

/* заставка */
.splash { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; background: var(--bg); }
.splash-card { width: min(420px, 100%); text-align: center; background: #fff; border: 1px solid var(--line); border-radius: 24px; padding: 32px 24px; box-shadow: 0 24px 60px #10182818; animation: rise .5s ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } }
.splash-logo svg { width: 72px; height: 72px; } .l-a { fill: #fff; stroke: #111; stroke-width: 2; } .l-b { fill: #17171a; }
.splash h1 { margin: 6px 0 18px; font-size: 38px; letter-spacing: .5px; }
.who { display: grid; gap: 12px; margin-top: 14px; }
.who button { font: inherit; font-size: 20px; color: var(--text); padding: 16px; border-radius: 16px; border: 1px solid var(--line); background: var(--panel); cursor: pointer; display: flex; align-items: center; gap: 14px; justify-content: center; }
.who button:hover { background: #e8f1fe; border-color: var(--blue); }
.who .tok { font-size: 28px; }
.greet { font-size: 22px; margin: 0 0 16px; }
.login input[type=password] { width: 100%; font: inherit; font-size: 18px; padding: 14px 16px; border-radius: 14px; border: 1px solid #cfd5df; background: #fff; color: var(--text); outline: none; text-align: center; }
.login input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px #0b5ad933; }
.error { color: var(--bad); min-height: 22px; margin: 8px 0; font-size: 14px; }
.login .btn { margin-bottom: 4px; }
.shake { animation: shake .35s; } @keyframes shake { 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }

/* игра */
.app { max-width: 1280px; margin: 0 auto; padding: 10px 14px 24px; }
.topbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: space-between; padding: 6px 2px 12px; }
.brand { font-weight: 800; font-size: 22px; }
.scoreboard { display: flex; gap: 10px; align-items: stretch; flex: 1; justify-content: center; flex-wrap: wrap; }
.pchip { display: flex; align-items: center; gap: 10px; padding: 8px 14px; border-radius: 14px; background: var(--panel); border: 2px solid transparent; min-width: 160px; }
.pchip.turn { border-color: var(--blue); background: #e8f1fe; }
.pchip .tok { font-size: 26px; } .pchip .nm { font-weight: 700; } .pchip .sub { font-size: 12px; color: var(--muted); }
.pchip .score { margin-left: auto; font-size: 24px; font-weight: 800; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #b5bcc8; margin-right: 5px; } .dot.on { background: var(--good); }
.match-info { align-self: center; color: var(--muted); font-size: 13px; text-align: center; }
.menu { display: flex; gap: 8px; position: relative; }
.popmenu { position: absolute; right: 14px; top: 58px; z-index: 20; background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 6px; display: grid; min-width: 180px; box-shadow: 0 16px 40px #10182822; }
.popmenu button { font: inherit; color: var(--text); background: none; border: 0; text-align: left; padding: 10px 12px; border-radius: 9px; cursor: pointer; } .popmenu button:hover { background: var(--panel); }

.stage { display: grid; grid-template-columns: minmax(0, 1fr) 280px; grid-template-areas: "board side" "controls side"; gap: 12px; align-items: start; }
.board-wrap { grid-area: board; position: relative; border-radius: 22px; padding: 10px; background: var(--ink); box-shadow: 0 20px 40px #10182833; }
#board { width: 100%; height: auto; display: block; border-radius: 14px; touch-action: manipulation; user-select: none; -webkit-user-select: none; }
.controls { grid-area: controls; display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; background: var(--panel); border-radius: var(--radius); padding: 12px 16px; }
.status { font-size: 17px; flex: 1; min-width: 200px; line-height: 1.4; } .status b { color: var(--blue); }
.actions { display: flex; gap: 10px; flex-wrap: wrap; }
.side { grid-area: side; display: grid; gap: 10px; }
.side details { background: var(--panel); border-radius: var(--radius); padding: 10px 14px; }
.side summary { cursor: pointer; font-weight: 700; }
.log { margin: 10px 0 0; padding: 0; list-style: none; max-height: 340px; overflow: auto; font-size: 13.5px; display: flex; flex-direction: column-reverse; }
.log li { padding: 4px 0; border-bottom: 1px solid var(--line); color: #4b5563; } .log li:first-child { color: var(--text); font-weight: 600; }
.stats table { width: 100%; border-collapse: collapse; font-size: 13px; margin: 8px 0; } .stats td, .stats th { padding: 3px 4px; text-align: center; } .stats th { color: var(--muted); font-weight: 600; }

/* кости — на центральной планке */
.dice-overlay { position: absolute; left: calc(10px + 62%); top: 50%; transform: translateY(-50%); display: flex; gap: 14px; align-items: center; pointer-events: none; z-index: 3; }
.die { width: clamp(38px, 6.2vw, 64px); aspect-ratio: 1; border-radius: 16%; background: #fff; box-shadow: 0 4px 10px #0007, inset 0 -3px 0 #0001; display: grid; grid-template: repeat(3, 1fr) / repeat(3, 1fr); padding: 12%; transition: opacity .25s, filter .25s, transform .25s; }
.die i { width: 78%; height: 78%; margin: auto; border-radius: 50%; background: #111; opacity: 0; }
.die.used { opacity: .3; filter: grayscale(1); transform: scale(.88); }
.die.roll { animation: tumble .6s cubic-bezier(.2, .8, .3, 1); }
@keyframes tumble { 0% { transform: translateY(-40px) rotate(-200deg) scale(.6); opacity: 0; } 70% { transform: translateY(4px) rotate(12deg); opacity: 1; } 100% { transform: none; } }

/* модалки */
.modal { position: fixed; inset: 0; background: #0b0f1a99; display: grid; place-items: center; z-index: 50; padding: 16px; backdrop-filter: blur(3px); }
.modal-card { width: min(460px, 100%); max-height: 90dvh; overflow: auto; background: #fff; border: 1px solid var(--line); border-radius: 22px; padding: 26px; text-align: center; box-shadow: 0 30px 80px #0006; animation: rise .25s ease both; }
.modal-card h2 { margin: 0 0 8px; } .modal-card p { color: #374151; line-height: 1.5; }
.modal-card .row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 16px; }
.modal-card.rules { text-align: left; font-size: 14.5px; } .modal-card.rules h3 { margin: 14px 0 4px; color: var(--blue); } .modal-card.rules p, .modal-card.rules li { margin: 4px 0; }
.big-emoji { font-size: 56px; }
.toast { position: fixed; left: 50%; bottom: 22px; transform: translate(-50%, 30px); background: #111d; color: #fff; padding: 11px 18px; border-radius: 12px; opacity: 0; transition: .25s; z-index: 60; pointer-events: none; max-width: 90vw; text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); } .toast.err { background: #d92d3aee; }

/* SVG */
.hit { fill: transparent; cursor: default; } .hit.click { cursor: pointer; }
.pulse { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; } }
text.num { font-size: 13px; fill: #ffffffa0; text-anchor: middle; font-weight: 600; }
text.num.head { fill: #ffc233; font-weight: 800; }

@media (max-width: 900px) {
  .stage { grid-template-columns: 1fr; grid-template-areas: "board" "controls" "side"; }
  .brand { display: none; } .pchip { min-width: 0; padding: 6px 10px; flex: 1; }
  .menu { margin-left: auto; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
