:root {
  --paper: #f3ead7;
  --paper-2: #ebdfc5;
  --card: #fbf6ea;
  --ink: #231f1c;
  --ink-2: #5d544b;
  --ink-3: #8d8274;
  --line: #d8c9a8;
  --x: #e2552f;
  --x-dark: #b23d1d;
  --o: #1f6c8c;
  --o-dark: #134e67;
  --mark: #fff7e8;
  --ok: #3f8f4f;
  --gold: #f0b400;
  --radius: 14px;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--paper);
  background-image: radial-gradient(rgba(35, 31, 28, .05) 1px, transparent 1px);
  background-size: 18px 18px;
  color: var(--ink);
  font: 500 16px/1.45 Manrope, system-ui, sans-serif;
}
button, input { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.wrap {
  max-width: 480px;
  margin: 0 auto;
  padding: max(14px, env(safe-area-inset-top)) 16px max(28px, env(safe-area-inset-bottom));
}

/* ---------- шапка ---------- */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.logo { font: 800 30px/1 Unbounded, sans-serif; text-decoration: none; letter-spacing: -.02em; }
.lx { color: var(--x); }
.lo { color: var(--o); }
.who { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.who-name { font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link { background: none; border: 0; padding: 0; color: var(--ink-3); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; font-size: 14px; white-space: nowrap; }
.link:hover { color: var(--ink); }

/* ---------- общие ---------- */
h1 { font: 800 clamp(28px, 8vw, 38px)/1.08 Unbounded, sans-serif; letter-spacing: -.02em; margin: 18px 0 14px; }
h1 em { font-style: normal; color: var(--x); }
h2 { font: 800 24px/1.1 Unbounded, sans-serif; margin: 0; }
h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-3); margin: 26px 0 10px; }
.lead { color: var(--ink-2); font-size: 17px; margin: 0 0 24px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 0 18px;
  border: 2px solid var(--ink); border-radius: 12px;
  background: var(--card); font-weight: 700; cursor: pointer;
  box-shadow: 0 3px 0 var(--ink);
  transition: transform .08s, box-shadow .08s, background .15s;
  white-space: nowrap;
}
.btn:hover { background: #fff; }
.btn:active { transform: translateY(3px); box-shadow: 0 0 0 var(--ink); }
.btn:disabled { opacity: .5; cursor: default; transform: none; box-shadow: 0 3px 0 var(--ink); }
.btn.primary { background: var(--ink); color: var(--paper); box-shadow: 0 3px 0 var(--x); }
.btn.primary:hover { background: #3a332e; }
.btn.primary:active { box-shadow: 0 0 0 var(--x); }
.btn.ghost { border-color: transparent; box-shadow: none; background: transparent; color: var(--ink-2); }
.btn.ghost:hover { background: var(--paper-2); }
.btn.big { width: 100%; min-height: 56px; font-size: 18px; }
.btn:focus-visible, .cell:focus-visible, .slot:focus-visible, input:focus-visible { outline: 3px solid var(--o); outline-offset: 2px; }

.card { background: var(--card); border: 2px solid var(--ink); border-radius: var(--radius); }

/* ---------- вход ---------- */
.nameform label { display: block; font-weight: 700; margin-bottom: 8px; }
.nameform .row { display: flex; gap: 10px; }
.nameform input {
  flex: 1; min-width: 0; min-height: 50px; padding: 0 14px;
  border: 2px solid var(--ink); border-radius: 12px; background: var(--card); font-size: 17px; font-weight: 600;
}
.err { color: var(--x-dark); font-weight: 600; margin: 10px 0 0; }
.demo { display: flex; align-items: flex-end; justify-content: center; gap: 14px; margin: 40px 0 8px; height: 96px; }
.demo .pc { position: relative; }
.demo .s0 { width: 44px; } .demo .s1 { width: 68px; } .demo .s2 { width: 92px; }

/* ---------- лобби ---------- */
.lobby-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.stat { color: var(--ink-3); font-size: 14px; }
.waitcard { display: grid; grid-template-columns: auto 1fr; gap: 12px 14px; padding: 16px; margin-bottom: 16px; align-items: center; }
.wait-text { display: flex; flex-direction: column; }
.wait-text span { color: var(--ink-2); font-size: 14px; }
.wait-actions { grid-column: 1 / -1; display: flex; gap: 8px; flex-wrap: wrap; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 4px solid var(--paper-2); border-top-color: var(--x); border-right-color: var(--o); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.glist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.glist li { display: flex; align-items: center; gap: 12px; padding: 10px 10px 10px 14px; background: var(--card); border: 2px solid var(--line); border-radius: 12px; }
.glist .g-host { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.glist .g-host b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.glist .g-host span { color: var(--ink-3); font-size: 13px; }
.glist .btn { min-height: 40px; padding: 0 14px; }
.empty { color: var(--ink-3); margin: 0; padding: 18px; border: 2px dashed var(--line); border-radius: 12px; text-align: center; }

/* ---------- фишки ---------- */
.pc {
  position: relative; display: block; aspect-ratio: 1; border-radius: 50%; flex: none;
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, .18), inset 0 3px 0 rgba(255, 255, 255, .22), 0 3px 6px rgba(35, 31, 28, .25);
}
.pc.p0 { background: var(--x); }
.pc.p1 { background: var(--o); }
.pc::before, .pc::after { content: ""; position: absolute; left: 50%; top: 50%; }
.pc.p0::before, .pc.p0::after {
  width: 58%; height: 13%; border-radius: 99px; background: var(--mark);
  transform: translate(-50%, -50%) rotate(45deg);
}
.pc.p0::after { transform: translate(-50%, -50%) rotate(-45deg); }
.pc.p1::before {
  width: 56%; height: 56%; transform: translate(-50%, -50%);
  background: radial-gradient(circle closest-side, transparent 58%, var(--mark) 60% 98%, transparent 100%);
}
.pc.p1::after { display: none; }
/* гигантская фишка из «помощи» */
.pc.s3 { box-shadow: 0 0 0 3px var(--gold), 0 0 14px rgba(240, 180, 0, .8), inset 0 -4px 0 rgba(0, 0, 0, .18); }
/* перекрашенная за донат: полосы обоих цветов, чтобы все видели */
.pc.painted { background: repeating-linear-gradient(45deg, var(--x) 0 7px, var(--o) 7px 14px); outline: 2px dashed var(--gold); outline-offset: 2px; }
.pc.shrunk { outline: 2px dashed var(--gold); outline-offset: 2px; }

/* ---------- партия ---------- */
.plate { display: flex; flex-direction: column; gap: 8px; padding: 10px; background: var(--card); border: 2px solid var(--line); border-radius: var(--radius); transition: border-color .2s, box-shadow .2s; }
.plate.active { border-color: var(--ink); box-shadow: 0 3px 0 var(--ink); }
.pl-id { display: flex; align-items: center; gap: 10px; min-width: 0; }
.pl-mark { width: 26px; flex: none; }
.pl-mark .pc { width: 100%; }
.pl-name { font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pl-you { color: var(--ink-3); font-weight: 600; font-size: 14px; white-space: nowrap; }
.pl-flag { margin-left: auto; font-size: 13px; font-weight: 700; padding: 2px 10px; border-radius: 99px; background: var(--ink); color: var(--paper); white-space: nowrap; }
.pl-off { margin-left: auto; font-size: 13px; color: var(--x-dark); font-weight: 700; white-space: nowrap; }

.reserve { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.slot {
  position: relative; display: flex; align-items: center; justify-content: center;
  height: 60px; padding: 0; border: 2px dashed transparent; border-radius: 12px; background: var(--paper);
  cursor: default;
}
.slot .pc { position: relative; }
.slot .s0 { width: 18px; } .slot .s1 { width: 29px; } .slot .s2 { width: 40px; } .slot .s3 { width: 53px; }
.slot.hint { border: 3px solid var(--gold); background: #fff6d6; }
.reserve.four { grid-template-columns: repeat(4, 1fr); }
.xray { font-size: 12px; font-weight: 700; color: var(--ink-3); }
.slot .cnt { position: absolute; right: 6px; bottom: 3px; font-size: 13px; font-weight: 800; color: var(--ink-2); }
.slot.zero .pc { opacity: .15; box-shadow: none; }
.slot.zero .cnt { color: var(--ink-3); }
.slot.can { cursor: pointer; }
.slot.can:hover { background: var(--paper-2); }
.slot.sel { border-color: var(--ink); border-style: solid; background: var(--paper-2); }
.slot.sel .pc { transform: translateY(-4px); }

.status { min-height: 48px; display: flex; flex-direction: column; justify-content: center; text-align: center; margin: 8px 0; }
.status b { font: 800 20px/1.2 Unbounded, sans-serif; }
.status span { color: var(--ink-2); font-size: 14px; }
.status.win b { color: var(--ok); }
.status.lose b { color: var(--x-dark); }

.board-wrap { position: relative; margin: 0 auto 12px; width: min(100%, calc(max(260px, 100svh - 440px) * var(--w, 3) / var(--h, 3))); }
.board {
  display: grid; grid-template-columns: repeat(var(--w, 3), 1fr); gap: 8px;
  width: 100%; aspect-ratio: var(--w, 3) / var(--h, 3); padding: 8px;
  background: var(--ink); border-radius: 18px;
}
.board.shake { animation: shake .5s; }
@keyframes shake { 20% { transform: translate(-6px, 2px) rotate(-1deg); } 40% { transform: translate(6px, -2px) rotate(1deg); } 60% { transform: translate(-4px, 1px); } 80% { transform: translate(3px, 0); } }
.cell {
  position: relative; display: flex; align-items: center; justify-content: center;
  padding: 0; border: 0; border-radius: 10px; background: var(--paper); cursor: default;
  transition: background .15s;
}
.cell .pc { position: relative; }
/* размеры заложены так, что в клетку влезает и гигантская фишка — поле никогда не меняется */
.cell .s0 { width: 32%; } .cell .s1 { width: 52%; } .cell .s2 { width: 72%; } .cell .s3 { width: 94%; }
.cell.hint { box-shadow: inset 0 0 0 4px var(--gold); background: #fff6d6; animation: glow 1s ease-in-out infinite alternate; }
@keyframes glow { to { box-shadow: inset 0 0 0 4px var(--gold), 0 0 18px var(--gold); } }
.cell.target { background: #fff9ec; box-shadow: inset 0 0 0 3px var(--ink); cursor: pointer; }
.cell.target::after { content: ""; position: absolute; width: 14%; aspect-ratio: 1; border-radius: 50%; background: var(--ink); opacity: .22; }
.cell.target:has(.pc)::after { display: none; }
.cell.last { background: #f8f0dc; }
.cell.win { background: #e3f0d9; }
.cell.win .pc { animation: pulse 1s ease-in-out infinite alternate; }
.cell.pop .pc { animation: pop .28s cubic-bezier(.3, 1.6, .5, 1); }
@keyframes pop { from { transform: scale(.5); } to { transform: scale(1); } }
@keyframes pulse { to { transform: scale(1.06); } }
.pips { position: absolute; left: 6px; top: 6px; display: flex; gap: 3px; }
.pips i { width: 8px; height: 8px; border-radius: 50%; border: 1.5px solid var(--paper); }
.pips i.p0 { background: var(--x); }
.pips i.p1 { background: var(--o); }

.actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 12px; }
.actions .btn { flex: 1; min-width: 140px; }

/* ---------- правила ---------- */
.rules { margin-top: 30px; border-top: 2px solid var(--line); padding-top: 14px; }
.rules summary { cursor: pointer; font-weight: 800; }
.rules ol { padding-left: 20px; color: var(--ink-2); margin: 10px 0 0; }
.rules li { margin-bottom: 8px; }

/* ---------- уведомления ---------- */
.conn, .toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 12px;
  font-weight: 700; font-size: 14px; text-align: center; z-index: 10;
}
.conn { top: 12px; background: var(--x-dark); color: #fff; }
.toast { bottom: max(18px, env(safe-area-inset-bottom)); background: var(--ink); color: var(--paper); box-shadow: 0 6px 20px rgba(0, 0, 0, .2); }

/* ---------- шапка: звук ---------- */
.top-right { display: flex; align-items: center; gap: 12px; min-width: 0; }
.icon-btn {
  flex: none; width: 40px; height: 40px; display: inline-flex; align-items: center; justify-content: center;
  border: 2px solid var(--line); border-radius: 10px; background: var(--card); cursor: pointer; font-size: 18px; padding: 0;
}
.icon-btn:hover { border-color: var(--ink); }
.icon-btn[aria-expanded="true"] { border-color: var(--ink); background: var(--paper-2); }

/* ---------- партия + чат справа ---------- */
body.in-game .wrap { max-width: 920px; }
body.in-game .rules { max-width: 480px; }
.game-main { min-width: 0; }
.plate.opp .pl-badge { font-size: 12px; font-weight: 800; padding: 2px 8px; border-radius: 99px; background: #fff0b8; border: 1.5px solid var(--gold); white-space: nowrap; }

.chat { display: flex; flex-direction: column; margin-top: 18px; height: 420px; overflow: hidden; }
.chat-head { display: flex; align-items: baseline; gap: 8px; padding: 10px 14px; border-bottom: 2px solid var(--line); }
.chat-head span { color: var(--ink-3); font-size: 13px; }
.chat-log { flex: 1; list-style: none; margin: 0; padding: 12px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.chat-log li { max-width: 85%; overflow-wrap: anywhere; }
.chat-log .who-line { display: block; font-size: 12px; color: var(--ink-3); font-weight: 700; margin-bottom: 2px; }
.chat-log .bubble { display: inline-block; padding: 7px 11px; border-radius: 14px; background: var(--paper); line-height: 1.35; }
.chat-log .mine { align-self: flex-end; text-align: right; }
.chat-log .mine .bubble { background: var(--ink); color: var(--paper); }
.chat-log .sys { align-self: center; max-width: 100%; text-align: center; font-size: 13px; font-weight: 700; padding: 6px 10px; border-radius: 10px; background: #fff0b8; border: 1.5px solid var(--gold); }
.chat-log .stk { display: inline-flex; flex-direction: column; align-items: center; }
.chat-log .stk i { font-style: normal; font-size: 44px; line-height: 1.1; }
.chat-log .stk span { font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .03em; }
.chat-log .empty-chat { align-self: center; color: var(--ink-3); font-size: 14px; margin: auto; text-align: center; }
.stickers { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; padding: 8px; border-top: 2px solid var(--line); background: var(--paper); max-height: 190px; overflow-y: auto; }
.stickers button { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 2px; border: 0; border-radius: 10px; background: var(--card); cursor: pointer; }
.stickers button:hover { background: #fff; transform: scale(1.05); }
.stickers i { font-style: normal; font-size: 26px; line-height: 1.1; }
.stickers span { font-size: 10px; font-weight: 700; color: var(--ink-2); text-align: center; line-height: 1.15; }
.chat-form { display: flex; gap: 6px; padding: 8px; border-top: 2px solid var(--line); }
.chat-form input { flex: 1; min-width: 0; height: 40px; padding: 0 12px; border: 2px solid var(--line); border-radius: 10px; background: #fff; }
.chat-form input:focus { border-color: var(--ink); outline: none; }
.chat-form .send { background: var(--ink); color: var(--paper); border-color: var(--ink); }

@media (min-width: 880px) {
  .screen.game:not([hidden]) { display: grid; grid-template-columns: minmax(0, 480px) minmax(0, 1fr); gap: 24px; align-items: start; }
  .chat { margin-top: 0; position: sticky; top: 16px; height: min(640px, calc(100svh - 110px)); }
}

/* ---------- эффекты поверх поля ---------- */
.fx-layer { position: absolute; inset: 0; pointer-events: none; overflow: hidden; border-radius: 18px; }
.fx-banner {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%) rotate(-4deg);
  padding: 12px 18px; border-radius: 14px; background: var(--gold); color: var(--ink); border: 3px solid var(--ink);
  font: 800 clamp(18px, 5vw, 26px)/1.1 Unbounded, sans-serif; text-align: center; white-space: nowrap;
  box-shadow: 0 6px 0 var(--ink); animation: banner 2.4s ease-out forwards;
}
@keyframes banner { 0% { transform: translate(-50%, -50%) scale(.3) rotate(-12deg); opacity: 0; } 12% { transform: translate(-50%, -50%) scale(1.1) rotate(-4deg); opacity: 1; } 80% { opacity: 1; } 100% { transform: translate(-50%, -60%) scale(1) rotate(-4deg); opacity: 0; } }
.sticker-pop {
  position: absolute; display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 10px 14px; border-radius: 16px; background: var(--card); border: 3px solid var(--ink); box-shadow: 0 5px 0 var(--ink);
  animation: stick 2.6s cubic-bezier(.3, 1.5, .5, 1) forwards;
}
.sticker-pop i { font-style: normal; font-size: 64px; line-height: 1; }
.sticker-pop span { font: 800 14px/1.1 Unbounded, sans-serif; text-transform: uppercase; }
.sticker-pop.theirs { left: 8%; top: 10%; }
.sticker-pop.mine { right: 8%; bottom: 10%; }
@keyframes stick { 0% { transform: scale(0) rotate(-20deg); opacity: 0; } 15% { transform: scale(1) rotate(6deg); opacity: 1; } 85% { opacity: 1; } 100% { transform: scale(.9) rotate(0); opacity: 0; } }

/* ---------- помощь за донат ---------- */
.help { margin-top: 14px; padding: 14px; display: flex; gap: 12px; align-items: center; border-color: var(--gold); background: #fffbea; }
.help .h-emoji { font-size: 30px; flex: none; }
.help .h-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.help .h-text span { color: var(--ink-2); font-size: 14px; }
.help .btn { flex: none; }
@media (max-width: 420px) { .help { flex-wrap: wrap; } .help .btn { width: 100%; } }

.dlg { max-width: min(420px, calc(100vw - 32px)); padding: 22px; border: 3px solid var(--ink); border-radius: 18px; background: var(--card); color: var(--ink); box-shadow: 0 8px 0 var(--ink); }
.dlg::backdrop { background: rgba(35, 31, 28, .45); }
.dlg h2 { margin: 6px 0 10px; }
.dlg p { margin: 0 0 10px; color: var(--ink-2); }
.dlg .dlg-emoji { font-size: 44px; }
.dlg .dlg-note { font-size: 13px; font-weight: 700; color: var(--x-dark); }
.dlg-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.dlg-actions .btn { flex: 1; }
body:not([data-pay="demo"]) .demo-note, body[data-pay="demo"] .pay-note { display: none; }

.bid-presets { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 4px 0 10px; }
.bid-presets .btn { min-height: 42px; padding: 0 6px; box-shadow: 0 2px 0 var(--ink); }
.bid-presets .btn.on { background: var(--gold); }
.bid-custom { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-weight: 700; }
.bid-custom input { width: 120px; height: 42px; padding: 0 10px; border: 2px solid var(--ink); border-radius: 10px; font-weight: 700; font-size: 17px; }

/* уведомление сбоку: «возможно, соперник донатер» */
.bid-notice {
  position: fixed; right: 16px; top: 50%; z-index: 9; width: min(260px, calc(100vw - 32px));
  padding: 16px; border: 3px solid var(--ink); border-radius: 16px; background: #fff6d6; box-shadow: 0 6px 0 var(--ink);
  transform: translateY(-50%); animation: slidein .45s cubic-bezier(.3, 1.4, .5, 1);
}
.bid-notice p { margin: 6px 0 12px; font-weight: 800; line-height: 1.3; }
.bid-notice .btn { width: 100%; }
.bid-notice .dlg-emoji { font-size: 34px; }
.bid-close { position: absolute; right: 6px; top: 4px; border: 0; background: none; font-size: 24px; cursor: pointer; color: var(--ink-2); }
@keyframes slidein { from { transform: translate(120%, -50%); } }
@media (max-width: 879px) {
  .bid-notice { top: auto; bottom: max(16px, env(safe-area-inset-bottom)); transform: none; animation-name: slideup; }
  @keyframes slideup { from { transform: translateY(140%); } }
}

/* ---------- оферта и подвал ---------- */
.wrap.doc { max-width: 760px; }
.doc h1 { font-size: clamp(24px, 6vw, 32px); }
.doc h2 { font-size: 19px; margin: 30px 0 8px; padding-top: 14px; border-top: 2px solid var(--line); }
.doc p { margin: 0 0 10px; }
.doc .muted { color: var(--ink-3); }
.doc a { color: var(--o); }
.doc table { width: 100%; border-collapse: collapse; margin: 6px 0 12px; background: var(--card); }
.doc th, .doc td { border: 2px solid var(--line); padding: 8px 10px; text-align: left; vertical-align: top; }
.site-foot { margin-top: 30px; padding-top: 14px; border-top: 2px solid var(--line); color: var(--ink-3); font-size: 14px; display: flex; flex-wrap: wrap; gap: 6px 16px; }
.site-foot a { color: var(--ink-2); }

.paypage { text-align: center; padding-top: 12vh; }
.paypage .dlg-emoji { font-size: 64px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
