@font-face {
  font-family: "Cormorant Garamond";
  src: url("../fonts/CormorantGaramond.ttf") format("truetype");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Lora";
  src: url("../fonts/Lora.ttf") format("truetype");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

:root {
  --tg-bg: #10202a;
  --tg-text: #f3e6cf;
  --tg-hint: #b8a88a;
  --tg-link: #e2c07a;
  --tg-button: #8a4e22;
  --tg-button-text: #f8eedc;
  --tg-bg-2: #1a2a34;
  --tg-header: #0b141c;
  --wood: #2a1c12;
  --gold: #e2c07a;
  --ink: #f3e6cf;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--tg-header);
  color: var(--tg-text);
  font-family: "Lora", "DejaVu Serif", "Noto Serif", Georgia, serif;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

#app {
  position: relative;
  width: 100%;
  height: 100%;
  height: 100dvh;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #0b141c;
}

html.tg-insets-pending #hud { visibility: hidden; }

#hud {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 8px 10px 8px;
  padding-top: calc(8px + max(env(safe-area-inset-top, 0px), var(--tg-safe-area-inset-top, 0px)) + var(--tg-content-safe-area-inset-top, 0px));
  padding-left: calc(10px + max(env(safe-area-inset-left, 0px), var(--tg-safe-area-inset-left, 0px)) + var(--tg-content-safe-area-inset-left, 0px));
  padding-right: calc(10px + max(env(safe-area-inset-right, 0px), var(--tg-safe-area-inset-right, 0px)) + var(--tg-content-safe-area-inset-right, 0px));
  background:
    linear-gradient(180deg, rgba(42, 28, 18, 0.96), rgba(20, 14, 10, 0.92));
  border-bottom: 1px solid rgba(226, 192, 122, 0.35);
  z-index: 3;
}
#hud .brand {
  font-family: "Cormorant Garamond", "Times New Roman", serif;
  font-weight: 600;
  font-size: 22px;
  letter-spacing: 0.12em;
  color: var(--gold);
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding-right: 8px;
  line-height: 1;
}
#hud .brand small {
  font-family: "Lora", serif;
  font-size: 10px;
  letter-spacing: 0.16em;
  color: var(--tg-hint);
  text-transform: uppercase;
  margin-top: 3px;
}
#scores {
  display: flex;
  gap: 6px;
  flex: 1;
  overflow: auto;
  align-items: center;
}
.score {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: 8px;
  background: rgba(0,0,0,0.28);
  border: 1px solid transparent;
  font-size: 13px;
  white-space: nowrap;
}
.score.current {
  border-color: var(--team, var(--gold));
  box-shadow: 0 0 0 1px rgba(226, 192, 122, 0.25);
  animation: team-pulse 1.3s ease-in-out infinite;
}
@keyframes team-pulse {
  0%, 100% { box-shadow: 0 0 0 1px var(--team, rgba(226, 192, 122, 0.35)); }
  50% { box-shadow: 0 0 0 4px var(--team, var(--gold)); }
}
.score .swatch {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.3);
}
#hud-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}
#buy-pirate {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 4px;
  box-sizing: border-box;
  height: 36px;
  min-height: 36px;
  max-height: 36px;
  padding: 0 8px;
  line-height: 1;
  white-space: nowrap;
  flex: 0 0 auto;
}
#buy-pirate .buy-pirate {
  width: 16px;
  height: 24px;
  object-fit: cover;
  object-position: center 6%;
  pointer-events: none;
  flex: none;
}
#buy-pirate .buy-coin {
  width: 14px;
  height: 14px;
  object-fit: contain;
  pointer-events: none;
  flex: none;
}
#buy-pirate b { font-weight: 700; }
#buy-pirate[hidden] { display: none !important; }
@media (max-width: 420px) {
  #buy-pirate { height: 36px; font-size: 12px; padding: 0 6px; }
}
#buy-pirate.is-off,
#buy-pirate.is-broke,
#buy-pirate.is-capped,
#buy-pirate:disabled {
  opacity: 0.48;
  filter: grayscale(0.85);
  cursor: not-allowed;
}
button, .btn {
  font-family: "Lora", Georgia, serif;
  background: var(--tg-button);
  color: var(--tg-button-text);
  border: 1px solid rgba(226, 192, 122, 0.4);
  border-radius: 8px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 13px;
}
button:hover, .btn:hover { filter: brightness(1.08); }
button.ghost {
  background: rgba(0,0,0,0.3);
  color: var(--ink);
}

#board {
  flex: 1 1 0;
  display: block;
  width: 100%;
  min-height: 0;
  height: auto;
  cursor: grab;
}
#board.dragging { cursor: grabbing; }

#footer {
  flex: 0 0 auto;
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 8px 10px calc(10px + max(env(safe-area-inset-bottom, 0px), var(--tg-safe-area-inset-bottom, 0px)) + var(--tg-content-safe-area-inset-bottom, 0px));
  background: linear-gradient(0deg, rgba(42, 28, 18, 0.96), rgba(20, 14, 10, 0.9));
  border-top: 1px solid rgba(226, 192, 122, 0.35);
  z-index: 3;
  min-height: 72px;
}
#hint {
  flex: 1;
  font-size: 14px;
  line-height: 1.35;
  color: var(--ink);
}
#hint strong { color: var(--gold); }
#log {
  width: 42%;
  max-width: 360px;
  height: 8.6em;
  max-height: 8.6em;
  overflow-x: hidden;
  overflow-y: auto;
  scrollbar-width: thin;
  font-size: 15px;
  color: var(--tg-text);
  line-height: 1.45;
  cursor: pointer;
  -webkit-overflow-scrolling: touch;
}
#log.expanded {
  flex: 0 0 auto;
  width: min(46%, 420px);
  max-width: none;
  height: min(200px, 24vh);
  max-height: min(200px, 24vh);
}
#log-open {
  flex: none;
  align-self: center;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 44px;
  min-height: 44px;
  padding: 0 12px;
}
#log-sheet {
  position: absolute;
  inset: 0;
  z-index: 8;
  background: rgba(8, 12, 16, 0.82);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 12px;
}
#log-sheet.hidden { display: none !important; }
#log-sheet .panel {
  width: min(560px, 100%);
  height: min(70vh, 640px);
  max-height: min(70vh, 640px);
  display: flex;
  flex-direction: column;
  text-align: left;
  overflow: hidden;
}
#log-full {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  font-size: 16px;
  line-height: 1.45;
  color: var(--ink);
  -webkit-overflow-scrolling: touch;
}
#board-actions {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 4;
}
#board-actions .board-action {
  position: absolute;
  z-index: 6;
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 0;
  pointer-events: auto;
}
.board-action-face {
  width: 34px;
  height: 34px;
  border-radius: 17px;
  background: rgba(42, 22, 8, 0.88);
  border: 1px solid rgba(226, 192, 122, 0.85);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  pointer-events: none;
}
.board-action img {
  width: 22px;
  height: 22px;
  pointer-events: none;
}
.board-action-mark {
  position: absolute;
  right: -2px;
  bottom: -2px;
  width: 14px;
  height: 14px;
  padding: 1px;
  border-radius: 7px;
  background: #f0d48a;
  color: #2a1606;
  fill: #2a1606;
  box-shadow: 0 0 0 1px rgba(42, 22, 8, 0.65);
  pointer-events: none;
}
#carry-toggle { display: none; }
#carry-toggle.visible { display: inline-flex; }

