@media (max-width: 920px) {
  body {
    overflow: auto;
  }

  .topbar {
    position: sticky;
    top: 0;
    z-index: 40;
    height: auto;
    min-height: 68px;
    flex-wrap: wrap;
    gap: 12px;
    padding: 12px 14px;
  }

  .brand-mark {
    width: 32px;
    height: 32px;
  }

  .brand strong {
    font-size: 16px;
  }

  #roomLabel {
    max-width: 58vw;
  }

  .top-actions {
    flex: 1 1 100%;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    width: 100%;
  }

  .top-actions .ghost-button,
  .top-actions .primary-button,
  .top-actions .status-badge {
    min-width: 0;
    min-height: 38px;
    padding: 0 10px;
    justify-content: center;
    font-size: 13px;
  }

  .app-layout {
    grid-template-columns: 64px minmax(0, 1fr);
    height: auto;
    min-height: calc(100vh - 68px);
    min-height: calc(100svh - 68px);
  }

  .app-layout.chat-collapsed {
    grid-template-columns: 64px minmax(0, 1fr);
  }

  .room-lobby {
    min-height: calc(100vh - 68px);
    min-height: calc(100svh - 68px);
    padding: 28px 14px;
  }

  .room-lobby-form {
    grid-template-columns: 1fr;
  }

  .participant-sidebar {
    padding: 12px 8px;
  }

  .stage {
    padding: 12px;
  }

  .side-panel {
    grid-column: 1 / -1;
    grid-template-rows: none;
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .chat-panel-toggle {
    left: auto;
    right: 14px;
    top: -48px;
    width: 40px;
    height: 40px;
    border: 1px solid var(--line);
    border-radius: 8px;
  }

  .app-layout.chat-collapsed .side-panel {
    min-height: 44px;
    border-top-color: transparent;
  }

  .app-layout.chat-collapsed .chat-panel-toggle {
    left: auto;
    right: 8px;
    top: 4px;
    width: 64px;
    height: 36px;
  }

  .app-layout.chat-collapsed .chat-panel {
    display: none;
  }

  .video-grid {
    grid-template-columns: 1fr;
    grid-auto-rows: minmax(240px, 1fr);
  }

  .focus-layout.video-grid {
    height: calc(100vh - 112px);
    height: calc(100svh - 112px);
    min-height: 420px;
  }

  .focus-layout .video-tile.is-pip {
    right: 12px;
    bottom: var(--pip-offset, 12px);
    width: clamp(132px, 38vw, 210px);
  }

  .hidden-tile-dock {
    left: 12px;
    bottom: 12px;
    max-width: calc(100% - 24px);
  }

  .participant-popover {
    left: calc(100% + 8px);
    min-width: 170px;
  }
}

@media (max-width: 760px) {
  .topbar {
    min-height: 64px;
    padding: 10px;
  }

  .brand {
    flex: 1 1 auto;
  }

  #roomLabel {
    max-width: 66vw;
  }

  .app-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
    min-height: calc(100vh - 64px);
    min-height: calc(100svh - 64px);
  }

  .app-layout.chat-collapsed {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
  }

  .participant-sidebar {
    grid-row: 1;
    padding: 8px 10px 6px;
    overflow-x: auto;
    overflow-y: visible;
    background: rgba(8, 12, 18, 0.96);
    border-right: 0;
    border-bottom: 1px solid var(--line);
    scrollbar-width: none;
  }

  .participant-sidebar::-webkit-scrollbar {
    display: none;
  }

  .participant-sidebar .participants {
    height: auto;
  }

  .participant-sidebar .section-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 8px;
  }

  .participant-sidebar .section-heading h2 {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  .participant-sidebar .section-actions {
    display: flex;
    gap: 8px;
  }

  #participantList {
    display: flex;
    align-items: center;
    gap: 10px;
    overflow-x: auto;
    overflow-y: visible;
    padding: 3px 2px 8px;
    scrollbar-width: none;
  }

  #participantList::-webkit-scrollbar {
    display: none;
  }

  .participant-item {
    flex: 0 0 auto;
  }

  .participant-avatar {
    width: 46px;
    min-width: 46px;
    height: 46px;
    min-height: 46px;
  }

  .participant-popover {
    position: fixed;
    left: 10px;
    right: 10px;
    top: auto;
    bottom: calc(74px + env(safe-area-inset-bottom));
    z-index: 60;
    min-width: 0;
    max-width: none;
    max-height: min(430px, calc(100svh - 118px));
    overflow: auto;
    transform: none;
  }

  .participant-audio-row input[type="range"] {
    min-height: 32px;
  }

  .stage {
    grid-row: 2;
    padding: 10px;
    overflow: visible;
  }

  .video-grid {
    gap: 10px;
    min-height: 280px;
    height: auto;
    grid-auto-rows: minmax(220px, min(58svh, 420px));
  }

  .focus-layout.video-grid {
    height: calc(100vh - 150px);
    height: calc(100svh - 150px);
    min-height: 320px;
    max-height: 620px;
  }

  .focus-layout .video-tile.is-pip {
    right: 10px;
    bottom: var(--pip-offset, 10px);
    width: clamp(126px, 42vw, 190px);
    max-width: calc(100% - 20px);
  }

  .video-tile,
  .focus-layout .video-tile.is-featured {
    border-radius: 8px;
  }

  .video-tile,
  .video-tile video {
    min-height: 0;
  }

  .hidden-tile-dock {
    left: 10px;
    right: 10px;
    bottom: 10px;
    max-width: none;
  }

  .hidden-tile-button {
    width: 40px;
    height: 40px;
  }

  .side-panel {
    grid-row: 3;
    gap: 12px;
    padding: 12px 10px;
    overflow: visible;
    background: var(--bg);
  }

  .stage-controls {
    position: absolute;
    left: 50%;
    bottom: 14px;
    z-index: 35;
    grid-template-columns: repeat(3, 52px);
    gap: 6px;
    margin: 0;
    padding: 8px;
    transform: translate(-50%, var(--stage-controls-y));
  }

  .stage > .call-stats {
    left: 10px;
    bottom: 82px;
    width: min(500px, calc(100% - 20px));
  }

  .control-button {
    min-height: 52px;
    padding: 0 6px;
    font-size: 13px;
  }

  .control-icon {
    width: 26px;
    height: 26px;
  }

  .settings-grid {
    grid-template-columns: 1fr;
  }

  .settings-grid .device-setting {
    display: none;
  }

  .settings-dialog {
    width: calc(100vw - 20px);
    max-height: calc(100svh - 20px);
  }

  .settings-dialog-card {
    padding: 12px;
  }

  .settings-field.wide,
  .settings-toggle.wide,
  .settings-profile.wide {
    grid-column: auto;
  }

  .call-stats-grid {
    grid-template-columns: 1fr 1fr;
  }

  .chat-panel {
    min-height: 360px;
    grid-template-rows: auto minmax(220px, 40svh) auto;
  }

  .chat-messages {
    min-height: 220px;
    max-height: 40svh;
  }

  .chat-input-row {
    grid-template-columns: 40px 40px minmax(0, 1fr) 40px;
  }

  .chat-image-button {
    max-width: 100%;
  }

  .chat-image-dialog {
    width: calc(100vw - 20px);
    max-height: calc(100svh - 20px);
  }

  .emoji-picker {
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: calc(80px + env(safe-area-inset-bottom));
    max-height: min(280px, 48svh);
  }
}

