/* Tidebots — интерфейс.
   Палитра «прилив»: чернильный контур как у игровой графики, бирюзовая вода,
   оранжевый буй для главных действий, солнечно-жёлтый для вторых.
   Мотив — всё «заливается водой снизу»: вордмарк, кнопки при наведении, предупреждения. */

:root {
  --ink: #1a1e3a;
  --ink-2: #3b4270;
  --ink-3: #6a7299;
  --foam: #f4fbff;
  --foam-2: #e2f2fb;
  --foam-3: #cfe6f3;
  --sky-1: #4fb8ff;
  --sky-2: #8fd8ff;
  --sky-3: #c9f1ff;
  --lagoon: #14c4b0;
  --lagoon-2: #0f9c97;
  --deep: #2456d6;
  --buoy: #ff6a2b;
  --buoy-2: #e2501a;
  --sun: #ffcf3a;
  --coral: #ff4466;
  --kelp: #3fcf6a;
  --violet: #7a5cff;

  --r-sm: 12px;
  --r-md: 16px;
  --r-lg: 24px;
  --line: 3px;
  --lift: 0 4px 0 var(--ink);
  --lift-lg: 0 6px 0 var(--ink), 0 22px 40px rgba(16, 30, 80, 0.22);

  --font-display: "Arial Rounded MT Bold", ui-rounded, "SF Pro Rounded", "Nunito", "Trebuchet MS", system-ui, sans-serif;
  --font-body: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;

  --wave-white: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 7'%3E%3Cpath d='M0 7V3.5Q6 0 12 3.5T24 3.5V7Z' fill='white' fill-opacity='.26'/%3E%3C/svg%3E");
}

/* ---------- база ---------- */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--sky-2);
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-body);
  color: var(--ink);
  overscroll-behavior: none;
}

#game {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

#ui {
  position: fixed;
  inset: 0;
  z-index: 10;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
}

.noscript {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  font: 800 20px var(--font-body);
  background: var(--sky-2);
}

.tb-ui [hidden] {
  display: none !important;
}

.tb-ui input,
.tb-ui textarea {
  user-select: text;
  -webkit-user-select: text;
}

.tb-ui h1,
.tb-ui h2,
.tb-ui h3 {
  font-family: var(--font-display);
  margin: 0;
}

.tb-ui kbd {
  display: inline-block;
  min-width: 1.7em;
  padding: 1px 6px;
  border: 2px solid var(--ink);
  border-bottom-width: 4px;
  border-radius: 7px;
  background: #fff;
  font: 800 12px/1.3 var(--font-body);
  text-align: center;
  color: var(--ink);
}

.ico {
  display: inline-flex;
  flex: none;
  width: 1.15em;
  height: 1.15em;
}

.ico svg {
  width: 100%;
  height: 100%;
}

/* ---------- экраны ---------- */

.screen {
  position: absolute;
  inset: 0;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.28s ease, visibility 0s linear 0.28s;
}

.screen.is-active {
  opacity: 1;
  visibility: visible;
  transition: opacity 0.28s ease, visibility 0s;
}

