/* Интерфейс Hexa. Фишки рисуются в SVG (см. js/game.js), старый css/style.css больше не нужен. */
:root {
    --bg: #2b2421;
    --bg2: #352c28;
    --panel: #241e1b;
    --panel-line: #4a3d37;
    --text: #f1e9e2;
    --muted: #b3a69c;
    --accent: #e0b04a;
    --ok: #6ee7a0;
    --bad: #ff7a7a;

    --c-red: #cf4a4f;
    --c-green: #3f9a5c;
    --c-purple: #7a4ca8;
    --c-white: #dcdce6;
    --c-yellow: #ecc92e;
    --c-black: #1d1a1c;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
    background: radial-gradient(1200px 800px at 50% 30%, #3b302b 0%, var(--bg) 70%);
    color: var(--text);
    font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 15px;
    overscroll-behavior: none;
}
[hidden] { display: none !important; }
button, input { font: inherit; color: inherit; }

/* ---------- вход ---------- */
.screen { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.card {
    width: min(420px, 100%);
    background: var(--panel);
    border: 1px solid var(--panel-line);
    border-radius: 14px;
    padding: 24px;
    display: grid;
    gap: 14px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, .45);
}
.logo { margin: 0; font-weight: 800; letter-spacing: .35em; font-size: 34px; color: var(--accent); text-align: center; }
.logo.small { font-size: 18px; letter-spacing: .25em; text-align: left; }
label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }
input {
    background: #17120f;
    border: 1px solid var(--panel-line);
    border-radius: 8px;
    padding: 10px 12px;
    color: var(--text);
    outline: none;
}
input:focus { border-color: var(--accent); }
.muted { color: var(--muted); margin: 0; }
.small { font-size: 12.5px; }
.error { color: var(--bad); margin: 0; }

.btn {
    border: 1px solid var(--panel-line);
    background: #3a2f2a;
    border-radius: 9px;
    padding: 10px 16px;
    cursor: pointer;
    transition: filter .15s, transform .05s;
}
.btn:hover { filter: brightness(1.15); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #2a1d08; font-weight: 700; }
.btn[disabled] { opacity: .45; cursor: not-allowed; filter: none; }

/* ---------- каркас игры ---------- */
#app { height: 100dvh; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; grid-template-columns: minmax(0, 1fr); }
.topbar {
    display: flex; align-items: center; gap: 8px;
    padding: 6px 10px;
    background: rgba(20, 15, 13, .75);
    border-bottom: 1px solid var(--panel-line);
    backdrop-filter: blur(6px);
    z-index: 5;
}
.grow { flex: 1; }
.roomtag { color: var(--muted); font-size: 13px; padding: 3px 8px; border: 1px dashed var(--panel-line); border-radius: 999px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--bad); box-shadow: 0 0 0 3px rgba(255, 122, 122, .2); }
.dot.on { background: var(--ok); box-shadow: 0 0 0 3px rgba(110, 231, 160, .2); }
.icon-btn {
    width: 34px; height: 34px; border-radius: 9px;
    background: #3a2f2a; border: 1px solid var(--panel-line);
    cursor: pointer; font-size: 17px; line-height: 1; display: grid; place-items: center; padding: 0;
}
.icon-btn:hover { filter: brightness(1.2); }
.icon-btn[disabled] { opacity: .4; cursor: not-allowed; }

.stage { position: relative; overflow: hidden; min-height: 0; }
.board { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: grab; user-select: none; -webkit-user-select: none; }
.board.panning { cursor: grabbing; }