#menu {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at 50% 20%, rgba(80, 50, 20, 0.35), transparent 50%),
    rgba(8, 12, 16, 0.82);
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
#menu.hidden { display: none; }
.panel {
  width: min(420px, 100%);
  background: linear-gradient(180deg, #3a2618, #21150e);
  border: 1px solid rgba(226, 192, 122, 0.5);
  box-shadow: 0 16px 60px rgba(0,0,0,0.55);
  border-radius: 16px;
  padding: 28px 24px 22px;
  text-align: center;
}
.panel h1 {
  font-family: "Cormorant Garamond", "Times New Roman", serif;
  font-weight: 600;
  font-size: 56px;
  margin: 0;
  letter-spacing: 0.14em;
  color: var(--gold);
}
.panel .sub {
  letter-spacing: 0.22em;
  text-transform: uppercase;
  font-size: 12px;
  color: var(--tg-hint);
  margin: 0 0 22px;
}
.row {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
  margin: 10px 0;
}
.row label { font-size: 14px; display: flex; align-items: center; gap: 6px; }
.choice {
  min-width: 64px;
}
.choice.active {
  outline: none;
  background: linear-gradient(180deg, #ffe7a6, #e2b14a);
  color: #2a1606;
  border-color: #fff6cf;
  box-shadow: 0 0 0 3px rgba(255, 220, 120, 0.55);
}
.choice.active::after {
  content: "✓";
  margin-left: 6px;
  font-weight: 700;
}
#size-row .choice {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  min-height: 48px;
  line-height: 1.15;
}
#size-row .choice.shape { flex-direction: row; gap: 8px; text-align: left; }
#size-row .size-label {
  display: block;
  font-size: 11px;
  letter-spacing: 0.02em;
  opacity: 0.9;
}
#size-row .choice.active .size-label { color: #5a360c; opacity: 1; }
#start-btn {
  margin-top: 16px;
  font-size: 16px;
  padding: 10px 28px;
}
.note {
  margin-top: 16px;
  font-size: 12px;
  color: var(--tg-hint);
  line-height: 1.4;
}
#badge {
  position: absolute;
  bottom: calc(84px + env(safe-area-inset-bottom, 0px));
  right: 12px;
  z-index: 3;
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--tg-hint);
  pointer-events: none;
}

#endgame {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(8, 12, 16, 0.72);
  z-index: 4;
}
#endgame.visible { display: flex; }
#endgame .panel h2 {
  font-family: "Cormorant Garamond", serif;
  color: var(--gold);
  font-size: 32px;
  margin: 0 0 8px;
}

@media (max-width: 640px) {
  #log { display: none; }
  .panel h1 { font-size: 44px; }
  #hud .brand { font-size: 18px; }
}

#toast {
  position: absolute;
  left: 50%;
  bottom: calc(90px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 30;
  max-width: min(640px, 90%);
  padding: 10px 18px;
  border-radius: 10px;
  background: rgba(42, 28, 18, 0.94);
  border: 1px solid rgba(226, 192, 122, 0.65);
  color: #f8eedc;
  font-size: 16px;
  line-height: 1.35;
  text-align: center;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  pointer-events: none;
}
#toast[hidden] { display: none; }

