/* Touch layouts are isolated here so the desktop composition stays intact. */
.sidebar-close { display: none; }

@media (max-width:760px) {
  .workspace .topbar {
    height: calc(64px + env(safe-area-inset-top));
    padding: env(safe-area-inset-top) max(14px,env(safe-area-inset-right)) 0 max(12px,env(safe-area-inset-left));
    gap: 12px;
  }
  .topbar-left { flex: 1; gap: 8px; }
  .topbar h1 { min-width: 0; max-width: none; font-size: 12px; font-weight: 400; }
  .topbar-right { flex-shrink: 0; gap: 2px; }
  .topbar .icon-button, .send-button,
  .reader-header .icon-button, .utility-header .icon-button,
  .notice-header .icon-button { width: 44px; height: 44px; flex-shrink: 0; }
  .topbar .mobile-menu { margin-left: -4px; }
  .workspace .breadcrumb { font-size: 14px; letter-spacing: 1.5px; }
  .topbar:has(#conversation-menu:not([hidden])) .breadcrumb { display: none; }
  .workspace .service-status { min-height: 44px; padding: 8px 4px; font-size: 10px; }

  .sidebar {
    width: min(320px,calc(100vw - 40px));
    padding: max(24px,env(safe-area-inset-top)) 16px max(18px,env(safe-area-inset-bottom));
    overflow-y: auto; overscroll-behavior: contain;
    background: #151619; box-shadow: 16px 0 60px #0004;
  }
  .sidebar > * { flex-shrink: 0; }
  .sidebar .brand { padding: 0 48px 24px 12px; }
  .sidebar-close { display: flex; position: absolute; top: max(18px,env(safe-area-inset-top)); right: 12px; width: 44px; height: 44px; }
  .sidebar .key-hint { display: none; }
  .new-chat, .nav-item { min-height: 48px; font-size: 14px; border-radius: 12px; }
  .main-nav { margin-top: 18px; }
  .history-heading { padding-top: 16px; padding-bottom: 4px; }
  .history-heading .icon-button { width: 44px; height: 44px; }
  .sidebar .history-list { flex: 1 0 88px; }
  .history-item { min-height: 44px; font-size: 13px; }
  .sidebar-bottom { padding-top: 16px; }
  .edition-card { padding: 14px 2px; }
  .help-button { min-height: 44px; padding: 10px 13px; font-size: 12px; }
  .sidebar-backdrop { background: #0506088c; }

  .chat-scroll { scrollbar-gutter: auto; overscroll-behavior-y: contain; }
  .composer-area { padding: 10px max(16px,env(safe-area-inset-right)) max(12px,env(safe-area-inset-bottom)) max(16px,env(safe-area-inset-left)); }
  .composer { padding: 15px 16px 10px; border-radius: 18px; }
  .composer textarea { min-height: 50px; font-size: 16px; line-height: 1.6; }
  .composer-toolbar { margin-top: 6px; }
  .verify-control { min-height: 44px; gap: 7px; padding: 0 7px 0 0; font-size: 12px; }
  .switch-track { width: 28px; height: 16px; }
  .switch-track::after { width: 12px; height: 12px; }
  .verify-control input:checked ~ .switch-track::after { transform: translateX(12px); }
  .composer-hint { max-width: 360px; margin: 8px auto 0; font-size: 10px; line-height: 1.5; text-wrap: balance; }
  .conversation { width: calc(100% - 40px); margin-top: 20px; padding-top: 0; }
  .question-bubble { font-size: 15px; line-height: 1.75; padding: 12px 16px; border-radius: 16px 16px 4px 16px; }
  .answer-body { font-size: 15px; line-height: 1.9; }
  .answer-footer { flex-wrap: wrap; gap: 8px; }
  .answer-footer .icon-button { width: 44px; height: 44px; }
  .verification { max-width: 100%; font-size: 11px; }
  .source-list { grid-template-columns: minmax(0,1fr); }
  .source-card { min-width: 0; min-height: 58px; }
  .source-info { flex: 1; }
  .source-info strong { font-size: 12px; line-height: 1.6; white-space: normal; overflow-wrap: anywhere; }
  .source-info small { font-size: 11px; }

  .library-view, .saved-view { padding: 28px max(20px,env(safe-area-inset-right)) max(28px,env(safe-area-inset-bottom)) max(20px,env(safe-area-inset-left)); }
  .section-heading { margin-bottom: 24px; }
  .section-heading h2 { font-size: 29px; margin: 8px 0 10px; }
  .section-heading p { font-size: 13px; line-height: 1.8; }
  .library-search { min-height: 52px; padding: 12px 14px; border-radius: 14px; }
  .library-filters { flex-wrap: nowrap; overflow-x: auto; gap: 6px; margin: 14px -4px 18px; padding: 4px; scrollbar-width: none; }
  .library-filters::-webkit-scrollbar { display: none; }
  .filter-chip { flex-shrink: 0; min-height: 44px; padding: 10px 15px; font-size: 13px; white-space: nowrap; }
  .document-grid { gap: 10px; }
  .document-card { gap: 12px; padding: 17px 15px; border-radius: 14px; }
  .document-details h3 { font-size: 14px; line-height: 1.7; }
  .document-details p { font-size: 12px; }
  .saved-card { padding: 20px; }
  .saved-card-bottom { gap: 12px; flex-wrap: wrap; }
  .saved-card-bottom button { min-height: 44px; font-size: 12px; }
  .reader-dialog { width: calc(100vw - 16px); max-height: 94dvh; border-radius: 22px; }
  .reader-header { padding: 18px 16px; gap: 12px; }
  .reader-header h2 { font-size: 17px; }
  .reader-body { padding: 18px 12px; }
  .reader-chunk { padding: 16px; }
  .reader-chunk p { font-size: 14px; line-height: 1.95; }
  .reader-footer { padding: 10px 16px max(10px,env(safe-area-inset-bottom)); flex-wrap: wrap; gap: 4px 12px; }
  .reader-footer .text-button { min-height: 44px; font-size: 12px; }
  .notice-header { gap: 10px; padding: 18px 16px; }
  .notice-header h2 { font-size: 18px; line-height: 1.4; }
  .notice-symbol { display: none; }
  .notice-acknowledgement { font-size: 12px; }
  .notice-actions button, .dialog-actions button { min-height: 44px; }
}

/* A portrait composition, rather than a scaled-down two-line desktop banner. */
@media (max-width:600px) {
  .welcome {
    width: calc(100% - 40px); max-width: 520px;
    margin: auto; padding: 42px 0 max(24px,env(safe-area-inset-bottom));
  }
  .welcome h2, .intro-dialog h2 {
    font-size: clamp(36px,13.7cqw,68px); line-height: 1.04;
    letter-spacing: -.045em; word-spacing: .045em;
  }
  .headline-rest { display: block; background: inherit; -webkit-background-clip: text; background-clip: text; animation: inherit; }
  .welcome h2 > .welcome-location, .intro-location {
    display: flex; align-items: baseline; gap: .18em; margin-top: 10px;
    white-space: nowrap;
  }
  .welcome-location .location-prefix, .intro-location .location-prefix {
    font-size: .43em; letter-spacing: -.035em; word-spacing: .04em;
  }
  .welcome-location .njfu-wordmark, .intro-location .njfu-wordmark {
    font-size: 1.35em; line-height: 1;
  }
  .campus-caption { margin-top: 20px; gap: 7px 10px; font-size: 12px; }
  .campus-caption strong { flex-basis: 100%; font-size: 18px; letter-spacing: .3px; }
  .campus-caption > .assistant-tagline { padding-left: 0; border-left: 0; }
  .welcome-workspace { margin-top: 24px; }
  #welcome-input { margin: 0 0 16px; }
  .welcome .composer { padding: 17px 16px 10px; border-radius: 20px; }
  .welcome .composer textarea { min-height: 52px; font-size: 16px; line-height: 1.6; }
  .welcome .composer-toolbar { margin-top: 6px; }
  .welcome .suggestions { gap: 0; padding: 0 15px; background: #ffffff02; border: 1px solid #ffffff10; border-radius: 16px; }
  .welcome .suggestion-card { min-height: 54px; padding: 12px 0; gap: 11px; border: 0; border-radius: 0; }
  .welcome .suggestion-card + .suggestion-card { border-top: 1px solid #ffffff0d; }
  .welcome .suggestion-card:hover { transform: none; background: transparent; }
  .welcome .suggestion-card:active { opacity: .65; }
  .welcome .suggestion-question { font-size: 13px; line-height: 1.65; }
  .welcome .suggestion-symbol svg { width: 17px; height: 17px; }
  .welcome .suggestion-arrow { color: #6e8275; }
  .welcome-footer { gap: 12px; margin-top: 8px; padding: 0 2px; }
  .welcome .browse-link, .welcome .shuffle-button { min-height: 44px; font-size: 12px; }
  .intro-content { width: calc(100% - 40px); container-type: inline-size; padding: 40px 0; }
  .intro-line { overflow: visible; padding-bottom: 0; }
  #intro-description { margin-top: 24px; font-size: 14px; line-height: 1.8; letter-spacing: 0; }
  .intro-school { flex-basis: 100%; font-size: 16px; }
  .intro-description-divider { display: none; }
  .intro-top, .intro-bottom { padding-left: 20px; padding-right: 20px; }
  .intro-skip { min-height: 44px; font-size: 12px; }
}

@media (max-width:360px) {
  .welcome { width: calc(100% - 32px); padding-top: 32px; }
  .campus-caption { gap: 3px 8px; font-size: 11px; }
  .campus-caption strong { font-size: 17px; }
  .welcome .suggestions { padding: 0 12px; }
  .welcome .suggestion-card { gap: 8px; }
  .welcome .suggestion-question { font-size: 12px; }
  .workspace .topbar { padding-left: 8px; padding-right: 10px; gap: 6px; }
  .workspace .breadcrumb { font-size: 13px; }
}

@media (max-width:760px) and (max-height:500px) {
  .welcome { margin: 0 auto; padding-top: 30px; padding-bottom: 24px; }
  .sidebar .history-list { min-height: 88px; }
  .notice-header { padding-top: 12px; padding-bottom: 12px; }
  .notice-footer { padding-top: 10px; padding-bottom: 12px; }
}
