:root {
  color-scheme: light dark;
  --bg: var(--tg-theme-bg-color, #06070d);
  --bg-secondary: var(--tg-theme-secondary-bg-color, #0d0f1a);
  --bg-elevated: #141726;
  --text: var(--tg-theme-text-color, #f5f6f9);
  --hint: var(--tg-theme-hint-color, #9aa2b8);
  --link: var(--tg-theme-link-color, #7fc4ff);
  --button: var(--tg-theme-button-color, #4f7fff);
  --button-text: var(--tg-theme-button-text-color, #ffffff);
  --accent: #ffb648;
  --accent-2: #ff8a5a;
  --danger: #ff5266;
  --success: #33e6ab;

  /* --- жидке скло: токени поверхонь ------------------------------------
     Справжнє скло тут лише в "хромі" інтерфейсу (банери, кнопки, панелі,
     чіпи, поле вводу) — напівпрозорий заповнювач + backdrop-filter, що
     розмиває й підсилює насиченість кольорових плям фону під ним, тонка
     світла окантовка (заломлення на краю скла) і м'яка глибина тінню.
     Ігрові картки (органи/рука) лишаються НЕпрозорими — колір за
     категорією є ігровою інформацією, її не можна розмивати. */
  --glass-fill: rgba(255, 255, 255, 0.07);
  --glass-fill-strong: rgba(255, 255, 255, 0.13);
  --glass-fill-press: rgba(255, 255, 255, 0.2);
  --glass-border: rgba(255, 255, 255, 0.26);
  --glass-border-soft: rgba(255, 255, 255, 0.13);
  --glass-highlight: rgba(255, 255, 255, 0.45);
  --glass-blur: 20px;
  --glass-blur-strong: 30px;

  --card-radius: 20px;
  --radius-lg: 28px;
  --radius-sm: 16px;
  --radius-pill: 999px;

  --shadow-card: 0 4px 14px rgba(0, 0, 0, 0.36), 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-float: 0 18px 40px rgba(0, 0, 0, 0.48), 0 2px 8px rgba(0, 0, 0, 0.35);
  --shadow-pop: 0 -10px 40px rgba(0, 0, 0, 0.5);

  --font-display: "Russo One", "Segoe UI", sans-serif;
  --font-body: "Manrope", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

:root[data-theme="light"] {
  --bg-elevated: #ffffff;
  --glass-fill: rgba(255, 255, 255, 0.5);
  --glass-fill-strong: rgba(255, 255, 255, 0.66);
  --glass-fill-press: rgba(255, 255, 255, 0.8);
  --glass-border: rgba(255, 255, 255, 0.75);
  --glass-border-soft: rgba(120, 120, 140, 0.18);
  --glass-highlight: rgba(255, 255, 255, 0.9);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}

/* ---------------------------------------------------------------------------
   Фон "рідкого скла": фіксований шар кількох великих розмитих кольорових
   плям, що повільно дрейфують. Саме їх бачить (і розмиває) кожна скляна
   поверхня інтерфейсу зверху — без цього шару backdrop-filter скла
   вирізняв би просто рівне тло, без жодного ефекту.
--------------------------------------------------------------------------- */
.liquid-bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
  background: var(--bg);
}
.liquid-blob {
  position: absolute;
  width: 62vmax;
  height: 62vmax;
  border-radius: 50%;
  filter: blur(64px);
  opacity: 0.5;
  will-change: transform;
}
.liquid-blob-1 {
  background: radial-gradient(circle, rgba(79, 127, 255, 0.6), transparent 70%);
  top: -22%;
  left: -18%;
  animation: liquidDriftA 28s ease-in-out infinite;
}
.liquid-blob-2 {
  background: radial-gradient(circle, rgba(255, 138, 90, 0.5), transparent 70%);
  bottom: -26%;
  right: -20%;
  animation: liquidDriftB 34s ease-in-out infinite;
}
.liquid-blob-3 {
  background: radial-gradient(circle, rgba(255, 82, 102, 0.36), transparent 70%);
  top: 26%;
  right: -26%;
  animation: liquidDriftC 31s ease-in-out infinite;
}
.liquid-blob-4 {
  background: radial-gradient(circle, rgba(51, 230, 171, 0.3), transparent 70%);
  bottom: 6%;
  left: -22%;
  animation: liquidDriftD 36s ease-in-out infinite;
}
@keyframes liquidDriftA {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(7%, 9%) scale(1.08); }
}
@keyframes liquidDriftB {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(-9%, -6%) scale(1.1); }
}
@keyframes liquidDriftC {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(-6%, 8%) scale(1.05); }
}
@keyframes liquidDriftD {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(8%, -5%) scale(1.07); }
}
/* Ледь помітне зерно поверх плям — та сама "плівкова" глибина, що й раніше. */
.liquid-bg::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.035;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='120' height='120'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
}
@media (prefers-reduced-motion: reduce) {
  .liquid-blob { animation: none; }
}

#app {
  position: relative;
  z-index: 1;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  padding: 12px 12px calc(24px + env(safe-area-inset-bottom));
  gap: 14px;
}

#content {
  display: flex;
  flex-direction: column;
  gap: 14px;
  animation: viewIn 0.28s ease both;
  /* Кнопки в кутах (❓/🎮/💬/❤️) — position:fixed, не займають місця в
     потоці. Поки #status-line непорожній (текст завантаження/помилки),
     він своїм margin:auto відштовхував #content вниз від них — щойно
     #status-line порожній (успішний вхід, :empty{display:none}), перший
     елемент #content (напр. .lobby-code-chip зліва) інакше наліз би просто
     під кнопки. Явний відступ зверху — надійніше, ніж покладатись на це. */
  padding-top: calc(44px + env(safe-area-inset-top));
}
@keyframes viewIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Лого на стартовому екрані (немає лобі) — бігучий блік лишається, добре
   пасує до світу рідкого скла (як відблиск на кромці). */