.panel.wide { width: min(520px, 100%); text-align: left; max-height: calc(100dvh - 24px); overflow: auto; }
.cab-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.cab-head h2 {
  font-family: "Cormorant Garamond", "Times New Roman", serif;
  color: var(--gold);
  margin: 0;
  letter-spacing: 0.08em;
}
#cabinet {
  position: absolute;
  inset: 0;
  background: rgba(8, 12, 16, 0.82);
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
#cabinet.hidden { display: none; }
#cabinet .tabs { display: flex; gap: 6px; flex-wrap: wrap; margin: 12px 0; }
#cabinet .tabs button { min-width: 0; padding: 6px 12px; font-size: 13px; }
#cabinet .tabs button.active { outline: 2px solid var(--gold); }
.cab-card h3, .cab-card h4 { margin: 0 0 8px; color: var(--gold); }
.points-big { font-size: 28px; margin: 8px 0 14px; color: var(--gold); }
.plain { list-style: none; padding: 0; margin: 0; }
.plain li, .shop-item { padding: 3px 0; font-size: 13px; }
.shop-list { list-style: none; padding: 0; margin: 0 0 10px; }
.shop-item { display: flex; justify-content: space-between; align-items: center; gap: 8px; border-bottom: 1px solid rgba(226,192,122,0.15); }
.shop-item.equipped span { color: var(--gold); }
.copy-row { display: flex; gap: 8px; margin: 8px 0 12px; }
.copy-row input { flex: 1; min-width: 0; background: #1a100a; color: #f3e2b0; border: 1px solid rgba(226,192,122,0.4); border-radius: 8px; padding: 8px; }
.banner {
  background: rgba(80, 50, 20, 0.45);
  border: 1px solid rgba(226, 192, 122, 0.4);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 12px;
  line-height: 1.4;
  color: #f3e2b0;
}
.muted { color: var(--tg-hint); font-size: 12px; }
a.btn { display: inline-flex; align-items: center; padding: 8px 14px; background: #3a2618; color: var(--gold); border-radius: 8px; text-decoration: none; border: 1px solid rgba(226,192,122,0.4); }
#size-row .choice { min-width: 110px; }

#lobby {
  position: absolute;
  inset: 0;
  background: rgba(8, 12, 16, 0.82);
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
#lobby.hidden { display: none; }
#lobby .panel.wide { width: min(560px, 100%); }
.lobby-code {
  font-family: "Cormorant Garamond", "Times New Roman", serif;
  font-size: 36px;
  letter-spacing: 0.2em;
  color: var(--gold);
  margin: 8px 0;
  text-align: center;
}
.seat-list { list-style: none; padding: 0; margin: 8px 0 12px; }
.seat-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid rgba(226,192,122,0.15);
}
.seat-list .you { color: var(--gold); }
.turn-banner {
  position: static;
  flex: 1 0 100%;
  order: -1;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-sizing: border-box;
  height: 40px;
  min-height: 40px;
  max-height: 40px;
  overflow: hidden;
  background: rgba(18, 12, 8, 0.94);
  color: #ffe7a3;
  border: 1px solid rgba(255, 220, 140, 0.85);
  border-left: 6px solid var(--team, #ffe08a);
  border-radius: 12px;
  padding: 0 12px;
  font-size: 15px;
  pointer-events: none;
  letter-spacing: 0.02em;
  box-shadow: inset 0 0 0 1px rgba(255, 248, 220, 0.12);
}
.turn-banner .swatch {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.7);
  flex: none;
}
.turn-banner b { color: #fff8e6; font-weight: 700; flex: 0 0 auto; white-space: nowrap; }
.turn-banner span {
  display: inline-flex;
  align-items: center;
  box-sizing: border-box;
  height: 22px;
  min-height: 22px;
  max-height: 22px;
  line-height: 22px;
  padding: 0 10px;
}
.turn-banner.mine span {
  color: #2a1606;
  background: #ffe08a;
  border: 1px solid #fff6cf;
  border-radius: 999px;
  padding: 0 10px;
  font-weight: 700;
  line-height: 22px;
}
.turn-banner.theirs { color: #fff1d0; }
.turn-banner.theirs span { color: #fff6df; font-weight: 700; }
.turn-banner.bot {
  background: rgba(14, 12, 10, 0.78);
  color: #a89880;
  border-color: rgba(168, 152, 128, 0.35);
  border-left-color: rgba(168, 152, 128, 0.55);
  box-shadow: none;
}
.turn-banner.bot b,
.turn-banner.bot span {
  color: #b7a890;
  background: none;
  border: 0;
  padding: 0 10px;
  font-weight: 500;
  height: 22px;
  line-height: 22px;
}
.turn-banner.pulse { animation: turn-arrive 0.7s ease-out 1; }
@keyframes turn-arrive {
  0% { transform: scale(0.98); box-shadow: 0 0 0 0 rgba(255, 214, 90, 0.55); }
  50% { transform: scale(1.03); box-shadow: 0 0 0 7px rgba(255, 214, 90, 0.28); }
  100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(255, 214, 90, 0); }
}
#turn-banner.hidden, #turn-banner[hidden] { display: none !important; }
#ship-pulse {
  position: absolute;
  width: 64px;
  height: 26px;
  margin-left: -32px;
  margin-top: -10px;
  border-radius: 50%;
  border: 3px solid var(--team, #e2c07a);
  box-shadow: 0 0 14px var(--team, #e2c07a);
  pointer-events: none;
  z-index: 4;
  animation: ship-pulse 1.3s ease-in-out infinite;
}
#ship-pulse[hidden] { display: none !important; }
@keyframes ship-pulse {
  0%, 100% { transform: scale(1); opacity: 0.95; }
  50% { transform: scale(1.22); opacity: 0.65; }
}
@media (prefers-reduced-motion: reduce) {
  .score.current, #ship-pulse, .turn-banner.pulse { animation: none; }
}
#react-bar {
  position: absolute;
  left: 50%;
  bottom: calc(92px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 5;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: center;
  max-width: min(640px, 96vw);
  background: rgba(16, 10, 6, 0.78);
  border: 1px solid rgba(226,192,122,0.35);
  border-radius: 16px;
  padding: 6px 8px;
}
#react-bar.hidden { display: none; }
#react-bar button {
  min-width: 0;
  padding: 4px 8px;
  font-size: 16px;
  line-height: 1.2;
}
#react-bubbles { position: absolute; inset: 0; pointer-events: none; z-index: 7; }
.react-bubble {
  position: absolute;
  transform: translate(-50%, -100%);
  background: rgba(30,18,8,0.92);
  color: #fff3c0;
  border: 1px solid rgba(226,192,122,0.65);
  border-radius: 16px;
  padding: 6px 12px;
  font-size: 20px;
  white-space: nowrap;
  animation: react-pop 0.28s ease-out;
  box-shadow: 0 6px 18px rgba(0,0,0,0.45);
}
.react-bubble.hud {
  font-size: 14px;
  padding: 2px 8px;
  transform: translate(-20%, -120%);
}
@keyframes react-pop {
  0% { transform: translate(-50%, -60%) scale(0.4); opacity: 0; }
  40% { transform: translate(-50%, -110%) scale(1.15); opacity: 1; }
  100% { transform: translate(-50%, -100%) scale(1); opacity: 1; }
}
#scores .score { position: relative; }
.mute-btn { min-width: 0; padding: 2px 6px; font-size: 10px; margin-left: 6px; }

/* --- v2: тема, туториал, итоги, реклама, прогресс --- */
html.theme-light, html[data-theme="light"] {
  --tg-bg: #f4e6c8;
  --tg-text: #2a1c12;
  --tg-hint: #6a5740;
  --tg-link: #8a4e22;
  --tg-button: #8a4e22;
  --tg-button-text: #f8eedc;
  --tg-bg-2: #efe0bc;
  --tg-header: #e8d5a8;
  --wood: #c9b48a;
  --gold: #7a4e16;
  --ink: #2a1c12;
}
html.theme-light, html[data-theme="light"] body,
html.theme-light #app, html[data-theme="light"] #app {
  background: #e8d5a8;
  color: #2a1c12;
}
html.theme-light #hud, html[data-theme="light"] #hud,
html.theme-light #footer, html[data-theme="light"] #footer {
  background: linear-gradient(180deg, rgba(236, 214, 160, 0.96), rgba(220, 196, 140, 0.92));
  border-color: rgba(122, 78, 22, 0.35);
}
html.theme-light .panel, html[data-theme="light"] .panel {
  background: linear-gradient(180deg, #f7ead0, #ead7b0);
  border-color: rgba(122, 78, 22, 0.45);
}
html.theme-light .copy-row input, html[data-theme="light"] .copy-row input {
  background: #f8eedc;
  color: #2a1c12;
}
html.theme-light .banner, html[data-theme="light"] .banner {
  background: rgba(226, 192, 122, 0.35);
  color: #2a1c12;
}
html.theme-light #toast, html[data-theme="light"] #toast {
  background: rgba(247, 234, 208, 0.96);
  color: #2a1c12;
}

.hidden { display: none !important; }
#share-btn.hidden { display: none !important; }
#resume-btn.hidden { display: none !important; }

#tutorial, #ad-overlay, #paywall {
  position: absolute;
  inset: 0;
  background: rgba(8, 12, 16, 0.82);
  z-index: 8;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
#tutorial.hidden, #ad-overlay.hidden, #paywall.hidden { display: none !important; }
#tutorial { overflow: hidden; padding: 12px; }
#tutorial .panel {
  width: min(440px, 100%);
  height: min(480px, calc(100dvh - 32px));
  min-height: min(480px, calc(100dvh - 32px));
  max-height: min(480px, calc(100dvh - 32px));
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-sizing: border-box;
}
#tutorial .tut-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  text-align: left;
  -webkit-overflow-scrolling: touch;
}
#tutorial .tut-nav {
  flex: 0 0 auto;
  flex-wrap: nowrap;
  align-items: center;
  gap: 8px;
  margin: 12px 0 0;
}
#tut-back, #tut-skip, #tut-next {
  flex: 1 1 0;
  height: 44px;
  min-height: 44px;
  max-height: 44px;
  min-width: 44px;
  padding: 0 8px;
  font-size: 15px;
  line-height: 1;
}
#tut-back:disabled { opacity: 0.45; cursor: default; }
#tut-title, #ad-overlay h2, #paywall h2, #endgame h2 {
  font-family: "Cormorant Garamond", serif;
  color: var(--gold);
}

.scoreboard { list-style: none; padding: 0; margin: 12px 0; }
.scoreboard li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 4px;
  border-bottom: 1px solid rgba(226,192,122,0.2);
  font-size: 15px;
}
.scoreboard li.winner { color: var(--gold); font-weight: 600; }

.xp-bar {
  height: 10px;
  border-radius: 6px;
  background: rgba(0,0,0,0.28);
  overflow: hidden;
  margin: 8px 0 14px;
  border: 1px solid rgba(226,192,122,0.35);
}
.xp-bar i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #c9a227, #e2c07a);
  width: 0;
}