@media (max-width: 520px) {
  .top-actions {
    grid-template-columns: 48px 48px minmax(0, 1fr);
    align-items: center;
  }

  .status-badge {
    grid-column: 1 / -1;
  }

  .top-actions .icon-text-button {
    width: 48px;
    min-width: 48px;
    height: 48px;
    min-height: 48px;
    padding: 0;
  }

  .top-actions .icon-text-button span:not(.button-icon) {
    display: none;
  }

  .top-actions .icon-text-button .button-icon {
    width: 24px;
    height: 24px;
  }

  #joinButton {
    grid-column: 3;
  }

  .status-badge,
  .control-button,
  .primary-button {
    width: 100%;
    justify-content: center;
  }

  .chat-input-row .chat-send-button {
    width: 40px;
    min-width: 40px;
  }

  .room-lobby {
    padding: 22px 12px;
  }

  .room-lobby-heading h1 {
    font-size: 24px;
  }

  .recent-room-list,
  .call-stats-grid {
    grid-template-columns: 1fr;
  }

  .recent-room-card {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .settings-dialog,
  .chat-image-dialog,
  .settings-panel,
  .call-stat,
  .chat-message {
    border-radius: 8px;
  }

  .tile-footer {
    margin: 8px;
    min-height: 34px;
    font-size: 12px;
  }

  .tile-action {
    width: 34px;
    height: 34px;
  }

  .hide-button {
    left: 52px;
  }

  .zoom-reset-button {
    top: 52px;
  }
}

@media (max-width: 390px) {
  #roomLabel {
    max-width: 58vw;
  }

  .stage-controls {
    grid-template-columns: repeat(3, 48px);
  }

  .stage-controls .control-button {
    width: 48px;
  }

  .focus-layout.video-grid {
    height: calc(100vh - 170px);
    height: calc(100svh - 170px);
    min-height: 300px;
  }

  .focus-layout .video-tile.is-pip {
    width: clamp(112px, 44vw, 156px);
  }

  .participant-popover {
    bottom: calc(126px + env(safe-area-inset-bottom));
  }
}

@media (orientation: landscape) and (max-height: 520px) and (max-width: 920px) {
  .topbar {
    position: relative;
  }

  .app-layout {
    grid-template-columns: 60px minmax(0, 1fr) minmax(280px, 34vw);
    grid-template-rows: 1fr;
    height: calc(100vh - 64px);
    height: calc(100svh - 64px);
  }

  .app-layout.chat-collapsed {
    grid-template-columns: 60px minmax(0, 1fr) 44px;
  }

  .participant-sidebar {
    display: block;
    grid-row: auto;
    padding: 8px 7px;
    border-right: 1px solid var(--line);
    border-bottom: 0;
  }

  #participantList {
    display: grid;
    overflow: visible;
  }

  .stage {
    grid-row: auto;
    padding: 8px;
  }

  .side-panel {
    grid-row: auto;
    grid-column: auto;
    padding: 8px;
    overflow: auto;
    border-top: 0;
    border-left: 1px solid var(--line);
  }

  .focus-layout.video-grid {
    height: 100%;
    min-height: 0;
  }

  .stage-controls {
    position: absolute;
    left: 50%;
    bottom: 8px;
    grid-template-columns: repeat(3, 48px);
    margin: 0;
    padding: 6px;
    transform: translate(-50%, var(--stage-controls-y));
  }
}