.logo-text {
  align-self: center;
  margin: 16px 0 4px;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 25px;
  letter-spacing: 0.02em;
  text-align: center;
  background: linear-gradient(100deg, var(--accent) 0%, #fff 20%, var(--accent) 40%, var(--accent-2) 60%, #fff 80%, var(--accent) 100%);
  background-size: 220% auto;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: logoShine 5s linear infinite;
}
@keyframes logoShine {
  to { background-position: -220% center; }
}
@media (prefers-reduced-motion: reduce) {
  .logo-text {
    animation: none;
    background-position: 0 center;
  }
}

.center-msg {
  margin: auto;
  text-align: center;
  color: var(--hint);
  padding: 24px 20px;
  line-height: 1.5;
  border-radius: var(--radius-lg);
  background: var(--glass-fill);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(160%);
  backdrop-filter: blur(var(--glass-blur)) saturate(160%);
  border: 1px solid var(--glass-border-soft);
  box-shadow: var(--shadow-card), inset 0 1px 0 var(--glass-highlight);
}
/* #status-line лишається в DOM і після statusLine("") (порожній текст після
   вдалого входу) — без цього правила порожня скляна панель висіла б
   привидом на екрані замість зникати, як робила невидима звичайна .center-msg
   до цього редизайну. */
#status-line:empty {
  display: none;
}

.spinner {
  width: 30px;
  height: 30px;
  margin: 0 auto 12px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.14);
  border-top-color: var(--accent);
  animation: spin 0.75s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* --- шапка стану (скляний банер) --- */
.turn-banner {
  position: sticky;
  top: 4px;
  z-index: 40;
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  background: var(--glass-fill-strong);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(180%);
  backdrop-filter: blur(var(--glass-blur)) saturate(180%);
  border: 1px solid var(--glass-border);
  display: flex;
  align-items: center;
  gap: 12px;
  overflow: hidden;
  box-shadow: var(--shadow-float), inset 0 1px 0 var(--glass-highlight);
}
.turn-banner::before {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0;
  background: linear-gradient(135deg, rgba(79, 127, 255, 0.45), rgba(255, 182, 72, 0.4));
  transition: opacity 0.3s ease;
  pointer-events: none;
}
.turn-banner.your-turn::before {
  opacity: 1;
}
.turn-banner.your-turn {
  border-color: rgba(255, 182, 72, 0.65);
  animation: bannerPulse 2.2s ease-in-out infinite;
}
@keyframes bannerPulse {
  0%, 100% { box-shadow: var(--shadow-float), inset 0 1px 0 var(--glass-highlight), 0 0 0 1.5px rgba(255, 182, 72, 0.5); }
  50% { box-shadow: var(--shadow-float), inset 0 1px 0 var(--glass-highlight), 0 0 0 1.5px rgba(255, 182, 72, 0.9), 0 0 22px rgba(255, 182, 72, 0.35); }
}
.turn-banner-icon {
  position: relative;
  font-size: 26px;
  line-height: 1;
  flex-shrink: 0;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.4));
}
.turn-banner-text {
  position: relative;
  flex: 1;
  min-width: 0;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 15px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* --- секції --- */
.section-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--hint);
  margin: 6px 2px 2px;
}
.section-title::before {
  content: "";
  width: 3px;
  height: 12px;
  border-radius: 2px;
  background: linear-gradient(180deg, var(--accent), var(--accent-2));
  flex-shrink: 0;
}

