.stream-mobile-controls,
.stream-mobile-hint,
#streamVirtualPointer {
  display: none;
}

@media (max-width: 900px) and (pointer: coarse), (max-width: 600px), (max-width: 1000px) and (max-height: 600px) {
  .stream-modal {
    max-width: 100vw;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
  }

  .stream-shell {
    max-width: 100vw;
    padding: 6px;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
  }

  .stream-head {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    min-height: 44px;
    margin-bottom: 6px;
    align-items: center;
  }

  .stream-head > div:first-child {
    min-width: 0;
  }

  .stream-head-actions {
    display: block;
    min-width: 0;
    max-width: 100%;
  }

  .stream-head strong {
    font-size: 14px;
  }

  .stream-head small {
    max-width: 58vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .stream-head .stream-shortcut-picker,
  .stream-head .stream-shortcut-send {
    display: none;
  }

  .stream-head #streamClose {
    min-width: 86px;
    min-height: 42px;
    padding: 8px 12px;
    font-size: 15px;
    font-weight: 700;
  }

  .stream-stage {
    border-radius: 6px;
  }

  .stream-stage canvas {
    touch-action: none;
    cursor: none;
  }

  #streamVirtualPointer {
    position: absolute;
    z-index: 4;
    display: block;
    width: 2px;
    height: 2px;
    box-sizing: border-box;
    border: 0;
    border-radius: 50%;
    background: #ff00d4;
    box-shadow: none;
    mix-blend-mode: normal;
    pointer-events: none;
    transform: translate(-50%, -50%);
  }

  #streamVirtualPointer::before,
  #streamVirtualPointer::after {
    content: none;
  }

  .stream-mobile-controls {
    display: grid;
    flex: 0 0 auto;
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
    grid-template-columns: 92px minmax(0, 1fr) 76px;
    grid-template-rows: 52px 54px 54px;
    gap: 6px;
    margin-top: 6px;
  }

  .stream-mobile-controls select,
  .stream-mobile-controls button {
    width: 100%;
    min-width: 0;
    min-height: 52px;
    box-sizing: border-box;
    border-radius: 9px;
    font-size: 16px;
  }

  .stream-mobile-controls select,
  .stream-head select {
    font-size: 16px !important;
    touch-action: manipulation;
  }

  .stream-mobile-controls select {
    grid-column: 2;
    grid-row: 1;
    padding: 8px 28px 8px 10px;
    border: 1px solid #5b8178;
    background: #0a1d18;
    color: #fff;
  }

  .stream-mobile-send {
    grid-column: 3;
    grid-row: 1;
    padding: 8px 7px;
    background: #176ba0;
    font-weight: 700;
  }

  .stream-aux-keys {
    grid-column: 1;
    grid-row: 1;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 3px;
    min-width: 0;
  }

  .stream-mobile-controls .stream-aux-keys button {
    width: 100%;
    min-width: 0;
    min-height: 0;
    height: 100%;
    padding: 4px 1px;
    font-size: 12px;
    line-height: 1;
    font-weight: 800;
    touch-action: manipulation;
  }

  #streamEsc {
    background: #6c3d78;
  }

  #streamEnter {
    background: #176ba0;
  }

  #streamBackspace {
    background: #4c5966;
  }

  .stream-mouse-key {
    padding: 8px 7px;
    background: #0b8069;
    font-weight: 800;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
  }

  #streamLeftMouse {
    grid-column: 1;
    grid-row: 2;
  }

  #streamRightMouse {
    grid-column: 1;
    grid-row: 3;
  }

  .stream-trackpad {
    grid-column: 2 / 4;
    grid-row: 2 / 4;
    display: flex;
    min-width: 0;
    min-height: 0;
    box-sizing: border-box;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border: 2px solid #4f8579;
    border-radius: 10px;
    background:
      radial-gradient(circle at center, #1d5549 0 2px, transparent 3px),
      linear-gradient(135deg, #0d2d26, #123b32);
    color: #d8eee8;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
  }

  .stream-trackpad strong {
    font-size: 16px;
  }

  .stream-trackpad small {
    margin-top: 5px;
    color: #9cc8bd;
    font-size: 12px;
  }

  .stream-mouse-key.right {
    background: #755027;
  }

  .stream-mouse-key.pressed {
    filter: brightness(1.35);
    transform: translateY(1px);
    box-shadow: inset 0 0 0 3px #fff8;
  }

  .stream-mobile-hint {
    display: block;
    flex: 0 0 auto;
    margin: 5px 1px 0;
    color: #b9d4cc;
    font-size: 11px;
    line-height: 1.25;
    text-align: center;
  }

  .stream-help {
    display: none;
  }
}

@media (max-width: 390px) {
  .stream-mobile-controls {
    grid-template-columns: 82px minmax(0, 1fr) 66px;
    grid-template-rows: 48px 50px 50px;
    gap: 4px;
  }

  .stream-mobile-controls select,
  .stream-mobile-controls button {
    min-height: 48px;
    font-size: 14px;
  }
}

@media (orientation: portrait) and (max-width: 900px) {
  .stream-head {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto;
    align-items: stretch;
  }

  .stream-head > div:first-child {
    grid-column: 1;
    grid-row: 1;
  }

  .stream-head-actions {
    grid-column: 1;
    grid-row: 2;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 70px;
    grid-template-rows: 42px 42px;
    gap: 5px;
    width: 100%;
    margin-top: 5px;
  }

  .stream-head .stream-shortcut-picker {
    display: flex;
    grid-column: 1;
    grid-row: 1;
    width: 100%;
  }

  .stream-head .stream-shortcut-picker select {
    width: 100%;
    max-width: none;
    height: 42px;
    box-sizing: border-box;
    font-size: 16px;
  }

  .stream-head .stream-shortcut-send {
    display: block;
    grid-column: 2;
    grid-row: 1;
    min-width: 0;
    min-height: 42px;
    padding: 6px;
  }

  .stream-head .stream-text-open {
    grid-column: 1;
    grid-row: 2;
    width: 100%;
    min-height: 42px;
  }

  .stream-head #streamClose {
    grid-column: 2;
    grid-row: 2;
    min-width: 0;
    min-height: 42px;
    padding: 6px;
    font-size: 14px;
  }

  .stream-mobile-controls {
    grid-template-columns: 88px minmax(0, 1fr);
    grid-template-rows: 42px 50px 50px;
    gap: 5px;
  }

  .stream-mobile-controls > select,
  .stream-mobile-controls > .stream-mobile-send {
    display: none;
  }

  .stream-aux-keys {
    grid-column: 1 / 3;
    grid-row: 1;
  }

  #streamLeftMouse {
    grid-column: 1;
    grid-row: 2;
  }

  #streamRightMouse {
    grid-column: 1;
    grid-row: 3;
  }

  .stream-trackpad {
    grid-column: 2;
    grid-row: 2 / 4;
  }

  .stream-modal.read-only .stream-head-actions {
    grid-template-columns: minmax(0, 1fr) 86px;
    grid-template-rows: auto;
  }

  .stream-modal.read-only .stream-watch-lease {
    grid-column: 1;
    grid-row: 1;
    width: auto;
  }

  .stream-modal.read-only .stream-head #streamClose {
    grid-column: 2;
    grid-row: 1;
  }
}