#endgame .panel.wide { width: min(480px, 100%); text-align: left; }
#endgame .panel.wide h2, #endgame .panel.wide #end-text { text-align: center; }

.share-row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin: 10px 0; }
.share-row a.btn, .share-row button { font-size: 14px; padding: 8px 16px; }

.lock-note { font-size: 12px; color: var(--tg-hint); margin: 4px 0 0; }
button[disabled] { opacity: 0.55; cursor: not-allowed; }

/* --- v3: меню, турнирное лобби, компактный HUD --- */
#hud-actions .icon-btn {
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  font-size: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
#menu-btn, #carry-toggle {
  min-height: 44px;
  min-width: 44px;
  padding: 8px 14px;
}

.menu-shell {
  width: min(440px, 100%);
  max-height: calc(100dvh - 16px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, #3a2618, #21150e);
  border: 1px solid rgba(226, 192, 122, 0.5);
  box-shadow: 0 16px 60px rgba(0,0,0,0.55);
  border-radius: 16px;
  padding: 24px 20px 18px;
  text-align: center;
  -webkit-overflow-scrolling: touch;
}
.menu-shell h1 {
  font-family: "Cormorant Garamond", "Times New Roman", serif;
  font-weight: 600;
  font-size: clamp(40px, 12vw, 56px);
  margin: 0;
  letter-spacing: 0.14em;
  color: var(--gold);
}
.menu-shell h2 {
  font-family: "Cormorant Garamond", serif;
  color: var(--gold);
  margin: 8px 0 16px;
  letter-spacing: 0.06em;
}
.menu-shell .sub {
  letter-spacing: 0.22em;
  text-transform: uppercase;
  font-size: 12px;
  color: var(--tg-hint);
  margin: 0 0 20px;
}
.btn-primary, #start-btn, #play-open, #resume-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 48px;
  margin: 6px 0;
  font-size: 17px;
  padding: 12px 20px;
}
#resume-btn.hidden { display: none !important; }
#menu-cancel.hidden { display: none !important; }

.menu-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 16px 0 8px;
}
.menu-grid button {
  min-height: 48px;
  padding: 10px 8px;
  font-size: 14px;
  line-height: 1.25;
  background: rgba(0,0,0,0.28);
  color: var(--ink);
}
.menu-grid button:nth-child(1) { border-color: rgba(80, 180, 210, 0.55); }
.menu-grid button:nth-child(2) { border-color: rgba(226, 192, 122, 0.75); }
.menu-grid button:nth-child(3) { border-color: rgba(200, 120, 60, 0.65); }
.menu-grid button:nth-child(4) { border-color: rgba(120, 170, 90, 0.6); }
.menu-grid button:nth-child(5) { border-color: rgba(180, 140, 200, 0.55); }
.menu-grid button:nth-child(6) { border-color: rgba(160, 160, 160, 0.45); }

.btn-back {
  min-height: 44px;
  min-width: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin: 0 0 8px;
}
.menu-view { width: 100%; flex: 1 1 auto; min-height: 0; min-width: 0; overflow-x: hidden; overflow-y: auto; }
.settings-list { display: flex; flex-direction: column; gap: 8px; min-width: 0; max-width: 100%; }
.settings-list > button {
  min-height: 48px;
  width: 100%;
}

