/* CRYOTALE MOBILE PORTRAIT V1 | isolated narrow-screen override
 * Load AFTER style.css and profile_chat.css.
 * Desktop and unfolded Fold remain unchanged. No JS / auth / chat changes.
 */
@media screen and (max-width:600px) {
  html, body { width:100%; max-width:100%; overflow-x:hidden; }
  #chat-view.app-layout, .chat-main, .chat-scroll { width:100%; max-width:100%; min-width:0; }

  /* Header: all controls have explicit width; names must NOT stack vertically. */
  .topbar { height:64px; min-height:64px; padding:0 10px !important; gap:7px !important; justify-content:flex-start; }
  .topbar .menu-toggle { flex:0 0 auto; padding:7px; }
  .topbar-bot { flex:0 1 auto; min-width:0; margin-right:0 !important; gap:7px; }
  .topbar-bot .avatar-small { flex:0 0 38px; width:38px; height:38px; border-radius:10px; }
  .topbar-identity { min-width:0; max-width:106px; }
  .topbar-identity strong { display:block; font-size:12px; line-height:1.3; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; word-break:keep-all; }
  .topbar .topbar-sparkle { display:none; }
  .topbar .online-line { font-size:10px; white-space:nowrap; margin-top:2px; }
  .topbar .profile-top-wrap { margin-left:auto; min-width:0; flex:0 0 auto; }
  .topbar .profile-top-toggle { min-width:38px; height:38px; max-width:40px; padding:3px; }
  .topbar .profile-top-avatar { width:30px; height:30px; flex:0 0 30px; }
  .topbar .profile-top-name, .topbar .profile-chevron { display:none; }
  .topbar .character-picker-wrap { margin-left:0; min-width:0; max-width:min(43vw,165px); flex:0 1 auto; }
  .topbar .character-toggle { min-width:0; width:100%; max-width:100%; min-height:38px; gap:5px; padding:4px 7px; font-size:11px; white-space:nowrap; }
  .topbar .character-toggle-label { display:block; min-width:0; flex:1 1 auto; max-width:none; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; word-break:keep-all; }
  .topbar .character-toggle .picker-avatar { width:27px; height:27px; flex:0 0 27px; }
  .topbar .model-pill { display:none; }
  .character-menu { right:0; width:min(310px, calc(100vw - 22px)); max-height:min(70dvh,530px); overflow-y:auto; overscroll-behavior:contain; }
  .character-menu .role-option .role-caption { min-width:0; }

  /* Welcome: never leave role cards and session card sharing a cramped row. */
  #empty-chat.terminal-home { display:block; min-width:0; width:100%; max-width:100%; padding:12px 12px 20px; }
  #empty-chat .terminal-dashboard { display:flex !important; flex-direction:column !important; gap:12px; width:100%; min-width:0; min-height:0; }
  #empty-chat .terminal-center { order:0; width:100%; min-width:0; min-height:clamp(350px,57svh,500px); flex:0 0 auto; }
  #empty-chat .terminal-left { order:1; display:flex !important; flex-direction:column; min-width:0; width:100%; gap:12px; }
  #empty-chat .terminal-right { order:2; display:flex !important; flex-direction:column !important; grid-template-columns:none !important; grid-column:auto; min-width:0; width:100%; gap:12px; }
  #empty-chat .terminal-left > .terminal-panel,
  #empty-chat .terminal-right > .terminal-panel { width:100%; min-width:0; max-width:100%; }
  #empty-chat .greeting-panel, #empty-chat .micro-panel, #empty-chat .companion-card { display:none; }
  #empty-chat .quicktalk-panel, #empty-chat .access-card, #empty-chat .link-card { display:block !important; min-height:0; flex:0 0 auto; }
  #empty-chat .terminal-panel { padding:15px; }
  #empty-chat .panel-title { display:flex; align-items:center; gap:8px; min-width:0; font-size:14px; line-height:1.4; white-space:nowrap; word-break:keep-all; }
  #empty-chat .panel-title small { margin-left:auto; font-size:10px; flex:0 0 auto; }
  #empty-chat .terminal-quick-list { grid-template-columns:minmax(0,1fr); }
  #empty-chat .terminal-quick-list button { min-height:57px; }
  #empty-chat .link-data { font-size:12px; padding:11px 0; }
  #empty-chat .link-data strong { font-size:13px; }

  /* Vertical names are the core defect: use a full-width scrollable list. */
  #character-panel-options.role-card-list { display:grid !important; grid-template-columns:minmax(0,1fr) !important; grid-auto-rows:76px; gap:9px; width:100%; min-width:0; max-width:100%; max-height:334px; overflow-x:hidden; overflow-y:auto; padding-right:3px; }
  #character-panel-options .role-option { display:flex !important; flex-direction:row !important; align-items:center; width:100%; min-width:0; max-width:100%; height:76px; min-height:0; padding:9px 10px; gap:11px; text-align:left; writing-mode:horizontal-tb; }
  #character-panel-options .role-icon { flex:0 0 48px; width:48px; height:48px; }
  #character-panel-options .role-caption { display:flex; flex:1 1 auto; flex-direction:column; min-width:0; gap:4px; writing-mode:horizontal-tb; }
  #character-panel-options .role-caption strong { display:block; font-size:14px; line-height:1.35; font-weight:750; letter-spacing:normal; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; writing-mode:horizontal-tb; word-break:keep-all; }
  #character-panel-options .role-caption small { display:block; font-size:11px; line-height:1.4; letter-spacing:normal; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; writing-mode:horizontal-tb; }
  #character-panel-options .role-status { flex:0 0 auto; font-size:10px; padding:5px 7px; white-space:nowrap; }
  #empty-chat .role-panel-hint { margin:12px 0 0; line-height:1.65; font-size:11px; }

  /* Active chat: full width, readable messages, fixed bottom composer. */
  #conversation-scene.conversation-scene { display:block; width:100%; max-width:100%; min-width:0; padding:10px 10px 18px; }
  #conversation-scene .conversation-feed { width:100%; max-width:100%; min-width:0; min-height:260px; }
  #conversation-scene .conversation-title { padding:12px 12px; gap:6px; flex-wrap:wrap; font-size:11px; }
  #conversation-scene .conversation-feed .messages { min-width:0; padding:15px 10px 24px; gap:17px; }
  #conversation-scene .message { min-width:0; max-width:100%; gap:8px; }
  #conversation-scene .message .message-content { min-width:0; overflow-wrap:anywhere; word-break:break-word; }
  #conversation-scene .message.bot .message-content { max-width:calc(100% - 44px); padding:11px; }
  #conversation-scene .message.user .message-content { max-width:calc(100% - 43px); padding:10px 12px; }
  #conversation-scene .message-text { font-size:13px; line-height:1.8; overflow-wrap:anywhere; }
  #conversation-scene .conversation-companion { display:none; }
  .composer-wrap { width:100%; max-width:100%; padding:6px 10px max(9px, env(safe-area-inset-bottom)); }
  .composer { min-width:0; padding:6px 7px 6px 12px; }
  .composer textarea { min-width:0; font-size:16px; line-height:1.45; }
  .composer .send-btn { min-width:43px; width:43px; height:43px; }
  .composer-footer { margin:6px 0 0; font-size:9px; }
  .toast { max-width:calc(100vw - 28px); overflow-wrap:anywhere; }
}

@media screen and (max-width:390px) {
  .topbar { gap:5px !important; padding:0 7px !important; }
  .topbar .menu-toggle { padding:5px; }
  .topbar-bot { gap:5px; }
  .topbar-bot .avatar-small { flex-basis:34px; width:34px; height:34px; }
  .topbar-identity { max-width:72px; }
  .topbar-identity strong { font-size:11px; }
  .topbar .character-picker-wrap { max-width:38vw; }
  .topbar .character-toggle .picker-avatar { display:none; }
  #empty-chat.terminal-home { padding-left:9px; padding-right:9px; }
  #empty-chat .terminal-panel { padding:12px; }
  #character-panel-options .role-icon { flex-basis:44px; width:44px; height:44px; }
  #character-panel-options .role-caption strong { font-size:13px; }
  #character-panel-options .role-status { font-size:9px; padding:5px 6px; }
}
