:root {
  --bg: #1a3a8f;
  --bg-deep: #122a6b;
  --panel: #16307a;
  --ink: #ffffff;
  --muted: #b8c9f0;
  --accent: #3dd6c6;
  --accent-2: #ffb454;
  --danger: #ff6b7a;
  --ok: #5dde8a;
  --line: rgba(255, 255, 255, 0.18);
  --font: "Trebuchet MS", "Segoe UI", sans-serif;

  /* Базовый «логический» размер макета; scale.js подстраивает --ui-scale */
  --ui-scale: 1;
  --space: calc(16px * var(--ui-scale));
  --space-sm: calc(10px * var(--ui-scale));
  --radius: calc(12px * var(--ui-scale));
  --text: calc(16px * var(--ui-scale));
  --text-sm: calc(13px * var(--ui-scale));
  --text-lg: calc(22px * var(--ui-scale));
  --hud-w: calc(280px * var(--ui-scale));
  --tile-gap: calc(14px * var(--ui-scale));
  --header-h: calc(56px * var(--ui-scale));
}

* { box-sizing: border-box; }

html {
  height: 100%;
  /* Не даём браузеру «ломать» текст своим автозумом на мобилках */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: linear-gradient(180deg, var(--bg) 0%, var(--bg-deep) 100%);
  color: var(--ink);
  font-family: var(--font);
  font-size: var(--text);
  line-height: 1.35;
}

body {
  min-height: 100dvh;
}

#app {
  width: 100%;
  height: 100%;
  max-width: none;
  margin: 0;
  padding: var(--space);
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  min-height: 0;
}

.top {
  flex: 0 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-sm);
  min-height: var(--header-h);
  flex-wrap: wrap;
}

.brand {
  font-weight: 800;
  letter-spacing: 0.02em;
  font-size: calc(1.15 * var(--text));
}

.brand-btn {
  display: inline-flex;
  align-items: center;
  gap: calc(8px * var(--ui-scale));
  margin: 0;
  padding: calc(6px * var(--ui-scale)) calc(10px * var(--ui-scale));
  border: 1px solid transparent;
  background: transparent;
  color: inherit;
  cursor: pointer;
  border-radius: calc(10px * var(--ui-scale));
}

.brand-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: var(--line);
}

.brand-ico {
  display: block;
  border-radius: 6px;
}

.btn-danger {
  background: linear-gradient(180deg, #ff7b88, #e44555) !important;
  color: #fff !important;
  border: none !important;
  font-weight: 700;
}

.btn-danger.small {
  padding: calc(6px * var(--ui-scale)) calc(10px * var(--ui-scale));
  font-size: var(--text-sm);
}

.observer-placeholder {
  display: grid;
  place-items: center;
  height: 100%;
  color: var(--muted);
  padding: var(--space);
  text-align: center;
}

.bank-header-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--space);
  margin-bottom: var(--space-sm);
}

.bank-header-row .ghost {
  margin-top: 0;
  flex: 0 0 auto;
}

.bank-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
  align-items: end;
  margin-bottom: var(--space);
}

.bank-toolbar label {
  margin: 0;
  min-width: calc(140px * var(--ui-scale));
}

.bank-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(240px, 0.8fr);
  gap: var(--space);
  min-height: 0;
  flex: 1;
}

.bank-list {
  display: flex;
  flex-direction: column;
  gap: calc(6px * var(--ui-scale));
  max-height: 55dvh;
  overflow: auto;
  padding-right: 4px;
}

.bank-item {
  display: grid;
  grid-template-columns: auto auto 1fr;
  gap: 10px;
  align-items: center;
  margin: 0;
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid var(--line);
  color: var(--ink);
  font-size: var(--text-sm);
  cursor: pointer;
}

.bank-item input[type="checkbox"] {
  width: calc(28px * var(--ui-scale));
  height: calc(28px * var(--ui-scale));
  min-width: 28px;
  min-height: 28px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}
.bank-meta {
  color: var(--accent-2);
  white-space: nowrap;
  font-size: 11px;
}

.bank-side {
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--space-sm);
  overflow: auto;
  max-height: 70dvh;
}

@media (max-width: 900px) {
  .bank-layout { grid-template-columns: 1fr; }
}