#tourney-lobby {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse at 50% 0%, rgba(120, 70, 20, 0.45), transparent 55%),
    rgba(8, 12, 16, 0.88);
  z-index: 20;
  display: flex;
  align-items: stretch;
  justify-content: center;
  padding: 12px;
}
#tourney-lobby.hidden { display: none !important; }
.tourney-shell {
  width: min(720px, 100%);
  max-height: 100%;
  overflow: auto;
  background: linear-gradient(180deg, #2c1c12, #18100b);
  border: 1px solid rgba(226, 192, 122, 0.45);
  border-radius: 16px;
  padding: 14px 14px 18px;
}
.tourney-head {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 10px;
}
.tourney-head h2 {
  font-family: "Cormorant Garamond", serif;
  color: var(--gold);
  margin: 4px 0 0;
  letter-spacing: 0.06em;
  font-size: 26px;
}
.tourney-tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin: 8px 0 12px;
}
.tourney-tabs button {
  min-height: 44px;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(0,0,0,0.3);
}
.tourney-tabs button.active {
  outline: 2px solid var(--gold);
  background: rgba(226, 192, 122, 0.18);
}
.tourney-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}
@media (min-width: 640px) {
  .tourney-list { grid-template-columns: 1fr 1fr; }
}
.tourney-card {
  text-align: left;
  border-radius: 14px;
  padding: 12px;
  border: 1px solid rgba(226,192,122,0.35);
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: linear-gradient(160deg, #4a3018, #24160e);
  box-shadow: 0 8px 20px rgba(0,0,0,0.35);
}
.tourney-card[data-accent="gold"] { background: linear-gradient(160deg, #5a4010, #2a1c08); border-color: #e2c07a; }
.tourney-card[data-accent="teal"] { background: linear-gradient(160deg, #163a40, #0e2024); border-color: #5ad0c0; }
.tourney-card[data-accent="crimson"] { background: linear-gradient(160deg, #4a1820, #240e12); border-color: #e07070; }
.tourney-card[data-accent="bone"] { background: linear-gradient(160deg, #3a3428, #1c1812); border-color: #c8b89a; }
.tourney-card[data-accent="azure"] { background: linear-gradient(160deg, #163050, #0c1828); border-color: #6aa8e0; }
.tourney-card h3 {
  font-family: "Cormorant Garamond", serif;
  color: var(--gold);
  margin: 0;
  font-size: 22px;
  letter-spacing: 0.03em;
}
.tourney-card .flavor { font-size: 12px; color: var(--tg-hint); line-height: 1.35; margin: 0; }
.tourney-meta { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0; }
.pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: rgba(0,0,0,0.35);
  border: 1px solid rgba(255,255,255,0.12);
}
.pill.open, .pill.soon { background: rgba(80, 140, 60, 0.45); color: #e8ffd0; }
.pill.live { background: rgba(180, 40, 40, 0.55); color: #ffe0e0; animation: live-pulse 1.6s ease-in-out infinite; }
.pill.finished { background: rgba(80,80,80,0.45); color: #ddd; }
.pill.prize { color: #ffe56a; border-color: rgba(226,192,122,0.5); }
@keyframes live-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(224, 80, 80, 0.0); }
  50% { box-shadow: 0 0 0 3px rgba(224, 80, 80, 0.35); }
}
.tourney-count {
  font-family: "Cormorant Garamond", serif;
  font-size: 24px;
  color: #fff3c0;
  letter-spacing: 0.08em;
  margin: 2px 0 6px;
}
.tourney-card .row { justify-content: flex-start; margin: 6px 0 0; }
.tourney-card button { min-height: 44px; padding: 8px 14px; }
.tourney-empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 36px 16px;
  color: var(--tg-hint);
  border: 1px dashed rgba(226,192,122,0.35);
  border-radius: 14px;
}
.legal-note {
  font-size: 11px;
  color: var(--tg-hint);
  line-height: 1.4;
  margin: 14px 4px 4px;
}

html.theme-light .menu-shell,
html[data-theme="light"] .menu-shell,
html.theme-light .tourney-shell,
html[data-theme="light"] .tourney-shell {
  background: linear-gradient(180deg, #f7ead0, #ead7b0);
  border-color: rgba(122, 78, 22, 0.45);
}
html.theme-light .tourney-card,
html[data-theme="light"] .tourney-card {
  color: #f8eedc;
}
html.theme-light .tourney-card h3,
html[data-theme="light"] .tourney-card h3,
html.theme-light .tourney-count,
html[data-theme="light"] .tourney-count { color: #ffe56a; }
html.theme-light .tourney-card .flavor,
html[data-theme="light"] .tourney-card .flavor { color: rgba(248, 238, 220, 0.82); }
html.theme-light .tourney-head h2,
html[data-theme="light"] .tourney-head h2 { color: #7a4e16; }

@media (max-width: 420px) {
  #hud .brand { font-size: 16px; padding-right: 4px; }
  #hud { gap: 4px; padding-left: 8px; padding-right: 8px; }
  .menu-shell { padding: 18px 14px 14px; border-radius: 14px; }
  .tourney-shell { padding: 10px; }
  .tourney-head h2 { font-size: 22px; }
  .menu-grid { gap: 8px; }
}

@media (max-width: 360px) {
  .menu-grid button { font-size: 13px; }
}
.menu-view .choice, .menu-view .row label {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 14px;
}
.menu-view .row label { justify-content: flex-start; }

/* --- v4: логотип «Сокровища лагуны», экран «Об игре» --- */
.logo-emblem { width: 120px; height: 64px; display: block; margin: 0 auto 4px; }
.menu-shell h1.logo-title {
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 0.95;
  font-size: clamp(34px, 10vw, 50px);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-shadow: 0 2px 0 rgba(0,0,0,0.35);
}
.menu-shell h1.logo-title .logo-sub {
  font-size: 0.56em;
  letter-spacing: 0.34em;
  color: #5ad0c0;
  margin-top: 4px;
}
.about-text { text-align: left; font-size: 14px; line-height: 1.5; margin: 0 0 12px; }
#about-disclaimer {
  font-size: 13px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(226,192,122,0.35);
  background: rgba(0,0,0,0.22);
}
#hud .brand { font-size: 18px; letter-spacing: 0.08em; }
#hud .brand small { letter-spacing: 0.3em; }
html.theme-light .menu-shell h1.logo-title .logo-sub,
html[data-theme="light"] .menu-shell h1.logo-title .logo-sub { color: #1f7f86; }
html.theme-light #about-disclaimer,
html[data-theme="light"] #about-disclaimer { background: rgba(255,255,255,0.35); }
@media (max-width: 420px) {
  #hud .brand { font-size: 14px; }
  #hud .brand small { font-size: 9px; }
}
.menu-shell h1.logo-title + .sub { margin-top: 12px; }
.lang-switch {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  margin: 0 0 8px;
}
.lang-switch span {
  flex: 1 0 100%;
  min-width: 0;
  text-align: left;
  font-size: 14px;
  line-height: 1.3;
  color: var(--ink, var(--tg-text));
}
.lang-switch button {
  flex: 1 1 0;
  width: auto;
  min-width: 0;
  max-width: 100%;
  min-height: 44px;
  padding: 8px 6px;
  color: #f8eedc;
  background: #8a4e22;
  white-space: nowrap;
}
.lang-switch button.active {
  border-color: #6b4a16;
  background: #f3d48a;
  color: #1a1008;
}
html[lang="en"] .menu-shell h1.logo-title {
  letter-spacing: 0.03em;
  font-size: clamp(30px, 8.6vw, 46px);
}
html[lang="en"] .menu-shell h1.logo-title .logo-sub {
  letter-spacing: 0.12em;
  font-size: 0.48em;
}
html[lang="en"] #hud .brand { letter-spacing: 0.04em; font-size: 15px; }
html[lang="en"] #hud .brand small { letter-spacing: 0.12em; }
html[lang="en"] .turn-banner { letter-spacing: 0; font-size: 14px; }
html[lang="en"] .menu-grid button { font-size: 13px; padding: 8px 6px; }
html[lang="en"] #menu-play #size-row .choice { font-size: 12px; padding-right: 8px; }
html[lang="en"] .brand-text { letter-spacing: 0.04em; }
@media (max-width: 420px) {
  html[lang="en"] #hud .brand { font-size: 13px; }
  html[lang="en"] .menu-shell h1.logo-title { font-size: clamp(28px, 8vw, 40px); }
}

/* --- v5: командный запас --- */
#stash-bar {
  position: relative;
  flex: 0 0 auto;
  align-self: flex-start;
  z-index: 3;
  pointer-events: none;
  display: flex;
  align-items: center;
  gap: 4px;
  box-sizing: border-box;
  height: 52px;
  min-height: 52px;
  max-height: 52px;
  max-width: calc(100% - 16px);
  margin: 6px 8px 0;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 3px 6px 3px 8px;
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(42, 28, 18, 0.92), rgba(20, 14, 10, 0.88));
  border: 1px solid rgba(226, 192, 122, 0.45);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
  scrollbar-width: none;
}
#stash-bar.hidden { display: none !important; }
#stash-bar::-webkit-scrollbar { display: none; }
.stash-label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--gold);
  padding-right: 4px;
  white-space: nowrap;
}
.stash-label .swatch { width: 10px; height: 10px; border-radius: 50%; border: 1px solid rgba(255,255,255,0.35); }
.stash-empty { font-size: 12px; color: var(--tg-hint); white-space: nowrap; padding: 0 4px; }
.stash-item {
  position: relative;
  pointer-events: auto;
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 10px;
  background: radial-gradient(circle at 50% 40%, rgba(255, 230, 160, 0.22), rgba(0, 0, 0, 0.28));
  border: 1px solid rgba(226, 192, 122, 0.55);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.stash-item img { width: 34px; height: 34px; pointer-events: none; }
.stash-item b {
  position: absolute;
  right: 2px;
  bottom: 1px;
  min-width: 16px;
  padding: 0 3px;
  border-radius: 8px;
  font-size: 11px;
  line-height: 15px;
  background: #2a1606;
  color: #ffe9a8;
  border: 1px solid rgba(226, 192, 122, 0.7);
}
.stash-item.off { opacity: 0.45; filter: grayscale(0.4); }
.stash-item.armed {
  outline: 2px solid #ffe56a;
  box-shadow: 0 0 0 4px rgba(255, 229, 106, 0.25);
  animation: stash-pulse 1.2s ease-in-out infinite;
}
@keyframes stash-pulse { 50% { box-shadow: 0 0 0 6px rgba(255, 229, 106, 0.12); } }
html.theme-light #stash-bar, html[data-theme="light"] #stash-bar {
  background: linear-gradient(180deg, rgba(247, 234, 208, 0.95), rgba(234, 215, 176, 0.92));
  border-color: rgba(122, 78, 22, 0.45);
}
html.theme-light .stash-label, html[data-theme="light"] .stash-label { color: #5a360c; font-weight: 700; }
html.theme-light .stash-label .swatch, html[data-theme="light"] .stash-label .swatch { border-color: rgba(60, 36, 8, 0.7); }
html.theme-light .stash-item, html[data-theme="light"] .stash-item {
  background: radial-gradient(circle at 50% 40%, rgba(255, 255, 255, 0.7), rgba(200, 170, 120, 0.35));
  border-color: rgba(122, 78, 22, 0.5);
}
@media (max-width: 420px) {
  #stash-bar { left: 6px; gap: 3px; padding: 2px 4px 2px 6px; }
  .stash-label { font-size: 10px; letter-spacing: 0.06em; }
}

/* --- v6: шапка на 360, запасы соперников, ловушки --- */
#scores { min-width: 0; }
#scores .score { cursor: default; flex: 0 0 auto; }
#scores .score.rival { cursor: pointer; }
.score .rv {
  font-style: normal;
  font-size: 10px;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  line-height: 16px;
  padding: 0 4px;
  border-radius: 8px;
  text-align: center;
  background: rgba(226, 192, 122, 0.22);
  border: 1px solid rgba(226, 192, 122, 0.55);
  color: var(--gold, #e2c07a);
}
#rival-stash {
  position: relative;
  flex: 0 0 auto;
  align-self: flex-start;
  z-index: 4;
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: calc(100% - 16px);
  margin: 4px 8px 0;
  pointer-events: none;
}
#rival-stash.hidden { display: none !important; }
.rival-row {
  display: flex;
  align-items: center;
  gap: 4px;
  box-sizing: border-box;
  height: 32px;
  min-height: 32px;
  max-height: 32px;
  padding: 0 8px 0 6px;
  border-radius: 10px;
  background: rgba(14, 10, 6, 0.72);
  border: 1px solid rgba(226, 192, 122, 0.35);
  font-size: 12px;
  color: var(--tg-text, #f3e7cf);
  width: max-content;
  max-width: 100%;
  overflow: hidden;
  pointer-events: none;
}
.rival-row .swatch { width: 10px; height: 10px; border-radius: 50%; border: 1px solid rgba(255,255,255,0.35); flex: 0 0 auto; }
.rv-name { margin-right: 2px; white-space: nowrap; }
.rv-item { position: relative; display: inline-flex; width: 26px; height: 26px; flex: 0 0 auto; }
.rv-item img { width: 26px; height: 26px; }
.rv-item b {
  position: absolute;
  right: -3px;
  bottom: -3px;
  font-size: 10px;
  line-height: 14px;
  min-width: 14px;
  text-align: center;
  border-radius: 7px;
  background: #2a1606;
  color: #ffe56a;
  border: 1px solid rgba(255, 229, 106, 0.6);
}
.rv-empty { color: var(--tg-hint); font-size: 11px; }
.rv-stuck { font-size: 11px; color: #ffcf8a; margin-left: 2px; white-space: nowrap; }
.stash-item.ransom img { width: 32px; height: 32px; object-fit: contain; }
.stash-item.ransom b.wide {
  left: 2px;
  right: 2px;
  bottom: 1px;
  font-size: 9px;
  letter-spacing: 0;
  text-align: center;
  white-space: nowrap;
}
html.theme-light .rival-row, html[data-theme="light"] .rival-row {
  background: rgba(247, 234, 208, 0.92);
  border-color: rgba(122, 78, 22, 0.45);
  color: #2a1c12;
}
html.theme-light .score .rv, html[data-theme="light"] .score .rv { color: #5a360c; border-color: rgba(122, 78, 22, 0.55); }
@media (max-width: 420px) {
  #hud .brand { display: none; }
  #hud { gap: 6px; }
  #scores { gap: 4px; flex: 1 1 100%; order: 5; min-width: 0; overflow: visible; }
  #scores.n2 { flex: 1 1 100%; }
  #scores .score { padding: 4px 6px; gap: 4px; font-size: 13px; }
  #scores.n2 .score { flex: 0 0 auto; overflow: visible; font-size: 12px; padding: 3px 5px; }
  #scores.n2 .score .nm { display: inline; overflow: visible; text-overflow: clip; white-space: nowrap; }
  #scores:not(.n2) .score .nm { display: none; }
  #hud-actions { gap: 4px; flex: 0 0 auto; }
  #menu-btn { padding-left: 10px; padding-right: 10px; }
  .mute-btn { margin-left: 2px; padding: 2px 4px; }
}
@media (max-width: 420px) {
  #menu-btn { font-size: 0; min-width: 44px; padding: 0; display: inline-flex; align-items: center; justify-content: center; }
  #menu-btn::before { content: '☰'; font-size: 20px; line-height: 1; }
  #scores.n3 .score, #scores.n4 .score { padding: 4px 5px; gap: 3px; font-size: 12px; }
  #scores.n4 .score .rv { display: none; }
  #scores.n4 .score .swatch { width: 10px; height: 10px; }
}

/* v7: выбор формы поля */
#size-row { flex-wrap: wrap; gap: 8px; }
#size-row .choice.shape { display: inline-flex; align-items: center; gap: 6px; }
.shape-ic { width: 18px; height: 18px; fill: currentColor; opacity: 0.85; flex: none; }
#lobby-size { flex-wrap: wrap; gap: 6px; }

/* v7: логотип «Атолл» */
#hud .brand { flex-direction: row; align-items: center; gap: 8px; }
#hud .brand .brand-text { display: flex; flex-direction: column; justify-content: center; line-height: 1; }
#hud .brand .brand-logo { width: 30px; height: 30px; flex: none; filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.45)); }
.logo-emblem { width: 112px; height: 112px; object-fit: contain; filter: drop-shadow(0 6px 12px rgba(0, 0, 0, 0.45)); }

/* v9: выбор «человек / бот» для каждой команды */
.seat-row { flex-wrap: wrap; gap: 6px; }
.seat-chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; font-size: 13px; border-radius: 999px; }
.seat-chip .swatch { width: 12px; height: 12px; border-radius: 50%; border: 1px solid rgba(255,255,255,0.4); flex: none; }
.seat-chip.bot { opacity: 0.8; border-style: dashed; }
#lobby-max { flex-wrap: wrap; gap: 6px; }

/* v9: шапка на 5–6 команд — сетка 3×2 на узком экране */
#scores.n5 .score .nm, #scores.n6 .score .nm { display: none; }
@media (max-width: 420px) {
  #scores.n5, #scores.n6 {
    display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 3px; overflow: visible;
  }
  #scores.n5 .score, #scores.n6 .score {
    padding: 2px 4px; gap: 3px; font-size: 11px; line-height: 1.25; min-width: 0; white-space: nowrap; justify-content: flex-start;
  }
  #scores.n5 .score .rv, #scores.n6 .score .rv, #scores.n5 .score .mute-btn, #scores.n6 .score .mute-btn { display: none; }
  #scores.n5 .score .swatch, #scores.n6 .score .swatch { width: 9px; height: 9px; }
}
.seat-list .swatch { display: inline-block; width: 12px; height: 12px; border-radius: 50%; border: 1px solid rgba(0,0,0,0.35); vertical-align: middle; margin-right: 2px; }

/* Узкое окно Telegram Desktop (~320×420): шапка переносится, ничего не обрезается. */
@media (max-height: 520px) {
  #hud { gap: 4px; padding-bottom: 4px; }
  #hud .brand {
    display: flex;
    font-size: 12px;
    letter-spacing: 0.04em;
    padding-right: 4px;
    gap: 4px;
  }
  #hud .brand small { display: none; }
  #hud .brand .brand-logo { width: 22px; height: 22px; }
  #scores { flex: 1 1 100%; order: 5; min-width: 0; }
  #hud-actions { margin-left: auto; }
  #footer { min-height: 0; gap: 6px; padding-top: 4px; }
  #hint { font-size: 12px; }
  #log { height: 4.8em; max-height: 4.8em; }
  .turn-banner {
    height: 40px;
    min-height: 40px;
    max-height: 40px;
    padding: 0 8px;
    font-size: 13px;
  }
  #badge { display: none; }
  #menu { padding: 6px; }
  .menu-shell { padding: 10px 10px 8px; }
}

/* «Новая партия»: высота не прыгает при смене поля и числа команд. */
#menu-play {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}
#menu-play .play-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}
#menu-play #start-btn {
  flex: none;
  margin: 8px 0 0;
  height: 48px;
  min-height: 48px;
  max-height: 48px;
}
#menu-play .choice { position: relative; }
#menu-play .choice.active::after {
  position: absolute;
  top: 3px;
  right: 4px;
  margin: 0;
  font-size: 11px;
  line-height: 1;
  pointer-events: none;
}
#menu-play #size-row,
#menu-play #players-row {
  display: grid;
  align-content: start;
  justify-content: stretch;
  margin: 8px 0;
}
#menu-play #size-row {
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 18px 52px 52px;
  gap: 8px;
  height: calc(18px + 52px + 52px + 16px);
  min-height: calc(18px + 52px + 52px + 16px);
  max-height: calc(18px + 52px + 52px + 16px);
}
#menu-play #players-row {
  grid-template-columns: repeat(5, minmax(0, 1fr));
  grid-template-rows: 18px 44px;
  gap: 6px;
  height: calc(18px + 44px + 6px);
  min-height: calc(18px + 44px + 6px);
  max-height: calc(18px + 44px + 6px);
}
#menu-play #size-row > span,
#menu-play #players-row > span {
  grid-column: 1 / -1;
  height: 18px;
  line-height: 18px;
  text-align: left;
  font-size: 13px;
}
#menu-play #size-row .choice,
#menu-play #size-row .choice.shape {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  justify-content: flex-start;
  gap: 6px;
  width: 100%;
  height: 52px;
  min-width: 0;
  min-height: 52px;
  max-height: 52px;
  margin: 0;
  padding: 4px 16px 4px 8px;
  overflow: hidden;
  font-size: 13px;
  line-height: 1.15;
  text-align: left;
}
#menu-play #size-row .choice span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#menu-play #players-row .choice {
  width: 100%;
  height: 44px;
  min-width: 0;
  min-height: 44px;
  max-height: 44px;
  margin: 0;
  padding: 0 4px;
}
#menu-play #seat-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-auto-rows: 44px;
  align-content: start;
  gap: 6px;
  height: calc(44px * 3 + 6px * 2);
  min-height: calc(44px * 3 + 6px * 2);
  max-height: calc(44px * 3 + 6px * 2);
  margin: 8px 0;
  overflow: hidden;
}
#menu-play .seat-chip {
  width: 100%;
  height: 44px;
  min-height: 44px;
  max-height: 44px;
  margin: 0;
  padding: 0 8px;
  justify-content: flex-start;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: 12px;
  box-sizing: border-box;
}
#menu-play .note {
  box-sizing: border-box;
  height: 7.2em;
  min-height: 7.2em;
  max-height: 7.2em;
  margin: 8px 0 0;
  overflow: auto;
  text-align: left;
}