.card-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(126px, 1fr));
  gap: 9px;
}
/* Карти в ряду з'являються не всі разом, а невеликим каскадом зліва
   направо — дешевий CSS-ефект (animation-delay по nth-child), без жодних
   бібліотек. Обмежено 10 карт, далі затримка не росте. */
.card-row > .card:nth-child(1) { animation-delay: 0.02s; }
.card-row > .card:nth-child(2) { animation-delay: 0.05s; }
.card-row > .card:nth-child(3) { animation-delay: 0.08s; }
.card-row > .card:nth-child(4) { animation-delay: 0.11s; }
.card-row > .card:nth-child(5) { animation-delay: 0.14s; }
.card-row > .card:nth-child(6) { animation-delay: 0.17s; }
.card-row > .card:nth-child(7) { animation-delay: 0.2s; }
.card-row > .card:nth-child(8) { animation-delay: 0.23s; }
.card-row > .card:nth-child(9) { animation-delay: 0.26s; }
.card-row > .card:nth-child(n+10) { animation-delay: 0.29s; }

/* ---------------------------------------------------------------------------
   Ігрова картка (орган чи картка з руки). ЗАЛИШАЄТЬСЯ НЕпрозорою — колір
   градієнта за категорією ставить render.js інлайн-стилем і несе ігрову
   інформацію (тип картки), тому справжнє скло (backdrop-filter) тут не
   застосовується — воно просто не мало б сенсу на суцільній заливці.
   Натомість картка отримує "скляну" огранку: тонка світла кромка, глянцевий
   відблиск у верхньому куті (::before) окремо від тонування пошкодження
   (::after), заокруглені кути й глибша шарова тінь для ефекту "самоцвіту",
   що ніби плаває над поверхнею.
--------------------------------------------------------------------------- */
.card {
  position: relative;
  border-radius: var(--card-radius);
  padding: 11px;
  min-height: 100px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 3px;
  color: #fff;
  overflow: hidden;
  background: var(--bg-secondary);
  box-shadow: var(--shadow-card), 0 12px 26px -12px rgba(0, 0, 0, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.16);
  animation: cardIn 0.22s ease both;
}
@keyframes cardIn {
  from { opacity: 0; transform: scale(0.94); }
  to { opacity: 1; transform: scale(1); }
}
.card::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(120% 60% at 18% 0%, rgba(255, 255, 255, 0.4), transparent 60%);
  pointer-events: none;
}
.card::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0) 45%);
  pointer-events: none;
}
.card .card-name {
  position: relative;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 15px;
  line-height: 1.3;
  letter-spacing: 0.01em;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}
.card .card-meta {
  position: relative;
  font-family: var(--font-body);
  font-size: 13.5px;
  font-weight: 500;
  opacity: 0.92;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}
.card .chip {
  position: relative;
  display: inline-block;
  align-self: flex-start;
  font-family: var(--font-body);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.02em;
  background: rgba(255, 255, 255, 0.16);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  border: 1px solid rgba(255, 255, 255, 0.28);
  padding: 2px 7px;
  border-radius: var(--radius-pill);
  margin-top: 2px;
}

/* Пошкоджений орган — легкий червонястий відтінок поверх глянцю. */
.card.damaged::after {
  background: linear-gradient(160deg, rgba(255, 82, 102, 0.26), rgba(255, 255, 255, 0.08) 45%);
}

/* Значок у ЛІВОМУ кутку: картка миттєва (не займає хід, можна зіграти
   будь-коли) — щоб відрізнялась від звичайних карток з першого погляду. */
.instant-badge {
  position: absolute;
  top: 8px;
  left: 8px;
  font-size: 15px;
  line-height: 1;
  filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.55));
  z-index: 2;
}

/* Кружечок у ПРАВОМУ кутку картки атаки: чи є прямо зараз законна ціль на
   столі — тонке скляне кільце навколо насиченої заливки, колір лишається
   інформативним (зелений/червоний), скло тут лише в окантовці. */
.playable-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  line-height: 1;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.45), 0 0 0 2px rgba(255, 255, 255, 0.22) inset;
  z-index: 2;
}
.playable-badge.playable-yes {
  background: var(--success);
}
.playable-badge.playable-no {
  background: var(--danger);
}

/* Полоска ХП органа: на всю ширину картки, поділена на hits_needed частин.
   Ціла = зелена, отримала удар = червона; під щитом — суцільно синя. Колір
   лишається чітким сигналом (ігрова інформація), додано лише тонкий
   глянцевий верх для узгодження зі склом решти інтерфейсу. */
