:root {
  --bg: #0f1412;
  --panel: #171e1b;
  --line: #26302c;
  --text: #e7ece9;
  --muted: #8a9690;
  --felt: #1d5a3c;
  --felt-edge: #123a27;
  --accent: #e0b44c;
  --ok: #5fcf8f;
  --warn: #e7b34a;
  --err: #ff6b6b;
  --red-suit: #c8202f;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0; min-height: 100vh; background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex; flex-direction: column;
}
header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 20px; border-bottom: 1px solid var(--line);
}
.brand { font-weight: 650; font-size: 17px; }
.muted { color: var(--muted); font-weight: 400; }
.small { font-size: 13px; }
.pill { font-size: 13px; padding: 3px 10px; border-radius: 999px; background: var(--panel); color: var(--muted); }
.pill.on { color: var(--ok); }
.pill.off { color: var(--err); }

button {
  font: inherit; border: 1px solid var(--line); background: var(--panel); color: var(--text);
  padding: 9px 16px; border-radius: 8px; cursor: pointer;
}
button:disabled { opacity: .45; cursor: default; }
button.primary { background: #2f7d56; border-color: #2f7d56; }
button.accent { background: var(--accent); border-color: var(--accent); color: #1b1404; font-weight: 600; }
button.link { background: none; border: none; color: var(--accent); padding: 0 0 0 8px; font-size: 13px; }

.join { max-width: 420px; margin: 60px auto; display: flex; flex-direction: column; gap: 14px; padding: 0 20px; }
.join h1 { margin: 0; font-size: 26px; }
.join p { margin: 0; }
.join label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.join input {
  font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; padding: 9px 12px;
}

main { flex: 1; display: grid; grid-template-columns: 1fr 340px; gap: 16px; padding: 16px; min-height: 0; }
@media (max-width: 860px) { main { grid-template-columns: 1fr; } }

.table-area { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.felt {
  position: relative; width: 100%; aspect-ratio: 16 / 10; max-height: 70vh;
  border-radius: 50% / 46%;
  background: radial-gradient(ellipse at center, #237048 0%, var(--felt) 55%, var(--felt-edge) 100%);
  border: 10px solid #3a2a1c; box-shadow: inset 0 0 40px rgba(0,0,0,.45);
}
.center {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 10px; pointer-events: none;
}
.phase { font-size: 13px; letter-spacing: .06em; text-transform: uppercase; color: #cfe6d8; opacity: .8; }
.status { font-size: 14px; color: #f3f7f4; text-align: center; max-width: 60%; }
.board { display: flex; gap: 6px; min-height: 70px; }

.seat {
  position: absolute; transform: translate(-50%, -50%);
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  background: rgba(10, 16, 13, .82); border: 1px solid var(--line); border-radius: 10px;
  padding: 6px 10px 8px; min-width: 112px;
}
.seat.me { border-color: var(--accent); }
.seat.active { box-shadow: 0 0 0 2px var(--accent), 0 0 18px rgba(224,180,76,.4); }
.seat .who { font-size: 13px; font-weight: 600; white-space: nowrap; }
.seat .who .tag { color: var(--accent); font-weight: 500; }
.seat .hand { display: flex; gap: 4px; }
.seat .mark { font-size: 11px; color: var(--muted); }
.seat .mark.done { color: var(--ok); }

.card {
  width: 46px; height: 66px; border-radius: 6px; background: #fbfbf8; color: #1c1c1c;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-weight: 700; box-shadow: 0 1px 3px rgba(0,0,0,.4); line-height: 1;
}
.card .r { font-size: 20px; }
.card .s { font-size: 20px; margin-top: 2px; }
.card.red { color: var(--red-suit); }
.card.back {
  background: repeating-linear-gradient(45deg, #7b2131 0 6px, #942a3c 6px 12px);
  border: 3px solid #f2ece0;
}
.card.slot { background: transparent; border: 1px dashed rgba(255,255,255,.25); box-shadow: none; }
.board .card { width: 52px; height: 74px; }
.card.flip { animation: flip .35s ease-out; }
.card.hint { box-shadow: 0 0 0 2px var(--accent), 0 0 10px rgba(224,180,76,.75); transform: translateY(-3px); }
.seat .hint { text-align: center; max-width: 220px; line-height: 1.25; }
.seat .hint-hand { font-size: 12px; font-weight: 650; color: var(--accent); }
.seat .hint-hand::first-letter { text-transform: uppercase; }
.seat .hint-odds { font-size: 11px; color: #cfe6d8; }
@keyframes flip { from { transform: rotateY(90deg); } to { transform: none; } }

.controls { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.busy { color: var(--muted); font-size: 14px; display: inline-flex; align-items: center; gap: 8px; }
.spinner {
  width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--line); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

aside { display: flex; flex-direction: column; gap: 16px; min-height: 0; max-height: calc(100vh - 90px); }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.panel.grow { flex: 1; display: flex; flex-direction: column; min-height: 200px; }
.panel-title { font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.people { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.people li { background: #212a26; border-radius: 999px; padding: 3px 10px; font-size: 13px; }
.people li.me { outline: 1px solid var(--accent); }
.log { margin: 0; padding: 0; list-style: none; overflow-y: auto; flex: 1; font-size: 13px; }
.log li { padding: 4px 0; border-bottom: 1px solid #1f2824; }
.log li.ok { color: var(--ok); }
.log li.warn { color: var(--warn); }
.log li.error { color: var(--err); font-weight: 600; }

/* --- покер: стеки, ставки, панель действий --- */
.pot { font-size: 15px; font-weight: 650; color: #fff; background: rgba(0,0,0,.28); padding: 2px 12px; border-radius: 999px; }
.pot:empty { display: none; }
.seat .stack { font-size: 13px; color: #f1e3b5; font-variant-numeric: tabular-nums; }
.seat .badges { display: flex; gap: 4px; align-items: center; }
.badge { font-size: 10px; font-weight: 700; border-radius: 999px; padding: 1px 6px; background: #2b3531; color: var(--muted); }
.badge.dealer { background: #f4f1e8; color: #1c1c1c; }
.seat.folded { opacity: .5; }
.seat.won { border-color: var(--ok); box-shadow: 0 0 0 2px var(--ok), 0 0 20px rgba(95,207,143,.45); }
.seat .won-amt { font-size: 12px; color: var(--ok); font-weight: 700; }
.seat .act { font-size: 11px; color: #d7dfda; min-height: 14px; }
.chip-bet {
  position: absolute; transform: translate(-50%, -50%);
  font-size: 12px; font-weight: 700; color: #1b1404; background: var(--accent);
  border-radius: 999px; padding: 2px 8px; box-shadow: 0 1px 3px rgba(0,0,0,.4);
  font-variant-numeric: tabular-nums;
}
.actions {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  background: var(--panel); border: 1px solid var(--accent); border-radius: 12px; padding: 12px;
}
.actions button { min-width: 96px; }
button.danger { background: #5b2a2a; border-color: #6d3333; }
.raise { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; flex: 1; }
.raise input[type=range] { flex: 1; min-width: 140px; accent-color: var(--accent); }
.raise input[type=number] {
  width: 90px; font: inherit; color: var(--text); background: #0f1412; border: 1px solid var(--line);
  border-radius: 8px; padding: 8px;
}
.quick { display: flex; gap: 6px; }
.quick button { min-width: 0; padding: 6px 10px; font-size: 13px; }
.log li.act { color: #c9d4ce; }
.log li.deal { color: #9fd3ff; font-weight: 600; }
.log li.win { color: var(--accent); font-weight: 650; }
.people .chips { color: #f1e3b5; margin-left: 4px; font-variant-numeric: tabular-nums; }

/* --- таймер хода и переподключение --- */
.timer { font-variant-numeric: tabular-nums; font-weight: 650; color: var(--muted); min-width: 56px; }
.timer.hurry, .seat .act.hurry { color: var(--err); font-weight: 700; }
.people li.offline { opacity: .5; }
.sd-text { flex: 1; min-width: 200px; }
.pit { display: inline-flex; gap: 6px; align-items: center; }
.pit button { padding: 6px 10px; font-size: 13px; }
.link-btn { background: none; border: 1px solid var(--line); color: var(--muted); margin-left: auto; }
.pill.away { color: var(--muted); }

button { touch-action: manipulation; }

/* --- выигравшая комбинация: карты приподняты, вокруг — огненный ореол ------ */
@property --flame { syntax: '<angle>'; inherits: false; initial-value: 0deg; }
.card { position: relative; }
.card.win {
  transform: translateY(-8px) scale(1.05); z-index: 2;
  animation: flame 1.4s ease-in-out infinite alternate;
}
.card.win.flip { animation: flip .35s ease-out, flame 1.4s ease-in-out .35s infinite alternate; }
/* вращающееся кольцо пламени: виден только обод, середина прозрачна */
.card.win::after {
  content: ''; position: absolute; inset: -5px; border-radius: 9px; padding: 3px; pointer-events: none;
  background: conic-gradient(from var(--flame), #ff3d00, #ffb300, #fff3b0, #ff8f00, #ff3d00, #ffd54f, #ff3d00);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor; mask-composite: exclude;
  animation: flame-spin 2.4s linear infinite;
}
@keyframes flame-spin { to { --flame: 360deg; } }
@keyframes flame {
  from { box-shadow: 0 0 6px 2px rgba(255,236,160,.9), 0 0 16px 6px rgba(255,170,0,.7), 0 0 30px 12px rgba(255,80,0,.35); }
  to   { box-shadow: 0 0 9px 3px rgba(255,244,190,1),  0 0 24px 9px rgba(255,190,40,.8), 0 0 46px 18px rgba(255,90,0,.45); }
}
.board:has(.card.win) { margin: 12px 0 4px; }
.seat .card.win { transform: translateY(-3px) scale(1.04); }
.seat:has(.card.win) .hand { margin-top: 6px; }
/* остальные открытые карты чуть гаснут, чтобы комбинация читалась сразу */
.felt:has(.card.win) .card:not(.win):not(.kicker):not(.slot):not(.back) { filter: brightness(.72) saturate(.7); }
/* решающий кикер: холодное серебристо-голубое свечение и метка — чтобы не
   путать с огнём самой комбинации */
.card.kicker {
  transform: translateY(-5px); z-index: 1;
  animation: kicker-glow 1.8s ease-in-out infinite alternate;
}
.card.kicker.flip { animation: flip .35s ease-out, kicker-glow 1.8s ease-in-out .35s infinite alternate; }
.card.kicker::before {
  content: 'кикер'; position: absolute; left: 50%; top: 100%; transform: translate(-50%, -50%);
  font-size: max(8px, .62em); font-weight: 700; letter-spacing: .04em; line-height: 1; white-space: nowrap;
  color: #0d2236; background: #cfe8ff; padding: .2em .5em; border-radius: 999px;
  box-shadow: 0 0 8px rgba(120,190,255,.8); pointer-events: none;
}
@keyframes kicker-glow {
  from { box-shadow: 0 0 0 2px #e3f2ff, 0 0 8px 2px rgba(140,200,255,.75), 0 0 18px 6px rgba(70,140,255,.3); }
  to   { box-shadow: 0 0 0 2px #ffffff, 0 0 12px 4px rgba(160,215,255,.9), 0 0 26px 10px rgba(70,140,255,.4); }
}
.seat .card.kicker { transform: translateY(-2px); }
.seat:has(.card.kicker) .hand { margin-bottom: .4em; } /* место под метку на нижнем крае */
@media (prefers-reduced-motion: reduce) {
  .card.win, .card.win.flip, .card.win::after, .card.kicker, .card.kicker.flip { animation: none; }
  .card.kicker { box-shadow: 0 0 0 2px #fff, 0 0 12px 4px rgba(160,215,255,.9); }
  .card.win { box-shadow: 0 0 9px 3px rgba(255,244,190,1), 0 0 24px 9px rgba(255,190,40,.8); }
}

/* --- телефон в горизонтальной ориентации ----------------------------------
   Стол — на всю высоту слева; кнопки, панель хода, комната и журнал — в узкой
   колонке справа. Дочерние элементы .table-area становятся ячейками сетки
   main (display: contents), так что разметку менять не нужно. */
@media (orientation: landscape) and (max-height: 520px) {
  body { font-size: 13px; min-height: 0; height: 100dvh; overflow: hidden; }
  body:has(#join:not([hidden])) { overflow: auto; height: auto; }
  header {
    position: fixed; top: 4px; right: max(6px, env(safe-area-inset-right)); z-index: 5;
    padding: 0; border: none;
  }
  header .brand { display: none; }
  .pill { font-size: 11px; padding: 1px 8px; }

  .join { margin: 10px auto; gap: 8px; }
  .join h1 { font-size: 20px; }
  .join input { padding: 7px 10px; }

  main {
    flex: none; height: 100vh; height: 100dvh; padding: 6px max(6px, env(safe-area-inset-right)) 6px max(6px, env(safe-area-inset-left));
    gap: 6px; grid-template-columns: 1fr minmax(200px, 30vw);
    grid-template-rows: auto auto auto minmax(0, 1fr);
  }
  .table-area { display: contents; }
  .felt {
    grid-column: 1; grid-row: 1 / -1; align-self: center;
    width: 100%; height: auto; max-height: calc(100dvh - 12px); aspect-ratio: 16 / 10;
    border-width: 6px;
  }
  .controls, #sdPanel, #actions, aside { grid-column: 2; min-width: 0; }
  .controls { gap: 6px; padding-top: 22px; } /* место под индикатор связи */
  aside { grid-row: 4; max-height: none; gap: 6px; min-height: 0; }
  .panel { padding: 6px 8px; }
  .panel.grow { min-height: 0; }
  .panel-title { font-size: 11px; margin-bottom: 4px; }
  .people li { font-size: 11px; padding: 1px 8px; }
  .log { font-size: 11px; }
  .log li { padding: 2px 0; }

  button { padding: 6px 10px; border-radius: 7px; }
  .pit { flex-wrap: wrap; gap: 4px; }
  .pit button { padding: 4px 8px; font-size: 12px; }
  .link-btn { margin-left: 0; }
  .busy { font-size: 12px; }

  .actions { gap: 6px; padding: 6px; border-radius: 10px; }
  .actions button { min-width: 0; flex: 1; }
  .raise { gap: 6px; flex-basis: 100%; }
  .raise input[type=range] { min-width: 0; flex-basis: 100%; }
  .raise input[type=number] { width: 70px; padding: 5px; }
  .quick { flex: 1; gap: 4px; }
  #raise { flex-basis: 100%; }
  .quick button { padding: 4px 6px; font-size: 11px; }
  .sd-text { min-width: 0; flex-basis: 100%; font-size: 12px; }
  .timer { min-width: 0; }

}

/* --- масштаб стола ---------------------------------------------------------
   Всё внутри сукна задано в em, а размер шрифта сукна — доля его ширины
   (container query units). На компьютере (стол ≈ 870 px) это прежние 13 px,
   на телефоне места, карты и подписи уменьшаются пропорционально столу. */
.felt { container-type: inline-size; }
/* cqw считается от ближайшего контейнера-предка, поэтому размер задаём детям сукна */
.felt > .center, .felt > .seat, .felt > .chip-bet { font-size: clamp(8px, 1.5cqw, 13px); }
.center { gap: .75em; }
.phase { font-size: max(9px, 1em); }
.status { font-size: max(10px, 1.08em); }
.pot { font-size: max(10px, 1.15em); padding: .15em .9em; }
.board { gap: .45em; min-height: 5.7em; }
.seat { gap: .3em; border-radius: .77em; padding: .45em .77em .6em; min-width: 8.6em; }
.seat .who { font-size: max(9px, 1em); max-width: 11em; overflow: hidden; text-overflow: ellipsis; }
.seat .stack { font-size: max(9px, 1em); }
.seat .act { font-size: max(8px, .85em); min-height: 1.25em; }
.seat .won-amt { font-size: max(8px, .92em); }
.seat .hand { gap: .3em; }
.badge { font-size: max(8px, .77em); padding: .1em .5em; }
.card { width: 3.55em; height: 5.1em; border-radius: .46em; }
.card .r, .card .s { font-size: 1.54em; }
.card .s { margin-top: .1em; }
.board .card { width: 4em; height: 5.7em; }
.card.back { border-width: max(2px, .23em); }
.seat .hint { max-width: 17em; }
.seat .hint-hand { font-size: max(9px, .92em); }
.seat .hint-odds { font-size: max(8px, .85em); }
.chip-bet { padding: .15em .6em; }
.felt > .chip-bet { font-size: clamp(8px, 1.38cqw, 12px); }

/* Маленький стол: своё место — горизонтально (карты слева, имя, стек и
   таймер справа, подсказка снизу), чтобы не закрывать центр стола. */
@container (max-width: 700px) {
  .seat { padding: .3em .5em .4em; min-width: 7em; gap: .2em; }
  .seat.me {
    display: grid; column-gap: .6em; row-gap: 0; align-items: center; justify-items: start;
    grid-template-columns: auto auto;
    grid-template-areas: "hand who" "hand badges" "hand act" "hand won" "hint hint";
  }
  .seat.me .hand { grid-area: hand; }
  .seat.me .who { grid-area: who; }
  .seat.me .badges { grid-area: badges; }
  .seat.me .act { grid-area: act; }
  .seat.me .won-amt { grid-area: won; }
  .seat.me .hint { grid-area: hint; justify-self: stretch; max-width: 26em; margin-top: .15em; }
}

/* Телефон вертикально: стол во всю ширину, тоньше бортик и отступы. */
@media (max-width: 600px) and (orientation: portrait) {
  header { padding: 8px 12px; }
  header .brand .muted { display: none; }
  main { padding: 8px; gap: 10px; grid-template-columns: minmax(0, 1fr); }
  /* вертикальный овал: места раскладываются по высоте (см. app.js, R) */
  .felt { border-width: 6px; aspect-ratio: 4 / 5; max-height: 68dvh; border-radius: 50%; }
  .brand { font-size: 15px; }
  .pill { font-size: 11px; white-space: nowrap; }
  .controls { gap: 8px; }
  .link-btn { margin-left: 0; }
  .actions { gap: 8px; padding: 8px; }
  .actions button { min-width: 0; flex: 1; }
  .raise { flex-basis: 100%; }
  .raise input[type=range] { min-width: 0; flex-basis: 100%; }
  .quick { flex: 1; }
  #raise { flex-basis: 100%; }
  .sd-text { min-width: 0; flex-basis: 100%; }
  aside { max-height: none; }
}

/* Установленное приложение (экран «Домой»): статус-бар поверх страницы. */
body { padding-top: env(safe-area-inset-top); }

/* Подсказка про экран «Домой» на iPhone */
.tip { position: fixed; inset: 0; z-index: 20; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; padding: 16px; }
.tip-box { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px; max-width: 380px; font-size: 14px; }
.tip-box p { margin: 8px 0; }
.tip-box ol { margin: 8px 0 14px; padding-left: 20px; }
.tip-box li { margin: 4px 0; }
.tip-box button { width: 100%; }