/* Поле на весь экран, тонкие полупрозрачные панели поверх него. */
#board {
  position: absolute;
  inset: 0;
  z-index: 0;
  width: 100%;
  height: 100%;
}
#hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 8;
  flex-wrap: nowrap;
  gap: 4px;
  height: auto;
  min-height: 0;
  max-height: none;
  padding: 4px 8px;
  padding-top: calc(4px + max(env(safe-area-inset-top, 0px), var(--tg-safe-area-inset-top, 0px)) + var(--tg-content-safe-area-inset-top, 0px));
  padding-right: calc(8px + max(env(safe-area-inset-right, 0px), var(--tg-safe-area-inset-right, 0px)) + var(--tg-content-safe-area-inset-right, 0px));
  padding-left: calc(8px + max(env(safe-area-inset-left, 0px), var(--tg-safe-area-inset-left, 0px)) + var(--tg-content-safe-area-inset-left, 0px));
  background: rgba(8, 10, 14, 0.58);
  border: 0;
  border-bottom: 1px solid rgba(255, 220, 160, 0.28);
  box-shadow: none;
  pointer-events: none;
  overflow: hidden;
}
#hud > * { pointer-events: auto; }
#hud .brand { display: none; }
#scores { flex: 1 1 auto; min-width: 0; overflow: hidden; }
#scores .score { min-width: 0; }
.turn-banner {
  flex: 0 1 auto;
  order: 0;
  width: auto;
  max-width: min(240px, 42vw);
  margin: 0;
  border-radius: 8px;
  background: rgba(12, 10, 8, 0.45);
}
@media (max-width: 900px) {
  .turn-banner {
    position: absolute;
    width: max-content;
    max-width: none;
    height: 40px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    pointer-events: none;
  }
}
.stash-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #e2c07a;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.45);
  flex: none;
}
#footer,
html.theme-light #footer,
html[data-theme="light"] #footer {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 8;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-height: 0;
  padding: 0 8px calc(6px + max(env(safe-area-inset-bottom, 0px), var(--tg-safe-area-inset-bottom, 0px)) + var(--tg-content-safe-area-inset-bottom, 0px));
  background: none;
  background-color: transparent;
  background-image: none;
  border: 0;
  box-shadow: none;
  pointer-events: none;
}
#stash-bar {
  position: relative;
  pointer-events: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  box-sizing: border-box;
  width: max-content;
  max-width: calc(100% - 8px);
  height: 48px;
  min-height: 48px;
  max-height: 48px;
  margin: 0;
  padding: 4px 6px;
  overflow-x: auto;
  overflow-y: hidden;
  border-radius: 12px;
  background: rgba(8, 10, 14, 0.62);
  border: 1px solid rgba(255, 220, 160, 0.35);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.28);
}
.stash-label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}
.stash-item.hot-slot {
  width: 40px;
  height: 40px;
  min-width: 40px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 220, 160, 0.28);
}
.stash-item.hot-slot.empty {
  opacity: 0.38;
}
.stash-item.hot-slot img { width: 28px; height: 28px; }
.stash-item.hot-slot b {
  right: 1px;
  bottom: 0;
  min-width: 14px;
  font-size: 10px;
  line-height: 14px;
}
#readout {
  pointer-events: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  box-sizing: border-box;
  width: max-content;
  max-width: calc(100% - 8px);
  min-height: 0;
  max-height: none;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(8, 10, 14, 0.62);
  border: 1px solid rgba(255, 220, 160, 0.28);
  color: #f3e6cf;
}
#hint {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  font-size: 13px;
  line-height: 1.25;
  max-height: 2.5em;
  overflow: hidden;
  text-overflow: ellipsis;
  color: #f3e6cf;
}
#hint strong { color: #e2c07a; }
#log {
  display: none !important;
}
#toast {
  bottom: calc(100% + 8px);
}
#rival-stash {
  position: absolute;
  z-index: 12;
  margin: 0;
  max-width: calc(100% - 16px);
  pointer-events: auto;
}
#rival-stash.hidden { display: none !important; }
.rival-pop {
  display: flex;
  align-items: center;
  gap: 6px;
  box-sizing: border-box;
  height: 48px;
  min-height: 48px;
  max-height: 48px;
  padding: 4px 8px;
  border-radius: 12px;
  background: rgba(8, 10, 14, 0.78);
  border: 1px solid rgba(255, 220, 160, 0.4);
  color: #f3e6cf;
}
.rival-pop .rv-name { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
.rival-slots { display: inline-flex; gap: 3px; }
.rival-pop .hot-slot {
  position: relative;
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 220, 160, 0.25);
}
.rival-pop .hot-slot.empty { opacity: 0.35; }
.rival-pop .hot-slot img { width: 26px; height: 26px; }
.rival-pop .hot-slot b {
  position: absolute;
  right: 1px;
  bottom: 0;
  font-size: 10px;
  line-height: 14px;
  color: #ffe9a8;
}
#menu { z-index: 20; }
#lobby, #cabinet, #endgame, #log-sheet, #tutorial, #paywall, #ad-overlay { z-index: 30; }
@media (max-width: 640px) {
  #log { display: none; }
}
@media (max-width: 360px) {
  #fit-btn, #menu-btn, #buy-pirate { width: 32px; min-width: 32px; height: 32px; min-height: 32px; }
  #scores { gap: 1px; }
  #scores .score { font-size: 10px; padding: 1px 1px; flex: 1 1 0; min-width: 0; }
  #scores.n4 .score b { font-size: 9px; }
  #scores.n3 .score .swatch, #scores.n4 .score .swatch,
  #scores.n5 .score .swatch, #scores.n6 .score .swatch { display: none; }
  #scores.n3 .score, #scores.n4 .score, #scores.n5 .score, #scores.n6 .score {
    border-left: 3px solid var(--team, #e2c07a);
    padding-left: 2px;
    padding-right: 0;
  }
  #scores.n4 .score b, #scores.n5 .score b, #scores.n6 .score b { letter-spacing: -0.12em; }
}
@media (max-width: 520px) {
  #buy-pirate { width: 36px; min-width: 36px; padding: 0; }
  #buy-pirate .buy-coin,
  #buy-pirate b {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
  }
  #fit-btn, #menu-btn { width: 36px; min-width: 36px; padding: 0; }
  #scores { gap: 2px; }
  #scores .score { padding: 2px 3px; gap: 2px; font-size: 11px; flex: 1 1 0; justify-content: center; }
  #scores .score .swatch { width: 8px; height: 8px; }
}
html.theme-light #hud,
html[data-theme="light"] #hud,
html.theme-light #readout,
html[data-theme="light"] #readout,
html.theme-light #stash-bar,
html[data-theme="light"] #stash-bar,
html.theme-light .rival-pop,
html[data-theme="light"] .rival-pop,
html.theme-light #toast,
html[data-theme="light"] #toast,
html.theme-light #log-sheet .panel,
html[data-theme="light"] #log-sheet .panel {
  background: rgba(8, 10, 14, 0.72);
  color: #f3e6cf;
  border-color: rgba(255, 220, 160, 0.35);
}
html.theme-light .stash-item,
html[data-theme="light"] .stash-item,
html.theme-light .rival-pop .hot-slot,
html[data-theme="light"] .rival-pop .hot-slot {
  background: rgba(255, 255, 255, 0.06);
  color: #f3e6cf;
  border-color: rgba(255, 220, 160, 0.28);
}
html.theme-light #hint,
html[data-theme="light"] #hint,
html.theme-light #hint strong,
html[data-theme="light"] #hint strong,
html.theme-light #log-sheet h2,
html[data-theme="light"] #log-sheet h2,
html.theme-light #log-full,
html[data-theme="light"] #log-full,
html.theme-light #log-close,
html[data-theme="light"] #log-close,
html.theme-light #log-open,
html[data-theme="light"] #log-open {
  color: #f3e6cf;
}
#log-open.log-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 32px;
  min-height: 32px;
  min-width: 32px;
  padding: 0 8px;
  border-radius: 8px;
  background: rgba(8, 10, 14, 0.35);
  color: #f3e6cf;
  border: 1px solid rgba(255, 220, 160, 0.35);
  font-size: 12px;
  line-height: 1;
}
#log-open .log-dot {
  position: absolute;
  top: 1px;
  right: 1px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #e24b4b;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.55);
}
#log-open .log-dot[hidden] { display: none; }
#log-sheet {
  position: absolute;
  top: 52px;
  right: 8px;
  bottom: 108px;
  left: auto;
  width: min(300px, calc(100% - 16px));
  z-index: 12;
  display: flex;
  padding: 0;
  background: transparent;
  pointer-events: none;
}
#log-sheet .panel {
  pointer-events: auto;
  width: 100%;
  height: 100%;
  max-height: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  text-align: left;
  overflow: hidden;
  background: rgba(8, 10, 14, 0.78);
  color: #f3e6cf;
  border: 1px solid rgba(255, 220, 160, 0.35);
  border-radius: 12px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.35);
}
#log-sheet .cab-head {
  flex: none;
  padding: 8px 10px;
  border-bottom: 1px solid rgba(255, 220, 160, 0.22);
}
#log-sheet h2 { margin: 0; font-size: 16px; color: #f3e6cf; }
#log-close { color: #f3e6cf; min-height: 32px; }
#log-full {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 8px 10px 12px;
  color: #f3e6cf;
  background: transparent;
}
@media (max-width: 360px) {
  #log-open .log-word {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
  }
  #log-open.log-btn { width: 32px; padding: 0; }
  #log-open.log-btn::before { content: '☰'; font-size: 16px; line-height: 1; }
}
#hud-actions { margin-left: auto; order: 6; }
@media (max-width: 520px) {
  #hud-actions { gap: 2px; }
  #log-open.log-btn { padding: 0 5px; font-size: 11px; }
}
@media (max-width: 420px) {
  #scores.n3 .score .swatch, #scores.n4 .score .swatch,
  #scores.n5 .score .swatch, #scores.n6 .score .swatch { display: none; }
  #scores.n3 .score, #scores.n4 .score, #scores.n5 .score, #scores.n6 .score {
    border-left: 3px solid var(--team, #e2c07a);
    padding-left: 2px;
  }
  #scores.n4 .score b, #scores.n5 .score b, #scores.n6 .score b {
    font-size: 9px;
    letter-spacing: -0.12em;
  }
}
@media (max-width: 360px) {
  #hud {
    padding-left: calc(4px + max(env(safe-area-inset-left, 0px), var(--tg-safe-area-inset-left, 0px)) + var(--tg-content-safe-area-inset-left, 0px));
    padding-right: calc(4px + max(env(safe-area-inset-right, 0px), var(--tg-safe-area-inset-right, 0px)) + var(--tg-content-safe-area-inset-right, 0px));
  }
  #scores { gap: 0; }
  #scores.n4 .score b, #scores.n5 .score b, #scores.n6 .score b { letter-spacing: -0.18em; }
}