.hp-bar {
  position: relative;
  display: flex;
  width: 100%;
  height: 10px;
  border-radius: 5px;
  overflow: hidden;
  margin-top: 6px;
  gap: 2px;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.3) inset;
}
.hp-bar::after {
  content: "";
  position: absolute;
  inset: 0 0 50% 0;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.3), transparent);
  pointer-events: none;
}
.hp-segment {
  flex: 1 1 0;
  background: var(--success);
}
.hp-segment.hit {
  background: var(--danger);
}
.hp-bar.shielded {
  background: var(--button);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.3) inset, 0 0 10px rgba(79, 127, 255, 0.65);
}

/* Обрана картка в мульти-виборі (скидання карт замість ходу). */
.card.picked {
  box-shadow: 0 0 0 2px var(--accent), 0 0 18px rgba(255, 182, 72, 0.4), var(--shadow-card);
  transform: scale(0.97);
}

/* --- список гравців (скляні рядки) --- */
.player-rows {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.player-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--glass-fill);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(160%);
  backdrop-filter: blur(var(--glass-blur)) saturate(160%);
  border: 1px solid var(--glass-border-soft);
  font-size: 13px;
  box-shadow: var(--shadow-card), inset 0 1px 0 var(--glass-highlight);
  transition: box-shadow 0.2s ease;
}
.player-row.active {
  border-color: rgba(255, 182, 72, 0.55);
  box-shadow: var(--shadow-card), inset 0 1px 0 var(--glass-highlight), 0 0 0 1.5px rgba(255, 182, 72, 0.5), 0 0 16px rgba(255, 182, 72, 0.22);
}
.player-row .info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.player-row .name {
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.player-row .stats {
  color: var(--hint);
  font-size: 11.5px;
}

.avatar {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 13px;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35), 0 0 0 1.5px rgba(255, 255, 255, 0.24) inset;
}

.finished-banner {
  border-radius: var(--radius-lg);
  padding: 26px 18px;
  text-align: center;
  background: linear-gradient(135deg, rgba(255, 182, 72, 0.32), rgba(51, 230, 171, 0.18)), var(--glass-fill-strong);
  -webkit-backdrop-filter: blur(var(--glass-blur-strong)) saturate(180%);
  backdrop-filter: blur(var(--glass-blur-strong)) saturate(180%);
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow-float), inset 0 1px 0 var(--glass-highlight);
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 17px;
  letter-spacing: 0.01em;
  line-height: 1.5;
}

/* Стек сповіщень: фіксований контейнер зверху екрана (як системні
   сповіщення на телефоні). column-reverse тут ключовий — новий тост
   з'являється БІЛЯ ЯКОРЯ (тобто вгорі), а старіші зісуваються нижче. */
