#menu, #lobby {
  display: flex; flex-direction: column;
  padding: 18px 34px 14px;
}
/* общая ширина шапки и плиток — края разделов и профиля совпадают с краями плиток */
#menu { --menu-w: min(1700px, 100%, calc(100vw - 240px), calc((100dvh - 230px) * 1180 / 620)); }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; min-height: 44px; flex-shrink: 0;
}
.topnav { display: flex; gap: 6px; }
.nav-link {
  /* полупрозрачная подложка всегда (как при наведении), при наведении — светлее */
  background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.06); color: #e9e3d7;
  font-family: var(--font-display); font-size: 17px; font-weight: 400;
  letter-spacing: 1px; text-transform: uppercase;
  padding: 5px 12px; border-radius: 0; backdrop-filter: blur(4px);
  transition: background .15s, color .15s, border-color .15s;
}
.nav-link:hover { background: rgba(255,255,255,.16); border-color: rgba(255,255,255,.14); color: #fff; }
.nav-link.active { background: var(--accent); color: #fff; }

.profile {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 4px 4px 12px; border-radius: 8px;
  background: rgba(0,0,0,.35); border: 1px solid var(--line);
}
.profile-name {
  font-family: var(--font-display); font-size: 16px; letter-spacing: .5px;
  border-bottom: 2px solid rgba(255,255,255,.5); padding-bottom: 1px;
  max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.profile-rating { color: var(--gold); font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------- Плитки ---------- */
/* Сетка держит пропорции 1180×620 и растёт с высотой окна (до 1700 px в ширину, по бокам поля не уже 120 px):
   230 px — шапка, отступы и кнопки сообщества внизу. На ПК блок «плитки + низ» стоит по центру свободного места (pages.css),
   поэтому на высоком экране пустота не копится под меню. */
.tiles {
  flex: none;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 2fr);
  grid-template-rows: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px;
  width: var(--menu-w);
  aspect-ratio: 1180 / 620; min-height: 0; /* без min-height сетка растягивается под содержимое и ломает пропорции */
  margin: 26px auto 0;
}
/* невысокое окно: пустоты снизу нет — сетка, как раньше, во всю ширину и занимает остаток высоты */
@media (max-height: 800px) {
  #menu { --menu-w: min(1180px, 100%); }
  .tiles { flex: 1; max-height: 620px; aspect-ratio: auto; }
}
.tile {
  position: relative; overflow: hidden;
  border: none; border-radius: 4px; padding: 0;
  background: var(--cream); color: var(--cream-ink);
  text-align: left;
  display: flex; flex-direction: column;
  box-shadow: 0 10px 30px rgba(0,0,0,.45);
  transition: transform .18s cubic-bezier(.2,.9,.3,1.2), box-shadow .18s, background .18s, color .18s;
}
.tile:not(:disabled):hover {
  transform: translateY(-4px);
  box-shadow: 0 16px 40px rgba(0,0,0,.55), 0 0 0 3px var(--accent);
}
.tile:not(:disabled):active { transform: translateY(-1px); }
.tile-text { padding: 14px 16px 6px; position: relative; z-index: 2; }
.tile h2, .tile h3 {
  font-family: var(--font-display); font-weight: 600;
  text-transform: uppercase; letter-spacing: .5px;
  margin: 0 0 6px; line-height: 1;
}
.tile h2 { font-size: 30px; }
.tile h3 { font-size: 20px; }
.tile p { margin: 0; font-size: 12.5px; line-height: 1.4; opacity: .85; max-width: 34ch; }
.tile-art {
  position: absolute; left: 0; right: 0; bottom: 0;
  width: 100%; height: 72%;
  z-index: 1; pointer-events: none;
}

.tile-tall { grid-row: 1 / 4; }
.tile-classic { grid-column: 1; background: var(--accent); color: #fff; }
.tile-classic p { opacity: .95; }
.tile-classic:not(:disabled):hover { background: #f0912a; box-shadow: 0 16px 40px rgba(0,0,0,.55), 0 0 0 3px #fff; }
.tile-tournament { grid-column: 2; }
.tile-tournament:not(:disabled):hover { background: #fff6e6; }

.tile-wide { grid-column: 3; }
.tile-wide .tile-art { left: auto; width: 62%; height: 100%; }
.tile-wide .tile-text { max-width: 46%; }

.tile-row { grid-column: 3; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; min-height: 0; }
.tile-small .tile-art { left: auto; width: 55%; height: 100%; }
.tile-small .tile-text { max-width: 60%; }

.tile-locked {
  background: #7d7a74; color: #e9e6e0;
  cursor: not-allowed;
}
.tile-locked .tile-art { filter: grayscale(1) contrast(.9) brightness(.85); opacity: .7; }
.tile-locked::after {
  content: '🔒'; position: absolute; right: 14px; top: 12px; z-index: 3;
  font-size: 20px; filter: grayscale(1) brightness(1.6);
}
.tile-ribbon {
  position: absolute; left: 16px; bottom: 14px; z-index: 3;
  background: rgba(0,0,0,.45); color: #fff;
  font-family: var(--font-display); font-size: 13px; letter-spacing: 2px; text-transform: uppercase;
  padding: 3px 10px; border-radius: 3px;
}
.tile-tag {
  position: absolute; right: 8px; top: 8px; z-index: 3;
  background: var(--accent); color: #fff;
  font-family: var(--font-display); font-size: 11px; letter-spacing: 1px;
  padding: 2px 7px; border-radius: 3px;
}
.tile-online {
  position: absolute; left: 14px; bottom: 12px; z-index: 3;
  background: rgba(0,0,0,.55); color: #fff;
  font-size: 12px; font-weight: 600;
  padding: 4px 10px; border-radius: 999px;
  display: none;
}
.tile-online.show { display: inline-block; }
.tile-online .live { color: #7dff9b; }
/* «в поиске» — плашка как баланс билетов: значок бомберов и число */
.search-pill {
  display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 12px 0 6px; border-radius: 8px; white-space: nowrap;
  background: rgba(0,0,0,.45); border: 1px solid var(--line); color: #fff;
  font-family: var(--font-display); font-size: 17px; letter-spacing: .5px; font-variant-numeric: tabular-nums;
}
.search-pill .cur-ico { width: 30px; height: 30px; }
.search-pill small { font-family: var(--font-ui, Inter, sans-serif); font-size: 11px; letter-spacing: .3px; color: var(--muted); text-transform: uppercase; }
.search-pill .sp-live { display: inline-flex; align-items: center; gap: 6px; margin-left: 4px; padding: 2px 8px; border-radius: 6px; background: rgba(94,224,255,.16); color: #9ff0ff; font-size: 14px; }
.search-pill .sp-live i { width: 7px; height: 7px; border-radius: 50%; background: #5ee0ff; box-shadow: 0 0 8px #5ee0ff; animation: tsPulse 1s ease-in-out infinite; }
.search-pill.live { border-color: rgba(94,224,255,.6); box-shadow: 0 0 16px rgba(94,224,255,.25); }
@keyframes tsPulse { 50% { opacity: .25; } }
/* на плитке рейтинга — по центру под радаром */
#rankedOnline { position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 3; box-shadow: 0 4px 18px rgba(0,0,0,.45); }

.menu-footer {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding-top: 14px;
}
.menu-status { font-size: 11px; color: var(--muted); }

.topbar-logo { display: none; }
.top-tools { display: flex; gap: 6px; margin-left: auto; }
.nl-ico { display: none; }

/* на сенсорных экранах «подпрыгивание» при наведении залипает — только нажатие */
body.touch .tile:not(:disabled):hover { transform: none; box-shadow: 0 10px 30px rgba(0,0,0,.45); }
body.touch .tile:not(:disabled):active { transform: scale(.97); }

/* Узкое окно на ПК / планшет вертикально */
@media (max-width: 900px) {
  #menu { padding: 12px 16px; overflow-y: auto; --menu-w: 100%; }
  .tiles {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 300px 120px 120px 110px;
    max-height: none; flex: none; width: 100%; aspect-ratio: auto;
  }
  .tile-tall { grid-row: 1; }
  .tile-tall .tile-art { height: 58%; }
  .tile-wide, .tile-row { grid-column: 1 / 3; }
}

/* Порядок карточек на телефоне: сначала то, во что можно играть */
@media (max-height: 520px) and (orientation: landscape), (max-width: 700px) and (orientation: portrait) {
  .tile-row { display: contents; }
  .tile-classic { order: 0; }
  .tile-ranked, .tile-weekly { order: 1; }
  .tile[data-nav="tutorial"] { order: 2; }
  .tile-character, .tile-shop { order: 3; }
  .tile[data-nav="patches"] { order: 4; }
  .tile[data-room="arcade"] { order: 5; }
  .tile[data-room="coop"] { order: 6; }
  body:not(.tutorial-done) .tile[data-nav="tutorial"] { order: -1; }
  .tile { border-radius: 12px; }
  .tile .tile-text { max-width: none; }
  .tile p { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden; }
  .tile-locked::after { right: 10px; top: 10px; font-size: 16px; }
  .tile-ribbon { font-size: 11px; padding: 2px 8px; left: 12px; bottom: 10px; }
  .topbar-logo { display: flex; }
  .topbar-logo svg { height: 34px; filter: none; }
}

/* ---------- Телефон горизонтально: лента карточек ---------- */
@media (max-height: 520px) and (orientation: landscape) {
  #menu {
    overflow: hidden;
    padding: calc(6px + env(safe-area-inset-top)) calc(12px + env(safe-area-inset-right)) 6px calc(12px + env(safe-area-inset-left));
  }
  .topbar { min-height: 40px; gap: 8px; }
  .topnav { gap: 2px; }
  .nav-link { font-size: 14px; padding: 6px 9px; }
  .profile { padding: 3px 3px 3px 9px; gap: 6px; }
  .profile-name { font-size: 14px; max-width: 96px; }
  .tool-btn { height: 32px; min-width: 32px; padding: 0 7px; }
  .tiles {
    display: flex; flex: 1; min-height: 0; max-height: none; aspect-ratio: auto;
    width: auto; margin: 8px calc(-12px - env(safe-area-inset-right)) 0 calc(-12px - env(safe-area-inset-left));
    padding: 4px calc(12px + env(safe-area-inset-right)) 14px calc(12px + env(safe-area-inset-left));
    overflow-x: auto; overflow-y: hidden; overscroll-behavior-x: contain;
    scroll-snap-type: x mandatory; scroll-padding: 0 calc(12px + env(safe-area-inset-left));
    scrollbar-width: none;
  }
  .tiles::-webkit-scrollbar { display: none; }
  .tile { flex: 0 0 auto; width: clamp(190px, 29vw, 250px); height: 100%; scroll-snap-align: start; }
  .tile-tall { width: clamp(220px, 34vw, 290px); }
  .tile .tile-art, .tile-wide .tile-art, .tile-small .tile-art { left: 0; right: 0; width: 100%; height: 56%; top: auto; bottom: 0; }
  .tile-text { padding: 12px 14px 4px; }
  .tile h2 { font-size: 26px; }
  .tile h3 { font-size: 22px; }
  .tile p { font-size: 12px; }
  .tile-wide .tile-text, .tile-small .tile-text { max-width: none; }
  .menu-footer { position: fixed; left: calc(14px + env(safe-area-inset-left)); bottom: 2px; padding: 0; z-index: 3; }
  .menu-footer .logo { display: none; }
  .menu-status { font-size: 10px; }
}
/* совсем узкий телефон горизонтально — в меню только значки разделов */
@media (max-height: 520px) and (orientation: landscape) and (max-width: 760px) {
  .nl-txt { display: none; }
  .nl-ico { display: inline; font-size: 18px; }
  .tool-btn span { display: none; }
}

/* ---------- Телефон вертикально: список карточек ---------- */
@media (max-width: 700px) and (orientation: portrait) {
  #menu {
    overflow-y: auto; overflow-x: hidden;
    padding: calc(10px + env(safe-area-inset-top)) 14px calc(16px + env(safe-area-inset-bottom));
  }
  /* шапка в три строки: логотип и звук / разделы / профиль */
  .topbar { flex-wrap: wrap; row-gap: 10px; gap: 8px; }
  .top-tools { order: 1; gap: 4px; }
  .topnav { order: 2; width: 100%; gap: 6px; }
  .profile { order: 3; width: 100%; padding: 4px 4px 4px 12px; gap: 8px; }
  .profile .icon-btn { margin-left: auto; }
  .profile-name { font-size: 15px; max-width: 60vw; }
  .nav-link {
    flex: 1; font-size: 13.5px; padding: 9px 4px; text-align: center;
    background: rgba(0,0,0,.3);
  }
  .nav-link { white-space: nowrap; }
  .tool-btn { height: 32px; min-width: 32px; padding: 0 7px; }
  .tool-btn span { display: none; }
  #fullscreenBtn { display: none !important; }
  .tiles { display: flex; flex-direction: column; gap: 10px; margin: 14px 0 0; flex: none; width: 100%; aspect-ratio: auto; }
  .tile { flex: none; min-height: 132px; }
  .tile-tall { min-height: 168px; }
  .tile .tile-art, .tile-wide .tile-art, .tile-small .tile-art { left: auto; right: 0; top: 0; bottom: 0; width: 46%; height: 100%; }
  .tile .tile-text { max-width: 58%; padding: 14px 14px 6px; }
  .tile h2 { font-size: 28px; }
  .tile h3 { font-size: 22px; }
  .tile p { font-size: 12.5px; -webkit-line-clamp: 4; }
  .tile-online { left: 12px; bottom: 10px; font-size: 11px; padding: 3px 8px; }
  .menu-footer { padding-top: 16px; }
  .menu-footer .logo { display: none; }
}

/* ---------- Выбор комнаты ---------- */
.rooms-box { max-width: 620px; }
.rooms-head { display: flex; align-items: center; justify-content: space-between; }
.rooms-head h3 { margin: 0; }
#roomsList { display: flex; flex-direction: column; gap: 6px; margin: 16px 0; max-height: 50vh; overflow-y: auto; }
.room-row {
  display: grid; grid-template-columns: 1fr auto auto; gap: 12px; align-items: center;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
}
.room-row .rn { font-weight: 700; font-size: 15px; }
.room-row .rh { font-size: 12px; color: var(--muted); margin-top: 2px; }
.room-row .rp { font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.room-row .rs { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; margin-left: 6px; }
.room-row .rs.lobby { background: rgba(46,204,113,.2); color: #7dffb0; }
.room-row .rs.live { background: rgba(232,135,30,.2); color: #ffbf73; }
.room-row button { padding: 8px 14px; font-size: 15px; }
.rooms-empty { color: var(--muted); text-align: center; padding: 24px 0; font-size: 14px; }
.rooms-create { display: flex; gap: 8px; }
.rooms-create input { flex: 1; }
