:root {
  --bg: #0f3d2e;
  --bg2: #0b2f23;
  --panel: #14513c;
  --line: rgba(255,255,255,.14);
  --text: #f2efe6;
  --muted: #a9c4b8;
  --accent: #f5b83d;
  --danger: #e5584f;
  --ok: #55c58a;
  --tw: 42px;
  --th: 58px;
  --c-red: #d6322e;
  --c-blue: #1f5fd0;
  --c-amber: #e08a00;
  --c-black: #1c1c1c;
}
* { 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: 44px; letter-spacing: 1px; }

.screen { flex: 1; overflow: auto; padding: 20px 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; }
.tiny { font-size: 12px; color: var(--muted); }
.logo { display: flex; gap: 4px; margin-top: 6px; }
.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; }
tr.win td { color: var(--accent); font-weight: 700; }
.rulestext { font-size: 14px; line-height: 1.5; }
.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; }

/* ---------- игра (только горизонтально) ---------- */
.game { flex: 1; display: flex; flex-direction: column; min-height: 0; position: relative; }
.top { display: flex; gap: 5px; padding: calc(3px + env(safe-area-inset-top)) calc(6px + env(safe-area-inset-right)) 3px calc(6px + env(safe-area-inset-left)); background: var(--bg2); align-items: stretch; overflow: hidden; }
.pchip { flex: 1 1 0; min-width: 0; background: rgba(255,255,255,.07); border: 2px solid transparent; border-radius: 9px; padding: 1px 8px; font-size: 12px; display: flex; gap: 8px; align-items: center; white-space: nowrap; }
.pchip.turn { border-color: var(--accent); background: rgba(245,184,61,.15); }
.pchip b { font-size: 13px; overflow: hidden; text-overflow: ellipsis; }
.pchip .off { color: var(--danger); }
.meta { flex: 0 0 auto; display: flex; flex-direction: column; justify-content: center; align-items: flex-end; font-size: 10px; color: var(--muted); }
.qbtn { padding: 1px 10px; align-self: center; }

