/* V7.1: incremental iPhone layout only; preserve the existing CARL visual system. */
@media (max-width: 600px){
  #chatPanel {box-sizing:border-box;max-width:calc(100vw - 16px);max-height:calc(100dvh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 20px);}
  #chatPanel .messages {min-height:100px;overflow-y:auto;overscroll-behavior:contain;}
  #chatPanel .compose {min-width:0;box-sizing:border-box;}
  #chatPanel #commandInput {min-width:0;max-width:100%;font-size:16px!important;}
  #chatPanel .ai-console {max-width:100%;min-width:0;box-sizing:border-box;}
  #c60-file-status {overflow-wrap:anywhere;word-break:break-word;display:inline-block;max-width:100%;}
  #caRoot .ca-shell {min-width:0;max-width:100%;box-sizing:border-box;}
  #caRoot .ca-main {min-width:0;overflow-x:hidden;}
  #caRoot .ca-card, #caRoot .ca-transcript, #caRoot .ca-compose {box-sizing:border-box;max-width:100%;overflow-wrap:anywhere;}
  #caRoot textarea, #caRoot input, #caRoot select {max-width:100%;min-width:0;font-size:16px;box-sizing:border-box;}
  #b2Desk {max-width:calc(100vw - 12px);box-sizing:border-box;}
  #b2Desk input, #b2Desk textarea, #b2Desk select {max-width:100%;box-sizing:border-box;font-size:16px;}
}

/* CARL V7.1.1 — iPhone portrait HOME layout repair.
   Root cause: legacy carl-block3.css !important rules cap .stage to 330–460px
   even when .stage-grid flexes to fill the display. As a result, the empty
   remainder is a child of .stage-grid, invisible to the user.
   This overrides that compact rule ONLY for the idle HOME screen; panels keep
   the existing functional layout and all orbital controls remain available. */
