@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);
}
.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;
}
#menu-play .choice[hidden] { display: none; }
.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; }
.cab-card h3, .cab-card h4 { margin: 0 0 8px; 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; }
@media (prefers-reduced-motion: reduce) {
  .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-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-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; }
#endgame .panel.wide {
  position: relative;
  box-sizing: border-box;
  margin: 12px;
  max-height: calc(100% - 24px);
  overflow: auto;
  background: rgb(20 28 35 / 82%);
  color: #fff0d6;
  backdrop-filter: blur(12px);
}
#end-close {
  position: absolute;
  top: 6px;
  right: 6px;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  font-size: 25px;
}
.end-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.end-actions button { min-height: 44px; }
#again-btn[hidden], #results-btn[hidden] { display: none; }
#results-btn { padding-inline: 6px; }
@media (max-width: 420px) {
  #hud:has(#results-btn:not([hidden])) #fit-btn { display: none; }
}

.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; }

.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; }

#menu:has(#menu-leaderboards:not(.hidden)) { padding: 8px; }
.menu-shell:has(#menu-leaderboards:not(.hidden)) {
  width: min(850px, 100%);
  padding: clamp(10px, 3vw, 24px);
  background: linear-gradient(151deg, #1c3233, #131b23 66%);
  color: #f2e9d6;
}
#menu-leaderboards { text-align: start; padding-inline: 2px; overscroll-behavior: contain; }
#menu-leaderboards h2 { margin: 0 0 5px; font-size: clamp(26px, 5vw, 38px); letter-spacing: normal; color: #f4d68e; }
#menu-leaderboards :is(h3, h4) { margin: 0; color: #f6e2b7; overflow-wrap: anywhere; }
#menu-leaderboards h4 { font-size: 15px; }
.ranking-intro, .ranking-rules, .ranking-date, .ranking-empty { margin: 4px 0 10px; color: #c9d7d2; }
.ranking-intro { font-size: 14px; line-height: 1.45; }
.ranking-date { font: 600 12px/1.4 system-ui, sans-serif; }
.ranking-rules, .ranking-empty { font-size: 13px; line-height: 1.4; }
#ranking-summary, #ranking-spotlight { display: grid; gap: 8px; }
#ranking-summary { grid-template-columns: 3fr 2fr; }
#ranking-spotlight { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.ranking-card {
  min-width: 0;
  padding: 10px;
  border: 1px solid #799a905c;
  border-radius: 10px;
  background: #0e1923aa;
}
.ranking-spotlight { margin-block: 16px 8px; }
.ranking-spotlight-head { display: flex; align-items: start; justify-content: space-between; gap: 6px; flex-wrap: wrap; }
#ranking-period { display: flex; gap: 4px; margin-bottom: 7px; }
#ranking-period button, .ranking-demo, #ranking-retry { min-height: 44px; }
#ranking-period [aria-pressed="true"] { color: #0d2825; background: #94d3be; border-color: #94d3be; }
.ranking-list { list-style: none; margin: 7px 0 0; padding: 0; }
.ranking-row {
  display: grid;
  align-items: baseline;
  grid-template-columns: minmax(24px, auto) minmax(0, 1fr) auto;
  gap: 4px;
  padding: 5px 2px;
  border-top: 1px solid #8cb6a733;
  font: 500 13px/1.35 system-ui, sans-serif;
}
.ranking-place { color: #c9d7d2; font-variant-numeric: tabular-nums; }
.ranking-row[value="1"] .ranking-place, .ranking-value { color: #f4d68e; }
.ranking-name { overflow-wrap: anywhere; }
.ranking-you { color: #b4e9d6; }
.ranking-current { background: #3a716647; border-radius: 4px; }
.ranking-value { white-space: nowrap; font-variant-numeric: tabular-nums; }
@media (max-width: 620px) {
  #ranking-summary, #ranking-spotlight { grid-template-columns: minmax(0, 1fr); }
}

.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; }
.pill.finished { background: rgba(80,80,80,0.45); color: #ddd; }
.pill.prize { color: #ffe56a; border-color: rgba(226,192,122,0.5); }
.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-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; }

/* --- экран «Об игре» --- */
.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 #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; }
}
.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"] #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-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; }
}

/* --- 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);
}
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)); }

/* 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(7, 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:has([data-size="O8"].active) #seat-row {
  height: calc(44px * 4 + 6px * 3);
  min-height: calc(44px * 4 + 6px * 3);
  max-height: calc(44px * 4 + 6px * 3);
}
#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, #board-terrain {
  position: absolute;
  inset: 0;
  z-index: 0;
  width: 100%;
  height: 100%;
}
#board-terrain { pointer-events: none; }
#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;
}
#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; }
#spyglass-overlay {
  position: absolute;
  display: grid;
  inset: 0;
  place-content: center;
  padding: 16px;
  z-index: 19;
  background: rgb(12 21 30 / 64%);
  color: #fff3d6;
  text-align: center;
  backdrop-filter: blur(3px);
}
#spyglass-overlay[hidden] { display: none; }
#spyglass-overlay.private {
  inset: auto 10px calc(var(--safe-bottom, 0px) + 66px);
  border-radius: 8px;
  padding: 7px 10px;
  pointer-events: none;
}
#board-legend {
  box-sizing: border-box;
  width: min(650px, calc(100vw - 24px));
  max-height: min(520px, calc(100dvh - 36px));
  border: 1px solid rgb(255 255 255 / 18%);
  border-radius: 13px;
  background: rgb(18 27 34 / 92%);
  color: #fff1d8;
  padding: 12px;
  overflow: auto;
  backdrop-filter: blur(10px);
}
#board-legend::backdrop { background: rgb(0 0 0 / 53%); }
#board-legend .legend-header {
  position: sticky;
  top: -12px;
  background: rgb(18 27 34 / 96%);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  z-index: 1;
}
#board-legend h2 { margin: 0; font-size: 20px; }
#legend-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(240px, 100%), 1fr));
  list-style: none;
  margin: 0;
  padding: 0;
}
#legend-tiles li { display: flex; align-items: center; gap: 8px; min-height: 58px; }
#legend-tiles small { display: block; color: #d3d8d7; }
#legend-tiles canvas { width: 62px; height: 50px; object-fit: contain; flex-shrink: 0; }
#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 #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; }
}

#board-actions {
  position: static;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px;
  max-width: 100%;
}
#board-actions:empty { display: none; }
#board-actions .board-action {
  position: static;
  width: auto;
  height: auto;
  max-width: 100%;
  gap: 4px;
  padding: 2px 8px 2px 3px;
  border: 1px solid #e1b36b;
  border-radius: 10px;
  background: rgba(10, 16, 24, 0.86);
  color: #fff1cf;
  font-size: 12px;
  line-height: 1.2;
}
#board-actions .board-action-face { flex: none; }
#move-confirm { display: flex; gap: 6px; }
#move-confirm.hidden { display: none; }
#move-confirm button, #skip-turn { pointer-events: auto; min-height: 38px; }
#pirate-picker {
  position: absolute;
  z-index: 15;
  left: 50%;
  top: 46%;
  transform: translate(-50%, -50%);
  max-width: calc(100% - 16px);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  padding: 8px;
  border-radius: 12px;
  background: rgba(10, 16, 24, 0.85);
  backdrop-filter: blur(6px);
}
#pirate-picker.hidden { display: none; }
#pirate-picker button { display: grid; justify-items: center; gap: 3px; min-width: 54px; font-size: 12px; }
#pirate-picker button { pointer-events: auto; }
#pirate-picker img { width: 30px; height: 40px; object-fit: contain; }
.move-mode { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; justify-content: space-between; }
#move-mode { min-height: 40px; max-width: 100%; color: var(--tg-button-text); background: var(--tg-button); border-radius: 6px; }
#smart-camera-settings {
  display: grid;
  min-inline-size: 0;
  text-align: start;
  margin: 0;
  padding: 4px 10px 8px;
  border: 1px solid #9bcabc59;
  border-radius: 9px;
}
#smart-camera-settings legend { padding-inline: 5px; font-weight: 700; }
#smart-camera-settings .move-mode {
  display: flex;
  min-height: 44px;
  border-radius: 0;
  border-bottom: 1px solid #9bcabc29;
  padding: 5px 0;
  font-size: 13px;
}
#smart-camera-settings .move-mode:last-child { border-bottom: 0; }
#smart-camera-settings select {
  min-height: 44px;
  max-width: 100%;
  color: var(--tg-button-text);
  background: var(--tg-button);
  border-radius: 6px;
}
#smart-camera-toggle[hidden] { display: none; }
#smart-camera-toggle[aria-pressed="true"] { background: #173d3f; border-color: #a6e0cc; color: #defff3; }

#stash-bar,
html.theme-light #stash-bar,
html[data-theme="light"] #stash-bar {
  height: 42px;
  min-height: 42px;
  max-height: 42px;
  padding: 2px 5px;
  border: 0;
  background: rgba(8, 10, 14, 0.56);
  backdrop-filter: blur(5px);
}
#stash-bar .hot-slot {
  width: 40px;
  height: 40px;
  min-width: 40px;
  border: 0;
  background: transparent;
  flex: 0 0 40px;
}
#stash-bar .hot-slot img { width: 36px; height: 36px; }
#stash-bar .hot-slot b {
  min-width: 17px;
  padding-inline: 2px;
  font: 700 13px/16px system-ui, sans-serif;
  color: #fff1ca;
  background: #201b17;
}
.rival-pop,
html.theme-light .rival-pop,
html[data-theme="light"] .rival-pop {
  background: rgba(8, 10, 14, 0.64);
  backdrop-filter: blur(5px);
  border: 0;
}
.crew-roles { color: #ffe3aa; font-size: 12px; }
#scores .score b { flex: 0 0 auto; white-space: nowrap; }
@media (max-width: 520px) {
  #hud:has(#scores.n5, #scores.n6) { flex-wrap: wrap; }
  #scores.n5, #scores.n6 { flex: 0 0 100%; order: 7; }
  #scores.n2 .score { flex: 1 1 0; }
  #scores.n2 .score .nm {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}
#react-toggle, #react-bar {
  --reaction-side: calc(8px + max(env(safe-area-inset-right, 0px), var(--tg-safe-area-inset-right, 0px)) + var(--tg-content-safe-area-inset-right, 0px));
  position: absolute;
  z-index: 9;
  left: auto;
  top: 51%;
  bottom: auto;
  transform: translateY(-50%);
  background: rgba(8, 10, 14, 0.62);
  backdrop-filter: blur(5px);
}
#react-toggle { right: var(--reaction-side); width: 44px; height: 44px; padding: 0; font-size: 23px; }
#react-bar {
  right: calc(var(--reaction-side) + 48px);
  flex-direction: column;
  flex-wrap: nowrap;
  justify-content: flex-start;
  max-height: 45%;
  overflow: auto;
}
#react-bar button { min-height: 36px; flex: none; }
@media (max-width: 900px) {
  #hud { overflow: visible; }
  #turn-banner:not([hidden]) {
    left: 50%;
    top: calc(100% + 4px);
    translate: -50% 0;
    clip: auto;
    clip-path: none;
    height: 26px;
    min-height: 26px;
    max-width: calc(100vw - 20px);
    background: rgba(8, 10, 14, 0.64);
    backdrop-filter: blur(5px);
  }
}

#action-dock { display: contents; }

@media (max-width: 560px), (pointer: coarse) and (max-width: 900px) {
  #action-dock {
    position: relative;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    align-items: center;
    gap: 6px 8px;
    box-sizing: border-box;
    width: min(100%, 440px);
    padding: 7px;
    color: #fff2d8;
    background: rgba(10, 15, 22, 0.89);
    border: 1px solid rgba(233, 199, 134, 0.43);
    border-radius: 14px;
    backdrop-filter: blur(6px);
  }
  #action-dock:not(:has(#board-actions:not(:empty), :is(#stash-bar, #move-confirm, #skip-turn, #pirate-picker):not(.hidden))) {
    display: none;
  }
  #action-dock #stash-bar {
    grid-row: 1;
    grid-column: 1 / -1;
    width: max-content;
    max-width: 100%;
    height: 42px;
    min-height: 42px;
    max-height: 42px;
    justify-content: flex-start;
    padding: 1px 2px;
    margin: 0;
    background: transparent;
    box-shadow: none;
    backdrop-filter: none;
  }
  #action-dock[data-mode="confirm"] #stash-bar,
  #action-dock[data-mode="pick"] #stash-bar { display: none; }
  #board-actions, #move-confirm, #skip-turn, #pirate-picker { grid-column: 1 / -1; }
  #action-dock button { touch-action: manipulation; }
  #action-dock #board-actions .board-action {
    flex: 1 1 90px;
    min-height: 48px;
    border-color: rgba(233, 199, 134, 0.55);
  }
  #action-dock #move-confirm button, #action-dock #skip-turn { min-height: 48px; }
  #action-dock #move-accept {
    flex: 2 1 0;
    background: #edc477;
    color: #23170d;
    font-weight: 700;
  }
  #action-dock #move-cancel { flex: 1 1 0; color: #fff2d8; }
  #action-dock #pirate-picker {
    position: static;
    transform: none;
    max-width: 100%;
    padding: 0;
    gap: 4px;
    background: transparent;
    backdrop-filter: none;
  }
  #action-dock #pirate-picker button {
    display: grid;
    align-content: center;
    flex: 1 1 48px;
    min-width: 44px;
    min-height: 48px;
    padding: 3px 4px;
  }
  #action-dock #pirate-picker img { width: 24px; height: 30px; }
  #action-dock #pirate-picker .pirate-picker-cancel { flex: 1 1 54px; color: #fff2d8; }
  #action-dock #toast {
    bottom: calc(100% + 5px);
    width: max-content;
    max-width: calc(100% - 12px);
    box-sizing: border-box;
    padding: 5px 10px;
    font-size: 13px;
  }
}

.move-mode:has(input[type="checkbox"]) {
  min-height: 44px;
  cursor: pointer;
}

#render-perf {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 100;
  pointer-events: none;
  background: #0b141c;
  color: #e9f4ff;
  padding: 2px 6px;
  font: 11px monospace;
}

@media (pointer: coarse) {
  #app, #app * {
    -webkit-backdrop-filter: none !important;
    backdrop-filter: none !important;
  }
}

html.app-paused #app * {
  animation-play-state: paused;
}

#auto-play-toggle {
  position: absolute;
  z-index: 9;
  inset: 51% auto auto max(8px, env(safe-area-inset-left, 0px));
  min-width: 44px;
  min-height: 44px;
  font-size: 22px;
  transform: translateY(-50%);
  background: rgba(10, 16, 24, .65);
}

#auto-play-toggle[aria-pressed="true"],
#auto-play-menu[aria-pressed="true"] {
  border-color: #f0cd77;
  color: #ffe6a0;
}

#auto-play-banner, #last-tiles {
  position: absolute;
  z-index: 10;
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100% - 24px);
  width: max-content;
  padding: 5px 10px;
  background: rgba(10, 16, 24, .88);
  color: #fff1cc;
  border: 1px solid rgba(242, 204, 124, .5);
  border-radius: 10px;
  font-size: 12px;
  text-align: center;
}

#last-tiles { top: 25%; pointer-events: none; }

.auto-crew { color: #ffe29c; margin-inline: 3px; }

#game-rules {
  width: min(720px, calc(100% - 24px));
  max-height: calc(100dvh - 24px);
  padding: 0 12px 12px;
  color: #f4e7cb;
  background: #14202a;
  border: 1px solid #76634b;
  border-radius: 14px;
  overflow: auto;
}

#game-rules::backdrop { background: rgba(7, 11, 15, .77); }
#game-rules .legend-header { position: sticky; top: 0; background: #14202a; }
#rules-content ul { list-style: none; margin: 0; padding: 0; }
#rules-content h3 { margin: 14px 0 4px; color: #f5ca7d; }
#rules-content li { display: flex; align-items: center; gap: 8px; border-bottom: 1px solid #ffffff1f; }
#rules-content img, #rules-content canvas { flex: 0 0 72px; object-fit: contain; }
#rules-content p { margin: 3px 0 5px; font-size: 14px; }

#combine-ingots {
  position: absolute;
  z-index: 11;
  pointer-events: none;
  inset: 59% auto auto 50%;
  transform: translateX(-50%);
}

#combine-ingots img { animation: chest-combine .6s ease-out both; }
@keyframes chest-combine {
  0% { transform: scale(.65) translateY(10px); opacity: .4; }
  35% { transform: scale(1.1); opacity: 1; }
  100% { transform: translateY(-28px); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  #combine-ingots img { animation-duration: 1ms; }
}

#menu-play #size-row .choice.shape[hidden] { display: none; }
#scores:is(.n7, .n8) .nm, #scores:is(.n7, .n8) .rv { display: none; }
@media (max-width: 620px) {
  #hud:has(#scores:is(.n7, .n8)) { flex-wrap: wrap; }
  #scores:is(.n7, .n8) {
    flex: 0 0 100%;
    order: 7;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 3px;
  }
  #scores:is(.n7, .n8) .score { padding: 2px 4px; min-width: 0; }
}
@media (max-width: 460px) {
  #hud:has(#scores:not(:empty)) { flex-wrap: wrap; }
  #scores { flex: 0 0 100%; order: 7; }
}

#tile-inspector {
  position: absolute;
  z-index: 6;
  transform: translate(-50%, calc(-100% - 14px));
  color: #f9efd8;
  background: rgba(12, 25, 31, .94);
  border: 1px solid rgba(138, 215, 214, .4);
  border-radius: 8px;
  width: min(17rem, calc(100% - 36px));
  padding: 7px 10px;
  font-size: 13px;
  line-height: 1.35;
  pointer-events: none;
}
#tile-inspector.below { transform: translate(-50%, 14px); }

.crew-helper {
  color: #fff6e7;
  text-shadow: 0 1px 2px #101415, 0 0 2px #101415;
  border: 1px solid #eee2ce;
  border-radius: 3px 3px 6px 6px;
  background: var(--team, #666d70);
  text-align: center;
  flex: 0 0 auto;
  line-height: 1.2;
  min-width: 13px;
  font-size: 10px;
}

.gold-delivered {
  position: absolute;
  z-index: 5;
  inset: auto 2px -10px auto;
  padding: 2px 5px;
  border-radius: 4px;
  background: rgba(21, 34, 33, .9);
  color: #ffdd76;
  font-weight: 700;
  white-space: nowrap;
  pointer-events: none;
  animation: gold-delivered .7s ease-out both;
}

#scores:has(.gold-delivered) { overflow: visible; }
@keyframes gold-delivered {
  from { opacity: 1; transform: translateY(0); }
  66% { opacity: 1; }
  to { opacity: 0; transform: translateY(14px); }
}

.app-paused .gold-delivered { animation-play-state: paused; }
@media (prefers-reduced-motion: reduce) {
  .gold-delivered { animation-duration: .1s; }
}

.team-flag { display: inline-block; width: 23px; height: 23px; object-fit: contain; flex: 0 0 auto; vertical-align: middle; }
@media (max-width: 420px) {
  #scores .team-flag { width: 18px; height: 18px; }
}
.gold-values { width: 100%; border-collapse: collapse; }
.gold-values :is(td, th) { border-bottom: 1px solid rgba(196, 222, 222, .19); padding: 3px 6px; }
.gold-values td:first-child { width: 34px; }
.gold-values th { text-align: left; font-weight: 600; }
.gold-values td:last-child { text-align: right; white-space: nowrap; }
#dock-notices {
  display: flex;
  width: min(100%, 650px);
  flex-direction: column;
  align-items: center;
  gap: 6px;
  pointer-events: none;
}
#dock-notices > :is(#toast, #auto-play-banner, #hint) {
  position: static;
  transform: none;
  width: max-content;
  max-width: 100%;
  box-sizing: border-box;
  padding: 5px 10px;
  font-size: 13px;
}
#dock-notices :is(#auto-play-banner, #tutorial-exit) { pointer-events: auto; }
#dock-notices #tutorial-exit { min-height: 44px; }
#dock-notices #hint {
  max-height: none;
  text-align: center;
  border: 1px solid rgba(255, 220, 160, .28);
  border-radius: 10px;
  background: rgba(8, 10, 14, .68);
}
@media (max-width: 360px) {
  #hud-actions :is(#sound-hud, #fullscreen-hud, #legend-open, #fit-btn, #smart-camera-toggle, #menu-btn, #buy-pirate, #log-open) {
    min-width: 36px;
    min-height: 36px;
  }
}
#menu-play #size-row [data-size="O8"] { padding-inline: 6px; }
#menu-play #size-row [data-size="O8"] span { white-space: normal; overflow: visible; }
#lobby-size [data-lobby-size="O8"], [data-create-size="O8"] {
  white-space: normal;
  overflow-wrap: anywhere;
  max-width: 100%;
}

html[data-training] #dock-notices #hint {
  display: block;
  overflow: visible;
  -webkit-line-clamp: unset;
}
html[data-training] :is(#react-toggle, #log-open, #smart-camera-toggle) { display: none; }

.beta-report-text { width: 100%; min-height: 100px; margin-top: 10px; }