.check-row {
  display: flex !important;
  align-items: center;
  gap: 10px;
  color: var(--ink) !important;
  font-size: var(--text) !important;
}

.check-row input {
  width: auto !important;
  margin: 0 !important;
}

.join-toast {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 80;
  max-width: min(360px, calc(100vw - 24px));
}

.join-toast[hidden] { display: none !important; }

.join-toast-card {
  position: relative;
  overflow: hidden;
  background: #1a2f6b;
  border: 2px solid #ffb454;
  border-radius: 16px;
  padding: 18px 18px 16px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
  animation: toast-in 0.25s ease;
}

.join-toast-pulse {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at top right, rgba(255, 180, 84, 0.35), transparent 55%);
  pointer-events: none;
  animation: pulse-glow 1.4s ease-in-out infinite;
}

.join-toast h3 {
  margin: 0 0 6px;
  position: relative;
}

.join-toast-name {
  position: relative;
  margin: 0 0 14px;
  font-size: 1.35rem;
  font-weight: 800;
  color: #fff;
}

.join-toast-actions {
  position: relative;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.btn-allow {
  margin: 0 !important;
  flex: 1;
  min-width: 120px;
  background: linear-gradient(180deg, #5ef0d8, #2bb8aa) !important;
  color: #06241f !important;
  border: none !important;
  font-weight: 800;
  border-radius: 12px !important;
  padding: 12px 16px !important;
}

.btn-deny {
  margin: 0 !important;
  flex: 1;
  min-width: 110px;
  background: linear-gradient(180deg, #ff8a96, #e44555) !important;
  color: #fff !important;
  border: none !important;
  font-weight: 800;
  border-radius: 12px !important;
  padding: 12px 16px !important;
}

@keyframes toast-in {
  from { transform: translateY(-12px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

@keyframes pulse-glow {
  0%, 100% { opacity: 0.55; }
  50% { opacity: 1; }
}

.bank-item {
  cursor: pointer;
}

.bank-item .q-open {
  margin-left: auto;
  font-size: 11px;
  color: var(--accent);
}

.top-right {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  flex-wrap: wrap;
}

.pill {
  font-size: var(--text-sm);
  padding: calc(4px * var(--ui-scale)) calc(10px * var(--ui-scale));
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--line);
  color: var(--muted);
}

.pill.ok { color: var(--ok); }
.pill.bad { color: var(--danger); }

.admin-btn {
  margin: 0;
  padding: calc(8px * var(--ui-scale)) calc(14px * var(--ui-scale));
  border-radius: calc(10px * var(--ui-scale));
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.12);
  color: var(--ink);
  font-weight: 700;
  cursor: pointer;
  font-size: var(--text-sm);
}

.admin-btn.on {
  background: var(--accent-2);
  color: #3a2400;
  border-color: transparent;
}

.screen {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  overflow: auto;
  overscroll-behavior: contain;
}

.screen[hidden] { display: none !important; }

.hub-screen {
  gap: var(--space-sm);
}

.hub-lead {
  margin: 0;
  flex: 0 0 auto;
  color: var(--muted);
  font-size: var(--text-sm);
}

.games-grid {
  flex: 1 1 auto;
  display: grid;
  /* Автоколонки: плитки не схлопываются и не разъезжаются */
  grid-template-columns: repeat(auto-fill, minmax(min(100%, calc(260px * var(--ui-scale))), 1fr));
  gap: var(--tile-gap);
  align-content: start;
  width: 100%;
  min-height: 0;
  padding-bottom: var(--space);
}

.game-tile {
  position: relative;
  aspect-ratio: 16 / 10;
  width: 100%;
  border: calc(3px * var(--ui-scale)) solid rgba(255, 255, 255, 0.85);
  border-radius: calc(4px * var(--ui-scale));
  overflow: hidden;
  cursor: pointer;
  padding: 0;
  margin: 0;
  text-align: left;
  color: #fff;
  font: inherit;
  box-shadow: 0 calc(8px * var(--ui-scale)) 0 rgba(0, 0, 0, 0.25);
  transition: transform 0.12s ease, filter 0.12s ease;
}

.game-tile:hover {
  transform: translateY(calc(-2px * var(--ui-scale)));
  filter: brightness(1.05);
}

.game-tile:focus-visible {
  outline: calc(3px * var(--ui-scale)) solid var(--accent);
  outline-offset: 2px;
}

.game-tile .art {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
}

.game-tile .art-thumb {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  border: 0;
}

.game-tile .title {
  position: absolute;
  left: calc(10px * var(--ui-scale));
  bottom: calc(8px * var(--ui-scale));
  right: calc(10px * var(--ui-scale));
  margin: 0;
  font-size: clamp(11px, calc(14px * var(--ui-scale)), 18px);
  font-weight: 800;
  letter-spacing: 0.04em;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.55), 0 0 8px rgba(0, 0, 0, 0.4);
  line-height: 1.15;
}

.game-tile .badge-soon {
  position: absolute;
  top: calc(8px * var(--ui-scale));
  right: calc(8px * var(--ui-scale));
  font-size: calc(10px * var(--ui-scale));
  font-weight: 700;
  padding: calc(3px * var(--ui-scale)) calc(7px * var(--ui-scale));
  border-radius: calc(6px * var(--ui-scale));
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
}

.game-tile.playable .badge-soon { display: none; }

.art-jump {
  background: linear-gradient(180deg, #6ec8ff 0%, #9ad8ff 55%, #7ec8a0 55%, #5aaa58 100%);
}
.art-jump::before,
.art-jump::after {
  content: "";
  position: absolute;
  width: 28%;
  height: 14%;
  background: #4caf50;
  border-radius: 4px;
  border-bottom: 4px solid #2e7d32;
}
.art-jump::before { left: 18%; top: 42%; }
.art-jump::after { right: 22%; top: 28%; width: 22%; }

.art-brawl { background: linear-gradient(180deg, #9ad0ff, #e8f4ff 40%, #fff 40%); }
.art-snow { background: linear-gradient(180deg, #0b1b3a, #1a335f 50%, #dfe9f7 50%); }
.art-farm { background: linear-gradient(180deg, #87ceeb 0%, #87ceeb 45%, #7cb342 45%, #558b2f 100%); }
.art-blast { background: radial-gradient(circle at 50% 40%, #fff 0 8%, transparent 9%), linear-gradient(135deg, #4fc3f7, #0288d1); }
.art-tag { background: #9e9e9e; }
.art-mine { background: linear-gradient(160deg, #5d4037, #3e2723 40%, #795548); }
.art-jungle { background: linear-gradient(180deg, #81c784, #2e7d32); }
.art-knock { background: linear-gradient(180deg, #7e57c2, #311b92 60%, #ef5350 60%); }
.art-fish { background: linear-gradient(180deg, #4fc3f7 0%, #0288d1 55%, #795548 55%); }
.art-flag { background: linear-gradient(90deg, #cfd8dc 50%, #eceff1 50%); }
.art-desert { background: linear-gradient(180deg, #ffe082, #ffb300 40%, #8d6e63 40%); }
.art-clash { background: linear-gradient(135deg, #66bb6a, #ec407a); }

.blob {
  position: absolute;
  width: calc(18px * var(--ui-scale));
  height: calc(18px * var(--ui-scale));
  border-radius: 50% 50% 45% 45%;
  background: #ef5350;
  box-shadow: inset -3px -3px 0 rgba(0, 0, 0, 0.15);
}
.blob::after {
  content: "";
  position: absolute;
  width: 18%;
  height: 18%;
  background: #222;
  border-radius: 50%;
  left: 28%;
  top: 32%;
  box-shadow: 140% 0 #222;
}

h1, h2, h3 { margin: 0 0 calc(8px * var(--ui-scale)); }
h2 { font-size: var(--text-lg); }
h3 { font-size: calc(1.05 * var(--text)); }
.muted { color: var(--muted); }
.small { font-size: var(--text-sm); }
.hint { color: var(--muted); font-size: var(--text-sm); }
.error { color: var(--danger); margin-top: var(--space-sm); }
code {
  background: rgba(0, 0, 0, 0.25);
  padding: 2px 6px;
  border-radius: 4px;
}

label {
  display: block;
  margin: var(--space-sm) 0;
  font-size: var(--text-sm);
  color: var(--muted);
}

input, select, button, textarea {
  font: inherit;
}

input, select, textarea {
  display: block;
  width: 100%;
  max-width: 100%;
  margin-top: calc(6px * var(--ui-scale));
  padding: calc(12px * var(--ui-scale)) calc(14px * var(--ui-scale));
  border-radius: calc(10px * var(--ui-scale));
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.28);
  color: var(--ink);
  font-size: var(--text);
}

textarea {
  font-family: Consolas, "Courier New", monospace;
  font-size: var(--text-sm);
  resize: vertical;
  min-height: calc(160px * var(--ui-scale));
}

input.code {
  text-transform: uppercase;
  letter-spacing: 0.2em;
  font-size: calc(20px * var(--ui-scale));
  font-weight: 700;
}

button {
  margin-top: var(--space-sm);
  padding: calc(12px * var(--ui-scale)) calc(18px * var(--ui-scale));
  border-radius: calc(10px * var(--ui-scale));
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.12);
  color: var(--ink);
  cursor: pointer;
  font-size: var(--text);
}

button.primary {
  background: linear-gradient(180deg, #45e0cf, #2bb8aa);
  color: #06241f;
  border: none;
  font-weight: 700;
}

button.ghost { background: transparent; }
button.small {
  padding: calc(8px * var(--ui-scale)) calc(12px * var(--ui-scale));
  font-size: var(--text-sm);
}
button:disabled { opacity: 0.5; cursor: not-allowed; }

.panel {
  margin: var(--space) 0;
  padding: calc(14px * var(--ui-scale));
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.2);
}

.code-big {
  display: inline-block;
  padding: 2px calc(10px * var(--ui-scale));
  border-radius: calc(8px * var(--ui-scale));
  background: rgba(0, 0, 0, 0.35);
  letter-spacing: 0.18em;
  color: var(--accent-2);
}

.players {
  list-style: none;
  padding: 0;
  margin: var(--space) 0;
}

.players li {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: calc(10px * var(--ui-scale)) calc(12px * var(--ui-scale));
  border-radius: calc(10px * var(--ui-scale));
  background: rgba(0, 0, 0, 0.25);
  margin-bottom: calc(8px * var(--ui-scale));
  border: 1px solid var(--line);
}

.dot {
  width: calc(12px * var(--ui-scale));
  height: calc(12px * var(--ui-scale));
  border-radius: 50%;
  flex: 0 0 auto;
}

.badge {
  margin-left: auto;
  font-size: calc(11px * var(--ui-scale));
  color: var(--accent-2);
}

/* Игровой экран на всё доступное место */
.game-screen {
  display: grid !important;
  grid-template-columns: minmax(calc(180px * var(--ui-scale)), var(--hud-w)) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  gap: var(--space-sm);
  padding: 0;
  overflow: hidden;
  flex: 1 1 auto;
  min-height: 0;
  height: 100%;
}

.game-screen[hidden] {
  display: none !important;
}

.lobby-actions {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: var(--space-sm);
  margin-top: var(--space);
}

.btn-start-lg {
  font-size: calc(20px * var(--ui-scale));
  padding: calc(16px * var(--ui-scale)) calc(22px * var(--ui-scale));
  width: 100%;
  max-width: calc(420px * var(--ui-scale));
}

.btn-leave-sm {
  font-size: calc(12px * var(--ui-scale));
  padding: calc(6px * var(--ui-scale)) calc(12px * var(--ui-scale));
  width: auto;
  align-self: flex-start;
  opacity: 0.85;
}

.shared-timer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-sm);
  padding: calc(10px * var(--ui-scale)) calc(12px * var(--ui-scale));
  border-radius: calc(10px * var(--ui-scale));
  background: rgba(61, 214, 198, 0.18);
  border: 1px solid rgba(61, 214, 198, 0.45);
  font-size: var(--text-sm);
}

.shared-timer strong {
  font-size: calc(22px * var(--ui-scale));
  color: var(--accent);
}

.spectate-caption {
  position: absolute;
  left: 8px;
  bottom: 8px;
  z-index: 3;
  padding: 4px 8px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: var(--text-sm);
}

#spectate-frame {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #0b1f3a;
  image-rendering: auto;
}

.observer-placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  text-align: center;
  padding: var(--space);
  color: var(--muted);
}

.hud {
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: calc(14px * var(--ui-scale));
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
}

.controls-hint {
  margin: 0 0 var(--space-sm);
  padding: calc(8px * var(--ui-scale)) calc(10px * var(--ui-scale));
  border-radius: calc(8px * var(--ui-scale));
  background: rgba(255, 255, 255, 0.08);
  color: var(--muted);
  font-size: var(--text-sm);
  line-height: 1.35;
}

.hud-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: calc(8px * var(--ui-scale));
  color: var(--muted);
  font-size: var(--text-sm);
}

.hud-row strong {
  color: var(--ink);
  font-size: calc(18px * var(--ui-scale));
}

.board {
  margin: 0;
  padding-left: calc(18px * var(--ui-scale));
  color: var(--muted);
  font-size: var(--text-sm);
}

.board .you { color: var(--accent); font-weight: 700; }

.host-panel {
  margin-top: var(--space);
  padding-top: var(--space-sm);
  border-top: 1px solid var(--line);
}

.host-panel input { margin-bottom: calc(6px * var(--ui-scale)); }

#game-wrap {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--line);
  background: #0b1f3a;
  min-width: 0;
  min-height: 0;
  height: 100%;
  width: 100%;
}

#phaser-root {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  background: transparent;
}

#phaser-root canvas {
  display: block;
  margin: 0 auto;
}

.touch {
  display: none;
  position: absolute;
  top: 0;
  bottom: 0;
  width: 50%;
  z-index: 2;
}

#touch-left { left: 0; }
#touch-right { right: 0; }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(5, 10, 30, 0.72);
  display: grid;
  place-items: center;
  z-index: 50;
  padding: var(--space);
  overflow: auto;
}

.modal[hidden] { display: none !important; }

.modal-card {
  position: relative;
  width: min(calc(440px * var(--ui-scale)), 100%);
  max-height: min(90dvh, 100%);
  overflow: auto;
  background: #16307a;
  border: 1px solid var(--line);
  border-radius: calc(16px * var(--ui-scale));
  padding: calc(22px * var(--ui-scale));
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
}

#admin-ended-modal .modal-card {
  text-align: center;
}

#admin-ended-modal .modal-card .primary {
  display: inline-block;
  margin-top: var(--space-sm);
}

.order-fieldset {
  margin: var(--space-sm) 0 0;
  border: 1px solid var(--line);
  border-radius: calc(8px * var(--ui-scale));
  padding: calc(10px * var(--ui-scale));
}

.order-fieldset legend {
  padding: 0 6px;
  color: var(--muted);
  font-size: var(--text-sm);
}

.order-list {
  list-style: none;
  margin: var(--space-sm) 0;
  padding: 0;
  max-height: min(55dvh, 420px);
  overflow: auto;
  display: grid;
  gap: 8px;
}

.order-list li {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid var(--line);
  cursor: grab;
  user-select: none;
}

.order-list li.dragging {
  opacity: 0.55;
  border-color: var(--accent);
}

.order-list .ord-handle {
  color: var(--muted);
  font-weight: 700;
  min-width: 1.5em;
}

.order-list .ord-text {
  flex: 1;
  font-size: var(--text-sm);
  line-height: 1.35;
}

.modal-card.wide {
  width: min(calc(560px * var(--ui-scale)), 100%);
}

.modal-close {
  position: absolute;
  top: calc(8px * var(--ui-scale));
  right: calc(10px * var(--ui-scale));
  margin: 0;
  border: none;
  background: transparent;
  font-size: calc(24px * var(--ui-scale));
  line-height: 1;
  color: var(--muted);
  padding: 4px 8px;
}

.quiz-label {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: var(--text-sm);
  color: var(--accent);
}

.choices {
  display: grid;
  gap: var(--space-sm);
  margin-top: var(--space);
}

.choices button {
  margin: 0;
  text-align: left;
  background: rgba(0, 0, 0, 0.28);
}

.feedback { margin-top: calc(14px * var(--ui-scale)); font-weight: 700; }
.feedback.ok { color: var(--ok); }
.feedback.bad { color: var(--danger); }

/* Узкие окна: игра сверху на максимум, hud компактно снизу */
@media (max-width: 820px) {
  .game-screen {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) auto;
    overflow: hidden;
  }
  .hud {
    order: 2;
    max-height: 28dvh;
  }
  #game-wrap {
    order: 1;
    min-height: 0;
    height: 100%;
  }
  .touch { display: block; }
}

@media (max-width: 520px) {
  .games-grid {
    grid-template-columns: 1fr;
  }
}