.toast-stack {
  position: fixed;
  left: 12px;
  right: 12px;
  top: calc(12px + env(safe-area-inset-top));
  z-index: 80;
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
  pointer-events: none;
}
.error-toast {
  background: rgba(255, 82, 102, 0.82);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(180%);
  backdrop-filter: blur(var(--glass-blur)) saturate(180%);
  border: 1px solid rgba(255, 255, 255, 0.28);
  color: #fff;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow-pop), inset 0 1px 0 rgba(255, 255, 255, 0.35);
  pointer-events: auto;
  animation: toastIn 0.25s cubic-bezier(0.2, 0.9, 0.3, 1.2) both;
}
.error-toast.toast-ok {
  background: rgba(51, 230, 171, 0.82);
  color: #06231a;
}
.error-toast.toast-out {
  animation: toastOut 0.2s ease both;
}
@keyframes toastIn {
  from { opacity: 0; transform: translateY(14px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes toastOut {
  from { opacity: 1; transform: translateY(0) scale(1); }
  to { opacity: 0; transform: translateY(8px) scale(0.98); }
}

/* Отруєння спрацювало в тебе самого — весь екран на 2с спалахує червоним
   скляним маревом (сильніший blur, ніж у звичайних панелей — тут це не
   поверхня, а сама атмосфера екрана). */
.poison-flash {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
  text-align: center;
  background: rgba(210, 20, 20, 0.6);
  -webkit-backdrop-filter: blur(10px) saturate(160%);
  backdrop-filter: blur(10px) saturate(160%);
  animation: poisonFlashIn 0.2s ease both;
}
.poison-flash-text {
  font-family: var(--font-display);
  font-size: 21px;
  font-weight: 400;
  line-height: 1.4;
  color: #fff;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.65);
}
.poison-flash.poison-flash-out {
  animation: poisonFlashOut 0.4s ease both;
}
@keyframes poisonFlashIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes poisonFlashOut {
  from { opacity: 1; }
  to { opacity: 0; }
}

/* Реакція "Зміцнення імунітету" — щойно атакували твій орган: на весь екран,
   як спалах отруєння, але ЖОВТИЙ і НЕ зникає сам. */
.reaction-flash {
  position: fixed;
  inset: 0;
  z-index: 210;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  padding: 32px;
  text-align: center;
  background: rgba(255, 182, 72, 0.82);
  -webkit-backdrop-filter: blur(10px) saturate(160%);
  backdrop-filter: blur(10px) saturate(160%);
  animation: poisonFlashIn 0.2s ease both;
}
.reaction-flash-text {
  font-family: var(--font-display);
  font-size: 21px;
  font-weight: 400;
  line-height: 1.4;
  color: #26190a;
  text-shadow: 0 1px 4px rgba(255, 255, 255, 0.3);
}
.reaction-flash-buttons {
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ---------------------------------------------------------------------------
   Кнопки — скляні пігулки: напівпрозора заливка, що розмиває фон під собою,
   тонка світла кромка (заломлення на краю скла), внутрішній верхній відблиск.
--------------------------------------------------------------------------- */
.btn {
  position: relative;
  border: 1px solid var(--glass-border-soft);
  border-radius: var(--radius-pill);
  padding: 13px 20px;
  min-height: 44px;
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.01em;
  cursor: pointer;
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(180%);
  backdrop-filter: blur(var(--glass-blur)) saturate(180%);
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.12s ease, filter 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}
.btn:active {
  transform: scale(0.97) translateY(1px);
  filter: brightness(0.95);
}
.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.btn:disabled {
  opacity: 0.5;
  cursor: default;
}
.btn-block {
  width: 100%;
}
.btn-primary {
  background: linear-gradient(135deg, rgba(79, 127, 255, 0.6), rgba(37, 69, 160, 0.5));
  border-color: rgba(255, 255, 255, 0.32);
  color: var(--button-text);
  box-shadow: 0 8px 22px rgba(79, 127, 255, 0.4), inset 0 1px 0 var(--glass-highlight);
}
.btn-secondary {
  background: var(--glass-fill);
  color: var(--text);
  box-shadow: inset 0 1px 0 var(--glass-highlight), var(--shadow-card);
}
.btn-danger {
  background: rgba(255, 82, 102, 0.14);
  color: var(--danger);
  border-color: rgba(255, 82, 102, 0.5);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.15);
}
.btn-small {
  padding: 7px 14px;
  min-height: 0;
  font-size: 12px;
}

/* --- рядок адмін-дій (напр. дострокове завершення гри) --- */
.admin-row {
  display: flex;
  justify-content: flex-end;
}

/* --- панель головної дії (скинути карти замість ходу) — скляний "док",
   приклеєний до низу екрана, щоб завжди був під рукою --- */
.action-bar {
  position: sticky;
  bottom: calc(10px + env(safe-area-inset-bottom));
  z-index: 45;
  padding: 8px;
  border-radius: var(--radius-lg);
  background: var(--glass-fill-strong);
  -webkit-backdrop-filter: blur(var(--glass-blur-strong)) saturate(180%);
  backdrop-filter: blur(var(--glass-blur-strong)) saturate(180%);
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow-float), inset 0 1px 0 var(--glass-highlight);
}
.action-bar .btn {
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.4);
}

/* --- інтерактивні картки --- */
.card.tappable {
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.2s ease;
}
.card.tappable:active {
  transform: scale(0.95);
}

/* --- створення/приєднання до лобі --- */
.join-row {
  display: flex;
  gap: 8px;
}
.code-input {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  border: 1px solid var(--glass-border-soft);
  border-radius: var(--radius-sm);
  padding: 12px;
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 400;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  background: var(--glass-fill);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(160%);
  backdrop-filter: blur(var(--glass-blur)) saturate(160%);
  color: var(--text);
  box-shadow: inset 0 1px 0 var(--glass-highlight);
}
.code-input::placeholder {
  color: var(--hint);
  opacity: 0.8;
}
.code-input:focus {
  outline: none;
  box-shadow: 0 0 0 1.5px var(--accent) inset, inset 0 1px 0 var(--glass-highlight);
}
.code-input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.feedback-textarea {
  width: 100%;
  min-height: 110px;
  resize: vertical;
  border: 1px solid var(--glass-border-soft);
  border-radius: var(--radius-sm);
  padding: 12px;
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.5;
  background: var(--glass-fill);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(160%);
  backdrop-filter: blur(var(--glass-blur)) saturate(160%);
  color: var(--text);
  box-shadow: inset 0 1px 0 var(--glass-highlight);
}
.feedback-textarea:focus {
  outline: none;
  box-shadow: 0 0 0 1.5px var(--accent) inset, inset 0 1px 0 var(--glass-highlight);
}
.feedback-textarea::placeholder {
  color: var(--hint);
}

.lobby-code-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  align-self: flex-start;
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 400;
  letter-spacing: 0.08em;
  padding: 9px 18px;
  border-radius: var(--radius-pill);
  background: linear-gradient(135deg, rgba(79, 127, 255, 0.32), rgba(255, 182, 72, 0.26)), var(--glass-fill);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(180%);
  backdrop-filter: blur(var(--glass-blur)) saturate(180%);
  border: 1px solid var(--glass-border);
  box-shadow: inset 0 1px 0 var(--glass-highlight), var(--shadow-card);
}

