:root {
  --bg: #0f172a;
  --card-bg: #1e293b;
  --felt: #0d5c2e;
  --felt-dark: #094422;
  --accent: #22c55e;
  --accent-hover: #16a34a;
  --danger: #ef4444;
  --warning: #f59e0b;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --border: #334155;
  --radius: 12px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.hidden { display: none !important; }

.screen {
  min-height: 100vh;
}

/* ===== CREATE SCREEN ===== */
#screen-create {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.create-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.4);
}

.create-card h1 {
  font-size: 2rem;
  margin-bottom: 4px;
}

.subtitle {
  color: var(--muted);
  margin-bottom: 28px;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 6px;
}

.form-row {
  display: flex;
  gap: 12px;
}

.form-row .form-group {
  flex: 1;
}

input[type="number"],
input[type="text"],
select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
}

input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 18px;
  border: none;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-primary {
  background: var(--accent);
  color: #052e16;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--border);
  color: var(--text);
}

.btn-danger {
  background: var(--danger);
  color: white;
}

.btn-warning {
  background: var(--warning);
  color: #1c1917;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.85rem;
}

.btn-block {
  width: 100%;
  margin-top: 8px;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ===== GAME SCREEN ===== */
.topbar {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 12px 24px;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
}

.logo {
  font-weight: 700;
  font-size: 1.2rem;
}

.game-id {
  color: var(--muted);
  font-family: monospace;
}

.status-badge {
  margin-left: auto;
  padding: 4px 12px;
  border-radius: 20px;
  background: var(--border);
  font-size: 0.85rem;
}

.status-badge.playing {
  background: #166534;
  color: #bbf7d0;
}

.status-badge.hand_over {
  background: #854d0e;
  color: #fef3c7;
}

.layout {
  display: grid;
  grid-template-columns: 1fr 320px;
  height: calc(100vh - 56px);
}

/* Table */
.table-panel {
  display: flex;
  flex-direction: column;
  padding: 28px 20px 20px;
  overflow: visible; /* не обрезать балуны над местами игроков */
}

.table {
  /* Овальный покерный стол с бортиком */
  --rail-outer: #3e2723;
  --rail-mid: #6d4c41;
  --rail-inner: #8d6e63;
  background:
    radial-gradient(ellipse 70% 60% at 50% 45%, rgba(255,255,255,0.06) 0%, transparent 55%),
    radial-gradient(ellipse at center, var(--felt) 0%, var(--felt-dark) 72%);
  border-radius: 50% / 42%;
  border: 18px solid var(--rail, var(--rail-mid));
  outline: 6px solid var(--rail-outer);
  outline-offset: 0;
  box-shadow:
    inset 0 0 0 4px rgba(255,255,255,0.08),
    inset 0 0 80px rgba(0,0,0,0.35),
    0 12px 40px rgba(0,0,0,0.5);
  position: relative;
  box-sizing: border-box;
  flex: none;
  width: 100%;
  max-width: 980px;
  aspect-ratio: 16 / 10;
  min-height: 480px;
  margin: 0 auto;
  padding: 0;
  overflow: visible;
}

.table-center {
  position: absolute;
  left: 50%;
  top: 46%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  z-index: 2;
  pointer-events: none;
}

.table-seats {
  position: absolute;
  inset: 0;
  z-index: 3;
}

.pot-display {
  background: rgba(0,0,0,0.5);
  padding: 6px 20px;
  border-radius: 20px;
  text-align: center;
  flex: none;
}

.pot-display span {
  display: block;
  font-size: 0.75rem;
  color: #a7f3d0;
}

.pot-display strong {
  font-size: 1.4rem;
  color: #fef08a;
}

.community-cards {
  display: flex;
  gap: 10px;
  min-height: 84px;
  flex: none;
}

.card-face {
  width: 60px;
  height: 84px;
  background: white;
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.3rem;
  box-shadow: 0 4px 10px rgba(0,0,0,0.3);
  color: #111;
}

.card-face.red { color: #dc2626; }
.card-face.back {
  background: linear-gradient(135deg, #1e3a8a, #312e81);
  color: transparent;
}

.card-back {
  width: 36px;
  height: 50px;
  flex: none;
  box-sizing: border-box;
  background: linear-gradient(135deg, #1e3a8a, #312e81);
  border-radius: 5px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.4);
  border: 1px solid rgba(255,255,255,0.15);
  display: inline-block;
}

.players-row { display: none; } /* старая сетка больше не используется */

.player-seat {
  position: absolute;
  box-sizing: border-box;
  width: 118px;
  min-height: 108px;
  overflow: visible; /* балуны чата рисуются снаружи блока */
  padding: 6px 6px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  background: rgba(12, 12, 16, 0.82);
  border-radius: 12px;
  border: 2px solid rgba(255,255,255,0.12);
  transition: border-color 0.2s, box-shadow 0.2s;
  transform: translate(-50%, -50%);
  z-index: 4;
}

.player-seat.active {
  border-color: #fbbf24;
  box-shadow: 0 0 12px rgba(251, 191, 36, 0.4);
}

.player-seat.folded {
  opacity: 0.45;
}

.player-seat .name,
.player-seat .stack,
.player-seat .meta,
.player-seat .hand {
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.25;
}

.player-seat .name {
  font-weight: 600;
  font-size: 0.95rem;
}

.player-seat .stack {
  color: #86efac;
  font-size: 0.9rem;
}

.player-seat .meta {
  min-height: 1.25em;
  color: #fde68a;
  font-size: 0.75rem;
}

.player-seat .meta .badge-d { color: #93c5fd; }

.player-seat .hand {
  min-height: 1.25em;
  color: var(--deck-accent, #fbbf24);
  font-size: 0.78rem;
  font-weight: 600;
}


.player-seat .cards {
  /* Карты прижаты к низу места с небольшим отступом от края */
  margin-top: auto;
  height: 50px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 4px;
}

.player-seat .cards .card-face {
  width: 36px;
  height: 50px;
  flex: none;
  box-sizing: border-box;
  font-size: 0.85rem;
  border-radius: 5px;
}

.street-label {
  background: rgba(0,0,0,0.5);
  padding: 4px 14px;
  border-radius: 12px;
  font-size: 0.85rem;
  flex: none;
}

.history {
  margin-top: 16px;
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 12px 16px;
  max-height: 160px;
  overflow-y: auto;
  font-size: 0.85rem;
  color: var(--muted);
}

.history div {
  padding: 2px 0;
}

/* Controls sidebar */
.controls {
  background: var(--card-bg);
  border-left: 1px solid var(--border);
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.panel {
  background: var(--bg);
  border-radius: 10px;
  padding: 14px;
}

.panel h3 {
  font-size: 0.9rem;
  color: var(--muted);
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.add-player {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
}

.players-list {
  list-style: none;
  max-height: 180px;
  overflow-y: auto;
}

.players-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

.players-list li button {
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 1rem;
}

.action-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 8px 0;
}

.raise-amount {
  margin-top: 6px;
}

.switch-label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 0.9rem;
}

.input-sm {
  padding: 6px 8px;
  font-size: 0.85rem;
}

.bot-status .status-offline {
  color: var(--danger);
  font-weight: 600;
}

.bot-status .status-online {
  color: var(--accent);
  font-weight: 600;
}

.hint {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 6px;
}

/* Responsive */
@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
  }
  .controls {
    border-left: none;
    border-top: 1px solid var(--border);
  }
}

/* ===== Несколько столов / приглашение ===== */
.section-title { margin: 18px 0 8px; font-size: 14px; opacity: .8; text-transform: uppercase; letter-spacing: .05em; }
.players-list li.table-item { cursor: default; }
.players-list li.table-item button.open { width: auto; padding: 4px 10px; font-size: 13px; }
.share-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.share-label { font-size: 12px; opacity: .7; min-width: 62px; }
.share-value { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 4px 8px; border-radius: 6px; background: rgba(255,255,255,.08); font-size: 13px; }
#shareCode { font-size: 16px; font-weight: 700; letter-spacing: .1em; }
.max-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-left: 6px; background: #22c55e; }
.max-dot.off { background: #6b7280; }
.topbar .btn { margin-right: 10px; }

.player-seat.winner {
  border-color: #fbbf24;
  box-shadow: 0 0 14px rgba(251, 191, 36, 0.55);
}

/* Длинные имена в боковой панели тоже не раздвигают блок */
.players-list li > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ===== Уведомления ===== */
#toasts { position: fixed; top: 64px; right: 16px; z-index: 1000; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.toast { background: #1f2937; color: #f9fafb; border-left: 4px solid #3b82f6; padding: 10px 14px; border-radius: 8px; font-size: 14px; box-shadow: 0 6px 20px rgba(0,0,0,.4); max-width: 320px; animation: toast-in .2s ease-out; }
.toast.error { border-left-color: #ef4444; }
@keyframes toast-in { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }

/* ===== Редактирование имени ===== */
.players-list li .player-name { flex: 1; cursor: text; }
.players-list li .row-actions { display: flex; gap: 4px; flex: none; }
.players-list li .row-actions button { width: 26px; padding: 2px 0; }
.players-list li .row-actions .edit { color: #93c5fd; }
.players-list li input.name-edit { flex: 1; min-width: 0; padding: 4px 8px; font-size: 0.9rem; }
.field-label { display: block; font-size: 12px; opacity: .7; margin-bottom: 4px; }
.hint:empty { display: none; }
.action-buttons .btn:disabled { opacity: .35; cursor: not-allowed; }

/* ===== Рабочая колода (SVG). Цвета мастей и бумаги от темы не зависят ===== */
:root {
  --paper: #f4ecd8; --card-gold: #b8913f; --suit-red: #b3141f; --suit-black: #1b1a1f;
  --deck-accent: #c9a24b; --back: #5b1522; --back-2: #3a0e16;
}
.poker-card { display: block; flex: none; width: 72px; height: 108px; filter: drop-shadow(0 2px 4px rgba(0,0,0,.45)); }
.community-cards { min-height: 108px; }
.player-seat { height: 168px; }
.player-seat .cards { height: 69px; }
.player-seat .poker-card { width: 46px; height: 69px; }
.top-logo { height: 48px; max-width: 140px; object-fit: contain; background: #fff; border-radius: 6px; padding: 3px 6px; margin-right: 10px; }
.brand-preview { display: flex; gap: 10px; margin: 4px 0 14px; align-items: flex-end; min-height: 100px; }
.brand-preview .poker-card { width: 60px; height: 90px; }

/* Убрать стрелочки у number/text numeric полей */
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
input[type="number"] { -moz-appearance: textfield; appearance: textfield; }

/* Спойлеры */
.collapse-toggle { cursor: pointer; user-select: none; display: flex; align-items: center; justify-content: space-between; }
.collapse-toggle .chevron { transition: transform .15s; font-size: .85em; opacity: .7; }
.collapse-toggle.open .chevron { transform: rotate(90deg); }
.collapse-body { margin-top: 10px; }
.collapse-body.hidden { display: none; }

/* Чат */
.chat-panel { margin-top: 12px; }
.chat-log {
  max-height: 160px;
  overflow-y: auto;
  background: rgba(0,0,0,0.35);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.85rem;
  line-height: 1.35;
}
.chat-line { margin-bottom: 4px; word-break: break-word; }
.chat-time { opacity: 0.55; font-size: 0.75em; margin-right: 4px; }

/* Балун чата у места игрока */
.seat-bubble {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 6px);
  transform: translateX(-50%);
  max-width: 160px;
  padding: 6px 10px;
  background: #fff;
  color: #1a1a1a;
  font-size: 12px;
  line-height: 1.3;
  border-radius: 10px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.35);
  z-index: 20;
  pointer-events: none;
  white-space: pre-wrap;
  word-break: break-word;
  animation: bubbleIn .18s ease-out;
}
.seat-bubble::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 100%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: #fff;
}
.seat-bubble.hidden { display: none; }
@keyframes bubbleIn {
  from { opacity: 0; transform: translateX(-50%) translateY(4px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ===== Режим зрителя (/?watch=ID): только стол ===== */
body.viewer-mode .controls,
body.viewer-mode .chat-panel,
body.viewer-mode #btnBack { display: none !important; }
body.viewer-mode .layout { grid-template-columns: 1fr; }
.viewer-msg { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; text-align: center; font-size: 1.2rem; color: var(--muted); }

/* ===== Компактные места (7+ игроков): блоки не перекрывают друг друга ===== */
.player-seat.compact { width: 104px; height: 128px; min-height: 0; padding: 4px 4px 5px; border-radius: 10px; }
.player-seat.compact .name { font-size: .82rem; }
.player-seat.compact .stack { font-size: .8rem; }
.player-seat.compact .meta,
.player-seat.compact .hand { font-size: .68rem; min-height: 1.1em; }
.player-seat.compact .cards { height: 54px; gap: 3px; }
.player-seat.compact .poker-card { width: 36px; height: 54px; }

/* ===== Шоудаун: решение Show/Muck за игроков ===== */
.showdown-list { list-style: none; }
.showdown-list li { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--border); font-size: .9rem; }
.showdown-list li small { display: block; color: var(--muted); font-size: .72rem; }
.showdown-list .row-actions { display: flex; gap: 6px; flex: none; }
#btnRevealNext { margin-top: 8px; animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(245,158,11,.5); } 50% { box-shadow: 0 0 0 8px rgba(245,158,11,0); } }

/* ===== Игрок вышел из-за стола: место и фишки за ним, но в раздачу он не попадает ===== */
.player-seat.away { opacity: .5; filter: grayscale(.6); }
.player-seat.away.active, .player-seat.away .cards:not(:empty) { opacity: 1; }
