@media (max-width: 980px) {
  :root { --sidebar-width: 238px; }
  .nav-item { padding-left: 15px; grid-template-columns: 40px minmax(0,1fr) auto; }
  .profile-card { padding-left: 16px; padding-right: 16px; }
  .chat-title-line h1 { font-size: 17px; }
  #messages { padding-left: 34px; padding-right: 34px; }
  .composer { padding-left: 28px; padding-right: 28px; }
}

/* Mobile: chat and world are visible together immediately. */
@media (max-width: 1024px) {
  body { overflow: hidden; }
  .app-shell { display: block !important; height: 100dvh; width: 100%; overflow: hidden; }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(84vw, 320px);
    max-width: 320px;
    height: 100dvh;
    transform: translateX(-105%);
    transition: transform .2s ease;
    box-shadow: 18px 0 50px #25314225;
    z-index: 100;
  }
  body.sidebar-open .sidebar { transform: translateX(0); }
  body:not(.sidebar-open) .sidebar { pointer-events: none; }
  body.sidebar-open .sidebar { pointer-events: auto; }
  .sidebar-close, .mobile-menu { display: grid; place-items: center; }

  /* Always split: chat on top, world below. */
  .workspace {
    height: 100dvh;
    display: grid !important;
    grid-template-rows: minmax(0, 58%) minmax(0, 42%) !important;
    overflow: hidden;
  }
  .chat-pane,
  .world-pane {
    display: flex !important;
    width: 100%;
    height: auto !important;
    min-height: 0;
  }

  /* Desktop-only switcher and draggable separator are not needed on phones. */
  .split-resizer,
  .chat-actions,
  .mobile-dock { display: none !important; }

  /* Ignore legacy chat/world-only states on mobile. */
  body[data-mobile-view="chat"] .chat-pane,
  body[data-mobile-view="chat"] .world-pane,
  body[data-mobile-view="world"] .chat-pane,
  body[data-mobile-view="world"] .world-pane,
  body[data-view-mode="chat"] .chat-pane,
  body[data-view-mode="chat"] .world-pane,
  body[data-view-mode="world"] .chat-pane,
  body[data-view-mode="world"] .world-pane,
  body[data-view-mode="split"] .chat-pane,
  body[data-view-mode="split"] .world-pane {
    display: flex !important;
  }

  .mobile-menu { width: 34px; height: 34px; border-radius: 9px; background: #f4f5f7; font-size: 17px; }
  .chat-header { min-height: 56px; padding: 0 10px; }
  .chat-title-line h1 { max-width: 66vw; font-size: 15px; }
  .chat-title-wrap p { display: none; }
  .presence-strip { min-height: 38px; padding-left: 10px; padding-right: 10px; }
  .presence-more { display: none; }

  #messages { padding: 10px 10px 12px; }
  .msg { max-width: 91%; margin-bottom: 8px; }
  .msg > .character-portrait { width: 31px; height: 31px; }
  .composer { min-height: 54px; padding: 6px 8px; grid-template-columns: 31px minmax(0,1fr) 38px; }
  .composer input { height: 39px; }

  /* Compact world header leaves more vertical space for the scene. */
  .world-header {
    min-height: 48px;
    padding: 5px 8px;
    display: flex;
    align-items: center;
    gap: 7px;
  }
  .world-heading { min-width: 90px; margin: 0; display: block; }
  .world-heading strong { font-size: 10px; white-space: nowrap; }
  .world-kicker { display: none; }
  .world-tools { min-width: 0; flex: 1; display: block; }
  .location-tabs { justify-content: flex-start; gap: 5px; }
  .location-tabs button { height: 30px; padding: 0 9px; font-size: 10px; }
  .world-back { display: none !important; }

  .world-pane { overflow: hidden !important; }
  .scene-wrap { min-height: 0; flex: 1 1 auto; padding: 4px 5px 5px; display: block; overflow: hidden; }
  .scene {
    width: 100%;
    aspect-ratio: 16 / 9;
    height: auto;
    min-height: 0;
    border-radius: 10px;
  }
  #city { width: 100%; height: 100%; }
  .scene-status { top: 6px; left: 6px; }
  .hint { bottom: 6px; font-size: 8px; }

  dialog { padding: 24px; }

  body.sidebar-open::after {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 90;
    background: rgba(35,45,57,.25);
    backdrop-filter: blur(1px);
  }
}