/* Текст правил у модалці "❓" — звичайні абзаци зліва, на відміну від
   .center-msg (той призначений для одного центрованого рядка-заглушки). */
.help-text p {
  margin: 0 0 10px;
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--text);
}
.help-text p:last-child {
  margin-bottom: 0;
}

/* Кнопки "❓"/"🎮" і індикатор розриву зв'язку — живуть ПОЗА #content (те
   повністю перемальовується щокадру), тому не зникають між рендерами.
   Скляні круглі кнопки — та сама поверхня, що й .btn, лише кругла форма. */
.help-btn {
  position: fixed;
  top: calc(10px + env(safe-area-inset-top));
  right: 10px;
  z-index: 50;
  width: 36px;
  height: 36px;
  border: 1px solid var(--glass-border);
  border-radius: 50%;
  background: var(--glass-fill-strong);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(180%);
  backdrop-filter: blur(var(--glass-blur)) saturate(180%);
  color: var(--text);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--shadow-card), inset 0 1px 0 var(--glass-highlight);
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.12s ease, filter 0.15s ease;
}
.help-btn:active {
  transform: scale(0.92);
  filter: brightness(0.95);
}
.games-btn {
  right: 54px;
}
.feedback-btn {
  left: 10px;
}
.support-btn {
  left: 54px;
}

.conn-dot {
  position: fixed;
  top: calc(28px + env(safe-area-inset-top));
  left: 98px;
  transform: translateY(-50%);
  z-index: 50;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--danger);
  box-shadow: 0 0 0 4px rgba(255, 82, 102, 0.25), 0 0 0 1px rgba(255, 255, 255, 0.3) inset;
  animation: connPulse 1.4s ease-in-out infinite;
}
.conn-dot[hidden] {
  display: none;
}
@keyframes connPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* --- skeleton-заглушка на першому завантаженні (до першого render()) ---
   Чистий CSS, без жодного JS: render() перезаписує #content і сам її
   прибирає своїм першим викликом (root.innerHTML = ""). */