/* ---------- плитки в SVG ---------- */
.face { stroke: rgba(0, 0, 0, .42); stroke-width: 1.3; stroke-linejoin: round; }
.face.c-red { fill: var(--c-red); }
.face.c-green { fill: var(--c-green); }
.face.c-purple { fill: var(--c-purple); }
.face.c-white { fill: var(--c-white); }
.face.c-yellow { fill: var(--c-yellow); }
.face.c-black { fill: var(--c-black); }
.marble { fill: url(#marble); opacity: .3; mix-blend-mode: multiply; pointer-events: none; }
.tile-rim { fill: none; stroke: #8d8a86; stroke-width: 2.6; stroke-linejoin: round; pointer-events: none; }
.tile-side { fill: url(#wood); stroke: rgba(0, 0, 0, .55); stroke-width: 1.2; stroke-linejoin: round; }
.rot { transform-origin: 0 0; transition: transform .16s ease-out; }

.cell { fill: rgba(255, 255, 255, .035); stroke: rgba(255, 255, 255, .16); stroke-width: 1.2; stroke-dasharray: 5 5; }
.cell.legal { fill: rgba(110, 231, 160, .14); stroke: var(--ok); stroke-dasharray: none; stroke-width: 2; animation: pulse 1.4s ease-in-out infinite; }
.cell.hover { fill: rgba(255, 255, 255, .12); stroke: rgba(255, 255, 255, .45); }
.cell.first { stroke: var(--accent); stroke-dasharray: none; stroke-width: 2; animation: pulse 1.4s ease-in-out infinite; }
.dead { stroke: rgba(255, 122, 122, .55); stroke-width: 4; stroke-linecap: round; fill: none; }
.lastmove { fill: none; stroke: var(--accent); stroke-width: 3; stroke-linejoin: round; pointer-events: none; }
.preview { opacity: .72; pointer-events: none; }
@keyframes pulse { 50% { opacity: .55; } }

/* ---------- игроки и подсказка ---------- */
.players {
    position: absolute; top: 8px; left: 8px; right: 8px;
    display: flex; flex-wrap: wrap; gap: 6px; pointer-events: none; z-index: 3;
}
.pchip {
    display: flex; align-items: center; gap: 8px;
    background: rgba(24, 18, 15, .82);
    border: 1px solid var(--panel-line);
    border-radius: 999px; padding: 4px 12px 4px 5px;
    font-size: 13px; backdrop-filter: blur(4px);
}
.pchip .av {
    width: 24px; height: 24px; border-radius: 50%;
    display: grid; place-items: center; font-weight: 700; font-size: 12px; color: #1a120c;
}
.pchip .cnt { color: var(--muted); font-size: 12px; }
.pchip.turn { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(224, 176, 74, .35); }
.pchip.me .nm::after { content: " (вы)"; color: var(--muted); }
.pchip.off { opacity: .55; }
.pchip.left { opacity: .4; text-decoration: line-through; }

.banner {
    position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%);
    background: rgba(24, 18, 15, .9); border: 1px solid var(--panel-line);
    padding: 9px 18px; border-radius: 999px; z-index: 3; max-width: calc(100% - 24px);
    text-align: center; pointer-events: none;
}
.banner.mine { border-color: var(--accent); color: var(--accent); font-weight: 600; }

.panel {
    position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
    width: min(520px, calc(100% - 20px)); max-height: calc(100% - 20px); overflow: auto;
    background: var(--panel); border: 1px solid var(--panel-line); border-radius: 14px;
    padding: 20px; z-index: 6; box-shadow: 0 20px 60px rgba(0, 0, 0, .55); display: grid; gap: 12px;
}
.panel h2 { margin: 0; font-size: 20px; }
.panel ul { margin: 0; padding-left: 20px; color: var(--muted); display: grid; gap: 4px; }
.plist { list-style: none; padding: 0 !important; display: grid; gap: 6px; }
.plist li { display: flex; align-items: center; gap: 10px; background: #1c1613; border-radius: 9px; padding: 7px 10px; color: var(--text); }
.plist .av { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 12px; color: #1a120c; }
.plist .tag { margin-left: auto; font-size: 12px; color: var(--muted); }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.result-table { width: 100%; border-collapse: collapse; }
.result-table td, .result-table th { padding: 6px 8px; text-align: left; border-bottom: 1px solid var(--panel-line); }
.result-table th { color: var(--muted); font-weight: 500; font-size: 12px; }
.result-table tr.win td { color: var(--accent); font-weight: 700; }
.leftovers { display: flex; flex-wrap: wrap; gap: 0; max-width: 220px; }
.leftovers svg { width: 30px; height: 30px; }

.conn { position: absolute; top: 48px; left: 50%; transform: translateX(-50%); background: #5a2020; border: 1px solid var(--bad); padding: 6px 14px; border-radius: 999px; z-index: 9; }
.toasts { position: absolute; top: 52px; left: 50%; transform: translateX(-50%); display: grid; gap: 6px; z-index: 8; pointer-events: none; width: min(460px, calc(100% - 20px)); }
.toast { background: rgba(24, 18, 15, .95); border: 1px solid var(--panel-line); border-radius: 10px; padding: 8px 14px; text-align: center; animation: toast-in .2s ease-out; }
.toast.err { border-color: var(--bad); color: var(--bad); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-6px); } }

.ghost { position: fixed; left: 0; top: 0; pointer-events: none; z-index: 50; overflow: visible; filter: drop-shadow(0 8px 10px rgba(0, 0, 0, .45)); }

/* ---------- рука ---------- */
.handbar {
    display: flex; align-items: center; gap: 10px;
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
    background: rgba(20, 15, 13, .88); border-top: 1px solid var(--panel-line);
    min-height: 96px; z-index: 5;
}
.hand-tools { display: grid; gap: 6px; }
.hand { flex: 1; min-width: 0; display: flex; gap: 4px; overflow-x: auto; overflow-y: hidden; padding: 4px; align-items: center; scrollbar-width: thin; }
.hand-tile {
    flex: none; width: 76px; height: 76px; padding: 0; background: transparent; border: 2px solid transparent;
    border-radius: 12px; cursor: grab; touch-action: pan-x; position: relative;
}
.hand-tile svg { width: 100%; height: 100%; display: block; pointer-events: none; }
.hand-tile:hover { background: rgba(255, 255, 255, .06); }
.hand-tile.sel { border-color: var(--accent); background: rgba(224, 176, 74, .12); }
.hand-tile.dim { opacity: .38; }
.hand-tile.dragging { opacity: .25; }
.hand-hint { max-width: 230px; color: var(--muted); font-size: 12px; line-height: 1.35; }
.hand-empty { color: var(--muted); padding: 0 8px; }

@media (max-width: 720px) {
    .hand-hint { display: none; }
    .hand-tile { width: 66px; height: 66px; }
    .roomtag { display: none; }
    .panel { padding: 14px; }
}

.build { color: var(--muted); font-size: 11px; opacity: .7; }

/* ================= Пиксель-арт ================= */
:root {
    --bg: #23282b; --bg2: #2c3336; --panel: #1b2022; --panel-line: #0d1011;
    --text: #eef1e6; --muted: #a3b0a8; --accent: #f2c14e; --ok: #7ee08a; --bad: #ff7a7a;
}
html, body {
    font-family: ui-monospace, "Cascadia Mono", "Courier New", Consolas, monospace;
    -webkit-font-smoothing: none; font-smooth: never;
}
body { background: var(--bg); }
.stage { background-color: #55605e; background-image: radial-gradient(rgba(255,255,255,.05) 1px, transparent 1px); background-size: 6px 6px; }
.board, .ghost, .hand-tile img, .leftovers img { image-rendering: pixelated; }
.board { image-rendering: pixelated; shape-rendering: crispEdges; }
.cell { fill: none; stroke: rgba(255,255,255,.3); stroke-width: 1; stroke-dasharray: 3 3; }
.cell.first { fill: rgba(242,193,78,.12); stroke: var(--accent); stroke-width: 1.5; stroke-dasharray: 3 3; animation: pulse 1.4s steps(2) infinite; }
.cell.hover { fill: rgba(255,255,255,.18); stroke: rgba(255,255,255,.7); stroke-dasharray: none; }
.lastmove { stroke: var(--accent); stroke-width: 1.5; stroke-dasharray: 3 2; }
.preview { opacity: .75; }
.ghost { filter: none; }

.card, .panel, .pchip, .banner, .toast, .conn, .icon-btn, .btn, input, .roomtag, .hand-tile {
    border-radius: 0 !important;
}
.card, .panel { border: 3px solid #0d1011; box-shadow: 0 0 0 2px #3a4448, 6px 6px 0 rgba(0,0,0,.45); }
.btn, .icon-btn { border: 2px solid #0d1011; background: #3b464a; box-shadow: inset -2px -2px 0 #232b2e, inset 2px 2px 0 #5a686d; }
.btn:active, .icon-btn:active { box-shadow: inset 2px 2px 0 #232b2e; transform: none; }
.btn.primary { background: var(--accent); color: #2a1d08; box-shadow: inset -2px -2px 0 #b8892a, inset 2px 2px 0 #ffe08a; }
.topbar, .handbar { background: #1b2022; border-color: #0d1011; backdrop-filter: none; }
.topbar { border-bottom: 3px solid #0d1011; }
.handbar { border-top: 3px solid #0d1011; }
.pchip { border: 2px solid #0d1011; background: #1b2022; }
.pchip .av, .plist .av, .dot { border-radius: 0 !important; }
.pchip.turn { border-color: var(--accent); box-shadow: 0 0 0 2px #6b5521; }
.banner { border: 2px solid #0d1011; background: #1b2022; }
input { border: 2px solid #0d1011; background: #111617; }
.logo { text-shadow: 3px 3px 0 #0d1011; }

.hand-tile { width: 108px; height: 76px; display: grid; place-items: center; border: 2px solid transparent; }
.hand-tile img { width: 96px; height: 64px; display: block; pointer-events: none; }
.hand-tile.sel { border-color: var(--accent); background: rgba(242,193,78,.14); }
.leftovers img { width: 36px; height: 24px; }
@media (max-width: 720px) {
    .hand-tile { width: 78px; height: 56px; }
    .hand-tile img { width: 72px; height: 48px; }
}

/* рука без прокрутки: фишки переносятся на новые ряды, размер подбирает fitHand() */
.hand { --tw: 108px; flex-wrap: wrap; overflow: visible; align-content: center; }
.hand-tile { width: var(--tw); height: calc(var(--tw) * 0.7); touch-action: none; }
.hand-tile img { width: calc(var(--tw) - 12px); height: calc((var(--tw) - 12px) * 2 / 3); }
@media (max-width: 720px) {
    .hand-tile { width: var(--tw); height: calc(var(--tw) * 0.7); }
    .hand-tile img { width: calc(var(--tw) - 6px); height: calc((var(--tw) - 6px) * 2 / 3); }
}

/* выбор режима игры, куча, только что вытянутая фишка */
.modes { display: flex; gap: 8px; margin: 10px 0 4px; }
.modes .mode { flex: 1; }
.modes .mode.sel { border-color: var(--accent); background: rgba(242,193,78,.18); color: var(--accent); }
.modes .mode:disabled:not(.sel) { opacity: .55; }
.pchip.pile { border-style: dashed; }
.hand-tile.fresh { border-color: #7fd38a; background: rgba(127,211,138,.14); }
.hand-tile.fresh.sel { border-color: var(--accent); }

/* окно подтверждения после пропуска хода: внизу по центру, чтобы не закрывать поле */
.panel.ack { top: auto; bottom: 14px; transform: translateX(-50%); width: min(480px, calc(100% - 20px)); border-color: var(--accent); }
.panel.ack h2 { color: var(--accent); }
.panel.ack ul { color: var(--text, #e8e2d8); }