@media (max-width: 420px) {
  .workspace { grid-template-rows: minmax(0, 54%) minmax(0, 46%) !important; }
  .presence-label { display: none; }
  .room-count { min-width: 24px; padding: 0 5px; }
  .chat-title-line h1 { max-width: 56vw; }
  #people .character-portrait { width: 29px; height: 29px; }
  .msg-meta { font-size: 10px; }
  .msg p { font-size: 12.5px; }
  .world-heading { display: none; }
  .world-tools { width: 100%; }
  .world-header { min-height: 38px; padding: 3px 5px; }
  .location-tabs button { height: 28px; padding: 0 8px; font-size: 9px; }
}

@media (max-width: 1024px) and (orientation: landscape) {
  .workspace { grid-template-rows: minmax(0, 52%) minmax(0, 48%) !important; }
  .chat-header { min-height: 48px; }
  .presence-strip { min-height: 34px; }
  .composer { min-height: 48px; }
  .world-header { min-height: 42px; }
}


@media (max-width: 1024px) {
  .world-native-trigger {
    height: 30px;
    padding: 0 8px;
    font-size: 10px;
  }

  .world-native-popup {
    width: min(250px, calc(100vw - 14px));
  }
}

@media (max-width: 420px) {
  .world-native-trigger {
    width: 32px;
    padding: 0;
    justify-content: center;
  }

  .world-native-trigger > span:nth-child(2),
  .world-native-caret {
    display: none;
  }
}


@media (max-width: 1024px) {
  .room-native-popup {
    width: min(250px, calc(100vw - 16px));
  }
}

@media (max-width: 420px) {
  .room-native-trigger {
    width: 20px;
    height: 20px;
  }
}


@media (max-width: 1024px) {
  .room-world-switcher {
    max-height: min(260px, 42dvh);
  }

  .room-world-option {
    min-height: 50px;
  }

  /* Нижняя шапка мира теперь только с названием/онлайном. */
  .world-tools {
    flex: 0 0 auto !important;
  }
}

@media (max-width: 420px) {
  .room-native-popup {
    left: auto;
    right: -18px;
    width: min(290px, calc(100vw - 12px));
  }

  .room-native-popup::before {
    left: auto;
    right: 25px;
  }

  .room-world-option-content small {
    display: none;
  }
}


@media (max-width: 420px) {
  .room-world-category,
  .room-world-back {
    min-height: 40px;
    padding: 0 12px;
    font-size: 12px;
  }

  .room-world-category-icon {
    font-size: 16px;
  }
}


@media (max-width: 1024px) {
  .room-native-popup {
    max-height: calc(100dvh - 72px);
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }

  /* chat-pane overflow must stay visible on mobile too,
     otherwise the dropdown gets cut at the boundary between chat and world. */
  .chat-pane {
    overflow: visible !important;
    z-index: 40;
  }

  .world-pane {
    z-index: 1;
  }
}

@media (max-height: 620px) {
  .room-native-popup {
    max-height: calc(100dvh - 58px);
  }

  .room-native-item,
  .room-world-category,
  .room-world-back {
    min-height: 38px;
  }
}


@media (max-width: 1024px) {
  .world-browser {
    position: fixed;
    inset: 0;
    z-index: 160;
  }

  .world-browser-header {
    min-height: 64px;
    padding: 8px 10px;
    gap: 10px;
  }

  .world-browser-back {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    font-size: 27px;
  }

  .world-browser-title-wrap h2 {
    font-size: 17px;
  }

  .world-browser-title-wrap p {
    display: none;
  }

  .world-browser-search {
    margin: 10px 10px 0;
    height: 44px;
  }

  .world-browser-content {
    padding: 12px 10px 18px;
    -webkit-overflow-scrolling: touch;
  }

  .world-browser-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .world-card {
    border-radius: 14px;
  }

  .world-card-cover {
    aspect-ratio: 16 / 6.5;
  }

  .world-card-body {
    padding: 11px;
  }

  .world-card-body p {
    min-height: 0;
    margin-bottom: 10px;
  }
}


@media (max-width: 1024px) {
  .world-create-button {
    height: 34px;
    padding: 0 10px;
    font-size: 10px;
  }
  .world-create-form {
    grid-template-columns: minmax(0, 1fr) 270px;
    gap: 12px;
  }
  .world-create-main,
  .world-create-side-card { padding: 16px; }
}

@media (max-width: 1100px) {
  .world-template-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 980px) {
  .world-template-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 760px) {
  .world-create-form { grid-template-columns: 1fr; }
  .world-create-actions-card { position: static; }
}