.skeleton {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.skeleton-block {
  border-radius: var(--radius-lg);
  background: var(--glass-fill);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(140%);
  backdrop-filter: blur(var(--glass-blur)) saturate(140%);
  border: 1px solid var(--glass-border-soft);
  position: relative;
  overflow: hidden;
}
.skeleton-block::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(100deg, transparent 8%, rgba(255, 255, 255, 0.18) 24%, transparent 40%);
  background-size: 200% 100%;
  animation: skeletonShine 1.4s ease-in-out infinite;
}
.skeleton-banner { height: 56px; border-radius: var(--radius-lg); }
.skeleton-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(126px, 1fr)); gap: 9px; }
.skeleton-row .skeleton-block { height: 100px; border-radius: var(--card-radius); }
@keyframes skeletonShine {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
@media (prefers-reduced-motion: reduce) {
  .conn-dot, .skeleton-block::after { animation: none; }
}

/* --- оверлей-пікер (вибір цілі/органа/картки тощо) — скляний bottom-sheet --- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.42);
  -webkit-backdrop-filter: blur(6px) saturate(140%);
  backdrop-filter: blur(6px) saturate(140%);
  display: flex;
  align-items: flex-end;
  z-index: 60;
  animation: overlayIn 0.2s ease both;
}
@keyframes overlayIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
.overlay-panel {
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
  background: var(--glass-fill-strong);
  -webkit-backdrop-filter: blur(var(--glass-blur-strong)) saturate(190%);
  backdrop-filter: blur(var(--glass-blur-strong)) saturate(190%);
  border: 1px solid var(--glass-border);
  border-bottom: none;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 16px 14px calc(16px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: var(--shadow-pop), inset 0 1px 0 var(--glass-highlight);
  animation: sheetIn 0.28s cubic-bezier(0.2, 0.9, 0.3, 1.1) both;
}
@keyframes sheetIn {
  from { transform: translateY(24px); opacity: 0.6; }
  to { transform: translateY(0); opacity: 1; }
}
.overlay-panel::before {
  content: "";
  align-self: center;
  width: 36px;
  height: 4px;
  border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, 0.35);
  margin-bottom: 2px;
}

/* ---------------------------------------------------------------------------
   Дошка 16х16 — єдиний по-справжньому новий компонент порівняно з Organy/
   Perekup (ті не мають просторової сітки взагалі). Сама дошка НЕпрозора й
   контрастна (ігрова інформація — колір клітинки: ліс/вогонь/протидія/
   Вічний вогонь), скло лише в рамці навколо неї, як у решти "хрому".
--------------------------------------------------------------------------- */
.board-compass {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.board-row-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
}
.board-row-wrap .board-wrap {
  flex: 1;
  min-width: 0;
}

/* Літера сторони світу — скляна пігулка; та, куди зараз дме вітер, світиться
   блакитним і мерехтить, ніби нею проходять потоки повітря. */
.compass-label {
  position: relative;
  overflow: hidden;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 11px;
  letter-spacing: 0.06em;
  color: var(--hint);
  padding: 5px 9px;
  border-radius: var(--radius-pill);
  background: var(--glass-fill);
  border: 1px solid var(--glass-border-soft);
  box-shadow: inset 0 1px 0 var(--glass-highlight);
  transition: color 0.2s ease, background 0.2s ease, border-color 0.2s ease;
}
.compass-label.compass-n,
.compass-label.compass-s {
  width: 100%;
  max-width: 460px;
}
.compass-label.compass-w,
.compass-label.compass-e {
  writing-mode: vertical-rl;
  padding: 9px 5px;
}
.compass-label.active-wind {
  color: #eafcff;
  background: rgba(56, 189, 255, 0.32);
  border-color: rgba(120, 224, 255, 0.85);
  box-shadow: 0 0 10px rgba(56, 189, 255, 0.55), 0 0 22px rgba(56, 189, 255, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.5);
  animation: windGlow 1.5s ease-in-out infinite;
}
.compass-label.active-wind::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(100deg, transparent 15%, rgba(255, 255, 255, 0.65) 50%, transparent 85%);
  background-size: 260% 100%;
  animation: windFlow 1.7s linear infinite;
  mix-blend-mode: overlay;
  pointer-events: none;
}
@keyframes windGlow {
  0%, 100% { box-shadow: 0 0 8px rgba(56, 189, 255, 0.4), 0 0 16px rgba(56, 189, 255, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.5); }
  50% { box-shadow: 0 0 16px rgba(56, 189, 255, 0.8), 0 0 30px rgba(56, 189, 255, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.5); }
}
@keyframes windFlow {
  from { background-position: 220% 0; }
  to { background-position: -60% 0; }
}
@media (prefers-reduced-motion: reduce) {
  .compass-label.active-wind,
  .compass-label.active-wind::after {
    animation: none;
  }
}