.screen-menu,
.screen-garage,
.screen-lobby,
.screen-results,
.screen-connecting {
  pointer-events: auto;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

.screen-game {
  pointer-events: none;
}

.page {
  width: 100%;
  max-width: 1240px;
  margin: 0 auto;
  transform: translateY(10px);
  transition: transform 0.35s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.screen.is-active .page {
  transform: none;
}

/* ---------- фон: небо, острова, море ---------- */

.backdrop {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: linear-gradient(180deg, var(--sky-1) 0%, var(--sky-2) 48%, var(--sky-3) 74%);
  opacity: 0;
  transition: opacity 0.4s ease;
}

.tb-ui[data-screen="menu"] .backdrop,
.tb-ui[data-screen="garage"] .backdrop,
.tb-ui[data-screen="lobby"] .backdrop,
.tb-ui[data-screen="connecting"] .backdrop {
  opacity: 1;
}

.bd-sun {
  position: absolute;
  top: 8%;
  right: 11%;
  width: 110px;
  height: 110px;
  border-radius: 50%;
  background: #fff3b0;
  box-shadow: 0 0 0 18px rgba(255, 243, 176, 0.35), 0 0 0 42px rgba(255, 243, 176, 0.15);
}

.bd-cloud {
  position: absolute;
  height: 34px;
  border-radius: 34px;
  background: #fff;
  opacity: 0.92;
  animation: cloud-drift 60s linear infinite;
}

.bd-cloud::before,
.bd-cloud::after {
  content: "";
  position: absolute;
  bottom: 10px;
  border-radius: 50%;
  background: #fff;
}

.bd-cloud::before {
  left: 18%;
  width: 54px;
  height: 54px;
}

.bd-cloud::after {
  left: 46%;
  width: 40px;
  height: 40px;
}

.bd-cloud-1 {
  top: 16%;
  left: 8%;
  width: 150px;
}

.bd-cloud-2 {
  top: 30%;
  left: 62%;
  width: 110px;
  opacity: 0.75;
  animation-duration: 85s;
  animation-delay: -30s;
}

.bd-island {
  position: absolute;
  background: #63c79f;
  border-radius: 50% 50% 0 0 / 100% 100% 0 0;
  animation: tide-island 14s ease-in-out infinite alternate;
}

.bd-island-1 {
  left: 4%;
  bottom: 17%;
  width: 300px;
  height: 92px;
}

.bd-island-2 {
  right: 7%;
  bottom: 17%;
  width: 190px;
  height: 58px;
  background: #79d3ad;
}

.bd-sea {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 19%;
  background: linear-gradient(180deg, #1fc9bd 0%, #139bb8 100%);
  animation: tide 14s ease-in-out infinite alternate;
}

.bd-wave {
  position: absolute;
  left: 0;
  right: 0;
  height: 22px;
  background-repeat: repeat-x;
  background-size: 110px 22px;
}

.bd-wave-back {
  top: -26px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 110 22'%3E%3Cpath d='M0 22V12Q27.5 0 55 12T110 12V22Z' fill='%2366e0d2'/%3E%3C/svg%3E");
  opacity: 0.8;
  animation: wave-move 11s linear infinite reverse;
}

.bd-wave-front {
  top: -18px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 110 22'%3E%3Cpath d='M0 22V12Q27.5 2 55 12T110 12V22Z' fill='%231fc9bd'/%3E%3C/svg%3E");
  animation: wave-move 7s linear infinite;
}

@keyframes wave-move {
  from {
    background-position-x: 0;
  }
  to {
    background-position-x: 110px;
  }
}

@keyframes tide {
  from {
    height: 17%;
  }
  to {
    height: 22%;
  }
}

@keyframes tide-island {
  from {
    transform: translateY(0);
  }
  to {
    transform: translateY(6px);
  }
}

@keyframes cloud-drift {
  from {
    transform: translateX(-8vw);
  }
  50% {
    transform: translateX(8vw);
  }
  to {
    transform: translateX(-8vw);
  }
}

/* ---------- панели, кнопки, поля ---------- */

.panel {
  background: var(--foam);
  border: var(--line) solid var(--ink);
  border-radius: var(--r-lg);
  box-shadow: var(--lift-lg);
  padding: 20px;
}

.btn {
  appearance: none;
  position: relative;
  isolation: isolate;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 18px;
  border: var(--line) solid var(--ink);
  border-radius: 14px;
  background: #fff;
  color: var(--ink);
  box-shadow: var(--lift);
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 17px;
  line-height: 1.1;
  letter-spacing: 0.01em;
  cursor: pointer;
  white-space: nowrap;
  transition: transform 0.08s ease, box-shadow 0.08s ease, background-color 0.15s ease, opacity 0.15s;
}

/* «Прилив» при наведении: светлая вода с гребнем поднимается снизу. */
.btn::before {
  content: "";
  position: absolute;
  inset: -2px;
  z-index: -1;
  background: var(--wave-white) 0 0 / 24px 7px repeat-x, linear-gradient(rgba(255, 255, 255, 0.26), rgba(255, 255, 255, 0.26)) 0 7px / 100% 100% no-repeat;
  transform: translateY(102%);
  transition: transform 0.38s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.btn:hover:not(:disabled)::before {
  transform: translateY(0);
  animation: btn-wave 1.2s linear infinite;
}

@keyframes btn-wave {
  to {
    background-position: 24px 0, 0 7px;
  }
}

.btn:active:not(:disabled) {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--ink);
}

.btn:focus-visible,
.input:focus-visible,
.select:focus-visible,
.seg-btn:focus-visible,
.stepper-btn:focus-visible,
.opt-tile:focus-visible,
.opt-chip:focus-visible,
.swatch:focus-visible,
.who-preview:focus-visible,
.range:focus-visible {
  outline: 3px solid var(--deep);
  outline-offset: 3px;
}

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

.btn .ico {
  width: 1.1em;
  height: 1.1em;
}

.btn-primary {
  background: var(--buoy);
  color: #fff;
  text-shadow: 0 2px 0 rgba(26, 30, 58, 0.28);
}

.btn-secondary {
  background: var(--sun);
}

.btn-ink {
  background: var(--ink);
  color: #fff;
  box-shadow: 0 4px 0 #0a0c1e;
}

.btn-ghost {
  background: rgba(255, 255, 255, 0.82);
}

.btn-danger {
  background: var(--coral);
  color: #fff;
  text-shadow: 0 2px 0 rgba(26, 30, 58, 0.25);
}

.btn-big {
  width: 100%;
  font-size: 20px;
  padding: 14px 20px;
  border-radius: var(--r-md);
}

.btn-huge {
  width: 100%;
  font-size: 28px;
  padding: 18px 24px;
  border-radius: 20px;
  box-shadow: 0 6px 0 var(--ink);
}

.btn-huge:active:not(:disabled) {
  transform: translateY(5px);
}

.btn-small {
  font-size: 15px;
  padding: 8px 14px;
  border-radius: var(--r-sm);
  box-shadow: 0 3px 0 var(--ink);
}

.input {
  width: 100%;
  min-width: 0;
  padding: 12px 14px;
  border: var(--line) solid var(--ink);
  border-radius: 14px;
  background: #fff;
  color: var(--ink);
  box-shadow: inset 0 3px 0 rgba(26, 30, 58, 0.08);
  font: 700 18px var(--font-body);
  transition: border-color 0.15s;
}

.input::placeholder {
  color: #9aa2c0;
  font-weight: 600;
}

.field {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.field-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font: 800 13px var(--font-body);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-2);
}

.field-hint {
  font-size: 13px;
  line-height: 1.35;
  color: var(--ink-2);
}

.select-wrap {
  position: relative;
}

.select-wrap::after {
  content: "";
  position: absolute;
  right: 16px;
  top: 50%;
  width: 9px;
  height: 9px;
  border-right: 3px solid var(--ink);
  border-bottom: 3px solid var(--ink);
  transform: translateY(-70%) rotate(45deg);
  pointer-events: none;
}

.select {
  appearance: none;
  width: 100%;
  padding: 11px 42px 11px 14px;
  border: var(--line) solid var(--ink);
  border-radius: 14px;
  background: #fff;
  color: var(--ink);
  font: 800 17px var(--font-body);
  cursor: pointer;
}

.select:disabled {
  cursor: default;
  opacity: 1;
  background: var(--foam-2);
}

.range {
  --fill: 80%;
  appearance: none;
  width: 100%;
  height: 14px;
  border: var(--line) solid var(--ink);
  border-radius: 999px;
  background: linear-gradient(90deg, var(--lagoon) var(--fill), #fff var(--fill));
  cursor: pointer;
}

.range::-webkit-slider-thumb {
  appearance: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: var(--line) solid var(--ink);
  background: var(--sun);
  box-shadow: 0 2px 0 var(--ink);
}

.range::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: var(--line) solid var(--ink);
  background: var(--sun);
}

/* ---------- метки ---------- */

.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: #fff;
  font: 800 12px/1.3 var(--font-body);
  white-space: nowrap;
}

.tag .ico {
  width: 13px;
  height: 13px;
}

.tag-host {
  background: var(--sun);
}

.tag-me {
  background: var(--buoy);
  color: #fff;
}

.tag-bot {
  background: #e6e0ff;
}

.tag-spec {
  background: var(--foam-3);
}

/* ---------- главное меню ---------- */

.menu-wrap {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 22px;
  padding: 12px 0 28px;
}

.menu-wrap > :first-child {
  margin-top: auto;
}

.menu-wrap > :last-child {
  margin-bottom: auto;
}

.brand {
  text-align: center;
}

.wordmark {
  position: relative;
  display: inline-block;
  font-family: var(--font-display);
  font-weight: 900;
  font-size: clamp(60px, 11vw, 136px);
  line-height: 0.95;
  letter-spacing: -0.01em;
  padding: 0 0.08em 0.16em;
}

.wm-inner {
  display: inline-flex;
  letter-spacing: 0.015em;
  filter: drop-shadow(0 0.06em 0 var(--ink));
}

.wm-word {
  display: inline-flex;
}

.wm-bots {
  margin-left: 0.06em;
}

/* Буквы наполовину в воде: линия прилива ходит вверх-вниз волной по слову.
   Сама буква — толстый чернильный контур, заливка лежит сверху в ::after. */
.wm-l {
  --top: var(--sun);
  --top-2: #fff1a8;
  position: relative;
  display: inline-block;
  color: var(--ink);
  -webkit-text-stroke: 0.11em var(--ink);
  animation: wm-bob 3.4s ease-in-out infinite;
  animation-delay: calc(var(--i) * -0.22s);
}

.wm-l::after {
  content: attr(data-ch);
  position: absolute;
  inset: 0;
  color: transparent;
  -webkit-text-stroke: 0;
  background: linear-gradient(180deg, var(--top-2) 0%, var(--top) 36% 49%, #eafffb 49% 53%, #3fe0cc 53%, #0fa6a0 100%);
  background-size: 100% 200%;
  background-position: 0 30%;
  -webkit-background-clip: text;
  background-clip: text;
  animation: wm-tide 5.5s ease-in-out infinite;
  animation-delay: calc(var(--i) * -0.35s);
}

.wm-bots .wm-l {
  --top: var(--buoy);
  --top-2: #ffb27f;
}

@keyframes wm-bob {
  0%,
  100% {
    transform: translateY(0) rotate(-2deg);
  }
  50% {
    transform: translateY(-0.05em) rotate(2deg);
  }
}

@keyframes wm-tide {
  0%,
  100% {
    background-position: 0 22%;
  }
  50% {
    background-position: 0 40%;
  }
}

.wm-wave {
  position: absolute;
  left: 4%;
  right: 4%;
  bottom: 0;
  height: 0.13em;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 10'%3E%3Cpath d='M0 5Q10 -1 20 5T40 5' fill='none' stroke='%231a1e3a' stroke-width='3.2' stroke-linecap='round'/%3E%3C/svg%3E") 0 50% / 0.42em 100% repeat-x;
  animation: wm-wave 2.6s linear infinite;
}

@keyframes wm-wave {
  to {
    background-position-x: 0.42em;
  }
}

.tagline {
  margin: 10px auto 0;
  max-width: 34ch;
  font: 700 clamp(16px, 2vw, 19px)/1.35 var(--font-body);
  color: var(--ink);
  text-wrap: balance;
}

.menu-card {
  width: min(440px, 100%);
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 22px;
}

.who {
  display: flex;
  align-items: flex-end;
  gap: 14px;
}

.who-preview {
  position: relative;
  flex: none;
  width: 96px;
  height: 84px;
  padding: 0;
  border: var(--line) solid var(--ink);
  border-radius: 18px;
  background: linear-gradient(180deg, var(--sky-2) 0 68%, var(--lagoon) 68% 100%);
  box-shadow: var(--lift);
  cursor: pointer;
  transition: transform 0.12s;
}

.who-preview:hover {
  transform: translateY(-2px) rotate(-2deg);
}

.who-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.who-badge {
  position: absolute;
  left: 50%;
  bottom: -11px;
  transform: translateX(-50%);
  padding: 1px 8px;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  font: 800 11px/1.4 var(--font-body);
  white-space: nowrap;
}

.who-canvas {
  border-radius: 15px;
}

.field-name {
  flex: 1;
}

.input-name {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 800;
}

.invite {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border: 2px dashed var(--ink);
  border-radius: 14px;
  background: #fff4c6;
  font-weight: 700;
}

.invite-code {
  font-family: var(--font-mono);
  font-weight: 900;
  letter-spacing: 0.12em;
}

.menu-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.has-invite .join-form {
  order: -1;
}

.join-form {
  display: flex;
  gap: 10px;
}

.input-code {
  flex: 1;
  font: 900 24px var(--font-mono);
  letter-spacing: 0.3em;
  text-transform: uppercase;
  text-align: center;
  padding: 10px 8px;
}

.input-code::placeholder {
  letter-spacing: 0.2em;
}

.join-go {
  min-width: 112px;
  font-size: 19px;
}

.menu-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.menu-settings {
  padding: 14px;
  border-radius: 14px;
  background: var(--foam-2);
  border: 2px solid var(--foam-3);
}

.setting-row {
  display: grid;
  grid-template-columns: auto 1fr 46px;
  align-items: center;
  gap: 12px;
  font-weight: 800;
}

.setting-name {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.vol-out {
  font: 800 14px var(--font-mono);
  text-align: right;
}

.controls-hint {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 16px;
  max-width: 820px;
  padding: 10px 16px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.62);
  font-size: 14px;
  font-weight: 700;
  color: var(--ink-2);
}

.controls-hint kbd + kbd {
  margin-left: 3px;
}

/* ---------- общая шапка страниц ---------- */

.page-head {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 18px;
}

.page-title {
  flex: 1;
  min-width: 0;
}

.page-title h2 {
  font-size: clamp(28px, 4vw, 40px);
  line-height: 1;
  color: #fff;
  -webkit-text-stroke: 0.09em var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 0.09em 0 var(--ink);
}

.page-sub {
  margin: 6px 0 0;
  font-weight: 700;
  color: var(--ink);
}

.btn-back {
  flex: none;
}

.card-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 20px;
  margin-bottom: 14px;
}

.card-count {
  margin-left: auto;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  font: 800 14px/1.5 var(--font-mono);
}

.card-eyebrow {
  font: 800 13px var(--font-body);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-2);
}