@media (max-width: 420px) {
  .world-browser-header { flex-wrap: nowrap; }
  .world-create-button span { font-size: 16px; }
  .world-create-button { padding: 0 9px; }
  .world-template-grid { grid-template-columns: 1fr 1fr; }
  .world-template-grid label > span { height: 82px; }
  .world-create-main,
  .world-create-side-card { border-radius: 14px; }
  .my-world-actions { align-items: flex-end; }
}

@media (max-width: 520px) {
  .my-world-actions {
    align-items: stretch;
    flex-direction: column;
  }
  .my-world-action-buttons {
    width: 100%;
  }
  .my-world-enter,
  .my-world-manage {
    flex: 1 1 0;
  }
}

/* v31 — search теперь принадлежит только разделу /worlds/search */
@media (max-width: 1024px) {
  .world-section-search .world-browser-search {
    margin: 0 0 12px;
  }
}

@media (max-width: 1024px) {
  .workspace {
    display: flex !important;
    flex-direction: column;
    padding: 10px;
    gap: 0;
    background: #eef2f6;
  }

  .world-pane {
    flex: 1 1 auto !important;
    min-height: 0;
  }

  .chat-pane {
    flex: 0 0 42dvh !important;
    min-height: 240px;
    border-radius: 0 0 18px 18px;
  }

  .scene {
    min-height: 0;
    border-radius: 18px 18px 0 0;
  }

  .world-overlay-bar {
    top: 10px;
    left: 10px;
    max-width: calc(100% - 20px);
  }

  .world-overlay-pill {
    min-height: 54px;
    padding: 6px 8px 6px 9px;
    gap: 9px;
    border-radius: 17px;
  }

  .world-overlay-icon {
    width: 36px;
    height: 36px;
    border-radius: 12px;
  }

  .world-overlay-icon .ui-icon {
    width: 20px;
    height: 20px;
  }

  .world-overlay-copy strong {
    font-size: 14px;
  }

  .world-overlay-meta {
    font-size: 12px;
    gap: 6px;
  }

  .world-overlay-people .character-portrait,
  #people .character-portrait {
    width: 30px;
    height: 30px;
  }

  .room-native-menu-world .room-native-trigger {
    width: 34px;
    height: 34px;
  }

  .chat-header {
    min-height: 56px;
    padding: 0 12px;
    gap: 10px;
  }

  .chat-title-line-compact h2 {
    font-size: 16px;
  }

  .chat-title-line-compact .ui-icon {
    width: 24px;
    height: 24px;
  }

  .chat-presence-inline {
    gap: 8px;
  }

  .chat-presence-label {
    font-size: 11px;
  }

  #messages {
    padding: 10px 12px;
  }

  .msg {
    max-width: 92%;
    margin-bottom: 10px;
  }

  .msg > .character-portrait {
    width: 34px;
    height: 34px;
  }

  .msg p {
    font-size: 13px;
  }

  .composer {
    min-height: 62px;
    padding: 9px 10px 10px;
    grid-template-columns: 38px minmax(0,1fr) 58px;
    gap: 8px;
  }

  .composer-tool {
    width: 38px;
    height: 38px;
    font-size: 22px;
  }

  .composer input {
    height: 42px;
    padding: 0 14px;
    font-size: 13px;
    border-radius: 14px;
  }

  .send-button {
    width: 54px;
    height: 42px;
    border-radius: 14px;
    font-size: 23px;
  }
}

@media (max-width: 620px) {
  .workspace {
    padding: 8px;
  }

  .chat-presence-label {
    display: none;
  }

  .world-overlay-pill {
    min-height: 48px;
    padding: 5px 7px;
    gap: 7px;
  }

  .world-overlay-copy strong {
    font-size: 13px;
  }

  .world-overlay-meta {
    font-size: 11px;
  }

  .world-overlay-icon {
    width: 32px;
    height: 32px;
    border-radius: 10px;
  }

  .world-overlay-people .location-person-link + .location-person-link,
  #people .location-person-link + .location-person-link {
    margin-left: -7px;
  }

  .world-overlay-people .character-portrait,
  #people .character-portrait {
    width: 28px;
    height: 28px;
  }

  .room-native-menu-world .room-native-trigger {
    width: 30px;
    height: 30px;
  }

  .chat-pane {
    flex-basis: 44dvh !important;
    min-height: 220px;
  }
}

@media (max-width: 1024px) {
  .scene-wrap {
    flex: 1 1 auto;
    min-height: 0;
    padding: 0;
    display: flex;
  }

  .scene {
    width: 100%;
    height: 100%;
    min-height: 0;
    aspect-ratio: auto;
  }

  #city {
    width: 100%;
    height: 100%;
  }
}