.board-wrap {
  display: flex;
  justify-content: center;
}
.board {
  display: grid;
  grid-template-columns: repeat(16, 1fr);
  gap: 2px;
  width: 100%;
  max-width: 460px;
  aspect-ratio: 1;
  padding: 7px;
  border-radius: var(--radius-lg);
  background: var(--glass-fill);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(150%);
  backdrop-filter: blur(var(--glass-blur)) saturate(150%);
  border: 1px solid var(--glass-border-soft);
  box-shadow: var(--shadow-card), inset 0 1px 0 var(--glass-highlight);
}
.board-cell {
  position: relative;
  border-radius: 3px;
  background: linear-gradient(160deg, rgba(70, 140, 80, 0.55), rgba(35, 90, 45, 0.55));
  transition: transform 0.1s ease, box-shadow 0.15s ease;
}
.board-cell.zone-NW { box-shadow: inset 0 0 0 1px rgba(79, 127, 255, 0.55); background: linear-gradient(160deg, rgba(79, 127, 255, 0.28), rgba(35, 90, 45, 0.4)); }
.board-cell.zone-NE { box-shadow: inset 0 0 0 1px rgba(180, 120, 255, 0.55); background: linear-gradient(160deg, rgba(180, 120, 255, 0.28), rgba(35, 90, 45, 0.4)); }
.board-cell.zone-SW { box-shadow: inset 0 0 0 1px rgba(52, 211, 153, 0.55); background: linear-gradient(160deg, rgba(52, 211, 153, 0.28), rgba(35, 90, 45, 0.4)); }
.board-cell.zone-SE { box-shadow: inset 0 0 0 1px rgba(255, 90, 95, 0.55); background: linear-gradient(160deg, rgba(255, 90, 95, 0.28), rgba(35, 90, 45, 0.4)); }
.board-cell.kind-fire {
  background: linear-gradient(145deg, #ffab5c, #d1450f);
  box-shadow: 0 0 6px rgba(255, 120, 30, 0.65), inset 0 1px 0 rgba(255,255,255,0.3);
}
.board-cell.kind-eternal {
  background: linear-gradient(145deg, #ffd766, #ff5a1f);
  box-shadow: 0 0 10px rgba(255, 150, 30, 0.85), inset 0 1px 0 rgba(255,255,255,0.4);
}
.board-cell.kind-block {
  background: linear-gradient(145deg, #a98bff, #5c3fc4);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.3);
}
.board-cell.roof::after {
  content: "🏠";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 65%;
  line-height: 1;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.65));
  pointer-events: none;
}
.board-cell.mine::before {
  content: "";
  position: absolute;
  inset: 1px;
  border-radius: 2px;
  box-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, 0.9);
  pointer-events: none;
}
.board-cell.candidate {
  box-shadow: 0 0 0 2px var(--accent), 0 0 8px rgba(255, 182, 72, 0.6);
  cursor: pointer;
}
.board-cell.tappable {
  cursor: pointer;
}
.board-cell.tappable:active {
  transform: scale(0.82);
}
.board-cell.picked {
  box-shadow: 0 0 0 2px #fff, 0 0 10px rgba(255, 255, 255, 0.75);
}

/* Легенда кутів (кольоровий кружечок гравця + ім'я) над дошкою. */
.zone-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  justify-content: center;
  font-size: 11.5px;
  color: var(--hint);
}
.zone-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.zone-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}
.zone-dot.zone-NW { background: #4f7fff; }
.zone-dot.zone-NE { background: #b478ff; }
.zone-dot.zone-SW { background: #34d399; }
.zone-dot.zone-SE { background: #ff5a5f; }

/* Панель дій із просторовим вибором (вогонь/вода/протидія) — той самий
   overlay-panel, лише без картко-рядка знизу: клітинки тапаються прямо на
   дошці над панеллю. */
.picker-hint {
  text-align: center;
  color: var(--hint);
  font-size: 12.5px;
}

/* Рядок «Відро» — окрема одноразова кнопка, завжди видима у свій хід. */
.bucket-row {
  display: flex;
  gap: 8px;
}
.bucket-row .btn {
  flex: 1;
}

.pending-banner {
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  text-align: center;
  background: linear-gradient(135deg, rgba(255, 90, 95, 0.32), rgba(255, 182, 72, 0.28)), var(--glass-fill-strong);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(180%);
  backdrop-filter: blur(var(--glass-blur)) saturate(180%);
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow-float), inset 0 1px 0 var(--glass-highlight);
  font-weight: 700;
  line-height: 1.4;
}

/* ---------------------------------------------------------------------------
   Анімація кубика вітру (перекидання напрямку) — справжній 3D-кубик, як у
   perekup_bot, лише грані замість крапок показують сторону світу. Куб
   обертається й зупиняється на грані, яку вже визначив сервер (напрямок
   вітру), анімація нічого не вигадує, лише показує вже вирішений результат.
--------------------------------------------------------------------------- */
.dice-overlay {
  align-items: center;
  justify-content: center;
}
.wind-die-scene {
  width: 92px;
  height: 92px;
  perspective: 700px;
  filter: drop-shadow(0 10px 22px rgba(0, 0, 0, 0.55));
}
.wind-die {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 1.5s cubic-bezier(0.15, 0.85, 0.25, 1);
}
.wind-die-face {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 14px;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 30px;
  color: #1a2230;
  background: linear-gradient(150deg, #eaf6ff, #b9d6f2);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}
.wind-die-face-wind {
  font-size: 26px;
  color: #4f7fff;
}
.wind-die-face-1 { transform: translateZ(46px); }
.wind-die-face-2 { transform: rotateY(90deg) translateZ(46px); }
.wind-die-face-3 { transform: rotateX(-90deg) translateZ(46px); }
.wind-die-face-4 { transform: rotateX(90deg) translateZ(46px); }
.wind-die-face-5 { transform: rotateY(-90deg) translateZ(46px); }
.wind-die-face-6 { transform: rotateY(180deg) translateZ(46px); }