.card-note {
  margin: 0;
  font-size: 14px;
  color: var(--ink-2);
}

/* ---------- гараж ---------- */

.garage-page {
  display: flex;
  flex-direction: column;
  min-height: 100%;
}

.garage-body {
  display: grid;
  grid-template-columns: minmax(300px, 420px) 1fr;
  gap: 20px;
  align-items: start;
}

.garage-stage {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 16px;
}

.stage-sky {
  position: relative;
  width: 100%;
  aspect-ratio: 6 / 5;
  border: var(--line) solid var(--ink);
  border-radius: 18px;
  overflow: hidden;
  background: radial-gradient(circle at 80% 18%, #fff6c4 0 9%, transparent 9.5%), linear-gradient(180deg, var(--sky-1), var(--sky-3));
}

.stage-sky::after {
  content: "";
  position: absolute;
  left: -10%;
  right: -10%;
  bottom: 0;
  height: 15%;
  background: var(--wave-white) 0 0 / 40px 10px repeat-x, linear-gradient(#1fc9bd, #139bb8) 0 9px / 100% 100% no-repeat;
  animation: stage-water 4s linear infinite;
}

@keyframes stage-water {
  to {
    background-position: 40px 0, 0 9px;
  }
}

.stage-island {
  position: absolute;
  left: 17%;
  right: 17%;
  bottom: 4%;
  height: 26%;
  border: var(--line) solid var(--ink);
  border-radius: 50% 50% 44% 44% / 34% 34% 66% 66%;
  background: linear-gradient(180deg, #5bd36d 0 20%, #b47a43 20% 100%);
  box-shadow: inset 0 -10px 0 rgba(26, 30, 58, 0.15);
}

.garage-canvas {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
}

.stage-sky.is-pop .garage-canvas {
  animation: pop 0.35s cubic-bezier(0.2, 1.6, 0.4, 1);
}

@keyframes pop {
  from {
    transform: scale(0.85);
  }
  to {
    transform: scale(1);
  }
}

.garage-name {
  margin-top: -30px;
  z-index: 2;
  max-width: 90%;
  padding: 5px 16px;
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  font: 900 20px var(--font-display);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stage-actions {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  width: 100%;
}

.garage-editor-panel {
  padding: 20px 22px 8px;
}

.opt-group {
  margin-bottom: 22px;
}

.opt-title {
  font-size: 17px;
  margin-bottom: 10px;
}

.opt-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(86px, 1fr));
  gap: 10px;
}

.opt-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 4px 4px 7px;
  border: var(--line) solid var(--ink);
  border-radius: 14px;
  background: var(--foam-2);
  box-shadow: 0 3px 0 var(--ink);
  color: var(--ink);
  cursor: pointer;
  transition: transform 0.1s, background-color 0.15s;
}

.opt-tile:hover {
  transform: translateY(-2px);
  background: #fff;
}

.opt-tile[aria-checked="true"] {
  background: #fff;
  box-shadow: 0 3px 0 var(--ink), inset 0 0 0 3px var(--sun);
}

.opt-tile[aria-checked="true"] .opt-label {
  background: var(--ink);
  color: #fff;
}

.opt-canvas {
  width: 72px;
  height: 58px;
}

.opt-label {
  padding: 1px 8px;
  border-radius: 999px;
  font: 800 12px/1.4 var(--font-body);
  white-space: nowrap;
}

.opt-chips,
.opt-swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.opt-chip {
  padding: 8px 16px;
  border: var(--line) solid var(--ink);
  border-radius: 999px;
  background: var(--foam-2);
  box-shadow: 0 3px 0 var(--ink);
  color: var(--ink);
  font: 800 15px var(--font-body);
  cursor: pointer;
}

.opt-chip[aria-checked="true"] {
  background: var(--deep);
  color: #fff;
}

.swatch {
  position: relative;
  width: 34px;
  height: 34px;
  padding: 0;
  border: var(--line) solid var(--ink);
  border-radius: 50%;
  background: var(--c, #fff);
  box-shadow: 0 3px 0 var(--ink);
  cursor: pointer;
  transition: transform 0.1s;
}

.swatch:hover {
  transform: translateY(-2px);
}

.swatch[aria-checked="true"],
.swatch-custom.is-on {
  transform: scale(1.12);
  box-shadow: 0 3px 0 var(--ink), inset 0 0 0 3px #fff;
}

.swatch-custom {
  display: grid;
  place-items: center;
  overflow: hidden;
  background: conic-gradient(#ff4466, #ffcf3a, #3fcf6a, #14c4b0, #2f8cff, #7a5cff, #ff4466);
}

.swatch-custom.is-on {
  background: var(--c);
}

.swatch-custom.is-on .swatch-plus {
  display: none;
}

.swatch-plus {
  font: 900 20px/1 var(--font-display);
  color: #fff;
  -webkit-text-stroke: 4px var(--ink);
  paint-order: stroke fill;
  pointer-events: none;
}

.swatch-custom-input {
  position: absolute;
  inset: 0;
  opacity: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
}

/* ---------- лобби ---------- */

.lobby-page {
  display: flex;
  flex-direction: column;
  min-height: 100%;
}

.state-note {
  margin: -6px 0 14px;
  padding: 10px 16px;
  border: 2px dashed var(--ink);
  border-radius: 14px;
  background: #fff4c6;
  font-weight: 800;
}

.lobby-grid {
  flex: 1;
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(290px, 1fr) minmax(340px, 1.15fr) minmax(280px, 0.95fr);
  grid-template-rows: auto 1fr auto;
  grid-template-areas:
    "code settings chat"
    "players settings chat"
    "players start chat";
  min-height: 0;
}

.code-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #fff;
}

.code-tiles {
  display: flex;
  gap: 8px;
}

.code-tile {
  flex: 1;
  display: grid;
  place-items: center;
  height: 64px;
  border: var(--line) solid var(--ink);
  border-radius: 14px;
  background: var(--sun);
  box-shadow: 0 4px 0 var(--ink);
  font: 900 36px var(--font-mono);
  color: var(--ink);
  transform: rotate(calc((var(--i) - 2) * 1.4deg));
  animation: tile-in 0.4s cubic-bezier(0.2, 1.5, 0.4, 1) both;
  animation-delay: calc(var(--i) * 0.05s);
}

.code-tile:nth-child(even) {
  background: var(--foam);
}

@keyframes tile-in {
  from {
    transform: translateY(16px) scale(0.6);
    opacity: 0;
  }
}

.btn-copy.is-done {
  background: var(--kelp);
}

.players-card {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.player-list {
  list-style: none;
  margin: 0;
  padding: 0 4px 4px 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  min-height: 0;
}

.player {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr) auto;
  align-items: center;
  gap: 4px 10px;
  padding: 4px 10px 4px 4px;
  border: 2px solid var(--foam-3);
  border-radius: 16px;
  background: #fff;
}

.player.is-me {
  border-color: var(--buoy);
  background: #fff3ec;
}

.player.is-spec {
  opacity: 0.7;
}

.player-skin {
  width: 56px;
  height: 48px;
  border-radius: 12px;
  background: linear-gradient(180deg, var(--sky-3) 0 70%, #bfeee8 70%);
}

.player-name {
  font: 800 17px var(--font-display);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tags {
  display: flex;
  gap: 4px;
}

.player-ghost,
.player-free {
  border: 2px dashed var(--ink-3);
  background: transparent;
}

.player-ghost {
  grid-template-columns: 56px minmax(0, 1fr);
}

.player-ghost .player-sub {
  grid-column: 2;
  margin-top: -6px;
  font-size: 13px;
  color: var(--ink-2);
}

.ghost-skin {
  display: grid;
  place-items: center;
  color: var(--violet);
  font-size: 28px;
  background: #efeaff;
}

.player-free {
  display: block;
  padding: 10px 14px;
  text-align: center;
}

.player-free .player-name {
  font: 700 14px var(--font-body);
  color: var(--ink-2);
}

.settings-card {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.settings-card .card-title {
  margin-bottom: 0;
}

.readonly-note {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: -4px 0 0;
  padding: 8px 12px;
  border-radius: 12px;
  background: var(--foam-2);
  font-weight: 700;
  color: var(--ink-2);
}

.setting {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.setting-label {
  font: 800 13px var(--font-body);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-2);
}

.setting-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.stepper {
  display: inline-flex;
  align-items: stretch;
  width: fit-content;
  border: var(--line) solid var(--ink);
  border-radius: 14px;
  background: #fff;
  overflow: hidden;
}

.stepper-btn {
  display: grid;
  place-items: center;
  width: 44px;
  height: 42px;
  border: 0;
  background: var(--foam-2);
  color: var(--ink);
  font-size: 18px;
  cursor: pointer;
}

.stepper-btn:hover:not(:disabled) {
  background: var(--sun);
}

.stepper-btn:disabled {
  color: #b9c0d8;
  cursor: default;
}

.stepper-val {
  display: grid;
  place-items: center;
  min-width: 52px;
  border-inline: var(--line) solid var(--ink);
  font: 900 21px var(--font-display);
}

.seg {
  display: flex;
  gap: 3px;
  padding: 3px;
  border: var(--line) solid var(--ink);
  border-radius: 14px;
  background: var(--foam-2);
}

.seg-btn {
  flex: 1;
  min-width: 0;
  padding: 8px 6px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--ink);
  font: 800 15px var(--font-body);
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s;
}

.seg-btn:hover:not(:disabled):not([aria-checked="true"]) {
  background: #fff;
}

.seg-btn[aria-checked="true"] {
  background: var(--deep);
  color: #fff;
  box-shadow: 0 2px 0 var(--ink);
}

.seg-btn:disabled {
  cursor: default;
}

.is-readonly .seg-btn:disabled:not([aria-checked="true"]) {
  color: #9aa2c0;
}

.is-readonly .seg-btn[aria-checked="true"] {
  background: var(--ink-2);
}

.start-bar {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.btn-start .ico {
  width: 0.9em;
  height: 0.9em;
}

.start-hint {
  margin: 2px 0 0;
  text-align: center;
  font-weight: 700;
  font-size: 14px;
  color: var(--ink);
}

.wait-box {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 18px;
  border: var(--line) dashed var(--ink);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.85);
  font: 800 17px var(--font-display);
}

.wait-dots {
  display: inline-flex;
  gap: 5px;
}

.wait-dots i {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--lagoon);
  border: 2px solid var(--ink);
  animation: dot 1.2s ease-in-out infinite;
}

.wait-dots i:nth-child(2) {
  animation-delay: 0.15s;
}

.wait-dots i:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes dot {
  0%,
  100% {
    transform: translateY(0);
  }
  40% {
    transform: translateY(-7px);
  }
}

.chat-card {
  display: flex;
  flex-direction: column;
  min-height: 300px;
}

.chat-card .card-title .ico {
  color: var(--deep);
}

.chat-log-panel {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px;
  margin-bottom: 12px;
  border-radius: 14px;
  background: #fff;
  border: 2px solid var(--foam-3);
  user-select: text;
  -webkit-user-select: text;
}

.chat-empty {
  margin: auto;
  max-width: 24ch;
  text-align: center;
  color: var(--ink-3);
  font-weight: 700;
}

.msg {
  font-size: 15px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.msg-dot {
  display: inline-block;
  width: 11px;
  height: 11px;
  margin-right: 6px;
  border: 2px solid var(--ink);
  border-radius: 50%;
  vertical-align: -1px;
}

.msg-from {
  margin-right: 6px;
  font-family: var(--font-display);
}

.msg-from::after {
  content: ":";
}

.msg-mine .msg-from {
  color: var(--buoy-2);
}

.msg-system {
  align-self: center;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--foam-2);
  font-size: 13px;
  font-weight: 700;
  color: var(--ink-2);
}

.chat-form {
  display: flex;
  gap: 8px;
}

.chat-form .input {
  font-size: 16px;
  padding: 10px 12px;
}

/* ---------- подключение ---------- */

.screen-connecting {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  place-items: center;
}

.conn-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  text-align: center;
}

.conn-buoy {
  position: relative;
  display: grid;
  place-items: center;
  width: 110px;
  height: 110px;
  border: var(--line) solid var(--ink);
  border-radius: 50%;
  background: var(--buoy);
  color: #fff;
  font-size: 54px;
  box-shadow: var(--lift);
  animation: buoy 1.6s ease-in-out infinite;
}

.conn-ring {
  position: absolute;
  inset: -4px;
  border: 3px solid #fff;
  border-radius: 50%;
  opacity: 0;
  animation: ring 2s ease-out infinite;
}

.conn-ring + .conn-ring {
  animation-delay: 1s;
}

@keyframes buoy {
  0%,
  100% {
    transform: translateY(0) rotate(-6deg);
  }
  50% {
    transform: translateY(-10px) rotate(6deg);
  }
}

@keyframes ring {
  from {
    transform: scale(1);
    opacity: 0.9;
  }
  to {
    transform: scale(1.9);
    opacity: 0;
  }
}

.conn-text {
  margin: 0;
  font: 900 26px var(--font-display);
  color: #fff;
  -webkit-text-stroke: 0.1em var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 0.1em 0 var(--ink);
}

/* ---------- итоги ---------- */

.screen-results {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  place-items: center;
  background: radial-gradient(ellipse at 50% 30%, rgba(26, 30, 58, 0.35), rgba(16, 20, 44, 0.72));
}

.res-card {
  width: min(760px, 100%);
  padding: 22px;
  transform: translateY(16px) scale(0.98);
  transition: transform 0.4s cubic-bezier(0.2, 1.3, 0.4, 1);
}

.screen-results.is-active .res-card {
  transform: none;
}

.res-head {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 18px;
}

.res-winner {
  flex: none;
  width: 120px;
  height: 100px;
  border: var(--line) solid var(--ink);
  border-radius: 18px;
  background: radial-gradient(circle at 50% 60%, #fff6c4 0 35%, transparent 36%), linear-gradient(180deg, var(--sun), #ffb547);
  box-shadow: var(--lift);
}

.res-winner-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.res-eyebrow {
  font: 800 13px var(--font-body);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-2);
  margin-bottom: 4px;
}

.res-heading {
  min-width: 0;
}

.res-title.is-name {
  font-size: clamp(28px, 4.6vw, 46px);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  overflow-wrap: normal;
  padding-bottom: 0.1em;
}

.res-title {
  font-size: clamp(34px, 6vw, 56px);
  line-height: 1;
  color: #fff;
  -webkit-text-stroke: 0.09em var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 0.08em 0 var(--ink);
  overflow-wrap: anywhere;
}

[data-outcome="win"] .res-title {
  color: var(--sun);
}

[data-outcome="draw"] .res-title {
  color: var(--sky-3);
}

.res-sub {
  margin: 8px 0 0;
  font-weight: 700;
  font-size: 17px;
}

.res-table-wrap {
  overflow-x: auto;
  border-radius: 16px;
  border: var(--line) solid var(--ink);
  background: #fff;
}

.res-table,
.sb-table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

.res-table th,
.sb-table th {
  padding: 10px 12px;
  background: var(--ink);
  color: #fff;
  font: 800 12px var(--font-body);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  text-align: right;
  white-space: nowrap;
}

.res-table th .ico,
.th-short {
  display: none;
}

.res-table th.res-name,
.res-table th.res-place,
.sb-table th.sb-name {
  text-align: left;
}

.res-table td {
  padding: 8px 12px;
  border-top: 2px solid var(--foam-2);
  font-weight: 700;
  text-align: right;
  white-space: nowrap;
}

.res-table tbody tr {
  animation: row-in 0.35s ease both;
  animation-delay: calc(var(--i) * 0.04s + 0.1s);
}

@keyframes row-in {
  from {
    opacity: 0;
    transform: translateX(-10px);
  }
}

.res-table td.res-name {
  text-align: left;
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.res-player {
  font: 800 17px var(--font-display);
  margin-right: 6px;
  vertical-align: middle;
}

.res-name .tag,
.res-name .res-crown {
  vertical-align: middle;
  margin-right: 4px;
}

.res-crown {
  display: inline-flex;
  color: #f0a500;
}

.res-table td.res-place {
  text-align: left;
  width: 64px;
}

.place-badge {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: var(--foam-2);
  font: 900 15px var(--font-display);
}

.place-1 .place-badge {
  background: var(--sun);
}

.place-2 .place-badge {
  background: #dfe7f3;
}

.place-3 .place-badge {
  background: #efb07a;
}

.res-table tr.is-me td {
  background: #fff0e6;
}

.res-table tr.is-me td:first-child {
  box-shadow: inset 5px 0 0 var(--buoy);
}

.res-num.is-best {
  color: var(--buoy-2);
  font-weight: 900;
}

.res-empty {
  text-align: center !important;
  color: var(--ink-3);
}

.res-footer {
  margin: 16px 0 0;
  text-align: center;
  font-weight: 700;
  color: var(--ink-2);
}

.res-count {
  color: var(--ink);
}

/* ---------- HUD ---------- */

.hud-top {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.hud-stats {
  display: flex;
  gap: 8px;
}

.stat {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px 5px 8px;
  border: var(--line) solid var(--ink);
  border-radius: 999px;
  background: var(--foam);
  box-shadow: 0 3px 0 var(--ink);
}

.stat .ico {
  width: 22px;
  height: 22px;
}

.stat-alive .ico {
  color: var(--deep);
}

.stat-kills .ico {
  color: var(--coral);
}

.stat-coins .ico {
  color: #ffb800;
}

.stat-val {
  font: 900 21px/1 var(--font-display);
  font-variant-numeric: tabular-nums;
}

.stat-label {
  font-size: 12px;
  font-weight: 800;
  color: var(--ink-2);
}

.bump {
  animation: bump 0.35s cubic-bezier(0.2, 1.8, 0.4, 1);
}

@keyframes bump {
  from {
    transform: scale(1.25);
  }
  to {
    transform: scale(1);
  }
}

.spectate {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px 6px 14px;
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  font-weight: 700;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.25);
}

.spec-name {
  font-family: var(--font-display);
  color: var(--sun);
}

.spec-hint {
  display: inline-flex;
  gap: 3px;
}

.spec-hint kbd {
  font-size: 11px;
  min-width: 1.6em;
  padding: 0 4px;
}

.water-warn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 16px;
  border: var(--line) solid var(--ink);
  border-radius: 999px;
  background: var(--lagoon);
  color: #fff;
  font: 900 16px var(--font-display);
  text-shadow: 0 2px 0 rgba(26, 30, 58, 0.35);
  box-shadow: 0 3px 0 var(--ink);
  animation: warn-in 0.3s ease;
}

.water-warn .ico {
  width: 22px;
  height: 22px;
}

.water-warn[data-level="danger"] {
  background: var(--coral);
  animation: warn-pulse 0.7s ease-in-out infinite;
}

@keyframes warn-in {
  from {
    transform: translateY(-8px);
    opacity: 0;
  }
}

@keyframes warn-pulse {
  50% {
    transform: scale(1.06);
  }
}

.killfeed {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  max-width: min(420px, 40vw);
}

.kf-row {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  padding: 5px 12px;
  border-radius: 12px;
  background: rgba(26, 30, 58, 0.8);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  animation: kf-in 0.3s cubic-bezier(0.2, 1.4, 0.4, 1);
  transition: opacity 0.4s, transform 0.4s;
}

.kf-row.kf-mine {
  box-shadow: inset 0 0 0 2px var(--sun);
}

.kf-row.is-leaving {
  opacity: 0;
  transform: translateX(-14px);
}

@keyframes kf-in {
  from {
    opacity: 0;
    transform: translateX(-20px);
  }
}

.kf-name {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  font-family: var(--font-display);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.kf-name::before {
  content: "";
  flex: none;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--c, #9aa4c2);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.85);
}

.kf-name.is-me {
  color: var(--sun);
}

.kf-icon {
  flex: none;
  width: 30px;
  height: 30px;
}

.kf-weapon {
  flex: none;
  padding: 1px 7px;
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.16);
  font-size: 12px;
  font-weight: 800;
  color: #ffd6c4;
}

.kf-cause {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: #ffd6c4;
  white-space: nowrap;
}

.kf-water {
  color: #8ff0e6;
}

.announce {
  position: absolute;
  left: 0;
  right: 0;
  top: 30%;
  padding: 0 16px;
  text-align: center;
  font: 900 clamp(44px, 7.5vw, 92px)/1 var(--font-display);
  color: #fff;
  -webkit-text-stroke: 0.08em var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 0.08em 0 var(--ink);
  opacity: 0;
  pointer-events: none;
  overflow-wrap: anywhere;
}

.announce.is-huge {
  top: 24%;
  font-size: clamp(110px, 18vw, 200px);
  color: var(--sun);
}

.announce.is-long {
  font-size: clamp(30px, 5vw, 60px);
}

.announce.is-in {
  animation: ann-in 0.45s cubic-bezier(0.2, 1.6, 0.4, 1) forwards;
}

.announce.is-in.is-out {
  animation: ann-out 0.35s ease forwards;
}

@keyframes ann-in {
  from {
    opacity: 0;
    transform: scale(0.4) rotate(-6deg);
  }
  to {
    opacity: 1;
    transform: scale(1) rotate(0);
  }
}

@keyframes ann-out {
  from {
    opacity: 1;
    transform: scale(1);
  }
  to {
    opacity: 0;
    transform: scale(1.15) translateY(-10px);
  }
}

.hud-bl {
  position: absolute;
  left: max(14px, env(safe-area-inset-left));
  bottom: max(14px, env(safe-area-inset-bottom));
  width: min(340px, 34vw);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.vitals {
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: opacity 0.3s, filter 0.3s;
}

.bar {
  position: relative;
  height: 32px;
  border: var(--line) solid var(--ink);
  border-radius: 999px;
  background: rgba(26, 30, 58, 0.6);
  box-shadow: 0 3px 0 var(--ink);
  overflow: hidden;
  display: flex;
  align-items: center;
}

.bar-fill,
.bar-ghost {
  position: absolute;
  inset: 0;
  transform-origin: left center;
}

.bar-ghost {
  background: #fff;
  transition: transform 0.6s ease 0.25s;
}

.bar-fill {
  transition: transform 0.18s ease-out;
}

.bar-hp .bar-fill {
  background: linear-gradient(180deg, #7aea93 0 40%, #34b85a 40%);
}

.bar-hp[data-level="mid"] .bar-fill {
  background: linear-gradient(180deg, #ffe07a 0 40%, #f0a92a 40%);
}

.bar-hp[data-level="low"] .bar-fill {
  background: linear-gradient(180deg, #ff8aa0 0 40%, #ff4466 40%);
}

.bar-hp[data-level="low"] {
  animation: low-hp 0.9s ease-in-out infinite;
}

@keyframes low-hp {
  50% {
    box-shadow: 0 3px 0 var(--ink), 0 0 0 4px rgba(255, 68, 102, 0.45);
  }
}

.bar-hp.is-hit {
  animation: hit 0.3s ease;
}

@keyframes hit {
  25% {
    transform: translateX(-4px);
  }
  50% {
    transform: translateX(4px);
  }
  75% {
    transform: translateX(-2px);
  }
}

.bar-icon {
  position: relative;
  z-index: 1;
  display: inline-flex;
  margin-left: 8px;
  color: #fff;
  filter: drop-shadow(0 1.5px 0 var(--ink)) drop-shadow(0 -1px 0 var(--ink)) drop-shadow(1px 0 0 var(--ink)) drop-shadow(-1px 0 0 var(--ink));
}

.bar-icon .ico {
  width: 18px;
  height: 18px;
}

.bar-num {
  position: relative;
  z-index: 1;
  margin-left: 6px;
  font: 900 20px/1 var(--font-display);
  color: #fff;
  -webkit-text-stroke: 4px var(--ink);
  paint-order: stroke fill;
  font-variant-numeric: tabular-nums;
}

.bar-shield {
  height: 22px;
  width: 78%;
}

.bar-shield .bar-fill {
  background: linear-gradient(180deg, #a9f1ff 0 40%, #39b8ff 40%);
}

.bar-shield .bar-num {
  font-size: 15px;
  -webkit-text-stroke-width: 3.5px;
}

.bar-shield .bar-icon .ico {
  width: 15px;
  height: 15px;
}

.weapons {
  position: absolute;
  left: 50%;
  bottom: max(14px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  align-items: flex-end;
  gap: 6px;
  transition: opacity 0.3s, filter 0.3s;
}

.weapons-swap {
  align-self: center;
  opacity: 0.85;
}

.slot {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 150px;
  padding: 6px 14px 6px 6px;
  border: var(--line) solid var(--ink);
  border-radius: 18px;
  background: var(--foam-2);
  box-shadow: 0 3px 0 var(--ink);
  opacity: 0.8;
  transform: scale(0.9);
  transform-origin: 50% 100%;
  transition: transform 0.15s ease, opacity 0.15s, background-color 0.15s;
}

.slot.is-active {
  opacity: 1;
  transform: scale(1);
  background: #fff;
  box-shadow: 0 4px 0 var(--ink), 0 0 0 4px var(--sun);
}

.slot-key {
  position: absolute;
  top: -11px;
  left: -7px;
  padding: 1px 7px;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  font: 800 12px/1.5 var(--font-body);
}

.slot-art {
  position: relative;
  display: grid;
  place-items: center;
  flex: none;
  width: 46px;
  height: 46px;
  border-radius: 12px;
  background: var(--foam-3);
  border: 2px solid var(--ink);
}

.slot-icon {
  width: 44px;
  height: 44px;
}

.slot-abbr {
  font: 900 18px var(--font-display);
}

.slot-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.slot-name {
  font: 800 15px/1.1 var(--font-display);
  white-space: nowrap;
}

.slot-ammo {
  font: 900 20px/1 var(--font-display);
  color: var(--buoy-2);
}

.slot-special.is-empty .slot-name {
  color: var(--ink-3);
}

.slot-special.is-empty .slot-art {
  background: repeating-linear-gradient(45deg, var(--foam-2) 0 6px, var(--foam-3) 6px 12px);
}

.pips {
  display: flex;
  gap: 4px;
}

.pip {
  position: relative;
  width: 14px;
  height: 18px;
  border: 2px solid var(--ink);
  border-radius: 5px;
  background: rgba(26, 30, 58, 0.12);
  overflow: hidden;
}

.pip::after {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--buoy);
  transform: scaleY(var(--p, 1));
  transform-origin: 50% 100%;
}

.pip.is-loading::after {
  background: #ffb48f;
}

.slot-cannon.is-reloading .slot-name::after {
  content: " · заряжаю";
  color: var(--ink-3);
  font-size: 12px;
}

.is-dead .vitals,
.is-dead .weapons {
  opacity: 0.35;
  filter: grayscale(1);
}

.no-me .vitals,
.no-me .weapons {
  display: none;
}

@media (pointer: coarse) {
  .slot {
    pointer-events: auto;
    cursor: pointer;
  }

  .weapons-swap,
  .slot-key,
  .spec-hint {
    display: none;
  }
}

.hud-chat {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.chat-log-overlay {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  max-height: 28vh;
  overflow: hidden;
}

.chat-log-overlay .msg {
  max-width: 100%;
  padding: 4px 10px;
  border-radius: 10px;
  background: rgba(26, 30, 58, 0.72);
  color: #fff;
  font-size: 14px;
  transition: opacity 0.8s;
}

.chat-log-overlay .msg-dot {
  border-color: #fff;
}

.chat-log-overlay .msg-mine .msg-from {
  color: var(--sun);
}

.chat-log-overlay .msg-system {
  align-self: flex-start;
  background: rgba(26, 30, 58, 0.55);
  color: #cfe6f3;
}

.chat-log-overlay .msg.is-old {
  opacity: 0;
}

.chat-open .chat-log-overlay .msg.is-old {
  opacity: 0.85;
}

.hud-chat .chat-form {
  pointer-events: auto;
  padding: 6px;
  border: var(--line) solid var(--ink);
  border-radius: 16px;
  background: var(--foam);
  box-shadow: 0 3px 0 var(--ink);
}

.hud-chat .chat-form .input {
  border-width: 2px;
  box-shadow: none;
  padding: 8px 10px;
  font-size: 15px;
}

.scoreboard {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(560px, calc(100% - 32px));
  max-height: 80%;
  overflow: auto;
  padding: 16px;
  animation: sb-in 0.15s ease;
}

@keyframes sb-in {
  from {
    opacity: 0;
    transform: translate(-50%, -46%);
  }
}

.sb-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 10px;
}

.sb-head h3 {
  font-size: 22px;
}

.sb-alive {
  font-weight: 800;
  color: var(--ink-2);
}

.sb-table {
  border: var(--line) solid var(--ink);
  border-radius: 14px;
  overflow: hidden;
  border-collapse: separate;
  border-spacing: 0;
  background: #fff;
}

.sb-table td {
  padding: 7px 12px;
  border-top: 2px solid var(--foam-2);
  text-align: right;
  font-weight: 800;
}

.sb-table td.sb-name {
  text-align: left;
  font-family: var(--font-display);
}

.sb-table td.sb-status {
  width: 30px;
  padding-right: 0;
}

.sb-dot {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--ink);
}

.sb-table tr.is-me td {
  background: #fff0e6;
}

.sb-table tr.is-dead td {
  color: var(--ink-3);
}

.sb-dead {
  display: inline-flex;
  margin-left: 6px;
  vertical-align: -2px;
  color: var(--ink-3);
}

.sb-empty {
  text-align: center !important;
  color: var(--ink-3);
}

.esc-menu {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(16, 20, 44, 0.5);
  pointer-events: auto;
}

.esc-card {
  width: min(360px, 100%);
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: center;
  animation: sb-pop 0.25s cubic-bezier(0.2, 1.4, 0.4, 1);
}

@keyframes sb-pop {
  from {
    transform: scale(0.9);
    opacity: 0;
  }
}

.esc-card h3 {
  font-size: 28px;
}

.esc-note {
  margin: 0 0 6px;
  color: var(--ink-2);
  font-weight: 700;
}

/* ---------- уведомления ---------- */

.toasts {
  position: absolute;
  top: max(14px, env(safe-area-inset-top));
  left: 50%;
  z-index: 50;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: min(480px, calc(100% - 32px));
  pointer-events: none;
}

/* В игре уведомления ниже счётчиков HUD. */
.tb-ui[data-screen="game"] .toasts {
  top: calc(max(14px, env(safe-area-inset-top)) + 100px);
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 100%;
  padding: 10px 16px 10px 10px;
  border: var(--line) solid var(--ink);
  border-radius: 16px;
  background: #fff;
  box-shadow: var(--lift);
  font-weight: 800;
  font-size: 15px;
  line-height: 1.3;
  pointer-events: auto;
  cursor: pointer;
  animation: toast-in 0.35s cubic-bezier(0.2, 1.5, 0.4, 1);
  transition: opacity 0.25s, transform 0.25s;
}

.toast .ico {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  padding: 4px;
  border: 2px solid var(--ink);
  border-radius: 50%;
  color: #fff;
}

.toast-error {
  background: #ffe6ea;
}

.toast-error .ico {
  background: var(--coral);
}

.toast-ok {
  background: #e3fff5;
}

.toast-ok .ico {
  background: var(--kelp);
}

.toast-text {
  overflow-wrap: anywhere;
}

.toast.is-leaving {
  opacity: 0;
  transform: translateY(-10px);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(-16px) scale(0.95);
  }
}

/* ---------- адаптив ---------- */

@media (max-width: 1100px) {
  .lobby-grid {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-rows: auto auto auto auto;
    grid-template-areas:
      "code settings"
      "players settings"
      "players start"
      "chat chat";
  }

  .chat-card {
    min-height: 320px;
  }

  .player-list {
    max-height: 460px;
  }
}

@media (min-width: 1101px) and (min-height: 760px) {
  .screen-lobby {
    overflow: hidden;
  }

  .lobby-page {
    height: 100%;
  }

  .players-card,
  .chat-card {
    overflow: hidden;
  }
}

@media (min-width: 861px) and (min-height: 700px) {
  .screen-garage {
    overflow: hidden;
  }

  .garage-page {
    height: 100%;
  }

  .garage-body {
    flex: 1;
    min-height: 0;
    align-items: stretch;
  }

  .garage-stage {
    align-self: start;
  }

  .garage-editor-panel {
    overflow-y: auto;
    min-height: 0;
  }
}

@media (max-width: 860px) {
  .garage-body {
    grid-template-columns: 1fr;
  }

  .garage-stage {
    position: relative;
    max-width: 460px;
    width: 100%;
    margin: 0 auto;
  }
}

@media (max-width: 720px) {
  .lobby-grid {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      "code"
      "start"
      "players"
      "settings"
      "chat";
  }

  .panel {
    padding: 16px;
    border-radius: 20px;
  }

  .page-head {
    gap: 10px;
    margin-bottom: 14px;
  }

  .page-sub {
    font-size: 14px;
  }

  .btn-garage-mini {
    display: none;
  }

  .code-tile {
    height: 56px;
    font-size: 30px;
  }

  .btn-huge {
    font-size: 24px;
    padding: 15px 20px;
  }

  .hud-bl {
    width: min(260px, 46vw);
  }

  .slot {
    min-width: 0;
    padding: 4px 10px 4px 4px;
    gap: 6px;
  }

  .slot-art {
    width: 38px;
    height: 38px;
  }

  .slot-icon {
    width: 36px;
    height: 36px;
  }

  .slot-name {
    font-size: 13px;
  }

  .stat-label {
    display: none;
  }

  .killfeed {
    max-width: 58vw;
  }

  .kf-row {
    font-size: 12px;
    padding: 4px 8px;
  }
}

@media (max-width: 540px) {
  .menu-card {
    padding: 18px;
    gap: 14px;
  }

  .who-preview {
    width: 84px;
    height: 74px;
  }

  .controls-hint {
    font-size: 13px;
  }

  .setting-pair {
    grid-template-columns: 1fr;
  }

  .stage-actions {
    grid-template-columns: 1fr 1fr;
  }

  .res-card {
    padding: 16px;
  }

  .res-head {
    gap: 12px;
  }

  .res-winner {
    width: 84px;
    height: 72px;
  }

  .res-table th,
  .res-table td {
    padding: 8px 7px;
  }

  .res-table th .ico,
  .th-short {
    display: inline-flex;
  }

  .res-table th .ico {
    width: 17px;
    height: 17px;
    vertical-align: -3px;
  }

  .th-text {
    display: none;
  }

  .res-table td.res-name {
    max-width: 150px;
  }

  .res-table td.res-name .tag-me {
    display: none;
  }

  .bd-sun {
    width: 70px;
    height: 70px;
    top: 5%;
    right: 8%;
  }

  .res-player {
    font-size: 15px;
  }

  .place-badge {
    width: 28px;
    height: 28px;
  }

  /* HUD на телефоне. Верхний ряд: здоровье слева, счётчики справа.
     Под ними по центру — вода и наблюдение, ниже слева — килфид.
     Оружие — компактно снизу по центру (между стиком и кнопкой прыжка), чат — над оружием. */
  .hud-top {
    top: max(8px, env(safe-area-inset-top));
    left: auto;
    right: max(10px, env(safe-area-inset-right));
    transform: none;
    align-items: flex-end;
    gap: 6px;
  }

  .hud-stats {
    gap: 4px;
  }

  .spectate,
  .water-warn {
    position: fixed;
    left: 50%;
    top: calc(max(8px, env(safe-area-inset-top)) + 54px);
    transform: translateX(-50%);
    max-width: calc(100vw - 20px);
    white-space: nowrap;
  }

  .water-warn {
    font-size: 14px;
    padding: 5px 12px;
    border-width: 2px;
    animation: fade-in 0.3s ease;
  }

  @keyframes fade-in {
    from {
      opacity: 0;
    }
  }

  .water-warn[data-level="danger"] {
    animation: warn-pulse-m 0.7s ease-in-out infinite;
  }

  @keyframes warn-pulse-m {
    50% {
      transform: translateX(-50%) scale(1.05);
    }
  }

  .spectate {
    font-size: 14px;
    padding: 5px 12px;
  }

  .spectate:not([hidden]) ~ .water-warn {
    top: calc(max(8px, env(safe-area-inset-top)) + 90px);
  }

  .spec-name {
    max-width: 50vw;
    overflow: hidden;
    text-overflow: ellipsis;
    display: inline-block;
    vertical-align: bottom;
  }

  .stat {
    padding: 3px 9px 3px 6px;
    border-width: 2px;
    gap: 4px;
  }

  .stat .ico {
    width: 17px;
    height: 17px;
  }

  .stat-val {
    font-size: 16px;
  }

  .vitals {
    position: fixed;
    top: max(8px, env(safe-area-inset-top));
    left: max(10px, env(safe-area-inset-left));
    width: min(150px, 34vw);
    gap: 4px;
  }

  .killfeed {
    top: calc(max(8px, env(safe-area-inset-top)) + 96px);
    left: max(10px, env(safe-area-inset-left));
    max-width: 70vw;
  }

  .hud-bl {
    left: 0;
    right: 0;
    margin-inline: auto;
    bottom: calc(max(10px, env(safe-area-inset-bottom)) + 62px);
    width: min(300px, 76vw);
  }

  .chat-log-overlay {
    align-items: center;
  }

  .chat-log-overlay .msg {
    font-size: 12px;
    padding: 3px 8px;
  }

  .bar {
    height: 24px;
    border-width: 2px;
  }

  .bar-num {
    font-size: 15px;
    -webkit-text-stroke-width: 3px;
  }

  .bar-icon .ico {
    width: 14px;
    height: 14px;
  }

  .bar-shield {
    height: 18px;
  }

  .weapons {
    gap: 4px;
  }

  .slot {
    border-width: 2px;
    border-radius: 14px;
    padding: 3px 8px 3px 3px;
  }

  .slot.is-active {
    box-shadow: 0 3px 0 var(--ink), 0 0 0 3px var(--sun);
  }

  .slot-art {
    width: 32px;
    height: 32px;
    border-radius: 9px;
  }

  .slot-icon {
    width: 30px;
    height: 30px;
  }

  .slot-name {
    font-size: 12px;
  }

  .slot-ammo {
    font-size: 15px;
  }

  .pip {
    width: 10px;
    height: 13px;
  }

  .slot-cannon.is-reloading .slot-name::after {
    content: none;
  }

  .chat-log-overlay {
    max-height: 18vh;
  }

  .announce.is-huge {
    top: 26%;
  }
}

@media (pointer: coarse) {
  .controls-hint {
    display: none;
  }
}

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