.board { flex: 1; min-height: 0; overflow: auto; padding: 6px calc(8px + env(safe-area-inset-right)) 6px calc(8px + env(safe-area-inset-left)); background: radial-gradient(ellipse at center, #17604a 0%, var(--bg) 85%); }
.bgrid { display: flex; gap: calc(var(--tw) * .6); align-items: flex-start; }
/* группы: два столбика по 4 фишки, ряды совпадают с полосами */
.gcol { display: grid; grid-auto-flow: column; grid-template-rows: repeat(var(--rows), calc(var(--th) + 2px)); grid-template-columns: repeat(2, calc(var(--tw) * 4 + 3px)); column-gap: calc(var(--tw) * .5); row-gap: 2px; margin-top: calc(var(--tw) * .5 + 2px); flex: 0 0 auto; }
.lanes { display: flex; flex-direction: column; gap: 2px; flex: 0 0 auto; }
.lane { display: grid; grid-template-columns: repeat(13, var(--tw)); column-gap: 1px; height: calc(var(--th) + 2px); align-items: center; border-radius: 3px; background: rgba(0,0,0,.13); border-left: 3px solid transparent; }
.lane.red { border-left-color: var(--c-red); } .lane.blue { border-left-color: var(--c-blue); }
.lane.amber { border-left-color: var(--c-amber); } .lane.black { border-left-color: #777; }
.lane.head { height: calc(var(--tw) * .5); background: none; border-left-color: transparent; }
.lane.head span { text-align: center; font-size: calc(var(--tw) * .42); line-height: 1; color: rgba(255,255,255,.35); }
.loose { display: flex; flex-wrap: wrap; gap: 4px; align-content: flex-start; align-items: flex-start; flex: 1; min-width: calc(var(--tw) * 4); margin-top: calc(var(--tw) * .5 + 2px); }
.board .set { display: flex; gap: 1px; padding: 0; border-radius: 3px; align-self: center; outline-offset: 1px; }
.loose .set { padding: 1px; background: rgba(0,0,0,.2); }
.board .set.bad { outline: 2px solid var(--danger); background: rgba(229,88,79,.25); }
.board .set.flash { animation: flash .5s 3; }
@keyframes flash { 50% { background: rgba(229,88,79,.7); } }
.set.drop-hover, .rack.drop-hover, .newset.drop-hover, .board.drop-hover { outline: 2px dashed var(--accent); outline-offset: 1px; }
.newset { min-width: calc(var(--tw) * 3); height: calc(var(--th) + 4px); border: 2px dashed rgba(255,255,255,.3); border-radius: 5px; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 10px; line-height: 1.1; text-align: center; padding: 1px 4px; }
.board .tile { border-radius: calc(var(--tw) * .14); box-shadow: 0 1px 0 #b5a985, 0 1px 2px rgba(0,0,0,.35); font-size: calc(var(--tw) * .66); }
.board .tile::after { display: none; }

.status { padding: 2px calc(10px + env(safe-area-inset-right)) 2px calc(10px + env(safe-area-inset-left)); font-size: 12px; background: var(--bg2); height: 22px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.status .stext { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status .bad { color: var(--danger); } .status .good { color: var(--ok); }

.bottom { display: flex; gap: 8px; align-items: stretch; background: linear-gradient(#4a3220, #2f1f13); padding: 4px calc(6px + env(safe-area-inset-right)) calc(4px + env(safe-area-inset-bottom)) calc(6px + env(safe-area-inset-left)); }
.rack { flex: 1; min-width: 0; display: flex; flex-wrap: wrap; align-content: flex-start; gap: 4px 3px; padding: 4px; border-radius: 8px; background: rgba(0,0,0,.3); height: calc(var(--th) * 2 + 14px); overflow-y: auto; }
.rgroup { display: flex; gap: 1px; margin-right: calc(var(--tw) * .35); flex: 0 0 auto; }
.controls { flex: 0 0 200px; display: flex; flex-direction: column; gap: 4px; justify-content: space-between; }
.modes { display: grid; grid-template-columns: 1fr 1fr; gap: 3px; }
.mode { border: 0; border-radius: 7px; padding: 4px 2px; font-size: 11px; background: rgba(255,255,255,.1); color: var(--text); }
.mode.on { background: var(--accent); color: #2a1d00; font-weight: 700; }
.btnrow { display: flex; gap: 5px; }
.btnrow .btn { flex: 1; padding: 9px 4px; font-size: 14px; border-radius: 9px; }
.btnrow .btn.main { flex: 1.6; }
.btnrow .waiting { flex: 1; text-align: center; padding: 8px 0; }

.tile { width: var(--tw); height: var(--th); border-radius: calc(var(--tw) * .16); background: linear-gradient(#fdfaf0, #e9e0c6); box-shadow: 0 2px 0 #b5a985, 0 2px 3px rgba(0,0,0,.35); display: flex; flex-direction: column; align-items: center; justify-content: center; font-weight: 800; font-size: calc(var(--tw) * .58); line-height: 1; user-select: none; -webkit-user-select: none; touch-action: none; flex: 0 0 auto; position: relative; cursor: grab; }
.tile span { pointer-events: none; }
.tile::after { content: ""; width: 40%; height: max(3px, calc(var(--tw) * .09)); border-radius: 3px; background: currentColor; margin-top: calc(var(--tw) * .1); opacity: .85; }
.tile.red { color: var(--c-red); } .tile.blue { color: var(--c-blue); } .tile.amber { color: var(--c-amber); } .tile.black { color: var(--c-black); }
.tile.joker { color: #8a2be2; }
.tile.joker::after { display: none; }
.tile.fresh { box-shadow: 0 0 0 2px var(--accent), 0 2px 3px rgba(0,0,0,.35); }
.tile.placed { box-shadow: 0 0 0 2px #7fd3ff, 0 2px 3px rgba(0,0,0,.35); }
.tile.dragging { opacity: .25; }
.tile.ghost { position: fixed; left: 0; top: 0; z-index: 99; pointer-events: none; box-shadow: 0 10px 20px rgba(0,0,0,.5); opacity: .95; }
.tile.static { cursor: default; touch-action: auto; --tw: 30px; --th: 41px; }

/* в вертикальном положении играть нельзя — просим повернуть */
.rotate { display: none; }
@media (orientation: portrait) {
  .rotate { display: flex; position: fixed; inset: 0; z-index: 60; background: var(--bg); flex-direction: column; align-items: center; justify-content: center; gap: 12px; font-size: 18px; text-align: center; padding: 24px; }
  .rotate div:first-child { font-size: 54px; }
}

/* ---------- ПК ---------- */
.game.pc .rotate { display: none !important; }
.game.pc .top { padding: 6px 10px; }
.game.pc .pchip { font-size: 15px; padding: 4px 12px; }
.game.pc .pchip b { font-size: 16px; }
.game.pc .meta { font-size: 13px; }
.game.pc .status { font-size: 15px; height: 26px; }
.game.pc .board .tile::after { display: block; width: 40%; height: max(3px, calc(var(--tw) * .07)); margin-top: calc(var(--tw) * .08); }
.game.pc .board .tile { font-size: calc(var(--tw) * .58); }
.game.pc .bottom { padding: 6px 10px 8px; gap: 12px; }
.game.pc .controls { flex: 0 0 300px; gap: 8px; }
.game.pc .modes { gap: 6px; }
.game.pc .mode { font-size: 16px; padding: 10px 4px; border-radius: 10px; }
.game.pc .btnrow { gap: 8px; }
.game.pc .btnrow .btn { font-size: 18px; padding: 14px 6px; border-radius: 12px; }
.game.pc .newset { font-size: 13px; }
.game.pc .lane.head span { font-size: 13px; }
.game.pc .lane.head { height: 18px; }
.game.pc .gcol, .game.pc .loose { margin-top: 20px; }