@media (max-width: 700px) and (orientation: portrait) {
  #appView {
    box-sizing: border-box;
    height: 100svh;
    min-height: 100svh !important;
    padding: calc(env(safe-area-inset-top) + 12px) 12px calc(env(safe-area-inset-bottom) + 10px) !important;
  }
  #appView .topline {
    flex: 0 0 auto;
    flex-wrap: nowrap !important;
    gap: 7px !important;
    min-width: 0;
    align-items: center;
  }
  #appView .topline .carl-shortcuts {
    flex-wrap: nowrap !important;
    gap: 5px;
    margin-left: auto;
  }
  #appView .top-brand {
    font-size: clamp(20px, 5.5vw, 25px) !important;
  }
  #appView .topline button {
    min-height: 38px !important;
    padding: 7px 8px !important;
    margin: 0 !important;
    font-size: clamp(9px, 2.6vw, 11px) !important;
  }
  #appView .shield {flex:0 0 34px;width:34px;height:34px}
  #appView .stage-grid {
    flex: 1 1 auto;
    display: grid !important;
    grid-template-columns: minmax(0,1fr) !important;
    grid-template-rows: minmax(0,1fr) !important;
    align-items: stretch !important;
    min-height: 0 !important;
    margin-top: 0 !important;
    width: 100%;
  }
  #appView .stage:not(.chat-open):not(.settings-open):not(.voice-open) {
    height: 100% !important;
    min-height: 0 !important;
    width: 100%;
    align-self: stretch;
    margin-top: 0 !important;
  }
  #appView .stage:not(.chat-open):not(.settings-open):not(.voice-open) .core-region {
    width: clamp(200px, 62vw, 265px) !important;
    top: 46% !important;
  }
  #appView .stage:not(.chat-open):not(.settings-open):not(.voice-open) .ambient-ring.outer {inset:-30px!important}
  #appView .stage:not(.chat-open):not(.settings-open):not(.voice-open) .ambient-ring {inset:-18px!important}
  #appView .stage:not(.chat-open):not(.settings-open):not(.voice-open) .carl-telemetry {
    inset: 0;
    display: grid !important;
    grid-template-columns: repeat(3,minmax(0,1fr)) !important;
    grid-template-rows: 60px minmax(0,1fr) 60px !important;
    grid-auto-rows: auto !important;
    align-content: stretch !important;
    justify-content: stretch !important;
    align-items: stretch !important;
    padding: clamp(18px,3svh,30px) 2px clamp(16px,2.5svh,26px) !important;
    column-gap: 4px !important;
    row-gap: 0 !important;
  }
  #appView .stage:not(.chat-open):not(.settings-open):not(.voice-open) .carl-telemetry-cell {
    min-width: 0;
    padding: 5px 3px 5px 7px !important;
    gap: 4px;
    background: transparent !important;
    text-align: left !important;
    border-left: 1px solid #9c852e85 !important;
    border-right: 0 !important;
  }
  #appView .stage:not(.chat-open):not(.settings-open) .carl-telemetry-cell:nth-child(-n+3) {
    grid-row: 1 !important;
    align-self: start !important;
  }
  #appView .stage:not(.chat-open):not(.settings-open) .carl-telemetry-cell:nth-child(n+4) {
    grid-row: 3 !important;
    align-self: end !important;
  }
  #appView .carl-telemetry-cell span {font-size: 8px !important;letter-spacing: .02em !important;line-height:1.25}
  #appView .carl-telemetry-cell strong {font-size: 10px !important;letter-spacing: 0 !important;line-height:1.3}
  #appView .stage:not(.chat-open):not(.settings-open):not(.voice-open) .hold-hint {bottom: 25% !important;}
  #appView .stage:not(.chat-open):not(.settings-open):not(.voice-open) .core-message {bottom: 15% !important;}
  #appView .stage:not(.chat-open):not(.settings-open):not(.voice-open) .stage-code {display:none}
  #appView .bottomline {flex:0 0 auto; margin-top:0; padding-top:8px;min-height:23px}
  /* When a panel opens, retain a scrollable page instead of clipping chat or voice. */
  #appView:has(.stage.chat-open,.stage.settings-open,.stage.voice-open) {height:auto;min-height:100svh !important;}
  #appView:has(.stage.chat-open,.stage.settings-open,.stage.voice-open) .stage-grid {
    grid-template-rows:minmax(650px,auto) !important;
  }
}
@media (max-width: 700px) and (max-height: 720px) and (orientation: portrait) {
  #appView .stage:not(.chat-open):not(.settings-open):not(.voice-open) .core-region {width:clamp(182px,57vw,220px)!important;top:45%!important}
  #appView .stage:not(.chat-open):not(.settings-open):not(.voice-open) .hold-hint {bottom: 26% !important;}
  #appView .stage:not(.chat-open):not(.settings-open):not(.voice-open) .core-message {bottom: 14% !important;}
  #appView .stage:not(.chat-open):not(.settings-open):not(.voice-open) .carl-telemetry {grid-template-rows:54px minmax(0,1fr) 54px!important;padding-top:12px!important;padding-bottom:12px!important}
}
@media (max-width: 359px) and (orientation:portrait) {
  #appView .topline .carl-shortcuts button {font-size:9px!important;padding:7px 5px!important}
  #appView .top-brand {font-size:20px!important}
  #appView .stage:not(.chat-open):not(.settings-open):not(.voice-open) .carl-telemetry-cell strong {font-size:9px!important}
}
/* Short landscape viewports should scroll naturally, never crop core controls. */
@media (max-width: 950px) and (max-height: 520px) and (orientation:landscape) {
  #appView{height:auto;min-height:100svh!important}
  #appView .stage-grid{display:block!important;flex:1}
  #appView .stage{min-height:390px!important}
}
@media (max-width: 700px) {
  /* Invisible caption previously widened a 320px iPhone page to ~338px. */
  #appView .menu-caption {width:min(100%,calc(100vw - 32px));max-width:calc(100vw - 32px);white-space:normal!important;line-height:1.5;text-align:center}
}
@media (max-width: 359px) and (orientation:portrait) {
  #appView .orbit-item[data-control="voice"] {--x:105px!important}
  #appView .orbit-item[data-control="logout"] {--x:-103px!important}
}