@media (orientation: landscape) and (max-width: 1000px) and (max-height: 600px) {
  .stream-shell {
    display: grid;
    grid-template-columns: 78px minmax(0, 1fr) 110px;
    grid-template-rows: auto 76px minmax(0, 1fr);
    column-gap: 7px;
  }

  .stream-head {
    grid-column: 1 / 4;
    grid-row: 1;
  }

  .stream-stage {
    grid-column: 2;
    grid-row: 2 / 4;
  }

  .stream-mobile-controls {
    display: contents;
  }

  .stream-mobile-controls select,
  .stream-mobile-controls button {
    min-height: 0;
    font-size: 13px;
  }

  .stream-mobile-controls select,
  .stream-mobile-send {
    display: none;
  }

  .stream-head-actions {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 5px;
    min-width: 0;
    max-width: 100%;
  }

  .stream-head .stream-shortcut-picker,
  .stream-head .stream-shortcut-send {
    display: flex;
    min-width: 0;
  }

  .stream-head .stream-shortcut-picker span {
    display: none;
  }

  .stream-head .stream-shortcut-picker select {
    width: 170px;
    max-width: 22vw;
    height: 40px;
    padding: 6px 22px 6px 7px;
    font-size: 16px;
  }

  .stream-head .stream-shortcut-send {
    min-width: 52px;
    min-height: 40px;
    align-items: center;
    justify-content: center;
    padding: 6px 8px;
    font-size: 13px;
  }

  #streamLeftMouse,
  #streamRightMouse {
    grid-column: 1;
    grid-row: 3;
    width: 100%;
    height: calc(50% - 3px);
  }

  #streamLeftMouse {
    align-self: start;
  }

  #streamRightMouse {
    align-self: end;
  }

  .stream-aux-keys {
    grid-column: 1;
    grid-row: 2;
    width: 100%;
    height: 100%;
  }

  .stream-trackpad {
    grid-column: 3;
    grid-row: 2 / 4;
    align-self: stretch;
  }

  .stream-trackpad strong {
    font-size: 14px;
  }

  .stream-trackpad small {
    max-width: 90px;
    font-size: 10px;
    text-align: center;
  }

  .stream-mobile-hint {
    display: none;
  }
}

/* Read-only broadcasts may be pinch-zoomed by the viewer after orientation
   normalization. Interactive streams keep their touch surfaces locked. */
.stream-modal.read-only .stream-stage {
  touch-action: pinch-zoom;
}
